configure 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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* )
  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*) LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
  80. shared_ext='.sl'
  81. SHAREDLIB='libz.sl';;
  82. Darwin*) shared_ext='.dylib'
  83. SHAREDLIB=libz$shared_ext
  84. SHAREDLIBV=libz.$VER$shared_ext
  85. SHAREDLIBM=libz.$VER1$shared_ext
  86. LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name /usr/lib/$SHAREDLIBV -compatibility_version $VER2 -current_version $VER"}
  87. libdir='/usr/lib'
  88. includedir='/usr/include';;
  89. *) LDSHARED=${LDSHARED-"$cc -shared"};;
  90. esac
  91. else
  92. # find system name and corresponding cc options
  93. CC=${CC-cc}
  94. case `(uname -sr || echo unknown) 2>/dev/null` in
  95. HP-UX*) SFLAGS=${CFLAGS-"-O +z"}
  96. CFLAGS=${CFLAGS-"-O"}
  97. # LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
  98. LDSHARED=${LDSHARED-"ld -b"}
  99. shared_ext='.sl'
  100. SHAREDLIB='libz.sl';;
  101. IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
  102. CFLAGS=${CFLAGS-"-ansi -O2"}
  103. LDSHARED=${LDSHARED-"cc -shared"};;
  104. OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
  105. CFLAGS=${CFLAGS-"-O -std1"}
  106. LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"};;
  107. OSF1*) SFLAGS=${CFLAGS-"-O -std1"}
  108. CFLAGS=${CFLAGS-"-O -std1"}
  109. LDSHARED=${LDSHARED-"cc -shared"};;
  110. QNX*) SFLAGS=${CFLAGS-"-4 -O"}
  111. CFLAGS=${CFLAGS-"-4 -O"}
  112. LDSHARED=${LDSHARED-"cc"}
  113. RANLIB=${RANLIB-"true"}
  114. AR="cc -A";;
  115. SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
  116. CFLAGS=${CFLAGS-"-O3"}
  117. LDSHARED=${LDSHARED-"cc -dy -KPIC -G"};;
  118. SunOS\ 5*) SFLAGS=${CFLAGS-"-fast -xcg89 -KPIC -R."}
  119. CFLAGS=${CFLAGS-"-fast -xcg89"}
  120. LDSHARED=${LDSHARED-"cc -G"};;
  121. SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
  122. CFLAGS=${CFLAGS-"-O2"}
  123. LDSHARED=${LDSHARED-"ld"};;
  124. UNIX_System_V\ 4.2.0)
  125. SFLAGS=${CFLAGS-"-KPIC -O"}
  126. CFLAGS=${CFLAGS-"-O"}
  127. LDSHARED=${LDSHARED-"cc -G"};;
  128. UNIX_SV\ 4.2MP)
  129. SFLAGS=${CFLAGS-"-Kconform_pic -O"}
  130. CFLAGS=${CFLAGS-"-O"}
  131. LDSHARED=${LDSHARED-"cc -G"};;
  132. OpenUNIX\ 5)
  133. SFLAGS=${CFLAGS-"-KPIC -O"}
  134. CFLAGS=${CFLAGS-"-O"}
  135. LDSHARED=${LDSHARED-"cc -G"};;
  136. AIX*) # Courtesy of dbakker@arrayasolutions.com
  137. SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
  138. CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
  139. LDSHARED=${LDSHARED-"xlc -G"};;
  140. # send working options for other systems to support@gzip.org
  141. *) SFLAGS=${CFLAGS-"-O"}
  142. CFLAGS=${CFLAGS-"-O"}
  143. LDSHARED=${LDSHARED-"cc -shared"};;
  144. esac
  145. fi
  146. SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
  147. SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
  148. SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
  149. if test $shared -eq 1; then
  150. echo Checking for shared library support...
  151. # we must test in two steps (cc then ld), required at least on SunOS 4.x
  152. if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" &&
  153. test "`($LDSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then
  154. CFLAGS="$SFLAGS"
  155. LIBS="$SHAREDLIBV"
  156. echo Building shared library $SHAREDLIBV with $CC.
  157. elif test -z "$old_cc" -a -z "$old_cflags"; then
  158. echo No shared library support.
  159. shared=0;
  160. else
  161. echo 'No shared library support; try without defining CC and CFLAGS'
  162. shared=0;
  163. fi
  164. fi
  165. if test $shared -eq 0; then
  166. LDSHARED="$CC"
  167. echo Building static library $LIBS version $VER with $CC.
  168. else
  169. LDFLAGS="-L. ${SHAREDLIBV}"
  170. fi
  171. cat > $test.c <<EOF
  172. #include <unistd.h>
  173. int main() { return 0; }
  174. EOF
  175. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  176. sed < zconf.in.h "/HAVE_UNISTD_H/s%0%1%" > zconf.h
  177. echo "Checking for unistd.h... Yes."
  178. else
  179. cp -p zconf.in.h zconf.h
  180. echo "Checking for unistd.h... No."
  181. fi
  182. cat > $test.c <<EOF
  183. #include <stdio.h>
  184. #include <stdarg.h>
  185. #include "zconf.h"
  186. int main()
  187. {
  188. #ifndef STDC
  189. choke me
  190. #endif
  191. return 0;
  192. }
  193. EOF
  194. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  195. echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()"
  196. cat > $test.c <<EOF
  197. #include <stdio.h>
  198. #include <stdarg.h>
  199. int mytest(char *fmt, ...)
  200. {
  201. char buf[20];
  202. va_list ap;
  203. va_start(ap, fmt);
  204. vsnprintf(buf, sizeof(buf), fmt, ap);
  205. va_end(ap);
  206. return 0;
  207. }
  208. int main()
  209. {
  210. return (mytest("Hello%d\n", 1));
  211. }
  212. EOF
  213. if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
  214. echo "Checking for vsnprintf() in stdio.h... Yes."
  215. cat >$test.c <<EOF
  216. #include <stdio.h>
  217. #include <stdarg.h>
  218. int mytest(char *fmt, ...)
  219. {
  220. int n;
  221. char buf[20];
  222. va_list ap;
  223. va_start(ap, fmt);
  224. n = vsnprintf(buf, sizeof(buf), fmt, ap);
  225. va_end(ap);
  226. return n;
  227. }
  228. int main()
  229. {
  230. return (mytest("Hello%d\n", 1));
  231. }
  232. EOF
  233. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  234. echo "Checking for return value of vsnprintf()... Yes."
  235. else
  236. CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
  237. echo "Checking for return value of vsnprintf()... No."
  238. echo " WARNING: apparently vsnprintf() does not return a value. zlib"
  239. echo " can build but will be open to possible string-format security"
  240. echo " vulnerabilities."
  241. fi
  242. else
  243. CFLAGS="$CFLAGS -DNO_vsnprintf"
  244. echo "Checking for vsnprintf() in stdio.h... No."
  245. echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib"
  246. echo " can build but will be open to possible buffer-overflow security"
  247. echo " vulnerabilities."
  248. cat >$test.c <<EOF
  249. #include <stdio.h>
  250. #include <stdarg.h>
  251. int mytest(char *fmt, ...)
  252. {
  253. int n;
  254. char buf[20];
  255. va_list ap;
  256. va_start(ap, fmt);
  257. n = vsprintf(buf, fmt, ap);
  258. va_end(ap);
  259. return n;
  260. }
  261. int main()
  262. {
  263. return (mytest("Hello%d\n", 1));
  264. }
  265. EOF
  266. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  267. echo "Checking for return value of vsprintf()... Yes."
  268. else
  269. CFLAGS="$CFLAGS -DHAS_vsprintf_void"
  270. echo "Checking for return value of vsprintf()... No."
  271. echo " WARNING: apparently vsprintf() does not return a value. zlib"
  272. echo " can build but will be open to possible string-format security"
  273. echo " vulnerabilities."
  274. fi
  275. fi
  276. else
  277. echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()"
  278. cat >$test.c <<EOF
  279. #include <stdio.h>
  280. int mytest()
  281. {
  282. char buf[20];
  283. snprintf(buf, sizeof(buf), "%s", "foo");
  284. return 0;
  285. }
  286. int main()
  287. {
  288. return (mytest());
  289. }
  290. EOF
  291. if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
  292. echo "Checking for snprintf() in stdio.h... Yes."
  293. cat >$test.c <<EOF
  294. #include <stdio.h>
  295. int mytest()
  296. {
  297. char buf[20];
  298. return snprintf(buf, sizeof(buf), "%s", "foo");
  299. }
  300. int main()
  301. {
  302. return (mytest());
  303. }
  304. EOF
  305. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  306. echo "Checking for return value of snprintf()... Yes."
  307. else
  308. CFLAGS="$CFLAGS -DHAS_snprintf_void"
  309. echo "Checking for return value of snprintf()... No."
  310. echo " WARNING: apparently snprintf() does not return a value. zlib"
  311. echo " can build but will be open to possible string-format security"
  312. echo " vulnerabilities."
  313. fi
  314. else
  315. CFLAGS="$CFLAGS -DNO_snprintf"
  316. echo "Checking for snprintf() in stdio.h... No."
  317. echo " WARNING: snprintf() not found, falling back to sprintf(). zlib"
  318. echo " can build but will be open to possible buffer-overflow security"
  319. echo " vulnerabilities."
  320. cat >$test.c <<EOF
  321. #include <stdio.h>
  322. int mytest()
  323. {
  324. char buf[20];
  325. return sprintf(buf, "%s", "foo");
  326. }
  327. int main()
  328. {
  329. return (mytest());
  330. }
  331. EOF
  332. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  333. echo "Checking for return value of sprintf()... Yes."
  334. else
  335. CFLAGS="$CFLAGS -DHAS_sprintf_void"
  336. echo "Checking for return value of sprintf()... No."
  337. echo " WARNING: apparently sprintf() does not return a value. zlib"
  338. echo " can build but will be open to possible string-format security"
  339. echo " vulnerabilities."
  340. fi
  341. fi
  342. fi
  343. cat >$test.c <<EOF
  344. #include <errno.h>
  345. int main() { return 0; }
  346. EOF
  347. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  348. echo "Checking for errno.h... Yes."
  349. else
  350. echo "Checking for errno.h... No."
  351. CFLAGS="$CFLAGS -DNO_ERRNO_H"
  352. fi
  353. cat > $test.c <<EOF
  354. #include <sys/types.h>
  355. #include <sys/mman.h>
  356. #include <sys/stat.h>
  357. caddr_t hello() {
  358. return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
  359. }
  360. EOF
  361. if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
  362. CFLAGS="$CFLAGS -DUSE_MMAP"
  363. echo Checking for mmap support... Yes.
  364. else
  365. echo Checking for mmap support... No.
  366. fi
  367. CPP=${CPP-"$CC -E"}
  368. case $CFLAGS in
  369. *ASMV*)
  370. if test "`nm $test.o | grep _hello`" = ""; then
  371. CPP="$CPP -DNO_UNDERLINE"
  372. echo Checking for underline in external names... No.
  373. else
  374. echo Checking for underline in external names... Yes.
  375. fi;;
  376. esac
  377. rm -f $test.[co] $test $test$shared_ext
  378. # udpate Makefile
  379. sed < Makefile.in "
  380. /^CC *=/s#=.*#=$CC#
  381. /^CFLAGS *=/s#=.*#=$CFLAGS#
  382. /^CPP *=/s#=.*#=$CPP#
  383. /^LDSHARED *=/s#=.*#=$LDSHARED#
  384. /^LIBS *=/s#=.*#=$LIBS#
  385. /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
  386. /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
  387. /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
  388. /^AR *=/s#=.*#=$AR#
  389. /^RANLIB *=/s#=.*#=$RANLIB#
  390. /^EXE *=/s#=.*#=$EXE#
  391. /^prefix *=/s#=.*#=$prefix#
  392. /^exec_prefix *=/s#=.*#=$exec_prefix#
  393. /^libdir *=/s#=.*#=$libdir#
  394. /^includedir *=/s#=.*#=$includedir#
  395. /^mandir *=/s#=.*#=$mandir#
  396. /^LDFLAGS *=/s#=.*#=$LDFLAGS#
  397. " > Makefile