1 # Makefile for zlib
   2 # Copyright (C) 1995-2013 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 
  19 CC=cc
  20 
  21 CFLAGS=-O
  22 #CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
  23 #CFLAGS=-g -DDEBUG
  24 #CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
  25 #           -Wstrict-prototypes -Wmissing-prototypes
  26 
  27 SFLAGS=-O
  28 LDFLAGS=
  29 TEST_LDFLAGS=-L. libz.a
  30 LDSHARED=$(CC)
  31 CPP=$(CC) -E
  32 
  33 STATICLIB=libz.a
  34 SHAREDLIB=libz.so
  35 SHAREDLIBV=libz.so.1.2.8
  36 SHAREDLIBM=libz.so.1
  37 LIBS=$(STATICLIB) $(SHAREDLIBV)
  38 
  39 AR=ar
  40 ARFLAGS=rc
  41 RANLIB=ranlib
  42 LDCONFIG=ldconfig
  43 LDSHAREDLIBC=-lc
  44 TAR=tar
  45 SHELL=/bin/sh
  46 EXE=
  47 
  48 prefix = /usr/local
  49 exec_prefix = ${prefix}
  50 libdir = ${exec_prefix}/lib
  51 sharedlibdir = ${libdir}
  52 includedir = ${prefix}/include
  53 mandir = ${prefix}/share/man
  54 man3dir = ${mandir}/man3
  55 pkgconfigdir = ${libdir}/pkgconfig
  56 
  57 OBJZ = adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o
  58 OBJG = compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
  59 OBJC = $(OBJZ) $(OBJG)
  60 
  61 PIC_OBJZ = adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo
  62 PIC_OBJG = compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo
  63 PIC_OBJC = $(PIC_OBJZ) $(PIC_OBJG)
  64 
  65 # to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo
  66 OBJA =
  67 PIC_OBJA =
  68 
  69 OBJS = $(OBJC) $(OBJA)
  70 
  71 PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA)
  72 
  73 all: static shared
  74 
  75 static: example$(EXE) minigzip$(EXE)
  76 
  77 shared: examplesh$(EXE) minigzipsh$(EXE)
  78 
  79 all64: example64$(EXE) minigzip64$(EXE)
  80 
  81 check: test
  82 
  83 test: all teststatic testshared
  84 
  85 teststatic: static
  86         @TMPST=tmpst_$$; \
  87         if echo hello world | ./minigzip | ./minigzip -d && ./example $$TMPST ; then \
  88           echo '                *** zlib test OK ***'; \
  89         else \
  90           echo '                *** zlib test FAILED ***'; false; \
  91         fi; \
  92         rm -f $$TMPST
  93 
  94 testshared: shared
  95         @LD_LIBRARY_PATH=`pwd`:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
  96         LD_LIBRARYN32_PATH=`pwd`:$(LD_LIBRARYN32_PATH) ; export LD_LIBRARYN32_PATH; \
  97         DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \
  98         SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \
  99         TMPSH=tmpsh_$$; \
 100         if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh $$TMPSH; then \
 101           echo '                *** zlib shared test OK ***'; \
 102         else \
 103           echo '                *** zlib shared test FAILED ***'; false; \
 104         fi; \
 105         rm -f $$TMPSH
 106 
 107 test64: all64
 108         @TMP64=tmp64_$$; \
 109         if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64 $$TMP64; then \
 110           echo '                *** zlib 64-bit test OK ***'; \
 111         else \
 112           echo '                *** zlib 64-bit test FAILED ***'; false; \
 113         fi; \
 114         rm -f $$TMP64
 115 
 116 infcover.o: test/infcover.c zlib.h zconf.h
 117         $(CC) $(CFLAGS) -I. -c -o $@ test/infcover.c
 118 
 119 infcover: infcover.o libz.a
 120         $(CC) $(CFLAGS) -o $@ infcover.o libz.a
 121 
 122 cover: infcover
 123         rm -f *.gcda
 124         ./infcover
 125         gcov inf*.c
 126 
 127 libz.a: $(OBJS)
 128         $(AR) $(ARFLAGS) $@ $(OBJS)
 129         -@ ($(RANLIB) $@ || true) >/dev/null 2>&1
 130 
 131 match.o: match.S
 132         $(CPP) match.S > _match.s
 133         $(CC) -c _match.s
 134         mv _match.o match.o
 135         rm -f _match.s
 136 
 137 match.lo: match.S
 138         $(CPP) match.S > _match.s
 139         $(CC) -c -fPIC _match.s
 140         mv _match.o match.lo
 141         rm -f _match.s
 142 
 143 example.o: test/example.c zlib.h zconf.h
 144         $(CC) $(CFLAGS) -I. -c -o $@ test/example.c
 145 
 146 minigzip.o: test/minigzip.c zlib.h zconf.h
 147         $(CC) $(CFLAGS) -I. -c -o $@ test/minigzip.c
 148 
 149 example64.o: test/example.c zlib.h zconf.h
 150         $(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/example.c
 151 
 152 minigzip64.o: test/minigzip.c zlib.h zconf.h
 153         $(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/minigzip.c
 154 
 155 .SUFFIXES: .lo
 156 
 157 .c.lo:
 158         -@mkdir objs 2>/dev/null || test -d objs
 159         $(CC) $(SFLAGS) -DPIC -c -o objs/$*.o $<
 160         -@mv objs/$*.o $@
 161         -@if [ -f objs/$*.o.bc ]; then mv objs/$*.o.bc $@.bc; fi
 162 
 163 placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a
 164         $(LDSHARED) $(SFLAGS) -o $@ $(PIC_OBJS) $(LDSHAREDLIBC) $(LDFLAGS)
 165         rm -f $(SHAREDLIB) $(SHAREDLIBM)
 166         ln -s $@ $(SHAREDLIB)
 167         ln -s $@ $(SHAREDLIBM)
 168         -@rmdir objs
 169 
 170 example$(EXE): example.o $(STATICLIB)
 171         $(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS)
 172 
 173 minigzip$(EXE): minigzip.o $(STATICLIB)
 174         $(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS)
 175 
 176 examplesh$(EXE): example.o $(SHAREDLIBV)
 177         $(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV)
 178 
 179 minigzipsh$(EXE): minigzip.o $(SHAREDLIBV)
 180         $(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV)
 181 
 182 example64$(EXE): example64.o $(STATICLIB)
 183         $(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS)
 184 
 185 minigzip64$(EXE): minigzip64.o $(STATICLIB)
 186         $(CC) $(CFLAGS) -o $@ minigzip64.o $(TEST_LDFLAGS)
 187 
 188 install-libs: $(LIBS)
 189         -@if [ ! -d $(DESTDIR)$(exec_prefix)  ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi
 190         -@if [ ! -d $(DESTDIR)$(libdir)       ]; then mkdir -p $(DESTDIR)$(libdir); fi
 191         -@if [ ! -d $(DESTDIR)$(sharedlibdir) ]; then mkdir -p $(DESTDIR)$(sharedlibdir); fi
 192         -@if [ ! -d $(DESTDIR)$(man3dir)      ]; then mkdir -p $(DESTDIR)$(man3dir); fi
 193         -@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi
 194         cp $(STATICLIB) $(DESTDIR)$(libdir)
 195         chmod 644 $(DESTDIR)$(libdir)/$(STATICLIB)
 196         -@($(RANLIB) $(DESTDIR)$(libdir)/libz.a || true) >/dev/null 2>&1
 197         -@if test -n "$(SHAREDLIBV)"; then \
 198           cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir); \
 199           echo "cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)"; \
 200           chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV); \
 201           echo "chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV)"; \
 202           rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \
 203           ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB); \
 204           ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \
 205           ($(LDCONFIG) || true)  >/dev/null 2>&1; \
 206         fi
 207         cp zlib.3 $(DESTDIR)$(man3dir)
 208         chmod 644 $(DESTDIR)$(man3dir)/zlib.3
 209         cp zlib.pc $(DESTDIR)$(pkgconfigdir)
 210         chmod 644 $(DESTDIR)$(pkgconfigdir)/zlib.pc
 211 # The ranlib in install is needed on NeXTSTEP which checks file times
 212 # ldconfig is for Linux
 213 
 214 install: install-libs
 215         -@if [ ! -d $(DESTDIR)$(includedir)   ]; then mkdir -p $(DESTDIR)$(includedir); fi
 216         cp zlib.h zconf.h $(DESTDIR)$(includedir)
 217         chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h
 218 
 219 uninstall:
 220         cd $(DESTDIR)$(includedir) && rm -f zlib.h zconf.h
 221         cd $(DESTDIR)$(libdir) && rm -f libz.a; \
 222         if test -n "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \
 223           rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \
 224         fi
 225         cd $(DESTDIR)$(man3dir) && rm -f zlib.3
 226         cd $(DESTDIR)$(pkgconfigdir) && rm -f zlib.pc
 227 
 228 docs: zlib.3.pdf
 229 
 230 zlib.3.pdf: zlib.3
 231         groff -mandoc -f H -T ps zlib.3 | ps2pdf - zlib.3.pdf
 232 
 233 zconf.h.cmakein: zconf.h.in
 234         -@ TEMPFILE=zconfh_$$; \
 235         echo "/#define ZCONF_H/ a\\\\\n#cmakedefine Z_PREFIX\\\\\n#cmakedefine Z_HAVE_UNISTD_H\n" >> $$TEMPFILE &&\
 236         sed -f $$TEMPFILE zconf.h.in > zconf.h.cmakein &&\
 237         touch -r zconf.h.in zconf.h.cmakein &&\
 238         rm $$TEMPFILE
 239 
 240 zconf: zconf.h.in
 241         cp -p zconf.h.in zconf.h
 242 
 243 mostlyclean: clean
 244 clean:
 245         rm -f *.o *.lo *~ \
 246            example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
 247            example64$(EXE) minigzip64$(EXE) \
 248            infcover \
 249            libz.* foo.gz so_locations \
 250            _match.s maketree contrib/infback9/*.o
 251         rm -rf objs
 252         rm -f *.gcda *.gcno *.gcov
 253         rm -f contrib/infback9/*.gcda contrib/infback9/*.gcno contrib/infback9/*.gcov
 254 
 255 maintainer-clean: distclean
 256 distclean: clean zconf zconf.h.cmakein docs
 257         rm -f Makefile zlib.pc configure.log
 258         -@rm -f .DS_Store
 259         -@printf 'all:\n\t-@echo "Please use ./configure first.  Thank you."\n' > Makefile
 260         -@printf '\ndistclean:\n\tmake -f Makefile.in distclean\n' >> Makefile
 261         -@touch -r Makefile.in Makefile
 262 
 263 tags:
 264         etags *.[ch]
 265 
 266 depend:
 267         makedepend -- $(CFLAGS) -- *.[ch]
 268 
 269 # DO NOT DELETE THIS LINE -- make depend depends on it.
 270 
 271 adler32.o zutil.o: zutil.h zlib.h zconf.h
 272 gzclose.o gzlib.o gzread.o gzwrite.o: zlib.h zconf.h gzguts.h
 273 compress.o example.o minigzip.o uncompr.o: zlib.h zconf.h
 274 crc32.o: zutil.h zlib.h zconf.h crc32.h
 275 deflate.o: deflate.h zutil.h zlib.h zconf.h
 276 infback.o inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h
 277 inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
 278 inftrees.o: zutil.h zlib.h zconf.h inftrees.h
 279 trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
 280 
 281 adler32.lo zutil.lo: zutil.h zlib.h zconf.h
 282 gzclose.lo gzlib.lo gzread.lo gzwrite.lo: zlib.h zconf.h gzguts.h
 283 compress.lo example.lo minigzip.lo uncompr.lo: zlib.h zconf.h
 284 crc32.lo: zutil.h zlib.h zconf.h crc32.h
 285 deflate.lo: deflate.h zutil.h zlib.h zconf.h
 286 infback.lo inflate.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h
 287 inffast.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
 288 inftrees.lo: zutil.h zlib.h zconf.h inftrees.h
 289 trees.lo: deflate.h zutil.h zlib.h zconf.h trees.h