configure 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. #!/bin/sh
  2. # Copyright (C) 2008-2017 Cosmin Truta.
  3. #
  4. # This software is distributed under the zlib license.
  5. # Please see the accompanying LICENSE file.
  6. trap "rm -f conftest* core a.out; exit 1" 1 2 3 15
  7. LC_ALL=C
  8. export LC_ALL
  9. LANGUAGE=C
  10. export LANGUAGE
  11. prefix="${prefix-/usr/local}"
  12. exec_prefix="${exec_prefix-\$(prefix)}"
  13. bindir="${bindir-\$(exec_prefix)/bin}"
  14. mandir="${mandir-\$(prefix)/man}"
  15. man1dir="${man1dir-\$(mandir)/man1}"
  16. cc="${CC-gcc}"
  17. #cc="${CC-clang}"
  18. #cc="${CC-cc}"
  19. cflags="$CFLAGS"
  20. enable_debug=0
  21. with_system_libpng=0
  22. with_system_zlib=0
  23. with_preconfigured_libpng=1
  24. with_preconfigured_zlib=0
  25. unique_file=src/optipng/optipng.c
  26. for arg in "$@"
  27. do
  28. case "$arg" in
  29. -- )
  30. option="$arg"
  31. ;;
  32. --* )
  33. option=`expr "X$arg" : 'X-\(.*\)'`
  34. ;;
  35. * )
  36. option="$arg"
  37. ;;
  38. esac
  39. case "$arg" in
  40. *=* )
  41. optarg=`expr "X$arg" : 'X[^=]*=\(.*\)'`
  42. ;;
  43. * )
  44. optarg=""
  45. ;;
  46. esac
  47. case "$option" in
  48. -help | -hel | -he | -h )
  49. echo "Usage:"
  50. echo " $0 [options]"
  51. echo "Options:"
  52. echo " -h, -help Show this help"
  53. echo "Installation directories:"
  54. echo " -prefix=PREFIX Install architecture-independent files in PREFIX"
  55. echo " [default: $prefix]"
  56. echo " -exec-prefix=EPREFIX Install architecture-dependent files in EPREFIX"
  57. echo " [default: PREFIX]"
  58. echo " -bindir=DIR Install executable in DIR [default: EPREFIX/bin]"
  59. echo " -mandir=DIR Install manual in DIR [default: PREFIX/man]"
  60. echo "Optional features:"
  61. echo " -enable-debug Enable debug build flags and run-time checks"
  62. echo "Optional packages:"
  63. echo " -with-system-libs Use all system-supplied libraries (details below)"
  64. echo " -with-system-libpng Use the system-supplied libpng"
  65. echo " [default: false]"
  66. echo " -with-system-zlib Use the system-supplied zlib"
  67. echo " [default: with-system-libpng]"
  68. echo "Environment variables:"
  69. echo " CC C compiler command"
  70. echo " LD Linker command"
  71. echo " AR Library archiver command"
  72. echo " RANLIB Library indexer/randomizer command"
  73. echo " CFLAGS C compiler flags (e.g. -O3)"
  74. echo " CPPFLAGS C preprocessor flags (e.g. -I DIR)"
  75. echo " LDFLAGS Linker flags (e.g. -L DIR)"
  76. echo " ARFLAGS Library archiver flags (e.g. rcu)"
  77. echo " LIBS Additional libraries (e.g. -lfoo)"
  78. exit 0
  79. ;;
  80. -prefix | -prefi | -pref | -pre | -pr | -p )
  81. prefix="$2"
  82. shift
  83. ;;
  84. -prefix=* | -prefi=* | -pref=* | -pre=* | -pr=* | -p=* )
  85. prefix="$optarg"
  86. ;;
  87. -exec-prefix | -exec_prefix | -exec-prefi | -exec_prefi \
  88. | -exec-pref | -exec_pref | -exec-pre | -exec_pre \
  89. | -exec-pr | -exec_pr | -exec-p | -exec_p | exec- | -exec_ \
  90. | -exec | -exe | -ex | -e )
  91. exec_prefix="$2"
  92. shift
  93. ;;
  94. -exec-prefix=* | -exec_prefix=* | -exec-prefi=* | -exec_prefi=* \
  95. | -exec-pref=* | -exec_pref=* | -exec-pre=* | -exec_pre=* \
  96. | -exec-pr=* | -exec_pr=* | -exec-p=* | -exec_p=* | exec-=* | -exec_=* \
  97. | -exec=* | -exe=* | -ex=* | -e=* )
  98. exec_prefix="$optarg"
  99. ;;
  100. -bindir | -bindi | -bind | -bin | -bi | -b )
  101. bindir="$2"
  102. shift
  103. ;;
  104. -bindir=* | -bindi=* | -bind=* | -bin=* | -bi=* | -b=* )
  105. bindir="$optarg"
  106. ;;
  107. -mandir | -mandi | -mand | -man | -ma | -m )
  108. mandir="$2"
  109. shift
  110. ;;
  111. -mandir=* | -mandi=* | -mand=* | -man=* | -ma=* | -m=* )
  112. mandir="$optarg"
  113. ;;
  114. -enable-debug )
  115. enable_debug=1
  116. ;;
  117. -disable-debug )
  118. enable_debug=0
  119. ;;
  120. -with-system-libs )
  121. with_system_libpng=1
  122. with_system_zlib=1
  123. ;;
  124. -without-system-libs )
  125. with_system_zlib=0
  126. with_system_libpng=0
  127. ;;
  128. -with-system-libpng )
  129. with_system_libpng=1
  130. # Must use the system-supplied zlib with the system-supplied libpng.
  131. with_system_zlib=1
  132. ;;
  133. -without-system-libpng )
  134. with_system_libpng=0
  135. ;;
  136. -with-system-zlib )
  137. with_system_zlib=1
  138. ;;
  139. -without-system-zlib )
  140. with_system_zlib=0
  141. # Can't use the system-supplied libpng without the system-supplied zlib.
  142. with_system_libpng=0
  143. ;;
  144. * )
  145. echo "$0: error: unknown option: $arg"
  146. echo "Type \"$0 -help\" for help"
  147. exit 64 # EX_USAGE
  148. ;;
  149. esac
  150. done
  151. if test ! -f "$0"
  152. then
  153. echo "$0: error: cannot find myself; rerun with an absolute file name"
  154. exit 1
  155. fi
  156. if test ! -r "$unique_file"
  157. then
  158. echo "$0: error: cannot find: $unique_file"
  159. echo "$0: note: building outside the source directory tree is not supported"
  160. exit 1
  161. fi
  162. test=conftest$$
  163. cat > $test.c <<EOM
  164. int hello() { return 42; }
  165. EOM
  166. gccish=0
  167. case "$cc" in
  168. *gcc* | *clang* )
  169. echo "Checking for $cc..."
  170. if ($cc -c $cflags $test.c) 2>/dev/null
  171. then
  172. gccish=1
  173. fi
  174. ;;
  175. esac
  176. rm -f $test.c $test.o
  177. if test "$gccish" -ne 0
  178. then
  179. CC="${CC-$cc}"
  180. CFLAGS="${CFLAGS--O2 -Wall -Wextra}"
  181. else
  182. CC="${CC-cc}"
  183. CFLAGS="${CFLAGS--O}"
  184. fi
  185. if test "$enable_debug" -ne 0
  186. then
  187. CPPFLAGS="$CPPFLAGS -DDEBUG -D_DEBUG -DPNGX_DEBUG"
  188. CFLAGS="$CFLAGS -g"
  189. LDFLAGS="$LDFLAGS -g"
  190. fi
  191. if test "$with_system_libpng" -ne 0
  192. then
  193. USE_SYSTEM_LIBPNG_TRUE=""
  194. USE_SYSTEM_LIBPNG_FALSE="#"
  195. echo "Checking for system libpng..."
  196. test=conftest$$
  197. cat > $test.c <<EOM
  198. #include <png.h>
  199. #if PNG_LIBPNG_VER < 10209
  200. #error This program requires libpng version 1.2.9 or higher
  201. #endif
  202. int dummy;
  203. EOM
  204. ($CC -c $CPPFLAGS $CFLAGS $test.c) 2>/dev/null
  205. status=$?
  206. rm -f $test.c $test.o
  207. if test $status -ne 0
  208. then
  209. echo "$0: error: missing libpng or incorrect libpng version"
  210. echo "$0: note: libpng version 1.2.9 or higher is required"
  211. exit 1
  212. fi
  213. else
  214. USE_SYSTEM_LIBPNG_TRUE="#"
  215. USE_SYSTEM_LIBPNG_FALSE=""
  216. if test "$with_preconfigured_libpng" -ne 0
  217. then
  218. echo "Using pre-configured libpng..."
  219. libpng_preconfig_makefile=scripts/makefile.gcc
  220. if test ! -f "src/libpng/$libpng_preconfig_makefile"
  221. then
  222. echo "$0: warning: cannot find: src/libpng/$libpng_preconfig_makefile"
  223. with_preconfigured_libpng=0
  224. fi
  225. fi
  226. if test "$with_preconfigured_libpng" -ne 0
  227. then
  228. sed_preconfig_libpng=""
  229. if test "$CC"
  230. then
  231. sed_preconfig_libpng="
  232. $sed_preconfig_libpng
  233. s|^CC *=.*|CC = $CC|
  234. "
  235. fi
  236. if test "$CFLAGS"
  237. then
  238. sed_preconfig_libpng="
  239. $sed_preconfig_libpng
  240. s|^CFLAGS *=.*|CFLAGS = $CFLAGS|
  241. "
  242. fi
  243. if test "$CPPFLAGS"
  244. then
  245. sed_preconfig_libpng="
  246. $sed_preconfig_libpng
  247. s|^CPPFLAGS *=.*|CPPFLAGS = $CPPFLAGS|
  248. "
  249. fi
  250. if test "$LD"
  251. then
  252. sed_preconfig_libpng="
  253. $sed_preconfig_libpng
  254. s|^LD *=.*|LD = $LD|
  255. "
  256. fi
  257. if test "$LDFLAGS"
  258. then
  259. sed_preconfig_libpng="
  260. $sed_preconfig_libpng
  261. s|^LDFLAGS *=.*|LDFLAGS = $LDFLAGS|
  262. "
  263. fi
  264. if test "$AR$ARFLAGS"
  265. then
  266. AR="${AR-ar}"
  267. ARFLAGS="${ARFLAGS-cru}"
  268. sed_preconfig_libpng="
  269. $sed_preconfig_libpng
  270. s|^AR *=.*|AR = $AR|
  271. s|^ARFLAGS *=.*|ARFLAGS = $ARFLAGS|
  272. s|^AR_\([A-Z]*\) *=.*|AR_\1 = $AR $ARFLAGS|
  273. "
  274. fi
  275. if test "$RANLIB"
  276. then
  277. sed_preconfig_libpng="
  278. $sed_preconfig_libpng
  279. s|^RANLIB *=.*|RANLIB = $RANLIB|
  280. "
  281. fi
  282. sed "$sed_preconfig_libpng" \
  283. src/libpng/$libpng_preconfig_makefile > src/libpng/Makefile
  284. LIBPNG_MK=Makefile
  285. # The pre-configured makefiles in libpng don't do distclean.
  286. LIBPNG_DISTCLEAN="clean"
  287. LIBPNG_DISTCLEAN_XCMD="\$(RM_F) \$(LIBPNG_MK)"
  288. else
  289. echo "Configuring libpng..."
  290. (cd src/libpng && ./configure)
  291. if test $? -ne 0
  292. then
  293. echo "$0: error: could not configure: libpng"
  294. exit 1
  295. fi
  296. fi
  297. fi
  298. if test "$with_system_zlib" -ne 0
  299. then
  300. USE_SYSTEM_ZLIB_TRUE=""
  301. USE_SYSTEM_ZLIB_FALSE="#"
  302. echo "Checking for system zlib..."
  303. test=conftest$$
  304. cat > $test.c <<EOM
  305. #include <zlib.h>
  306. #if ZLIB_VERNUM < 0x1210
  307. #error This program requires zlib version 1.2.1 or higher.
  308. #endif
  309. int dummy;
  310. EOM
  311. ($CC -c $CPPFLAGS $CFLAGS $test.c) 2>/dev/null
  312. status=$?
  313. rm -f $test.c $test.o
  314. if test $status -ne 0
  315. then
  316. echo "$0: error: missing zlib or incorrect zlib version"
  317. echo "$0: note: zlib version 1.2.1 or higher is required"
  318. exit 1
  319. fi
  320. else
  321. USE_SYSTEM_ZLIB_TRUE="#"
  322. USE_SYSTEM_ZLIB_FALSE=""
  323. case `(uname -s) 2>/dev/null || echo unknown` in
  324. mingw* | MINGW* | windows* | WINDOWS* )
  325. with_preconfigured_zlib=1
  326. ZLIB_MK=win32/Makefile.gcc
  327. # This pre-configured makefile doesn't do distclean.
  328. ZLIB_DISTCLEAN=clean
  329. ;;
  330. *djgpp | *DJGPP | *dos | *DOS )
  331. with_preconfigured_zlib=1
  332. ZLIB_MK=msdos/Makefile.dj2
  333. # This pre-configured makefile doesn't do distclean.
  334. ZLIB_DISTCLEAN=clean
  335. ;;
  336. * )
  337. with_preconfigured_zlib=0
  338. ZLIB_MK=Makefile
  339. ZLIB_DISTCLEAN=distclean
  340. esac
  341. if test "$with_preconfigured_zlib" -ne 0
  342. then
  343. echo "Using pre-configured zlib..."
  344. if test ! -f "src/zlib/$ZLIB_MK"
  345. then
  346. echo "$0: error: cannot find: src/zlib/$ZLIB_MK"
  347. exit 1
  348. fi
  349. else
  350. echo "Configuring zlib..."
  351. (cd src/zlib && ./configure --static)
  352. if test $? -ne 0
  353. then
  354. echo "$0: error: could not configure: zlib"
  355. exit 1
  356. fi
  357. fi
  358. fi
  359. sed_config="
  360. s|@prefix@|$prefix|g
  361. s|@exec_prefix@|$exec_prefix|g
  362. s|@bindir@|$bindir|g
  363. s|@mandir@|$mandir|g
  364. s|@man1dir@|$man1dir|g
  365. s|@USE_SYSTEM_LIBPNG_FALSE@|$USE_SYSTEM_LIBPNG_FALSE|g
  366. s|@USE_SYSTEM_LIBPNG_TRUE@|$USE_SYSTEM_LIBPNG_TRUE|g
  367. s|@USE_SYSTEM_ZLIB_FALSE@|$USE_SYSTEM_ZLIB_FALSE|g
  368. s|@USE_SYSTEM_ZLIB_TRUE@|$USE_SYSTEM_ZLIB_TRUE|g
  369. s|@CC@|${CC-cc}|g
  370. s|@CFLAGS@|${CFLAGS--O}|g
  371. s|@CPP@|${CPP-\$(CC) -E}|g
  372. s|@CPPFLAGS@|${CPPFLAGS-}|g
  373. s|@LD@|${LD-\$(CC)}|g
  374. s|@LDFLAGS@|${LDFLAGS--s}|g
  375. s|@AR@|${AR-ar}|g
  376. s|@ARFLAGS@|${ARFLAGS-cru}|g
  377. s|@RANLIB@|${RANLIB-ranlib}|g
  378. s|@CP_FP@|${CP_FP-cp -f -p}|g
  379. s|@MKDIR_P@|${MKDIR_P-mkdir -p}|g
  380. s|@RM_F@|${RM_F-rm -f}|g
  381. s|@LIBM@|${LIBM--lm}|g
  382. s|@LIBPNG@|${LIBPNG--lpng}|g
  383. s|@LIBS@|${LIBS-}|g
  384. s|@LIBZ@|${LIBZ--lz}|g
  385. s|@LIBPNG_DISTCLEAN@|${LIBPNG_DISTCLEAN-distclean}|g
  386. s|@LIBPNG_DISTCLEAN_XCMD@|${LIBPNG_DISTCLEAN_XCMD-true}|g
  387. s|@LIBPNG_MK@|${LIBPNG_MK-Makefile}|g
  388. s|@LIBPNG_MK_DEF@|${LIBPNG_MK_DEF-PNGLIBCONF_H_PREBUILT=pnglibconf.h.optipng}|g
  389. s|@ZLIB_DISTCLEAN@|${ZLIB_DISTCLEAN-distclean}|g
  390. s|@ZLIB_MK@|${ZLIB_MK-Makefile}|g
  391. s|@[A-Z]*_MK@|Makefile|g
  392. s| *\$||
  393. "
  394. for makefile in \
  395. ./Makefile \
  396. src/Makefile \
  397. src/gifread/Makefile \
  398. src/minitiff/Makefile \
  399. src/opngreduc/Makefile \
  400. src/optipng/Makefile \
  401. src/optipng/man/Makefile \
  402. src/pngxtern/Makefile \
  403. src/pnmio/Makefile
  404. do
  405. sed "$sed_config" $makefile.in > $makefile
  406. done