Example: Multi-compiler OS/2 Makefile

This is the OS/2 makefile for UnZip 5.12; it supports six different compilers, two operating systems, two make utilities (nmake and dmake), and various flavors of executables (statically linked, dynamically linked and debug, for example). Kai Uwe Rommel wrote most of it; he has (or had) access to all of the supported compilers.

The makefile's one stumbling block is how to refer to files in subdirectories. emx+gcc requires regular slashes (Unix-style); Watcom C requires backslashes (DOS-style). This can probably be fixed with another macro, but we haven't tried that yet.


Recursive makefile.os2:

# Makefile for UnZip, UnZipSFX and fUnZip                    1 November 1994
#
# - for Microsoft C, version 6.00 or higher, for use under OS/2 1.x (16-bit)
# - for Watcom C/386, version 9.0+, for use under OS/2 1.x or 2.x (16/32-bit)
# - for emx+gcc, version 0.8e or higher, for use under OS/2 2.x (32-bit)
# - for IBM C Set/2 or C++ Set, for use under OS/2 2.x (32-bit)
# - for Borland C++, for use under OS/2 2.x (32-bit)
# - for Metaware High C, for use under OS/2 2.x (32-bit)
#
# cross-compilation:
# - for Microsoft C, version 6.0 or higher, for use under MS-DOS (16-bit)
# - for Watcom C/386, version 9.0+, for use under MS-DOS (16- or 32-bit)
# - for GNU gcc (emx), version 0.8h or higher, for use under MS-DOS (32-bit)

# To use, enter "{d,n}make -f makefile.os2" (this makefile depends on its
# name being "makefile.os2", and it must be in the main unzip directory).

#   [comments deleted...]

default:
	@echo "Enter `$(MAKE) -f makefile.os2 target' with makefile.os2 copied"
	@echo "to the main UnZip directory and where target is one of:"
	@echo "   msc mscdos ibm ibmdyn ibmdebug ibmprof"
	@echo "   metaware borland gcc gccdyn gccdebug gccdos"
	@echo "   watcom watcom16 watcomdos watcom16dos"

# MS C 6.00 for OS/2, 16-bit (should figure out way to split unzip/funzip 
# compiles so former is always large model and latter always small model...)
msc:
	$(MAKE) -f makefile.os2 all \
	CC="cl -nologo -AL -Ocegit -Gs -I. $(FP)" \
	CFLAGS="-G2 -Zp1 -W3 -DOS2 -DMSC $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-Lp -Fe" \
	LDFLAGS2="-link /noe" \
	OUT="-Fo" \
	OBJ=".obj" \
	DEF="os2\unzip16.def"

# MS C 6.00 for OS/2, debug version
mscdebug:
	$(MAKE) -f makefile.os2 all \
	CC="cl -nologo -AL -Zi -Od -I. $(FP)" \
	CFLAGS="-G2 -Zp1 -W3 -DOS2 -DMSC" \
	NFLAGS="" \
	LDFLAGS="-Lp -Fe" \
	LDFLAGS2="-link /noe" \
	OUT="-Fo" \
	OBJ=".obj" \
	DEF="os2\unzip16.def"

# cross-compilation for MS-DOS with MS C 6.00 (same comment as above, formerly;
# now unzip is small model again, with [almost] all strings in far memory)
mscdos:
	$(MAKE) -f makefile.os2 all \
	CC="cl -nologo -AS -Oaict -Gs -I. $(FP)" \
	CFLAGS="-Zp1 -W3 $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-F 0C00 -Lr -Fe" \
	LDFLAGS2="-link /noe /exe" \
	OUT="-Fo" \
	OBJ=".obj" \
	OBJU2="msdos.obj" \
	OBJX2="msdos_.obj"

# IBM C Set/2, statically linked runtime
ibm:
	$(MAKE) -f makefile.os2 all \
	CC="icc -Q -O -Gs -I." \
	CFLAGS="-Sm -Sp1 -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="-O-" \
	LDFLAGS="-Fe" \
	LDFLAGS2="" \
	OUT="-Fo" \
	OBJ=".obj" \
	DEF="os2\unzip.def"

# IBM C Set/2, dynamically linked runtime
ibmdyn:
	$(MAKE) -f makefile.os2 all \
	CC="icc -Q -O -Gs -Gd -I." \
	CFLAGS="-Sm -Sp1 -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="-O-" \
	LDFLAGS="-Fe" \
	LDFLAGS2="" \
	OUT="-Fo" \
	OBJ=".obj" \
	DEF="os2\unzip.def"

# IBM C Set/2, debug version
ibmdebug:
	$(MAKE) -f makefile.os2 all \
	CC="icc -Q -Ti -I." \
	CFLAGS="-Sm -Sp1 -D__DEBUG_ALLOC__ -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="-O-" \
	LDFLAGS="-Fe" \
	LDFLAGS2="" \
	OUT="-Fo" \
	OBJ=".obj" \
	DEF="os2\unzip.def"

# IBM C Set/2, profiling version for PROFIT
ibmprof:
	$(MAKE) -f makefile.os2 all \
	CC="icc -Q -O -Gs -Gh -Ti -I." \
	CFLAGS="-Sm -Sp1 -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="-O-" \
	LDFLAGS="-Fe" \
	LDFLAGS2="profit.obj" \
	OUT="-Fo" \
	OBJ=".obj" \
	DEF="os2\unzip.def"

# Watcom C/386 9.0 or higher
watcom:
	$(MAKE) -f makefile.os2 all \
	CC="wcl386 -zq -Ox -s -I." \
	CFLAGS="-Zp1 -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-k0x40000 -x -l=os2v2 -Fe=" \
	LDFLAGS2="" \
	OUT="-Fo" \
	OBJ=".obj" \
	DEF=""

# Watcom C/286 9.0 or higher
watcom16:
	$(MAKE) -f makefile.os2 all \
	CC="wcl -zq -ml -Ox -s -I." \
	CFLAGS="-Zp1 -DOS2" \
	NFLAGS="" \
	LDFLAGS="-k0x2000 -x -l=os2 -Fe=" \
	LDFLAGS2="" \
	OUT="-Fo" \
	OBJ=".obj"

# Watcom C/386 9.0 or higher, crosscompilation for DOS
watcomdos:
	$(MAKE) -f makefile.os2 all \
	CC="wcl386 -zq -Ox -s -I." \
	CFLAGS="-Zp1 -DMSDOS" \
	NFLAGS="" \
	LDFLAGS="-k0x40000 -x -l=dos4g -Fe=" \
	LDFLAGS2="" \
	OUT="-Fo" \
	OBJ=".obj" \
	OBJU2="msdos.obj" \
	OBJX2="msdos_.obj"

# Watcom C/286 9.0 or higher, crosscompilation for DOS
watcom16dos:
	$(MAKE) -f makefile.os2 all \
	CC="wcl -zq -mm -Ox -s -I." \
	CFLAGS="-Zp1 -DMSDOS" \
	NFLAGS="" \
	LDFLAGS="-k0xC00 -x -l=dos -Fe=" \
	LDFLAGS2="" \
	OUT="-Fo" \
	OBJ=".obj" \
	OBJU2="msdos.obj" \
	OBJX2="msdos_.obj"

# MetaWare High C/C++ 3.2
metaware:
	$(MAKE) -f makefile.os2 all \
	CC="hc -O2 -I." \
	CFLAGS="-D__32BIT__ -DOS2" \
	NFLAGS="" \
	LDFLAGS="-o " \
	LDFLAGS2="" \
	OUT="-o ./" \
	OBJ=".obj" \
	DEF="-Hdef=os2\unzip.def"

# Borland C++
borland:
	$(MAKE) -f makefile.os2 all \
	CC="bcc -O -I." \
	CFLAGS="-w- -D__cdecl -D__32BIT__ -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-e" \
	LDFLAGS2="" \
	OUT="-o" \
	OBJ=".obj" \
	DEF="-sDos2\unzip.def"

# emx 0.8f and later, gcc, OMF format, statically linked C runtime and emx
gcc:
	$(MAKE) -f makefile.os2 all \
	CC="gcc -Zomf -Zsys -O -I." \
	CFLAGS="-Wall -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-o ./" \
	LDFLAGS2="-s -los2" \
	OUT="-o" \
	OBJ=".obj" \
	DEF="os2/unzip.def"

# emx 0.8g and later, gcc, OMF format, dynamically linked C runtime and emx
# (for 0.8f or earlier, change -Zmtd to -Zmt)
gccdyn:
	$(MAKE) -f makefile.os2 all \
	CC="gcc -Zomf -Zmtd -O -I." \
	CFLAGS="-Wall -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-o ./" \
	LDFLAGS2="-s -los2" \
	OUT="-o" \
	OBJ=".obj" \
	DEF="os2/unzip.def"

# emx, gcc, a.out format, with debug info for gdb
gccdebug:
	$(MAKE) -f makefile.os2 all \
	CC="gcc -g -I." \
	CFLAGS="-Wall -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-o ./" \
	LDFLAGS2="-los2" \
	OUT="-o" \
	OBJ=".o"

# emx, gcc, a.out format, for MS-DOS
gccdos:
	$(MAKE) -f makefile.os2 all \
	CC="gcc -O -I." \
	CFLAGS="-Wall -DMSDOS $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-o ./" \
	LDFLAGS2="-s" \
	OUT="-o" \
	OBJ=".o" \
	OBJU2="msdos.o" \
	OBJX2="msdos_.o"

# variables
OBJU  = unzip$(OBJ) crypt$(OBJ) envargs$(OBJ) explode$(OBJ) \
	extract$(OBJ) file_io$(OBJ) inflate$(OBJ) match$(OBJ) \
	process$(OBJ) unreduce$(OBJ) unshrink$(OBJ) zipinfo$(OBJ)
OBJU2 = os2$(OBJ)
OBJX  = unzipsfx$(OBJ) crypt$(OBJ) extract_$(OBJ) file_io$(OBJ) \
	inflate$(OBJ) match$(OBJ) process_$(OBJ)
OBJX2 = os2_$(OBJ)
OBJF  = funzip$(OBJ) crypt_$(OBJ) inflate_$(OBJ)

.SUFFIXES:	.c $(OBJ)

.c$(OBJ):
	$(CC) -c $(CFLAGS) $<

all:	unzip.exe funzip.exe unzipsfx.exe
#all:	unzipsfx.exe

unzip.exe: $(OBJU) $(OBJU2)
	$(CC) $(LDFLAGS)$@ $(DEF) $(OBJU) $(OBJU2) $(LDFLAGS2)

funzip.exe: $(OBJF)
	$(CC) $(LDFLAGS)$@ $(DEF) $(OBJF) $(LDFLAGS2)

unzipsfx.exe:	$(OBJX) $(OBJX2)
	$(CC) $(LDFLAGS)$@ $(DEF) $(OBJX) $(OBJX2) $(LDFLAGS2)


envargs$(OBJ):	envargs.c unzip.h
explode$(OBJ):	explode.c unzip.h
extract$(OBJ):	extract.c unzip.h crypt.h
file_io$(OBJ):	file_io.c unzip.h crypt.h tables.h
funzip$(OBJ):	funzip.c unzip.h crypt.h tables.h
inflate$(OBJ):	inflate.c unzip.h
match$(OBJ):	match.c unzip.h
process$(OBJ):	process.c unzip.h
unreduce$(OBJ):	unreduce.c unzip.h
unshrink$(OBJ):	unshrink.c unzip.h
unzip$(OBJ):	unzip.c unzip.h crypt.h version.h
zipinfo$(OBJ):	zipinfo.c unzip.h

msdos$(OBJ):	msdos/msdos.c unzip.h version.h		# MS-DOS only
	$(CC) -c $(CFLAGS) msdos/msdos.c

msdos_$(OBJ):	msdos/msdos.c unzip.h			# MS-DOS unzipsfx only
	$(CC) -c $(CFLAGS) -DSFX $(OUT)$@ msdos/msdos.c

os2$(OBJ):	os2/os2.c unzip.h version.h		# OS/2 only
	$(CC) -c $(CFLAGS) os2/os2.c

os2_$(OBJ):	os2/os2.c unzip.h			# OS/2 unzipsfx only
	$(CC) -c $(CFLAGS) -DSFX $(OUT)$@ os2/os2.c

# NFLAGS are solely used as work-around for optimization bug in IBM C++ Set
crypt$(OBJ):	crypt.c unzip.h crypt.h zip.h
	$(CC) -c $(CFLAGS) $(NFLAGS) crypt.c

crypt_$(OBJ):	crypt.c unzip.h zip.h crypt.h		# funzip only
	$(CC) -c $(CFLAGS) $(NFLAGS) -DFUNZIP $(OUT)$@ crypt.c

extract_$(OBJ):	extract.c unzip.h crypt.h		# unzipsfx only
	$(CC) -c $(CFLAGS) -DSFX $(OUT)$@ extract.c

inflate_$(OBJ):	inflate.c inflate.h unzip.h crypt.h	# funzip only
	$(CC) -c $(CFLAGS) -DFUNZIP $(OUT)$@ inflate.c

process_$(OBJ):	process.c unzip.h			# unzipsfx only
	$(CC) -c $(CFLAGS) -DSFX $(OUT)$@ process.c

unzipsfx$(OBJ):	unzip.c unzip.h crypt.h version.h	# unzipsfx only
	$(CC) -c $(CFLAGS) -DSFX $(OUT)$@ unzip.c


Click here for predefined-macro usage in UnZip's OS/2 version() routine.
Click here to return to the February 1995 Tip o' the Month.
Last modified 12 August 2000 by newt@pobox.com , you betcha.