configure 25 KB

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