From d6ad12a3dc9faceec0278e3be82f9a02c40e82c2 Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Tue, 19 May 2009 21:39:29 +0000 Subject: [PATCH] Add Linux cross-compile capability, using Open Watcom: * Flip \ to / where possible. * Introduce $(DIRSEP) (/ or \) for use inside commands in makefiles where / won't work in DOS. * Override various settings for Linux in owlinux.mak. * Add quotes in exeflat.c to avoid shell expansion of $$$$$. * Let "make all", "make clean", and "make clobber" do the job. git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1387 6ac86273-5f31-0410-b378-82cca8765d1b --- config.m | 65 +++++++++++++++++++++++++++++++++++++++++++++ docs/build.txt | 29 +++++++++++++++++--- drivers/makefile | 10 +++---- kernel/makefile | 20 +++++++------- kernel/segs.inc | 5 ++++ makefile | 56 +++++++++++++++++++++++++++++++++++--- mkfiles/generic.mak | 13 +++++++-- mkfiles/owlinux.mak | 19 +++++++++++++ mkfiles/watcom.mak | 2 +- sys/makefile | 34 ++++++++++++------------ utils/exeflat.c | 3 +++ utils/makefile | 6 ++--- 12 files changed, 216 insertions(+), 46 deletions(-) create mode 100644 config.m create mode 100644 mkfiles/owlinux.mak diff --git a/config.m b/config.m new file mode 100644 index 0000000..994a8ec --- /dev/null +++ b/config.m @@ -0,0 +1,65 @@ +# +# Linux cross compilation only! +# config file that is included in the main makefile for configuration +# + +#**************************************************************** +# NOTICE! If you edit you must rename this file to config.mak!* +#**************************************************************** + +#********************************************************************** +#- define NASM executable +#********************************************************************** +XNASM=nasm + +#********************************************************************** +#- where is the BASE dir of your compiler(s) ?? +#********************************************************************** + +# if WATCOM maybe you need to set your WATCOM environment variables +# and path +ifndef WATCOM + WATCOM=$(HOME)/watcom + PATH:=$(WATCOM)/binl:$(PATH) +endif + +#********************************************************************** +# where is UPX and which options to use? +#********************************************************************** +XUPX=upx --8086 --best + +# or use +#unexport XUPX +# without the # if you don't want to use it + +#********************************************************************** +# (optionally) which linker to use: +# (otherwise will be determined automatically) + +# WATCOM Link +#XLINK=wlink + +#********************************************************************* +# optionally define your MAKE type here, if not then +# it will be automatically determined, pick one of them +# use MS nmake if you want to compile with MSCL +#********************************************************************* + +# Watcom MAKE in MS mode +#MAKE=wmake -ms -h + +#********************************************************************* +# select your default target: required CPU and what FAT system to support +#********************************************************************* + +XCPU=86 +# XCPU=186 +# XCPU=386 + +XFAT=16 +# XFAT=32 + +# Give extra compiler DEFINE flags here +# such as -DDEBUG : extra DEBUG output +# -DDOSEMU : printf output goes to dosemu log +# set ALLCFLAGS=-DDEBUG diff --git a/docs/build.txt b/docs/build.txt index c2f87de..58a7979 100644 --- a/docs/build.txt +++ b/docs/build.txt @@ -1,4 +1,7 @@ -To build the operating system, a batch file (BUILD.BAT) is included +Building on DOS or Windows: +=========================== + +To build the operating system a batch file (BUILD.BAT) is included to make life easier. This file is in the FDKERNEL directory of the distribution. In addition, there is a corresponding batch file (CLEAN.BAT) to clean up the source directories. @@ -12,8 +15,28 @@ kernel come out, you can extract them over your previous source, and not have to worry about resetting up your configuration because your CONFIG.BAT file will not get replaced! -The recommended compiler and assembler at the time of writing (2004/01/31) -are OpenWatcom 1.2 and NASM 0.98.38. +Building on Linux: +================== + +To cross compile on Linux you need to install Open Watcom 1.8 from +www.openwatcom.org and NASM which is probably included in your +distribution. You can then copy config.m to config.mak and adjust +for the same reasons mentioned above. + +Use the following commands: +- to build: +make all +- to build, overriding a config.mak setting, e.g.: +make all XCPU=386 +- to clean: +make clean +- to clobber (delete everything that was generated): +make clobber + +Notes: +====== +The recommended compiler and assembler at the time of writing (2009/05/19) +are OpenWatcom 1.8 and NASM 2.05.01. You may need to download the latest version of NASM and a C compiler Be sure to edit the CONFIG.BAT file to reflect where you put the tools. diff --git a/drivers/makefile b/drivers/makefile index 94bba96..8a8965e 100644 --- a/drivers/makefile +++ b/drivers/makefile @@ -24,7 +24,7 @@ OBJS = floppy.obj rdpcclk.obj wrpcclk.obj wratclk.obj -LIBOBJS= +floppy +rdpcclk +wrpcclk +wratclk +LIBOBJS= +floppy.obj +rdpcclk.obj +wrpcclk.obj +wratclk.obj @@ -32,13 +32,13 @@ LIBOBJS= +floppy +rdpcclk +wrpcclk +wratclk # ----------------- all: production -production: ..\lib\device.lib +production: ../lib/device.lib -..\lib\device.lib: device.lib - copy device.lib ..\lib +../lib/device.lib: device.lib + $(CP) device.lib ..$(DIRSEP)lib clobber: clean - -$(RM) device.lib status.me ..\lib\device.lib + -$(RM) device.lib status.me ..$(DIRSEP)lib$(DIRSEP)device.lib clean: -$(RM) *.obj *.bak *.crf *.xrf *.map *.lst *.cod *.err diff --git a/kernel/makefile b/kernel/makefile index dd49fed..58a6bdf 100644 --- a/kernel/makefile +++ b/kernel/makefile @@ -6,7 +6,7 @@ !include "../mkfiles/generic.mak" -LIBS=..\lib\device.lib ..\lib\libm.lib +LIBS=..$(DIRSEP)lib$(DIRSEP)device.lib ..$(DIRSEP)lib$(DIRSEP)libm.lib HDR=../hdr/ # *List Macros* @@ -29,15 +29,15 @@ OBJS=$(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) $(OBJS5) $(OBJS6) $(OBJS7) # *Explicit Rules* -production: ..\bin\$(TARGET).sys +production: ../bin/$(TARGET).sys -..\bin\$(TARGET).sys: kernel.sys - copy kernel.sys ..\bin - copy kernel.sys ..\bin\$(TARGET).sys - copy kernel.map ..\bin\$(TARGET).map +../bin/$(TARGET).sys: kernel.sys + $(CP) kernel.sys ..$(DIRSEP)bin + $(CP) kernel.sys ..$(DIRSEP)bin$(DIRSEP)$(TARGET).sys + $(CP) kernel.map ..$(DIRSEP)bin$(DIRSEP)$(TARGET).map -kernel.sys: kernel.exe ..\utils\exeflat.exe - ..\utils\exeflat kernel.exe kernel.sys 0x60 -S0x10 -S0x74 $(UPXOPT) $(XUPX) +kernel.sys: kernel.exe ../utils/exeflat.exe + ..$(DIRSEP)utils$(DIRSEP)exeflat.exe kernel.exe kernel.sys 0x60 -S0x10 -S0x74 $(UPXOPT) $(XUPX) kernel.exe: $(TARGET).lnk $(OBJS) $(LIBS) $(LINK) @$(TARGET).lnk; @@ -51,9 +51,7 @@ clean: # XXX: This is a very ugly way of linking the kernel, forced upon us by the # inability of Turbo `make' 2.0 to perform command line redirection. -- ror4 -ECHOTO=..\utils\echoto - -$(TARGET).lnk: turboc.cfg makefile ..\mkfiles\generic.mak ..\mkfiles\$(COMPILER).mak +$(TARGET).lnk: turboc.cfg makefile ../mkfiles/generic.mak ../mkfiles/$(COMPILER).mak -$(RM) *.lnk $(ECHOTO) $(TARGET).lnk $(OBJS1)+ $(ECHOTO) $(TARGET).lnk $(OBJS2)+ diff --git a/kernel/segs.inc b/kernel/segs.inc index a08ce71..e0a31c3 100644 --- a/kernel/segs.inc +++ b/kernel/segs.inc @@ -38,6 +38,11 @@ CPU XCPU %endif %endif +; for OW on Linux: +%ifdef owlinux +%define WATCOM +%endif + group PGROUP PSP group LGROUP _IRQTEXT _LOWTEXT _IO_TEXT _IO_FIXED_DATA _TEXT group DGROUP _FIXED_DATA _BSS _DATA _DATAEND CONST CONST2 DCONST DYN_DATA diff --git a/makefile b/makefile index 087b4b6..26fda16 100644 --- a/makefile +++ b/makefile @@ -1,9 +1,12 @@ -# IF NOTHING COMPILES, CHECK IF YOUR CVS CHECKOUT USES CORRECT DOS LINEBREAKS +# What you WANT on DOS is: +# EDIT CONFIG.B, COPY CONFIG.B to CONFIG.BAT, RUN BUILD.BAT +# On Linux, use config.mak, and "make all", "make clean", or "make clobber" -# What you WANT is: EDIT CONFIG.B, COPY CONFIG.B to CONFIG.BAT, RUN BUILD.BAT -# THIS file is provided only for people who have a habit of typing MAKE ALL... +default: + @echo On DOS, please type build, clean, or clobber. + @echo On Linux, please type make all, make clean, or make clobber. -all: +build: build bin\kwc8616.sys: @@ -54,3 +57,48 @@ zipfat32: bin\kwc8632.sys zip: zip_src zipfat16 zipfat32 +#Linux part +#defaults: override using config.mak +export +COMPILER=owlinux + +XCPU=86 +XFAT=32 +ifndef WATCOM + WATCOM=$(HOME)/watcom + PATH:=$(WATCOM)/binl:$(PATH) +endif +XUPX=upx --8086 --best +XNASM=nasm +MAKE=wmake -ms -h +XLINK=wlink +#ALLCFLAGS=-DDEBUG + +-include config.mak +ifdef XUPX + UPXOPT=-U +endif + +all: + cd utils && $(MAKE) production + cd lib && touch libm.lib + cd drivers && $(MAKE) production + cd boot && $(MAKE) production + cd sys && $(MAKE) production + cd kernel && $(MAKE) production + +clean: + cd utils && $(MAKE) clean + cd lib && $(MAKE) clean + cd drivers && $(MAKE) clean + cd boot && $(MAKE) clean + cd sys && $(MAKE) clean + cd kernel && $(MAKE) clean + +clobber: + cd utils && $(MAKE) clobber + cd lib && $(MAKE) clobber + cd drivers && $(MAKE) clobber + cd boot && $(MAKE) clobber + cd sys && $(MAKE) clobber + cd kernel && $(MAKE) clobber diff --git a/mkfiles/generic.mak b/mkfiles/generic.mak index 5e97ea2..997f4e2 100644 --- a/mkfiles/generic.mak +++ b/mkfiles/generic.mak @@ -25,11 +25,20 @@ NASMFLAGS = $(NASMFLAGS) -i../hdr/ -DXCPU=$(XCPU) LINK=$(XLINK) INITPATCH=@rem +DIRSEP=\ #a backslash +RM=..\utils\rmfiles +CP=copy +ECHOTO=..\utils\echoto +CLDEF=0 -!include "..\mkfiles\$(COMPILER).mak" +!include "../mkfiles/$(COMPILER).mak" + +!if $(CLDEF) == 0 +CLT=$(CL) $(CFLAGST) $(TINY) -I$(INCLUDEPATH) +CLC=$(CL) $(CFLAGSC) -I$(INCLUDEPATH) +!endif TARGET=$(TARGET)$(XCPU)$(XFAT) -RM=..\utils\rmfiles .asm.obj : $(NASM) -D$(COMPILER) $(NASMFLAGS) -f obj $*.asm diff --git a/mkfiles/owlinux.mak b/mkfiles/owlinux.mak new file mode 100644 index 0000000..8669f0a --- /dev/null +++ b/mkfiles/owlinux.mak @@ -0,0 +1,19 @@ +# +# WATCOM.MAK - kernel compiler options for Open Watcom on Linux (cross-compile) +# + +# Get definitions from watcom.mak, then override +include "../mkfiles/watcom.mak" + +DIRSEP=/ +INCLUDEPATH=$(COMPILERPATH)/h +RM=rm -f +CP=cp +ECHOTO=$# +INITPATCH=@echo > /dev/null +CLDEF=1 +CLT=gcc -DDOSC_TIME_H -I../hdr -o $@ +CLC=$(CLT) +CFLAGST=-fo=.obj $(CFLAGST) +ALLCFLAGS=-fo=.obj $(ALLCFLAGS) +XLINK=$(XLINK) debug all op symfile format dos option map op statics F { $(OBJS) ../lib/device.lib } N kernel.exe $# diff --git a/mkfiles/watcom.mak b/mkfiles/watcom.mak index e1754ef..e461688 100644 --- a/mkfiles/watcom.mak +++ b/mkfiles/watcom.mak @@ -61,7 +61,7 @@ MATH_INSERT=+i4m # -3 optimization for 386 - given in CONFIG.MAK, not here # -ALLCFLAGS=-I..\hdr $(TARGETOPT) $(ALLCFLAGS)-zq-os-s-e5-j-zl-zp1-wx-we-zgf-zff-r +ALLCFLAGS=-I..$(DIRSEP)hdr $(TARGETOPT) $(ALLCFLAGS)-zq-os-s-e5-j-zl-zp1-wx-we-zgf-zff-r INITCFLAGS=$(ALLCFLAGS)-ntINIT_TEXT-gTGROUP-ndI CFLAGS=$(ALLCFLAGS)-ntHMA_TEXT diff --git a/sys/makefile b/sys/makefile index ed4aad9..498b411 100644 --- a/sys/makefile +++ b/sys/makefile @@ -6,7 +6,7 @@ !include "../mkfiles/generic.mak" -CFLAGS = -I$(INCLUDEPATH) -I..\hdr -DFORSYS -DWITHFAT32 $(CFLAGST) +CFLAGS = -I$(INCLUDEPATH) -I..$(DIRSEP)hdr -DFORSYS -DWITHFAT32 $(CFLAGST) NASMFLAGS = -DSYS=1 # *List Macros* @@ -18,30 +18,30 @@ SYS_EXE_dependencies = \ talloc.obj # *Explicit Rules* -production: bin2c.com ..\bin\sys.com +production: bin2c.com ../bin/sys.com bin2c.com: bin2c.c - $(CL) $(CFLAGS) $(TINY) bin2c.c + $(CLT) bin2c.c -..\bin\sys.com: sys.com - copy sys.com ..\bin +../bin/sys.com: sys.com + $(CP) sys.com ..$(DIRSEP)bin -fat12com.h: ..\boot\fat12com.bin bin2c.com - .\bin2c ..\boot\fat12com.bin fat12com.h fat12com +fat12com.h: ../boot/fat12com.bin bin2c.com + .$(DIRSEP)bin2c.com ../boot/fat12com.bin fat12com.h fat12com -fat16com.h: ..\boot\fat16com.bin bin2c.com - .\bin2c ..\boot\fat16com.bin fat16com.h fat16com +fat16com.h: ../boot/fat16com.bin bin2c.com + .$(DIRSEP)bin2c.com ../boot/fat16com.bin fat16com.h fat16com -fat32chs.h: ..\boot\fat32chs.bin bin2c.com - .\bin2c ..\boot\fat32chs.bin fat32chs.h fat32chs +fat32chs.h: ../boot/fat32chs.bin bin2c.com + .$(DIRSEP)bin2c.com ../boot/fat32chs.bin fat32chs.h fat32chs -fat32lba.h: ..\boot\fat32lba.bin bin2c.com - .\bin2c ..\boot\fat32lba.bin fat32lba.h fat32lba +fat32lba.h: ../boot/fat32lba.bin bin2c.com + .$(DIRSEP)bin2c.com ../boot/fat32lba.bin fat32lba.h fat32lba -prf.obj: ..\kernel\prf.c - $(CC) $(CFLAGS) ..\kernel\prf.c +prf.obj: ../kernel/prf.c + $(CC) $(CFLAGS) ..$(DIRSEP)kernel$(DIRSEP)prf.c -fdkrncfg.obj: fdkrncfg.c ..\hdr\kconfig.h +fdkrncfg.obj: fdkrncfg.c ../hdr/kconfig.h talloc.obj: talloc.c @@ -55,6 +55,6 @@ clean: -$(RM) *.obj *.bak *.crf *.xrf *.map *.lst *.las *.cod *.err status.me # *Individual File Dependencies* -sys.obj: sys.c ..\hdr\portab.h ..\hdr\device.h fat12com.h fat16com.h fat32chs.h fat32lba.h +sys.obj: sys.c ../hdr/portab.h ../hdr/device.h fat12com.h fat16com.h fat32chs.h fat32lba.h $(CC) $(CFLAGS) $*.c diff --git a/utils/exeflat.c b/utils/exeflat.c index e43aeee..9862f36 100644 --- a/utils/exeflat.c +++ b/utils/exeflat.c @@ -416,7 +416,10 @@ int main(int argc, char **argv) len += n; } cmdbuf[len++] = ' '; + cmdbuf[len++] = '\''; memcpy(cmdbuf + len, tmpexe, len2); + cmdbuf[len + len2 - 1] = '\''; + cmdbuf[len + len2] = '\0'; printf("%s\n", cmdbuf); if (system(cmdbuf)) { diff --git a/utils/makefile b/utils/makefile index 7be6ec7..3709e7c 100644 --- a/utils/makefile +++ b/utils/makefile @@ -1,14 +1,14 @@ !include "../mkfiles/generic.mak" -CFLAGS = -I$(INCLUDEPATH) -I..\hdr +CFLAGS = -I..$(DIRSEP)hdr production: patchobj.com exeflat.exe patchobj.com: patchobj.c - $(CL) $(CFLAGST) $(TINY) $(CFLAGS) patchobj.c + $(CLT) $(CFLAGS) patchobj.c exeflat.exe: exeflat.c ../hdr/exe.h - $(CL) $(CFLAGSC) $(CFLAGS) exeflat.c + $(CLC) $(CFLAGS) exeflat.c clobber: clean