configure 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. #!/bin/sh
  2. # configure script for zlib.
  3. #
  4. # Normally configure builds both a static and a shared library.
  5. # If you want to build just a static library, use: ./configure --static
  6. #
  7. # To impose specific compiler or flags or install directory, use for example:
  8. # prefix=$HOME CC=cc CFLAGS="-O4" ./configure
  9. # or for csh/tcsh users:
  10. # (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure)
  11. # Incorrect settings of CC or CFLAGS may prevent creating a shared library.
  12. # If you have problems, try without defining CC and CFLAGS before reporting
  13. # an error.
  14. # start off configure.log
  15. echo -------------------- >> configure.log
  16. echo $0 $* >> configure.log
  17. date >> configure.log
  18. # set command prefix for cross-compilation
  19. if [ -n "${CHOST}" ]; then
  20. uname="`echo "${CHOST}" | sed -e 's/^[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)-.*$/\1/'`"
  21. CROSS_PREFIX="${CHOST}-"
  22. fi
  23. # destination name for static library
  24. STATICLIB=libz.a
  25. # extract zlib version numbers from zlib.h
  26. VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
  27. VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < zlib.h`
  28. VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h`
  29. VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h`
  30. # establish commands for library building
  31. if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
  32. AR=${AR-"${CROSS_PREFIX}ar"}
  33. test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
  34. else
  35. AR=${AR-"ar"}
  36. test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
  37. fi
  38. ARFLAGS=${ARFLAGS-"rc"}
  39. if "${CROSS_PREFIX}ranlib" --version >/dev/null 2>/dev/null || test $? -lt 126; then
  40. RANLIB=${RANLIB-"${CROSS_PREFIX}ranlib"}
  41. test -n "${CROSS_PREFIX}" && echo Using ${RANLIB} | tee -a configure.log
  42. else
  43. RANLIB=${RANLIB-"ranlib"}
  44. fi
  45. if "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then
  46. NM=${NM-"${CROSS_PREFIX}nm"}
  47. test -n "${CROSS_PREFIX}" && echo Using ${NM} | tee -a configure.log
  48. else
  49. NM=${NM-"nm"}
  50. fi
  51. # set defaults before processing command line options
  52. LDCONFIG=${LDCONFIG-"ldconfig"}
  53. LDSHAREDLIBC="${LDSHAREDLIBC--lc}"
  54. ARCHS=
  55. prefix=${prefix-/usr/local}
  56. exec_prefix=${exec_prefix-'${prefix}'}
  57. libdir=${libdir-'${exec_prefix}/lib'}
  58. sharedlibdir=${sharedlibdir-'${libdir}'}
  59. includedir=${includedir-'${prefix}/include'}
  60. mandir=${mandir-'${prefix}/share/man'}
  61. shared_ext='.so'
  62. shared=1
  63. solo=0
  64. cover=0
  65. zprefix=0
  66. build64=0
  67. gcc=0
  68. old_cc="$CC"
  69. old_cflags="$CFLAGS"
  70. OBJC='$(OBJZ) $(OBJG)'
  71. PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
  72. # process command line options
  73. while test $# -ge 1
  74. do
  75. case "$1" in
  76. -h* | --help)
  77. echo 'usage:' | tee -a configure.log
  78. echo ' configure [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]' | tee -a configure.log
  79. echo ' [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log
  80. echo ' [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log
  81. exit 0 ;;
  82. -p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;;
  83. -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;;
  84. -l*=* | --libdir=*) libdir=`echo $1 | sed 's/.*=//'`; shift ;;
  85. --sharedlibdir=*) sharedlibdir=`echo $1 | sed 's/.*=//'`; shift ;;
  86. -i*=* | --includedir=*) includedir=`echo $1 | sed 's/.*=//'`;shift ;;
  87. -u*=* | --uname=*) uname=`echo $1 | sed 's/.*=//'`;shift ;;
  88. -p* | --prefix) prefix="$2"; shift; shift ;;
  89. -e* | --eprefix) exec_prefix="$2"; shift; shift ;;
  90. -l* | --libdir) libdir="$2"; shift; shift ;;
  91. -i* | --includedir) includedir="$2"; shift; shift ;;
  92. -s* | --shared | --enable-shared) shared=1; shift ;;
  93. -t | --static) shared=0; shift ;;
  94. --solo) solo=1; shift ;;
  95. --cover) cover=1; shift ;;
  96. -z* | --zprefix) zprefix=1; shift ;;
  97. -6* | --64) build64=1; shift ;;
  98. -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;;
  99. --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;;
  100. --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;;
  101. *) echo "unknown option: $1"; echo "$0 --help for help" | tee -a configure.log; exit 1 ;;
  102. esac
  103. done
  104. # define functions for testing compiler and library characteristics and logging the results
  105. test=ztest$$
  106. show()
  107. {
  108. case "$*" in
  109. *$test.c*)
  110. echo === $test.c === >> configure.log
  111. cat $test.c >> configure.log
  112. echo === >> configure.log;;
  113. esac
  114. echo $* >> configure.log
  115. }
  116. cat > $test.c <<EOF
  117. #error error
  118. EOF
  119. if ($CC -c $CFLAGS $test.c) 2>/dev/null; then
  120. try()
  121. {
  122. show $*
  123. test "`( $* ) 2>&1 | tee -a configure.log`" = ""
  124. }
  125. echo - using any output from compiler to indicate an error >> configure.log
  126. else
  127. try()
  128. {
  129. show $*
  130. ( $* ) >> configure.log 2>&1
  131. ret=$?
  132. if test $ret -ne 0; then
  133. echo "(exit code "$ret")" >> configure.log
  134. fi
  135. return $ret
  136. }
  137. fi
  138. tryboth()
  139. {
  140. show $*
  141. got=`( $* ) 2>&1`
  142. ret=$?
  143. printf %s "$got" >> configure.log
  144. if test $ret -ne 0; then
  145. return $ret
  146. fi
  147. test "$got" = ""
  148. }
  149. echo >> configure.log
  150. # check for gcc vs. cc and set compile and link flags based on the system identified by uname
  151. cat > $test.c <<EOF
  152. extern int getchar();
  153. int hello() {return getchar();}
  154. EOF
  155. test -z "$CC" && echo Checking for ${CROSS_PREFIX}gcc... | tee -a configure.log
  156. cc=${CC-${CROSS_PREFIX}gcc}
  157. cflags=${CFLAGS-"-O3"}
  158. # to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
  159. case "$cc" in
  160. *gcc*) gcc=1 ;;
  161. *clang*) gcc=1 ;;
  162. esac
  163. case `$cc -v 2>&1` in
  164. *gcc*) gcc=1 ;;
  165. esac
  166. show $cc -c $cflags $test.c
  167. if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) >> configure.log 2>&1; then
  168. echo ... using gcc >> configure.log
  169. CC="$cc"
  170. CFLAGS="${CFLAGS--O3} ${ARCHS}"
  171. SFLAGS="${CFLAGS--O3} -fPIC"
  172. LDFLAGS="${LDFLAGS} ${ARCHS}"
  173. if test $build64 -eq 1; then
  174. CFLAGS="${CFLAGS} -m64"
  175. SFLAGS="${SFLAGS} -m64"
  176. fi
  177. if test "${ZLIBGCCWARN}" = "YES"; then
  178. CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
  179. fi
  180. if test -z "$uname"; then
  181. uname=`(uname -s || echo unknown) 2>/dev/null`
  182. fi
  183. case "$uname" in
  184. Linux* | linux* | GNU | GNU/* | solaris*)
  185. LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;;
  186. *BSD | *bsd* | DragonFly)
  187. LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"}
  188. LDCONFIG="ldconfig -m" ;;
  189. CYGWIN* | Cygwin* | cygwin* | OS/2*)
  190. EXE='.exe' ;;
  191. MINGW* | mingw*)
  192. # temporary bypass
  193. rm -f $test.[co] $test $test$shared_ext
  194. echo "Please use win32/Makefile.gcc instead." | tee -a configure.log
  195. exit 1
  196. LDSHARED=${LDSHARED-"$cc -shared"}
  197. LDSHAREDLIBC=""
  198. EXE='.exe' ;;
  199. QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
  200. # (alain.bonnefoy@icbt.com)
  201. LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;;
  202. HP-UX*)
  203. LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
  204. case `(uname -m || echo unknown) 2>/dev/null` in
  205. ia64)
  206. shared_ext='.so'
  207. SHAREDLIB='libz.so' ;;
  208. *)
  209. shared_ext='.sl'
  210. SHAREDLIB='libz.sl' ;;
  211. esac ;;
  212. Darwin* | darwin*)
  213. shared_ext='.dylib'
  214. SHAREDLIB=libz$shared_ext
  215. SHAREDLIBV=libz.$VER$shared_ext
  216. SHAREDLIBM=libz.$VER1$shared_ext
  217. LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"}
  218. AR="/usr/bin/libtool"
  219. ARFLAGS="-o" ;;
  220. *) LDSHARED=${LDSHARED-"$cc -shared"} ;;
  221. esac
  222. else
  223. # find system name and corresponding cc options
  224. CC=${CC-cc}
  225. gcc=0
  226. echo ... using $CC >> configure.log
  227. if test -z "$uname"; then
  228. uname=`(uname -sr || echo unknown) 2>/dev/null`
  229. fi
  230. case "$uname" in
  231. HP-UX*) SFLAGS=${CFLAGS-"-O +z"}
  232. CFLAGS=${CFLAGS-"-O"}
  233. # LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
  234. LDSHARED=${LDSHARED-"ld -b"}
  235. case `(uname -m || echo unknown) 2>/dev/null` in
  236. ia64)
  237. shared_ext='.so'
  238. SHAREDLIB='libz.so' ;;
  239. *)
  240. shared_ext='.sl'
  241. SHAREDLIB='libz.sl' ;;
  242. esac ;;
  243. IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
  244. CFLAGS=${CFLAGS-"-ansi -O2"}
  245. LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
  246. OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
  247. CFLAGS=${CFLAGS-"-O -std1"}
  248. LDFLAGS="${LDFLAGS} -Wl,-rpath,."
  249. LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;;
  250. OSF1*) SFLAGS=${CFLAGS-"-O -std1"}
  251. CFLAGS=${CFLAGS-"-O -std1"}
  252. LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
  253. QNX*) SFLAGS=${CFLAGS-"-4 -O"}
  254. CFLAGS=${CFLAGS-"-4 -O"}
  255. LDSHARED=${LDSHARED-"cc"}
  256. RANLIB=${RANLIB-"true"}
  257. AR="cc"
  258. ARFLAGS="-A" ;;
  259. SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
  260. CFLAGS=${CFLAGS-"-O3"}
  261. LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;;
  262. SunOS\ 5* | solaris*)
  263. LDSHARED=${LDSHARED-"cc -G -h libz$shared_ext.$VER1"}
  264. SFLAGS=${CFLAGS-"-fast -KPIC"}
  265. CFLAGS=${CFLAGS-"-fast"}
  266. if test $build64 -eq 1; then
  267. # old versions of SunPRO/Workshop/Studio don't support -m64,
  268. # but newer ones do. Check for it.
  269. flag64=`$CC -flags | egrep -- '^-m64'`
  270. if test x"$flag64" != x"" ; then
  271. CFLAGS="${CFLAGS} -m64"
  272. SFLAGS="${SFLAGS} -m64"
  273. else
  274. case `(uname -m || echo unknown) 2>/dev/null` in
  275. i86*)
  276. SFLAGS="$SFLAGS -xarch=amd64"
  277. CFLAGS="$CFLAGS -xarch=amd64" ;;
  278. *)
  279. SFLAGS="$SFLAGS -xarch=v9"
  280. CFLAGS="$CFLAGS -xarch=v9" ;;
  281. esac
  282. fi
  283. fi
  284. ;;
  285. SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
  286. CFLAGS=${CFLAGS-"-O2"}
  287. LDSHARED=${LDSHARED-"ld"} ;;
  288. SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
  289. CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"}
  290. LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;;
  291. UNIX_System_V\ 4.2.0)
  292. SFLAGS=${CFLAGS-"-KPIC -O"}
  293. CFLAGS=${CFLAGS-"-O"}
  294. LDSHARED=${LDSHARED-"cc -G"} ;;
  295. UNIX_SV\ 4.2MP)
  296. SFLAGS=${CFLAGS-"-Kconform_pic -O"}
  297. CFLAGS=${CFLAGS-"-O"}
  298. LDSHARED=${LDSHARED-"cc -G"} ;;
  299. OpenUNIX\ 5)
  300. SFLAGS=${CFLAGS-"-KPIC -O"}
  301. CFLAGS=${CFLAGS-"-O"}
  302. LDSHARED=${LDSHARED-"cc -G"} ;;
  303. AIX*) # Courtesy of dbakker@arrayasolutions.com
  304. SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
  305. CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
  306. LDSHARED=${LDSHARED-"xlc -G"} ;;
  307. # send working options for other systems to zlib@gzip.org
  308. *) SFLAGS=${CFLAGS-"-O"}
  309. CFLAGS=${CFLAGS-"-O"}
  310. LDSHARED=${LDSHARED-"cc -shared"} ;;
  311. esac
  312. fi
  313. # destination names for shared library if not defined above
  314. SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
  315. SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
  316. SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
  317. echo >> configure.log
  318. # see if shared library build supported
  319. if test $shared -eq 1; then
  320. echo Checking for shared library support... | tee -a configure.log
  321. # we must test in two steps (cc then ld), required at least on SunOS 4.x
  322. if try $CC -w -c $SFLAGS $test.c &&
  323. try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then
  324. echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log
  325. elif test -z "$old_cc" -a -z "$old_cflags"; then
  326. echo No shared library support. | tee -a configure.log
  327. shared=0;
  328. else
  329. echo 'No shared library support; try without defining CC and CFLAGS' | tee -a configure.log
  330. shared=0;
  331. fi
  332. fi
  333. if test $shared -eq 0; then
  334. LDSHARED="$CC"
  335. ALL="static"
  336. TEST="all teststatic"
  337. SHAREDLIB=""
  338. SHAREDLIBV=""
  339. SHAREDLIBM=""
  340. echo Building static library $STATICLIB version $VER with $CC. | tee -a configure.log
  341. else
  342. ALL="static shared"
  343. TEST="all teststatic testshared"
  344. fi
  345. echo >> configure.log
  346. # check for underscores in external names for use by assembler code
  347. CPP=${CPP-"$CC -E"}
  348. case $CFLAGS in
  349. *ASMV*)
  350. echo >> configure.log
  351. show "$NM $test.o | grep _hello"
  352. if test "`$NM $test.o | grep _hello | tee -a configure.log`" = ""; then
  353. CPP="$CPP -DNO_UNDERLINE"
  354. echo Checking for underline in external names... No. | tee -a configure.log
  355. else
  356. echo Checking for underline in external names... Yes. | tee -a configure.log
  357. fi ;;
  358. esac
  359. echo >> configure.log
  360. # check for large file support, and if none, check for fseeko()
  361. cat > $test.c <<EOF
  362. #include <sys/types.h>
  363. off64_t dummy = 0;
  364. EOF
  365. if try $CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c; then
  366. CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
  367. SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
  368. ALL="${ALL} all64"
  369. TEST="${TEST} test64"
  370. echo "Checking for off64_t... Yes." | tee -a configure.log
  371. echo "Checking for fseeko... Yes." | tee -a configure.log
  372. else
  373. echo "Checking for off64_t... No." | tee -a configure.log
  374. echo >> configure.log
  375. cat > $test.c <<EOF
  376. #include <stdio.h>
  377. int main(void) {
  378. fseeko(NULL, 0, 0);
  379. return 0;
  380. }
  381. EOF
  382. if try $CC $CFLAGS -o $test $test.c; then
  383. echo "Checking for fseeko... Yes." | tee -a configure.log
  384. else
  385. CFLAGS="${CFLAGS} -DNO_FSEEKO"
  386. SFLAGS="${SFLAGS} -DNO_FSEEKO"
  387. echo "Checking for fseeko... No." | tee -a configure.log
  388. fi
  389. fi
  390. echo >> configure.log
  391. # check for strerror() for use by gz* functions
  392. cat > $test.c <<EOF
  393. #include <string.h>
  394. #include <errno.h>
  395. int main() { return strlen(strerror(errno)); }
  396. EOF
  397. if try $CC $CFLAGS -o $test $test.c; then
  398. echo "Checking for strerror... Yes." | tee -a configure.log
  399. else
  400. CFLAGS="${CFLAGS} -DNO_STRERROR"
  401. SFLAGS="${SFLAGS} -DNO_STRERROR"
  402. echo "Checking for strerror... No." | tee -a configure.log
  403. fi
  404. # copy clean zconf.h for subsequent edits
  405. cp -p zconf.h.in zconf.h
  406. echo >> configure.log
  407. # check for unistd.h and save result in zconf.h
  408. cat > $test.c <<EOF
  409. #include <unistd.h>
  410. int main() { return 0; }
  411. EOF
  412. if try $CC -c $CFLAGS $test.c; then
  413. sed < zconf.h "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
  414. mv zconf.temp.h zconf.h
  415. echo "Checking for unistd.h... Yes." | tee -a configure.log
  416. else
  417. echo "Checking for unistd.h... No." | tee -a configure.log
  418. fi
  419. echo >> configure.log
  420. # check for stdarg.h and save result in zconf.h
  421. cat > $test.c <<EOF
  422. #include <stdarg.h>
  423. int main() { return 0; }
  424. EOF
  425. if try $CC -c $CFLAGS $test.c; then
  426. sed < zconf.h "/^#ifdef HAVE_STDARG_H.* may be/s/def HAVE_STDARG_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
  427. mv zconf.temp.h zconf.h
  428. echo "Checking for stdarg.h... Yes." | tee -a configure.log
  429. else
  430. echo "Checking for stdarg.h... No." | tee -a configure.log
  431. fi
  432. # if the z_ prefix was requested, save that in zconf.h
  433. if test $zprefix -eq 1; then
  434. sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h
  435. mv zconf.temp.h zconf.h
  436. echo >> configure.log
  437. echo "Using z_ prefix on all symbols." | tee -a configure.log
  438. fi
  439. # if --solo compilation was requested, save that in zconf.h and remove gz stuff from object lists
  440. if test $solo -eq 1; then
  441. sed '/#define ZCONF_H/a\
  442. #define Z_SOLO
  443. ' < zconf.h > zconf.temp.h
  444. mv zconf.temp.h zconf.h
  445. OBJC='$(OBJZ)'
  446. PIC_OBJC='$(PIC_OBJZ)'
  447. fi
  448. # if code coverage testing was requested, use older gcc if defined, e.g. "gcc-4.2" on Mac OS X
  449. if test $cover -eq 1; then
  450. CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
  451. if test -n "$GCC_CLASSIC"; then
  452. CC=$GCC_CLASSIC
  453. fi
  454. fi
  455. echo >> configure.log
  456. # conduct a series of tests to resolve eight possible cases of using "vs" or "s" printf functions
  457. # (using stdarg or not), with or without "n" (proving size of buffer), and with or without a
  458. # return value. The most secure result is vsnprintf() with a return value. snprintf() with a
  459. # return value is secure as well, but then gzprintf() will be limited to 20 arguments.
  460. cat > $test.c <<EOF
  461. #include <stdio.h>
  462. #include <stdarg.h>
  463. #include "zconf.h"
  464. int main()
  465. {
  466. #ifndef STDC
  467. choke me
  468. #endif
  469. return 0;
  470. }
  471. EOF
  472. if try $CC -c $CFLAGS $test.c; then
  473. echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log
  474. echo >> configure.log
  475. cat > $test.c <<EOF
  476. #include <stdio.h>
  477. #include <stdarg.h>
  478. int mytest(const char *fmt, ...)
  479. {
  480. char buf[20];
  481. va_list ap;
  482. va_start(ap, fmt);
  483. vsnprintf(buf, sizeof(buf), fmt, ap);
  484. va_end(ap);
  485. return 0;
  486. }
  487. int main()
  488. {
  489. return (mytest("Hello%d\n", 1));
  490. }
  491. EOF
  492. if try $CC $CFLAGS -o $test $test.c; then
  493. echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log
  494. echo >> configure.log
  495. cat >$test.c <<EOF
  496. #include <stdio.h>
  497. #include <stdarg.h>
  498. int mytest(const char *fmt, ...)
  499. {
  500. int n;
  501. char buf[20];
  502. va_list ap;
  503. va_start(ap, fmt);
  504. n = vsnprintf(buf, sizeof(buf), fmt, ap);
  505. va_end(ap);
  506. return n;
  507. }
  508. int main()
  509. {
  510. return (mytest("Hello%d\n", 1));
  511. }
  512. EOF
  513. if try $CC -c $CFLAGS $test.c; then
  514. echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log
  515. else
  516. CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
  517. SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
  518. echo "Checking for return value of vsnprintf()... No." | tee -a configure.log
  519. echo " WARNING: apparently vsnprintf() does not return a value. zlib" | tee -a configure.log
  520. echo " can build but will be open to possible string-format security" | tee -a configure.log
  521. echo " vulnerabilities." | tee -a configure.log
  522. fi
  523. else
  524. CFLAGS="$CFLAGS -DNO_vsnprintf"
  525. SFLAGS="$SFLAGS -DNO_vsnprintf"
  526. echo "Checking for vsnprintf() in stdio.h... No." | tee -a configure.log
  527. echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" | tee -a configure.log
  528. echo " can build but will be open to possible buffer-overflow security" | tee -a configure.log
  529. echo " vulnerabilities." | tee -a configure.log
  530. echo >> configure.log
  531. cat >$test.c <<EOF
  532. #include <stdio.h>
  533. #include <stdarg.h>
  534. int mytest(const char *fmt, ...)
  535. {
  536. int n;
  537. char buf[20];
  538. va_list ap;
  539. va_start(ap, fmt);
  540. n = vsprintf(buf, fmt, ap);
  541. va_end(ap);
  542. return n;
  543. }
  544. int main()
  545. {
  546. return (mytest("Hello%d\n", 1));
  547. }
  548. EOF
  549. if try $CC -c $CFLAGS $test.c; then
  550. echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log
  551. else
  552. CFLAGS="$CFLAGS -DHAS_vsprintf_void"
  553. SFLAGS="$SFLAGS -DHAS_vsprintf_void"
  554. echo "Checking for return value of vsprintf()... No." | tee -a configure.log
  555. echo " WARNING: apparently vsprintf() does not return a value. zlib" | tee -a configure.log
  556. echo " can build but will be open to possible string-format security" | tee -a configure.log
  557. echo " vulnerabilities." | tee -a configure.log
  558. fi
  559. fi
  560. else
  561. echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log
  562. echo >> configure.log
  563. cat >$test.c <<EOF
  564. #include <stdio.h>
  565. int mytest()
  566. {
  567. char buf[20];
  568. snprintf(buf, sizeof(buf), "%s", "foo");
  569. return 0;
  570. }
  571. int main()
  572. {
  573. return (mytest());
  574. }
  575. EOF
  576. if try $CC $CFLAGS -o $test $test.c; then
  577. echo "Checking for snprintf() in stdio.h... Yes." | tee -a configure.log
  578. echo >> configure.log
  579. cat >$test.c <<EOF
  580. #include <stdio.h>
  581. int mytest()
  582. {
  583. char buf[20];
  584. return snprintf(buf, sizeof(buf), "%s", "foo");
  585. }
  586. int main()
  587. {
  588. return (mytest());
  589. }
  590. EOF
  591. if try $CC -c $CFLAGS $test.c; then
  592. echo "Checking for return value of snprintf()... Yes." | tee -a configure.log
  593. else
  594. CFLAGS="$CFLAGS -DHAS_snprintf_void"
  595. SFLAGS="$SFLAGS -DHAS_snprintf_void"
  596. echo "Checking for return value of snprintf()... No." | tee -a configure.log
  597. echo " WARNING: apparently snprintf() does not return a value. zlib" | tee -a configure.log
  598. echo " can build but will be open to possible string-format security" | tee -a configure.log
  599. echo " vulnerabilities." | tee -a configure.log
  600. fi
  601. else
  602. CFLAGS="$CFLAGS -DNO_snprintf"
  603. SFLAGS="$SFLAGS -DNO_snprintf"
  604. echo "Checking for snprintf() in stdio.h... No." | tee -a configure.log
  605. echo " WARNING: snprintf() not found, falling back to sprintf(). zlib" | tee -a configure.log
  606. echo " can build but will be open to possible buffer-overflow security" | tee -a configure.log
  607. echo " vulnerabilities." | tee -a configure.log
  608. echo >> configure.log
  609. cat >$test.c <<EOF
  610. #include <stdio.h>
  611. int mytest()
  612. {
  613. char buf[20];
  614. return sprintf(buf, "%s", "foo");
  615. }
  616. int main()
  617. {
  618. return (mytest());
  619. }
  620. EOF
  621. if try $CC -c $CFLAGS $test.c; then
  622. echo "Checking for return value of sprintf()... Yes." | tee -a configure.log
  623. else
  624. CFLAGS="$CFLAGS -DHAS_sprintf_void"
  625. SFLAGS="$SFLAGS -DHAS_sprintf_void"
  626. echo "Checking for return value of sprintf()... No." | tee -a configure.log
  627. echo " WARNING: apparently sprintf() does not return a value. zlib" | tee -a configure.log
  628. echo " can build but will be open to possible string-format security" | tee -a configure.log
  629. echo " vulnerabilities." | tee -a configure.log
  630. fi
  631. fi
  632. fi
  633. # see if we can hide zlib internal symbols that are linked between separate source files
  634. if test "$gcc" -eq 1; then
  635. echo >> configure.log
  636. cat > $test.c <<EOF
  637. #define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
  638. int ZLIB_INTERNAL foo;
  639. int main()
  640. {
  641. return 0;
  642. }
  643. EOF
  644. if tryboth $CC -c $CFLAGS $test.c; then
  645. CFLAGS="$CFLAGS -DHAVE_HIDDEN"
  646. SFLAGS="$SFLAGS -DHAVE_HIDDEN"
  647. echo "Checking for attribute(visibility) support... Yes." | tee -a configure.log
  648. else
  649. echo "Checking for attribute(visibility) support... No." | tee -a configure.log
  650. fi
  651. fi
  652. echo >> configure.log
  653. # find a four-byte unsiged integer type for crc calculations
  654. cat > $test.c <<EOF
  655. #include <stdio.h>
  656. #define is32(n,t) for(n=1,k=0;n;n<<=1,k++);if(k==32){puts(t);return 0;}
  657. int main() {
  658. int k;
  659. unsigned i;
  660. unsigned long l;
  661. unsigned short s;
  662. is32(i, "unsigned")
  663. is32(l, "unsigned long")
  664. is32(s, "unsigned short")
  665. return 1;
  666. }
  667. EOF
  668. Z_U4=""
  669. if try $CC $CFLAGS $test.c -o $test && Z_U4=`./$test` && test -n "$Z_U4"; then
  670. sed < zconf.h "/#define Z_U4/s/\/\* \.\/configure may/#define Z_U4 $Z_U4 \/* .\/configure put the/" > zconf.temp.h
  671. mv zconf.temp.h zconf.h
  672. echo "Looking for a four-byte integer type... Found." | tee -a configure.log
  673. else
  674. echo "Looking for a four-byte integer type... Not found." | tee -a configure.log
  675. fi
  676. # clean up files produced by running the compiler and linker
  677. rm -f $test.[co] $test $test$shared_ext $test.gcno
  678. # show the results in the log
  679. echo >> configure.log
  680. echo ALL = $ALL >> configure.log
  681. echo AR = $AR >> configure.log
  682. echo ARFLAGS = $ARFLAGS >> configure.log
  683. echo CC = $CC >> configure.log
  684. echo CFLAGS = $CFLAGS >> configure.log
  685. echo CPP = $CPP >> configure.log
  686. echo EXE = $EXE >> configure.log
  687. echo LDCONFIG = $LDCONFIG >> configure.log
  688. echo LDFLAGS = $LDFLAGS >> configure.log
  689. echo LDSHARED = $LDSHARED >> configure.log
  690. echo LDSHAREDLIBC = $LDSHAREDLIBC >> configure.log
  691. echo OBJC = $OBJC >> configure.log
  692. echo PIC_OBJC = $PIC_OBJC >> configure.log
  693. echo RANLIB = $RANLIB >> configure.log
  694. echo SFLAGS = $SFLAGS >> configure.log
  695. echo SHAREDLIB = $SHAREDLIB >> configure.log
  696. echo SHAREDLIBM = $SHAREDLIBM >> configure.log
  697. echo SHAREDLIBV = $SHAREDLIBV >> configure.log
  698. echo STATICLIB = $STATICLIB >> configure.log
  699. echo TEST = $TEST >> configure.log
  700. echo VER = $VER >> configure.log
  701. echo Z_U4 = $Z_U4 >> configure.log
  702. echo exec_prefix = $exec_prefix >> configure.log
  703. echo includedir = $includedir >> configure.log
  704. echo libdir = $libdir >> configure.log
  705. echo mandir = $mandir >> configure.log
  706. echo prefix = $prefix >> configure.log
  707. echo sharedlibdir = $sharedlibdir >> configure.log
  708. echo uname = $uname >> configure.log
  709. echo -------------------- >> configure.log
  710. echo >> configure.log
  711. echo >> configure.log
  712. # udpate Makefile with the configure results
  713. sed < Makefile.in "
  714. /^CC *=/s#=.*#=$CC#
  715. /^CFLAGS *=/s#=.*#=$CFLAGS#
  716. /^SFLAGS *=/s#=.*#=$SFLAGS#
  717. /^LDFLAGS *=/s#=.*#=$LDFLAGS#
  718. /^LDSHARED *=/s#=.*#=$LDSHARED#
  719. /^CPP *=/s#=.*#=$CPP#
  720. /^STATICLIB *=/s#=.*#=$STATICLIB#
  721. /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
  722. /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
  723. /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
  724. /^AR *=/s#=.*#=$AR#
  725. /^ARFLAGS *=/s#=.*#=$ARFLAGS#
  726. /^RANLIB *=/s#=.*#=$RANLIB#
  727. /^LDCONFIG *=/s#=.*#=$LDCONFIG#
  728. /^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC#
  729. /^EXE *=/s#=.*#=$EXE#
  730. /^prefix *=/s#=.*#=$prefix#
  731. /^exec_prefix *=/s#=.*#=$exec_prefix#
  732. /^libdir *=/s#=.*#=$libdir#
  733. /^sharedlibdir *=/s#=.*#=$sharedlibdir#
  734. /^includedir *=/s#=.*#=$includedir#
  735. /^mandir *=/s#=.*#=$mandir#
  736. /^OBJC *=/s#=.*#= $OBJC#
  737. /^PIC_OBJC *=/s#=.*#= $PIC_OBJC#
  738. /^all: */s#:.*#: $ALL#
  739. /^test: */s#:.*#: $TEST#
  740. " > Makefile
  741. # create zlib.pc with the configure results
  742. sed < zlib.pc.in "
  743. /^CC *=/s#=.*#=$CC#
  744. /^CFLAGS *=/s#=.*#=$CFLAGS#
  745. /^CPP *=/s#=.*#=$CPP#
  746. /^LDSHARED *=/s#=.*#=$LDSHARED#
  747. /^STATICLIB *=/s#=.*#=$STATICLIB#
  748. /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
  749. /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
  750. /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
  751. /^AR *=/s#=.*#=$AR#
  752. /^ARFLAGS *=/s#=.*#=$ARFLAGS#
  753. /^RANLIB *=/s#=.*#=$RANLIB#
  754. /^EXE *=/s#=.*#=$EXE#
  755. /^prefix *=/s#=.*#=$prefix#
  756. /^exec_prefix *=/s#=.*#=$exec_prefix#
  757. /^libdir *=/s#=.*#=$libdir#
  758. /^sharedlibdir *=/s#=.*#=$sharedlibdir#
  759. /^includedir *=/s#=.*#=$includedir#
  760. /^mandir *=/s#=.*#=$mandir#
  761. /^LDFLAGS *=/s#=.*#=$LDFLAGS#
  762. " | sed -e "
  763. s/\@VERSION\@/$VER/g;
  764. " > zlib.pc