diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ee3bc4..b03b038 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,19 +60,6 @@ if(MSVC) set(CMAKE_DEBUG_POSTFIX "d") add_definitions(-D_CRT_SECURE_NO_DEPRECATE) add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -endif() - -if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) - # If we're doing an out of source build and the user has a zconf.h - # in their source tree... - if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h) - message(STATUS "Renaming") - message(STATUS " ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h") - message(STATUS "to 'zconf.h.included' because this file is included with zlib") - message(STATUS "but CMake generates it automatically in the build directory.") - file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included) - endif() endif() set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc) @@ -80,6 +67,11 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein ${ZLIB_PC} @ONLY) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) +# If building outside of the source tree, a copy of zlib.h is needed so +# that #include"zconf.h" pulls in the header created above +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h + ${CMAKE_CURRENT_BINARY_DIR}/zlib.h COPYONLY) +add_definitions(-DZLIB_INCPATH_SET) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) diff --git a/Makefile.in b/Makefile.in index 241deed..56c5e5b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -16,6 +16,9 @@ # To install in $HOME instead of /usr/local, use: # make install prefix=$HOME +srcdir=. +VPATH=$(srcdir) + CC=cc CFLAGS=-O @@ -114,7 +117,7 @@ test64: all64 rm -f $$TMP64 infcover.o: test/infcover.c zlib.h zconf.h - $(CC) $(CFLAGS) -I. -c -o $@ test/infcover.c + $(CC) $(CFLAGS) -DZLIB_INCPATH_SET -I. -I$(srcdir) -c -o $@ $(srcdir)/test/infcover.c infcover: infcover.o libz.a $(CC) $(CFLAGS) -o $@ infcover.o libz.a @@ -129,34 +132,37 @@ libz.a: $(OBJS) -@ ($(RANLIB) $@ || true) >/dev/null 2>&1 match.o: match.S - $(CPP) match.S > _match.s + $(CPP) $(srcdir)/match.S > _match.s $(CC) -c _match.s mv _match.o match.o rm -f _match.s match.lo: match.S - $(CPP) match.S > _match.s + $(CPP) $(srcdir)/match.S > _match.s $(CC) -c -fPIC _match.s mv _match.o match.lo rm -f _match.s example.o: test/example.c zlib.h zconf.h - $(CC) $(CFLAGS) -I. -c -o $@ test/example.c + $(CC) $(CFLAGS) -DZLIB_INCPATH_SET -I. -I$(srcdir) -c -o $@ $(srcdir)/test/example.c minigzip.o: test/minigzip.c zlib.h zconf.h - $(CC) $(CFLAGS) -I. -c -o $@ test/minigzip.c + $(CC) $(CFLAGS) -DZLIB_INCPATH_SET -I. -I$(srcdir) -c -o $@ $(srcdir)/test/minigzip.c example64.o: test/example.c zlib.h zconf.h - $(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/example.c + $(CC) $(CFLAGS) -DZLIB_INCPATH_SET -I. -I$(srcdir) -D_FILE_OFFSET_BITS=64 -c -o $@ $(srcdir)/test/example.c minigzip64.o: test/minigzip.c zlib.h zconf.h - $(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/minigzip.c + $(CC) $(CFLAGS) -DZLIB_INCPATH_SET -I. -I$(srcdir) -D_FILE_OFFSET_BITS=64 -c -o $@ $(srcdir)/test/minigzip.c .SUFFIXES: .lo +.c.o: + $(CC) $(CFLAGS) -DZLIB_INCPATH_SET -I. -I$(srcdir) -c -o $@ $< + .c.lo: -@mkdir objs 2>/dev/null || test -d objs - $(CC) $(SFLAGS) -DPIC -c -o objs/$*.o $< + $(CC) $(SFLAGS) -DZLIB_INCPATH_SET -I. -I$(srcdir) -DPIC -c -o objs/$*.o $< -@mv objs/$*.o $@ placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a @@ -203,7 +209,7 @@ install-libs: $(LIBS) ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \ ($(LDCONFIG) || true) >/dev/null 2>&1; \ fi - cp zlib.3 $(DESTDIR)$(man3dir) + cp $(srcdir)/zlib.3 $(DESTDIR)$(man3dir) chmod 644 $(DESTDIR)$(man3dir)/zlib.3 cp zlib.pc $(DESTDIR)$(pkgconfigdir) chmod 644 $(DESTDIR)$(pkgconfigdir)/zlib.pc @@ -237,7 +243,7 @@ zconf.h.cmakein: zconf.h.in rm $$TEMPFILE zconf: zconf.h.in - cp -p zconf.h.in zconf.h + cp -p $(srcdir)/zconf.h.in zconf.h mostlyclean: clean clean: @@ -254,10 +260,13 @@ clean: maintainer-clean: distclean distclean: clean zconf zconf.h.cmakein docs rm -f Makefile zlib.pc configure.log + test -r zconf.h.in || rm -f zconf.h zlib.h -@rm -f .DS_Store - -@printf 'all:\n\t-@echo "Please use ./configure first. Thank you."\n' > Makefile - -@printf '\ndistclean:\n\tmake -f Makefile.in distclean\n' >> Makefile - -@touch -r Makefile.in Makefile + -@if test -r Makefile.in; then \ + printf 'all:\n\t-@echo "Please use ./configure first. Thank you."\n' > Makefile; \ + printf '\ndistclean:\n\tmake -f Makefile.in distclean\n' >> Makefile; \ + touch -r Makefile.in Makefile; \ + fi tags: etags *.[ch] diff --git a/compress.c b/compress.c index ea4dfbe..db584b0 100644 --- a/compress.c +++ b/compress.c @@ -6,7 +6,12 @@ /* @(#) $Id$ */ #define ZLIB_INTERNAL -#include "zlib.h" + +#ifdef ZLIB_INCPATH_SET +# include +#else +# include "zlib.h" +#endif /* =========================================================================== Compresses the source buffer into the destination buffer. The level diff --git a/configure b/configure index 36c7d8e..4958e61 100755 --- a/configure +++ b/configure @@ -13,6 +13,8 @@ # If you have problems, try without defining CC and CFLAGS before reporting # an error. +srcdir=`echo "$0" | sed 's,/[^/]*$,,'` + # start off configure.log echo -------------------- >> configure.log echo $0 $* >> configure.log @@ -28,10 +30,10 @@ fi STATICLIB=libz.a # extract zlib version numbers from zlib.h -VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h` -VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < zlib.h` -VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h` -VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h` +VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < $srcdir/zlib.h` +VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < $srcdir/zlib.h` +VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < $srcdir/zlib.h` +VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < $srcdir/zlib.h` # establish commands for library building if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then @@ -427,8 +429,12 @@ else echo "Checking for strerror... No." | tee -a configure.log fi +# if building outside of the source tree, a copy of zlib.h is needed so +# that #include"zconf.h" pulls in the header edited below +test -f zconf.h.in || cp -p $srcdir/zlib.h . + # copy clean zconf.h for subsequent edits -cp -p zconf.h.in zconf.h +cp -p $srcdir/zconf.h.in zconf.h echo >> configure.log @@ -762,8 +768,9 @@ echo -------------------- >> configure.log echo >> configure.log echo >> configure.log -# udpate Makefile with the configure results -sed < Makefile.in " +# update Makefile with the configure results +sed < $srcdir/Makefile.in " +/^srcdir *=/s#=.*#=$srcdir# /^CC *=/s#=.*#=$CC# /^CFLAGS *=/s#=.*#=$CFLAGS# /^SFLAGS *=/s#=.*#=$SFLAGS# @@ -793,7 +800,7 @@ sed < Makefile.in " " > Makefile # create zlib.pc with the configure results -sed < zlib.pc.in " +sed < $srcdir/zlib.pc.in " /^CC *=/s#=.*#=$CC# /^CFLAGS *=/s#=.*#=$CFLAGS# /^CPP *=/s#=.*#=$CPP# diff --git a/gzguts.h b/gzguts.h index ee3f281..9dba035 100644 --- a/gzguts.h +++ b/gzguts.h @@ -19,7 +19,13 @@ #endif #include -#include "zlib.h" + +#ifdef ZLIB_INCPATH_SET +# include +#else +# include "zlib.h" +#endif + #ifdef STDC # include # include diff --git a/uncompr.c b/uncompr.c index ad98be3..3d8aed9 100644 --- a/uncompr.c +++ b/uncompr.c @@ -6,7 +6,12 @@ /* @(#) $Id$ */ #define ZLIB_INTERNAL -#include "zlib.h" + +#ifdef ZLIB_INCPATH_SET +# include +#else +# include "zlib.h" +#endif /* =========================================================================== Decompresses the source buffer into the destination buffer. sourceLen is diff --git a/win32/zlib1.rc b/win32/zlib1.rc index 0d1d7ff..011bb86 100644 --- a/win32/zlib1.rc +++ b/win32/zlib1.rc @@ -1,5 +1,10 @@ #include -#include "../zlib.h" + +#ifdef ZLIB_INCPATH_SET +# include +#else +# include "../zlib.h" +#endif #ifdef GCC_WINDRES VS_VERSION_INFO VERSIONINFO diff --git a/zutil.h b/zutil.h index 4e3dcc6..c361e00 100644 --- a/zutil.h +++ b/zutil.h @@ -19,7 +19,11 @@ # define ZLIB_INTERNAL #endif -#include "zlib.h" +#ifdef ZLIB_INCPATH_SET +# include +#else +# include "zlib.h" +#endif #if defined(STDC) && !defined(Z_SOLO) # if !(defined(_WIN32_WCE) && defined(_MSC_VER))