Guest User

Untitled

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