configure 28 KB

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