configure 28 KB

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