1# Makefile for Info-ZIP's unzip, zipinfo, funzip and unzipsfx
2# using djgpp v1.12m4.  Tested with unzip550 by Christian Spieler
3#
4# This Makefile is specifically tailored for GNU Make and GNU C and
5# may not work with a generic UNIX compatible Make utility.
6# Features use:
7# - pattern rules (%.o : %.c, etc.)
8# - GNUMake conditionals and functions  (ifeq, $(patsubst,,),...)
9#
10# To allow mixed use of real mode (16bit) vs. GO32 (32bit protected mode)
11# GNUMake utility and GCC driver, precautions have been taken to
12# limit command lines to the DOS 126 bytes limit.
13# In case you have an environment that supports long command lines
14# at all "interface" levels (e.g.: DJGPPv1 Gmake 3.71 and GO32 gcc.exe),
15# you may define the Makefile macro LONGARGS to take advantage of the
16# "long command lines" capability.
17# I have archived the fastest compilation (with LONGARGS support!) by
18# using both a real mode gnumake (private port) and the real mode
19# gcc.exe driver.
20#
21# The Makefile allows the optional creation of standalone exectutables.
22# This has the advantage that unzip.exe does not rely on any other file,
23# but results in much larger executables.
24#
25
26# Separators colon and <sp> are used in U**X, semi-colon and <sp> in DOS.
27VPATH=. msdos
28
29ifdef NOASM
30USE_ASMCRC=
31else
32USE_ASMCRC=1
33endif
34
35# UnZip flags
36LOC=-DDOS $(ASMFLG) $(LOCAL_UNZIP)
37CC=gcc
38LD=$(CC)
39CPPFLAGS=-I. $(LOC)
40ASFLAGS=$(CPPFLAGS)
41CFLAGS=-Wall -O2 -m486 $(CPPFLAGS)
42FUN_FLAGS=$(CFLAGS) -DFUNZIP
43SFX_FLAGS=$(CFLAGS) -DSFX
44LDFLAGS=-s -v
45LIBS=-lpc
46
47STRIP=strip
48
49# Define the STANDALONE macro to create executables which can be
50# used without any external extender file.
51# >>> NOTE: Either copy the go32 extender into your build directory, or
52# >>>       edit the STUBIFY macro and add the correct path to "go32.exe".
53ifdef STANDALONE
54STUBIFY=coff2exe -s go32.exe
55else
56STUBIFY=coff2exe
57endif
58
59# general-purpose stuff
60# If cp.exe is not found change to CP=copy /Y    .
61CP = cp -f
62# If install.exe is not found change to INSTALL=$(CP)   .
63INSTALL=install
64# The default value of RM is "rm -f"  .  If rm.exe is not found, uncomment
65# the following:
66RM=del
67E = .exe
68O = .o
69M=msdos
70
71# defaults for crc32 stuff and system dependent headers
72ifdef USE_ASMCRC
73ASMFLG = -DASM_CRC
74CRCA_O = crc_gcc$O
75else
76ASMFLG =
77CRCA_O =
78endif
79
80# object files
81OBJS1 = unzip$O crc32$O $(CRCA_O) crypt$O envargs$O explode$O
82OBJS2 = extract$O fileio$O globals$O inflate$O list$O match$O
83OBJS3 = process$O ttyio$O ubz2err$O unreduce$O unshrink$O zipinfo$O
84OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $M$O
85
86OBJX1 = unzipsfx$O crc32_$O $(CRCA_O) crypt_$O extract_$O fileio_$O
87OBJX2 = globals_$O inflate_$O match_$O process_$O ttyio_$O ubz2err_$O $M_$O
88OBJX = $(OBJX1) $(OBJX2)
89
90OBJF = funzip$O crc32-$O $(CRCA_O) crypt-$O globals-$O inflate-$O ttyio-$O
91
92OBJECTS_ALL = $(sort $(OBJS) $(OBJX) $(OBJF) crc_gcc$O)
93
94# Common header files included by all C sources:
95UNZIP_H = unzip.h unzpriv.h globals.h msdos/doscfg.h
96
97# executable files
98UNZIPS = unzip$E zipinfo$E funzip$E unzipsfx$E
99
100# pattern rules to compile the sources:
101%$O : %.c
102	$(CC) $(CFLAGS) -c $< -o $@
103
104%-$O: %.c
105	$(CC) $(FUN_FLAGS) -c $< -o $@
106
107%_$O: %.c
108	$(CC) $(SFX_FLAGS) -c $< -o $@
109
110%sfx$O: %.c
111	$(CC) $(SFX_FLAGS) -c $< -o $@
112
113all: unzips
114
115unzips:	unzip$E zipinfo$E funzip$E unzipsfx$E
116
117unzip$E: $(OBJS)
118ifdef LONGARGS
119	$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -o unzip
120else
121	echo $(OBJS1) > unzip.rsp
122	echo $(OBJS2) >> unzip.rsp
123	echo $(OBJS3) $M$O >> unzip.rsp
124	echo $(LIBS) >> unzip.rsp
125	$(LD) $(LDFLAGS) -o unzip @unzip.rsp
126	$(RM) unzip.rsp
127endif
128	$(STRIP) unzip
129	$(STUBIFY) unzip
130	stubedit $@ globbing=no
131	$(RM) unzip
132
133zipinfo$E: unzip$E
134	coff2exe -g zipinfo
135	stubedit $@ runfile=unzip globbing=no
136
137funzip$E: $(OBJF)
138	$(LD) $(LDFLAGS) $(OBJF) -o funzip
139	$(STRIP) funzip
140	$(STUBIFY) funzip
141	$(RM) funzip
142
143unzipsfx$E: $(OBJX)
144ifdef LONGARGS
145	$(LD) $(LDFLAGS) $(OBJX) $(LIBS) -o unzipsfx
146else
147	echo $(OBJX1) > unzipsfx.rsp
148	echo $(OBJX2) >> unzipsfx.rsp
149	echo $(LIBS) >> unzipsfx.rsp
150	$(LD) $(LDFLAGS) -o unzipsfx @unzipsfx.rsp
151	$(RM) unzipsfx.rsp
152endif
153	$(STRIP) unzipsfx
154	$(STUBIFY) unzipsfx
155	stubedit $@ globbing=no
156	$(RM) unzipsfx
157
158# explicit compilation instructions:
159crc_gcc$O: crc_i386.S		# 32bit, GNU AS
160	$(CC) $(ASFLAGS) -x assembler-with-cpp -c -o $@ crc_i386.S
161
162# BIN_PATH may be defined in djgpp.env [make] or defined above.
163install:
164	$(INSTALL) $(UNZIPS) $(BIN_PATH)
165
166uninstall:
167	cd $(BIN_PATH); $(RM) $(UNZIPS)
168
169clean:
170ifeq ($(firstword $(RM)), del)
171	$(RM) *$O
172	$(RM) *.zip
173else
174	$(RM) $(OBJECTS_ALL) *.zip
175endif
176
177# Source dependencies:
178crc_gcc$O:      crc_i386.S
179crc32$O:        crc32.c $(UNZIP_H) zip.h crc32.h
180crc32-$O:       crc32.c $(UNZIP_H) zip.h crc32.h
181crc32_$O:       crc32.c $(UNZIP_H) zip.h crc32.h
182crypt$O:        crypt.c $(UNZIP_H) zip.h crypt.h crc32.h ttyio.h
183crypt-$O:       crypt.c $(UNZIP_H) zip.h crypt.h crc32.h ttyio.h
184crypt_$O:       crypt.c $(UNZIP_H) zip.h crypt.h crc32.h ttyio.h
185envargs$O:      envargs.c $(UNZIP_H)
186explode$O:      explode.c $(UNZIP_H)
187extract$O:      extract.c $(UNZIP_H) crc32.h crypt.h
188extract_$O:     extract.c $(UNZIP_H) crc32.h crypt.h
189fileio$O:       fileio.c $(UNZIP_H) crc32.h crypt.h ttyio.h ebcdic.h
190fileio_$O:      fileio.c $(UNZIP_H) crc32.h crypt.h ttyio.h ebcdic.h
191funzip$O:       funzip.c $(UNZIP_H) crc32.h crypt.h ttyio.h
192globals$O:      globals.c $(UNZIP_H)
193globals-$O:     globals.c $(UNZIP_H)
194globals_$O:     globals.c $(UNZIP_H)
195inflate$O:      inflate.c inflate.h $(UNZIP_H)
196inflate-$O:     inflate.c inflate.h $(UNZIP_H) crypt.h
197inflate_$O:     inflate.c inflate.h $(UNZIP_H)
198list$O:         list.c $(UNZIP_H)
199match$O:        match.c $(UNZIP_H)
200match_$O:       match.c $(UNZIP_H)
201msdos$O:        msdos/msdos.c $(UNZIP_H)
202msdos_$O:       msdos/msdos.c $(UNZIP_H)
203process$O:      process.c $(UNZIP_H) crc32.h
204process_$O:     process.c $(UNZIP_H) crc32.h
205ttyio$O:        ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h
206ttyio-$O:       ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h
207ttyio_$O:       ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h
208ubz2err$O:      ubz2err.c $(UNZIP_H)
209ubz2err_$O:     ubz2err.c $(UNZIP_H)
210unreduce$O:     unreduce.c $(UNZIP_H)
211unshrink$O:     unshrink.c $(UNZIP_H)
212unzip$O:        unzip.c $(UNZIP_H) crypt.h unzvers.h consts.h
213unzipsfx$O:     unzip.c $(UNZIP_H) crypt.h unzvers.h consts.h
214zipinfo$O:      zipinfo.c $(UNZIP_H)
215