• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Makefile for zlib
2# Copyright (C) 1995-2017 Jean-loup Gailly, Mark Adler
3# For conditions of distribution and use, see copyright notice in zlib.h
4
5# To compile and test, type:
6#    ./configure; make test
7# Normally configure builds both a static and a shared library.
8# If you want to build just a static library, use: ./configure --static
9
10# To use the asm code, type:
11#    cp contrib/asm?86/match.S ./match.S
12#    make LOC=-DASMV OBJA=match.o
13
14# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
15#    make install
16# To install in $HOME instead of /usr/local, use:
17#    make install prefix=$HOME
18
19CC=cc
20
21CFLAGS=-O
22#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
23#CFLAGS=-g -DZLIB_DEBUG
24#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
25#           -Wstrict-prototypes -Wmissing-prototypes
26
27SFLAGS=-O
28LDFLAGS=
29TEST_LDFLAGS=-L. libz.a
30LDSHARED=$(CC)
31CPP=$(CC) -E
32
33STATICLIB=libz.a
34SHAREDLIB=libz.so
35SHAREDLIBV=libz.so.1.2.11
36SHAREDLIBM=libz.so.1
37LIBS=$(STATICLIB) $(SHAREDLIBV)
38
39AR=ar
40ARFLAGS=rc
41RANLIB=ranlib
42LDCONFIG=ldconfig
43LDSHAREDLIBC=-lc
44TAR=tar
45SHELL=/bin/sh
46EXE=
47
48prefix = /usr/local
49exec_prefix = ${prefix}
50libdir = ${exec_prefix}/lib
51sharedlibdir = ${libdir}
52includedir = ${prefix}/include
53mandir = ${prefix}/share/man
54man3dir = ${mandir}/man3
55pkgconfigdir = ${libdir}/pkgconfig
56SRCDIR=
57ZINC=
58ZINCOUT=-I.
59
60OBJZ = adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o
61OBJG = compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
62OBJC = $(OBJZ) $(OBJG)
63
64PIC_OBJZ = adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo
65PIC_OBJG = compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo
66PIC_OBJC = $(PIC_OBJZ) $(PIC_OBJG)
67
68# to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo
69OBJA =
70PIC_OBJA =
71
72OBJS = $(OBJC) $(OBJA)
73
74PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA)
75
76all: static shared
77
78static: example$(EXE) minigzip$(EXE)
79
80shared: examplesh$(EXE) minigzipsh$(EXE)
81
82all64: example64$(EXE) minigzip64$(EXE)
83
84check: test
85
86test: all teststatic testshared
87
88teststatic: static
89	@TMPST=tmpst_$$; \
90	if echo hello world | ./minigzip | ./minigzip -d && ./example $$TMPST ; then \
91	  echo '		*** zlib test OK ***'; \
92	else \
93	  echo '		*** zlib test FAILED ***'; false; \
94	fi; \
95	rm -f $$TMPST
96
97testshared: shared
98	@LD_LIBRARY_PATH=`pwd`:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
99	LD_LIBRARYN32_PATH=`pwd`:$(LD_LIBRARYN32_PATH) ; export LD_LIBRARYN32_PATH; \
100	DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \
101	SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \
102	TMPSH=tmpsh_$$; \
103	if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh $$TMPSH; then \
104	  echo '		*** zlib shared test OK ***'; \
105	else \
106	  echo '		*** zlib shared test FAILED ***'; false; \
107	fi; \
108	rm -f $$TMPSH
109
110test64: all64
111	@TMP64=tmp64_$$; \
112	if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64 $$TMP64; then \
113	  echo '		*** zlib 64-bit test OK ***'; \
114	else \
115	  echo '		*** zlib 64-bit test FAILED ***'; false; \
116	fi; \
117	rm -f $$TMP64
118
119infcover.o: $(SRCDIR)test/infcover.c $(SRCDIR)zlib.h zconf.h
120	$(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/infcover.c
121
122infcover: infcover.o libz.a
123	$(CC) $(CFLAGS) -o $@ infcover.o libz.a
124
125cover: infcover
126	rm -f *.gcda
127	./infcover
128	gcov inf*.c
129
130libz.a: $(OBJS)
131	$(AR) $(ARFLAGS) $@ $(OBJS)
132	-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
133
134match.o: match.S
135	$(CPP) match.S > _match.s
136	$(CC) -c _match.s
137	mv _match.o match.o
138	rm -f _match.s
139
140match.lo: match.S
141	$(CPP) match.S > _match.s
142	$(CC) -c -fPIC _match.s
143	mv _match.o match.lo
144	rm -f _match.s
145
146example.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h
147	$(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/example.c
148
149minigzip.o: $(SRCDIR)test/minigzip.c $(SRCDIR)zlib.h zconf.h
150	$(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/minigzip.c
151
152example64.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h
153	$(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -o $@ $(SRCDIR)test/example.c
154
155minigzip64.o: $(SRCDIR)test/minigzip.c $(SRCDIR)zlib.h zconf.h
156	$(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -o $@ $(SRCDIR)test/minigzip.c
157
158
159adler32.o: $(SRCDIR)adler32.c
160	$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)adler32.c
161
162crc32.o: $(SRCDIR)crc32.c
163	$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)crc32.c
164
165deflate.o: $(SRCDIR)deflate.c
166	$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)deflate.c
167
168infback.o: $(SRCDIR)infback.c
169	$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)infback.c
170
171inffast.o: $(SRCDIR)inffast.c
172	$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)inffast.c
173
174inflate.o: $(SRCDIR)inflate.c
175	$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)inflate.c
176
177inftrees.o: $(SRCDIR)inftrees.c
178	$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)inftrees.c
179
180trees.o: $(SRCDIR)trees.c
181	$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)trees.c
182
183zutil.o: $(SRCDIR)zutil.c
184	$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)zutil.c
185
186compress.o: $(SRCDIR)compress.c
187	$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)compress.c
188
189uncompr.o: $(SRCDIR)uncompr.c
190	$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)uncompr.c
191
192gzclose.o: $(SRCDIR)gzclose.c
193	$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)gzclose.c
194
195gzlib.o: $(SRCDIR)gzlib.c
196	$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)gzlib.c
197
198gzread.o: $(SRCDIR)gzread.c
199	$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)gzread.c
200
201gzwrite.o: $(SRCDIR)gzwrite.c
202	$(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)gzwrite.c
203
204
205adler32.lo: $(SRCDIR)adler32.c
206	-@mkdir objs 2>/dev/null || test -d objs
207	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/adler32.o $(SRCDIR)adler32.c
208	-@mv objs/adler32.o $@
209
210crc32.lo: $(SRCDIR)crc32.c
211	-@mkdir objs 2>/dev/null || test -d objs
212	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/crc32.o $(SRCDIR)crc32.c
213	-@mv objs/crc32.o $@
214
215deflate.lo: $(SRCDIR)deflate.c
216	-@mkdir objs 2>/dev/null || test -d objs
217	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/deflate.o $(SRCDIR)deflate.c
218	-@mv objs/deflate.o $@
219
220infback.lo: $(SRCDIR)infback.c
221	-@mkdir objs 2>/dev/null || test -d objs
222	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/infback.o $(SRCDIR)infback.c
223	-@mv objs/infback.o $@
224
225inffast.lo: $(SRCDIR)inffast.c
226	-@mkdir objs 2>/dev/null || test -d objs
227	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/inffast.o $(SRCDIR)inffast.c
228	-@mv objs/inffast.o $@
229
230inflate.lo: $(SRCDIR)inflate.c
231	-@mkdir objs 2>/dev/null || test -d objs
232	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/inflate.o $(SRCDIR)inflate.c
233	-@mv objs/inflate.o $@
234
235inftrees.lo: $(SRCDIR)inftrees.c
236	-@mkdir objs 2>/dev/null || test -d objs
237	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/inftrees.o $(SRCDIR)inftrees.c
238	-@mv objs/inftrees.o $@
239
240trees.lo: $(SRCDIR)trees.c
241	-@mkdir objs 2>/dev/null || test -d objs
242	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/trees.o $(SRCDIR)trees.c
243	-@mv objs/trees.o $@
244
245zutil.lo: $(SRCDIR)zutil.c
246	-@mkdir objs 2>/dev/null || test -d objs
247	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/zutil.o $(SRCDIR)zutil.c
248	-@mv objs/zutil.o $@
249
250compress.lo: $(SRCDIR)compress.c
251	-@mkdir objs 2>/dev/null || test -d objs
252	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/compress.o $(SRCDIR)compress.c
253	-@mv objs/compress.o $@
254
255uncompr.lo: $(SRCDIR)uncompr.c
256	-@mkdir objs 2>/dev/null || test -d objs
257	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/uncompr.o $(SRCDIR)uncompr.c
258	-@mv objs/uncompr.o $@
259
260gzclose.lo: $(SRCDIR)gzclose.c
261	-@mkdir objs 2>/dev/null || test -d objs
262	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/gzclose.o $(SRCDIR)gzclose.c
263	-@mv objs/gzclose.o $@
264
265gzlib.lo: $(SRCDIR)gzlib.c
266	-@mkdir objs 2>/dev/null || test -d objs
267	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/gzlib.o $(SRCDIR)gzlib.c
268	-@mv objs/gzlib.o $@
269
270gzread.lo: $(SRCDIR)gzread.c
271	-@mkdir objs 2>/dev/null || test -d objs
272	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/gzread.o $(SRCDIR)gzread.c
273	-@mv objs/gzread.o $@
274
275gzwrite.lo: $(SRCDIR)gzwrite.c
276	-@mkdir objs 2>/dev/null || test -d objs
277	$(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/gzwrite.o $(SRCDIR)gzwrite.c
278	-@mv objs/gzwrite.o $@
279
280
281placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a
282	$(LDSHARED) $(SFLAGS) -o $@ $(PIC_OBJS) $(LDSHAREDLIBC) $(LDFLAGS)
283	rm -f $(SHAREDLIB) $(SHAREDLIBM)
284	ln -s $@ $(SHAREDLIB)
285	ln -s $@ $(SHAREDLIBM)
286	-@rmdir objs
287
288example$(EXE): example.o $(STATICLIB)
289	$(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS)
290
291minigzip$(EXE): minigzip.o $(STATICLIB)
292	$(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS)
293
294examplesh$(EXE): example.o $(SHAREDLIBV)
295	$(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV)
296
297minigzipsh$(EXE): minigzip.o $(SHAREDLIBV)
298	$(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV)
299
300example64$(EXE): example64.o $(STATICLIB)
301	$(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS)
302
303minigzip64$(EXE): minigzip64.o $(STATICLIB)
304	$(CC) $(CFLAGS) -o $@ minigzip64.o $(TEST_LDFLAGS)
305
306install-libs: $(LIBS)
307	-@if [ ! -d $(DESTDIR)$(exec_prefix)  ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi
308	-@if [ ! -d $(DESTDIR)$(libdir)       ]; then mkdir -p $(DESTDIR)$(libdir); fi
309	-@if [ ! -d $(DESTDIR)$(sharedlibdir) ]; then mkdir -p $(DESTDIR)$(sharedlibdir); fi
310	-@if [ ! -d $(DESTDIR)$(man3dir)      ]; then mkdir -p $(DESTDIR)$(man3dir); fi
311	-@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi
312	rm -f $(DESTDIR)$(libdir)/$(STATICLIB)
313	cp $(STATICLIB) $(DESTDIR)$(libdir)
314	chmod 644 $(DESTDIR)$(libdir)/$(STATICLIB)
315	-@($(RANLIB) $(DESTDIR)$(libdir)/libz.a || true) >/dev/null 2>&1
316	-@if test -n "$(SHAREDLIBV)"; then \
317	  rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV); \
318	  cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir); \
319	  echo "cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)"; \
320	  chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV); \
321	  echo "chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV)"; \
322	  rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \
323	  ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB); \
324	  ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \
325	  ($(LDCONFIG) || true)  >/dev/null 2>&1; \
326	fi
327	rm -f $(DESTDIR)$(man3dir)/zlib.3
328	cp $(SRCDIR)zlib.3 $(DESTDIR)$(man3dir)
329	chmod 644 $(DESTDIR)$(man3dir)/zlib.3
330	rm -f $(DESTDIR)$(pkgconfigdir)/zlib.pc
331	cp zlib.pc $(DESTDIR)$(pkgconfigdir)
332	chmod 644 $(DESTDIR)$(pkgconfigdir)/zlib.pc
333# The ranlib in install is needed on NeXTSTEP which checks file times
334# ldconfig is for Linux
335
336install: install-libs
337	-@if [ ! -d $(DESTDIR)$(includedir)   ]; then mkdir -p $(DESTDIR)$(includedir); fi
338	rm -f $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h
339	cp $(SRCDIR)zlib.h zconf.h $(DESTDIR)$(includedir)
340	chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h
341
342uninstall:
343	cd $(DESTDIR)$(includedir) && rm -f zlib.h zconf.h
344	cd $(DESTDIR)$(libdir) && rm -f libz.a; \
345	if test -n "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \
346	  rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \
347	fi
348	cd $(DESTDIR)$(man3dir) && rm -f zlib.3
349	cd $(DESTDIR)$(pkgconfigdir) && rm -f zlib.pc
350
351docs: zlib.3.pdf
352
353zlib.3.pdf: $(SRCDIR)zlib.3
354	groff -mandoc -f H -T ps $(SRCDIR)zlib.3 | ps2pdf - $@
355
356zconf.h.cmakein: $(SRCDIR)zconf.h.in
357	-@ TEMPFILE=zconfh_$$; \
358	echo "/#define ZCONF_H/ a\\\\\n#cmakedefine Z_PREFIX\\\\\n#cmakedefine Z_HAVE_UNISTD_H\n" >> $$TEMPFILE &&\
359	sed -f $$TEMPFILE $(SRCDIR)zconf.h.in > $@ &&\
360	touch -r $(SRCDIR)zconf.h.in $@ &&\
361	rm $$TEMPFILE
362
363zconf: $(SRCDIR)zconf.h.in
364	cp -p $(SRCDIR)zconf.h.in zconf.h
365
366mostlyclean: clean
367clean:
368	rm -f *.o *.lo *~ \
369	   example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
370	   example64$(EXE) minigzip64$(EXE) \
371	   infcover \
372	   libz.* foo.gz so_locations \
373	   _match.s maketree contrib/infback9/*.o
374	rm -rf objs
375	rm -f *.gcda *.gcno *.gcov
376	rm -f contrib/infback9/*.gcda contrib/infback9/*.gcno contrib/infback9/*.gcov
377
378maintainer-clean: distclean
379distclean: clean zconf zconf.h.cmakein docs
380	rm -f Makefile zlib.pc configure.log
381	-@rm -f .DS_Store
382	@if [ -f Makefile.in ]; then \
383	printf 'all:\n\t-@echo "Please use ./configure first.  Thank you."\n' > Makefile ; \
384	printf '\ndistclean:\n\tmake -f Makefile.in distclean\n' >> Makefile ; \
385	touch -r $(SRCDIR)Makefile.in Makefile ; fi
386	@if [ ! -f zconf.h.in ]; then rm -f zconf.h zconf.h.cmakein ; fi
387	@if [ ! -f zlib.3 ]; then rm -f zlib.3.pdf ; fi
388
389tags:
390	etags $(SRCDIR)*.[ch]
391
392adler32.o zutil.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
393gzclose.o gzlib.o gzread.o gzwrite.o: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h
394compress.o example.o minigzip.o uncompr.o: $(SRCDIR)zlib.h zconf.h
395crc32.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h
396deflate.o: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
397infback.o inflate.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h $(SRCDIR)inffixed.h
398inffast.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h
399inftrees.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h
400trees.o: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)trees.h
401
402adler32.lo zutil.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
403gzclose.lo gzlib.lo gzread.lo gzwrite.lo: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h
404compress.lo example.lo minigzip.lo uncompr.lo: $(SRCDIR)zlib.h zconf.h
405crc32.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h
406deflate.lo: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
407infback.lo inflate.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h $(SRCDIR)inffixed.h
408inffast.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h
409inftrees.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h
410trees.lo: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)trees.h
411