configure 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. #!/bin/sh
  2. # configure script for zlib. This script is needed only if
  3. # you wish to build a shared library and your system supports them,
  4. # of if you need special compiler, flags or install directory.
  5. # Otherwise, you can just use directly "make test; make install"
  6. #
  7. # To create a shared library, use "configure --shared"; by default a static
  8. # library is created. If the primitive shared library support provided here
  9. # does not work, use ftp://prep.ai.mit.edu/pub/gnu/libtool-*.tar.gz
  10. #
  11. # To impose specific compiler or flags or install directory, use for example:
  12. # prefix=$HOME CC=cc CFLAGS="-O4" ./configure
  13. # or for csh/tcsh users:
  14. # (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure)
  15. # LDSHARED is the command to be used to create a shared library
  16. # Incorrect settings of CC or CFLAGS may prevent creating a shared library.
  17. # If you have problems, try without defining CC and CFLAGS before reporting
  18. # an error.
  19. LIBS=libz.a
  20. LDFLAGS="-L. ${LIBS}"
  21. VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
  22. VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h`
  23. VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h`
  24. AR=${AR-"ar rc"}
  25. RANLIB=${RANLIB-"ranlib"}
  26. prefix=${prefix-/usr/local}
  27. exec_prefix=${exec_prefix-'${prefix}'}
  28. libdir=${libdir-'${exec_prefix}/lib'}
  29. includedir=${includedir-'${prefix}/include'}
  30. mandir=${mandir-'${prefix}/share/man'}
  31. shared_ext='.so'
  32. shared=0
  33. gcc=0
  34. old_cc="$CC"
  35. old_cflags="$CFLAGS"
  36. while test $# -ge 1
  37. do
  38. case "$1" in
  39. -h* | --h*)
  40. echo 'usage:'
  41. echo ' configure [--shared] [--prefix=PREFIX] [--exec_prefix=EXPREFIX]'
  42. echo ' [--libdir=LIBDIR] [--includedir=INCLUDEDIR]'
  43. exit 0;;
  44. -p*=* | --p*=*) prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift;;
  45. -e*=* | --e*=*) exec_prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift;;
  46. -l*=* | --libdir=*) libdir=`echo $1 | sed 's/[-a-z_]*=//'`; shift;;
  47. -i*=* | --includedir=*) includedir=`echo $1 | sed 's/[-a-z_]*=//'`;shift;;
  48. -p* | --p*) prefix="$2"; shift; shift;;
  49. -e* | --e*) exec_prefix="$2"; shift; shift;;
  50. -l* | --l*) libdir="$2"; shift; shift;;
  51. -i* | --i*) includedir="$2"; shift; shift;;
  52. -s* | --s*) shared=1; shift;;
  53. *) echo "unknown option: $1"; echo "$0 --help for help"; exit 1;;
  54. esac
  55. done
  56. test=ztest$$
  57. cat > $test.c <<EOF
  58. extern int getchar();
  59. int hello() {return getchar();}
  60. EOF
  61. test -z "$CC" && echo Checking for gcc...
  62. cc=${CC-gcc}
  63. cflags=${CFLAGS-"-O3"}
  64. # to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
  65. case "$cc" in
  66. *gcc*) gcc=1;;
  67. esac
  68. if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
  69. CC="$cc"
  70. SFLAGS=${CFLAGS-"-fPIC -O3"}
  71. CFLAGS="$cflags"
  72. case `(uname -s || echo unknown) 2>/dev/null` in
  73. Linux | linux | GNU | GNU/*) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1"};;
  74. CYGWIN* | Cygwin* | cygwin* | OS/2* )
  75. EXE='.exe';;
  76. QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
  77. # (alain.bonnefoy@icbt.com)
  78. LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"};;
  79. HP-UX*)
  80. LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
  81. case `(uname -m || echo unknown) 2>/dev/null` in
  82. ia64)
  83. shared_ext='.so'
  84. SHAREDLIB='libz.so';;
  85. *)
  86. shared_ext='.sl'
  87. SHAREDLIB='libz.sl';;
  88. esac;;
  89. Darwin*) shared_ext='.dylib'
  90. SHAREDLIB=libz$shared_ext
  91. SHAREDLIBV=libz.$VER$shared_ext
  92. SHAREDLIBM=libz.$VER1$shared_ext
  93. LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER"};;
  94. *) LDSHARED=${LDSHARED-"$cc -shared"};;
  95. esac
  96. else
  97. # find system name and corresponding cc options
  98. CC=${CC-cc}
  99. case `(uname -sr || echo unknown) 2>/dev/null` in
  100. HP-UX*) SFLAGS=${CFLAGS-"-O +z"}
  101. CFLAGS=${CFLAGS-"-O"}
  102. # LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
  103. LDSHARED=${LDSHARED-"ld -b"}
  104. case `(uname -m || echo unknown) 2>/dev/null` in
  105. ia64)
  106. shared_ext='.so'
  107. SHAREDLIB='libz.so';;
  108. *)
  109. shared_ext='.sl'
  110. SHAREDLIB='libz.sl';;
  111. esac;;
  112. IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
  113. CFLAGS=${CFLAGS-"-ansi -O2"}
  114. LDSHARED=${LDSHARED-"cc -shared"};;
  115. OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
  116. CFLAGS=${CFLAGS-"-O -std1"}
  117. LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"};;
  118. OSF1*) SFLAGS=${CFLAGS-"-O -std1"}
  119. CFLAGS=${CFLAGS-"-O -std1"}
  120. LDSHARED=${LDSHARED-"cc -shared"};;
  121. QNX*) SFLAGS=${CFLAGS-"-4 -O"}
  122. CFLAGS=${CFLAGS-"-4 -O"}
  123. LDSHARED=${LDSHARED-"cc"}
  124. RANLIB=${RANLIB-"true"}
  125. AR="cc -A";;
  126. SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
  127. CFLAGS=${CFLAGS-"-O3"}
  128. LDSHARED=${LDSHARED-"cc -dy -KPIC -G"};;
  129. SunOS\ 5*) SFLAGS=${CFLAGS-"-fast -xcg89 -KPIC -R."}
  130. CFLAGS=${CFLAGS-"-fast -xcg89"}
  131. LDSHARED=${LDSHARED-"cc -G"};;
  132. SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
  133. CFLAGS=${CFLAGS-"-O2"}
  134. LDSHARED=${LDSHARED-"ld"};;
  135. SunStudio\ 9*) SFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
  136. CFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xtarget=ultra3 -xarch=v9b"}
  137. LDSHARED=${LDSHARED-"cc -xarch=v9b"};;
  138. UNIX_System_V\ 4.2.0)
  139. SFLAGS=${CFLAGS-"-KPIC -O"}
  140. CFLAGS=${CFLAGS-"-O"}
  141. LDSHARED=${LDSHARED-"cc -G"};;
  142. UNIX_SV\ 4.2MP)
  143. SFLAGS=${CFLAGS-"-Kconform_pic -O"}
  144. CFLAGS=${CFLAGS-"-O"}
  145. LDSHARED=${LDSHARED-"cc -G"};;
  146. OpenUNIX\ 5)
  147. SFLAGS=${CFLAGS-"-KPIC -O"}
  148. CFLAGS=${CFLAGS-"-O"}
  149. LDSHARED=${LDSHARED-"cc -G"};;
  150. AIX*) # Courtesy of dbakker@arrayasolutions.com
  151. SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
  152. CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
  153. LDSHARED=${LDSHARED-"xlc -G"};;
  154. # send working options for other systems to support@gzip.org
  155. *) SFLAGS=${CFLAGS-"-O"}
  156. CFLAGS=${CFLAGS-"-O"}
  157. LDSHARED=${LDSHARED-"cc -shared"};;
  158. esac
  159. fi
  160. SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
  161. SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
  162. SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
  163. if test $shared -eq 1; then
  164. echo Checking for shared library support...
  165. # we must test in two steps (cc then ld), required at least on SunOS 4.x
  166. if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" &&
  167. test "`($LDSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then
  168. CFLAGS="$SFLAGS"
  169. LIBS="$SHAREDLIBV"
  170. echo Building shared library $SHAREDLIBV with $CC.
  171. elif test -z "$old_cc" -a -z "$old_cflags"; then
  172. echo No shared library support.
  173. shared=0;
  174. else
  175. echo 'No shared library support; try without defining CC and CFLAGS'
  176. shared=0;
  177. fi
  178. fi
  179. if test $shared -eq 0; then
  180. LDSHARED="$CC"
  181. echo Building static library $LIBS version $VER with $CC.
  182. else
  183. LDFLAGS="-L. ${SHAREDLIBV}"
  184. fi
  185. cat > $test.c <<EOF
  186. #include <unistd.h>
  187. int main() { return 0; }
  188. EOF
  189. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  190. sed < zconf.in.h "/HAVE_UNISTD_H/s%0%1%" > zconf.h
  191. echo "Checking for unistd.h... Yes."
  192. else
  193. cp -p zconf.in.h zconf.h
  194. echo "Checking for unistd.h... No."
  195. fi
  196. cat > $test.c <<EOF
  197. #include <stdio.h>
  198. #include <stdarg.h>
  199. #include "zconf.h"
  200. int main()
  201. {
  202. #ifndef STDC
  203. choke me
  204. #endif
  205. return 0;
  206. }
  207. EOF
  208. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  209. echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()"
  210. cat > $test.c <<EOF
  211. #include <stdio.h>
  212. #include <stdarg.h>
  213. int mytest(char *fmt, ...)
  214. {
  215. char buf[20];
  216. va_list ap;
  217. va_start(ap, fmt);
  218. vsnprintf(buf, sizeof(buf), fmt, ap);
  219. va_end(ap);
  220. return 0;
  221. }
  222. int main()
  223. {
  224. return (mytest("Hello%d\n", 1));
  225. }
  226. EOF
  227. if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
  228. echo "Checking for vsnprintf() in stdio.h... Yes."
  229. cat >$test.c <<EOF
  230. #include <stdio.h>
  231. #include <stdarg.h>
  232. int mytest(char *fmt, ...)
  233. {
  234. int n;
  235. char buf[20];
  236. va_list ap;
  237. va_start(ap, fmt);
  238. n = vsnprintf(buf, sizeof(buf), fmt, ap);
  239. va_end(ap);
  240. return n;
  241. }
  242. int main()
  243. {
  244. return (mytest("Hello%d\n", 1));
  245. }
  246. EOF
  247. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  248. echo "Checking for return value of vsnprintf()... Yes."
  249. else
  250. CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
  251. echo "Checking for return value of vsnprintf()... No."
  252. echo " WARNING: apparently vsnprintf() does not return a value. zlib"
  253. echo " can build but will be open to possible string-format security"
  254. echo " vulnerabilities."
  255. fi
  256. else
  257. CFLAGS="$CFLAGS -DNO_vsnprintf"
  258. echo "Checking for vsnprintf() in stdio.h... No."
  259. echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib"
  260. echo " can build but will be open to possible buffer-overflow security"
  261. echo " vulnerabilities."
  262. cat >$test.c <<EOF
  263. #include <stdio.h>
  264. #include <stdarg.h>
  265. int mytest(char *fmt, ...)
  266. {
  267. int n;
  268. char buf[20];
  269. va_list ap;
  270. va_start(ap, fmt);
  271. n = vsprintf(buf, fmt, ap);
  272. va_end(ap);
  273. return n;
  274. }
  275. int main()
  276. {
  277. return (mytest("Hello%d\n", 1));
  278. }
  279. EOF
  280. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  281. echo "Checking for return value of vsprintf()... Yes."
  282. else
  283. CFLAGS="$CFLAGS -DHAS_vsprintf_void"
  284. echo "Checking for return value of vsprintf()... No."
  285. echo " WARNING: apparently vsprintf() does not return a value. zlib"
  286. echo " can build but will be open to possible string-format security"
  287. echo " vulnerabilities."
  288. fi
  289. fi
  290. else
  291. echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()"
  292. cat >$test.c <<EOF
  293. #include <stdio.h>
  294. int mytest()
  295. {
  296. char buf[20];
  297. snprintf(buf, sizeof(buf), "%s", "foo");
  298. return 0;
  299. }
  300. int main()
  301. {
  302. return (mytest());
  303. }
  304. EOF
  305. if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
  306. echo "Checking for snprintf() in stdio.h... Yes."
  307. cat >$test.c <<EOF
  308. #include <stdio.h>
  309. int mytest()
  310. {
  311. char buf[20];
  312. return snprintf(buf, sizeof(buf), "%s", "foo");
  313. }
  314. int main()
  315. {
  316. return (mytest());
  317. }
  318. EOF
  319. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  320. echo "Checking for return value of snprintf()... Yes."
  321. else
  322. CFLAGS="$CFLAGS -DHAS_snprintf_void"
  323. echo "Checking for return value of snprintf()... No."
  324. echo " WARNING: apparently snprintf() does not return a value. zlib"
  325. echo " can build but will be open to possible string-format security"
  326. echo " vulnerabilities."
  327. fi
  328. else
  329. CFLAGS="$CFLAGS -DNO_snprintf"
  330. echo "Checking for snprintf() in stdio.h... No."
  331. echo " WARNING: snprintf() not found, falling back to sprintf(). zlib"
  332. echo " can build but will be open to possible buffer-overflow security"
  333. echo " vulnerabilities."
  334. cat >$test.c <<EOF
  335. #include <stdio.h>
  336. int mytest()
  337. {
  338. char buf[20];
  339. return sprintf(buf, "%s", "foo");
  340. }
  341. int main()
  342. {
  343. return (mytest());
  344. }
  345. EOF
  346. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  347. echo "Checking for return value of sprintf()... Yes."
  348. else
  349. CFLAGS="$CFLAGS -DHAS_sprintf_void"
  350. echo "Checking for return value of sprintf()... No."
  351. echo " WARNING: apparently sprintf() does not return a value. zlib"
  352. echo " can build but will be open to possible string-format security"
  353. echo " vulnerabilities."
  354. fi
  355. fi
  356. fi
  357. cat >$test.c <<EOF
  358. #include <errno.h>
  359. int main() { return 0; }
  360. EOF
  361. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  362. echo "Checking for errno.h... Yes."
  363. else
  364. echo "Checking for errno.h... No."
  365. CFLAGS="$CFLAGS -DNO_ERRNO_H"
  366. fi
  367. cat > $test.c <<EOF
  368. #include <sys/types.h>
  369. #include <sys/mman.h>
  370. #include <sys/stat.h>
  371. caddr_t hello() {
  372. return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
  373. }
  374. EOF
  375. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  376. CFLAGS="$CFLAGS -DUSE_MMAP"
  377. echo Checking for mmap support... Yes.
  378. else
  379. echo Checking for mmap support... No.
  380. fi
  381. CPP=${CPP-"$CC -E"}
  382. case $CFLAGS in
  383. *ASMV*)
  384. if test "`nm $test.o | grep _hello`" = ""; then
  385. CPP="$CPP -DNO_UNDERLINE"
  386. echo Checking for underline in external names... No.
  387. else
  388. echo Checking for underline in external names... Yes.
  389. fi;;
  390. esac
  391. rm -f $test.[co] $test $test$shared_ext
  392. # udpate Makefile
  393. sed < Makefile.in "
  394. /^CC *=/s#=.*#=$CC#
  395. /^CFLAGS *=/s#=.*#=$CFLAGS#
  396. /^CPP *=/s#=.*#=$CPP#
  397. /^LDSHARED *=/s#=.*#=$LDSHARED#
  398. /^LIBS *=/s#=.*#=$LIBS#
  399. /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
  400. /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
  401. /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
  402. /^AR *=/s#=.*#=$AR#
  403. /^RANLIB *=/s#=.*#=$RANLIB#
  404. /^EXE *=/s#=.*#=$EXE#
  405. /^prefix *=/s#=.*#=$prefix#
  406. /^exec_prefix *=/s#=.*#=$exec_prefix#
  407. /^libdir *=/s#=.*#=$libdir#
  408. /^includedir *=/s#=.*#=$includedir#
  409. /^mandir *=/s#=.*#=$mandir#
  410. /^LDFLAGS *=/s#=.*#=$LDFLAGS#
  411. " > Makefile