configure 27 KB

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