autogen.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. #! /bin/sh
  2. # autogen.sh
  3. # Copyright (C) 2003, 2014 g10 Code GmbH
  4. #
  5. # This file is free software; as a special exception the author gives
  6. # unlimited permission to copy and/or distribute it, with or without
  7. # modifications, as long as this notice is preserved.
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
  11. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. #
  13. # This is a generic script to create the configure script and handle cross
  14. # build environments. It requires the presence of a autogen.rc file to
  15. # configure it for the respective package. It is maintained as part of
  16. # GnuPG and source copied by other packages.
  17. #
  18. # Version: 2014-06-06
  19. configure_ac="configure.ac"
  20. cvtver () {
  21. awk 'NR==1 {split($NF,A,".");X=1000000*A[1]+1000*A[2]+A[3];print X;exit 0}'
  22. }
  23. check_version () {
  24. if [ $(( `("$1" --version || echo "0") | cvtver` >= $2 )) = 1 ]; then
  25. return 0
  26. fi
  27. echo "**Error**: "\`$1\'" not installed or too old." >&2
  28. echo ' Version '$3' or newer is required.' >&2
  29. [ -n "$4" ] && echo ' Note that this is part of '\`$4\''.' >&2
  30. DIE="yes"
  31. return 1
  32. }
  33. fatal () {
  34. echo "autogen.sh:" "$*" >&2
  35. DIE=yes
  36. }
  37. info () {
  38. if [ -z "${SILENT}" ]; then
  39. echo "autogen.sh:" "$*" >&2
  40. fi
  41. }
  42. die_p () {
  43. if [ "$DIE" = "yes" ]; then
  44. echo "autogen.sh: Stop." >&2
  45. exit 1
  46. fi
  47. }
  48. replace_sysroot () {
  49. configure_opts=$(echo $configure_opts | sed "s#@SYSROOT@#${w32root}#g")
  50. extraoptions=$(echo $extraoptions | sed "s#@SYSROOT@#${w32root}#g")
  51. }
  52. # Allow to override the default tool names
  53. AUTOCONF=${AUTOCONF_PREFIX}${AUTOCONF:-autoconf}${AUTOCONF_SUFFIX}
  54. AUTOHEADER=${AUTOCONF_PREFIX}${AUTOHEADER:-autoheader}${AUTOCONF_SUFFIX}
  55. AUTOMAKE=${AUTOMAKE_PREFIX}${AUTOMAKE:-automake}${AUTOMAKE_SUFFIX}
  56. ACLOCAL=${AUTOMAKE_PREFIX}${ACLOCAL:-aclocal}${AUTOMAKE_SUFFIX}
  57. GETTEXT=${GETTEXT_PREFIX}${GETTEXT:-gettext}${GETTEXT_SUFFIX}
  58. MSGMERGE=${GETTEXT_PREFIX}${MSGMERGE:-msgmerge}${GETTEXT_SUFFIX}
  59. DIE=no
  60. FORCE=
  61. SILENT=
  62. PRINT_HOST=no
  63. PRINT_BUILD=no
  64. tmp=$(dirname "$0")
  65. tsdir=$(cd "${tmp}"; pwd)
  66. version_parts=3
  67. if [ -n "${AUTOGEN_SH_SILENT}" ]; then
  68. SILENT=" --silent"
  69. fi
  70. if test x"$1" = x"--help"; then
  71. echo "usage: ./autogen.sh [--silent] [--force] [--build-TYPE] [ARGS]"
  72. exit 0
  73. fi
  74. if test x"$1" = x"--silent"; then
  75. SILENT=" --silent"
  76. shift
  77. fi
  78. if test x"$1" = x"--force"; then
  79. FORCE=" --force"
  80. shift
  81. fi
  82. if test x"$1" = x"--print-host"; then
  83. PRINT_HOST=yes
  84. shift
  85. fi
  86. if test x"$1" = x"--print-build"; then
  87. PRINT_BUILD=yes
  88. shift
  89. fi
  90. # Reject unsafe characters in $HOME, $tsdir and cwd. We consider spaces
  91. # as unsafe because it is too easy to get scripts wrong in this regard.
  92. am_lf='
  93. '
  94. case `pwd` in
  95. *[\;\\\"\#\$\&\'\`$am_lf\ \ ]*)
  96. fatal "unsafe working directory name" ;;
  97. esac
  98. case $tsdir in
  99. *[\;\\\"\#\$\&\'\`$am_lf\ \ ]*)
  100. fatal "unsafe source directory: \`$tsdir'" ;;
  101. esac
  102. case $HOME in
  103. *[\;\\\"\#\$\&\'\`$am_lf\ \ ]*)
  104. fatal "unsafe home directory: \`$HOME'" ;;
  105. esac
  106. die_p
  107. # List of variables sourced from autogen.rc. The strings '@SYSROOT@' in
  108. # these variables are replaced by the actual system root.
  109. configure_opts=
  110. extraoptions=
  111. # List of optional variables sourced from autogen.rc and ~/.gnupg-autogen.rc
  112. w32_toolprefixes=
  113. w32_extraoptions=
  114. w32ce_toolprefixes=
  115. w32ce_extraoptions=
  116. w64_toolprefixes=
  117. w64_extraoptions=
  118. amd64_toolprefixes=
  119. # End list of optional variables sourced from ~/.gnupg-autogen.rc
  120. # What follows are variables which are sourced but default to
  121. # environment variables or lacking them hardcoded values.
  122. #w32root=
  123. #w32ce_root=
  124. #w64root=
  125. #amd64root=
  126. # Convenience option to use certain configure options for some hosts.
  127. myhost=""
  128. myhostsub=""
  129. case "$1" in
  130. --find-version)
  131. myhost="find-version"
  132. SILENT=" --silent"
  133. shift
  134. ;;
  135. --build-w32)
  136. myhost="w32"
  137. shift
  138. ;;
  139. --build-w32ce)
  140. myhost="w32"
  141. myhostsub="ce"
  142. shift
  143. ;;
  144. --build-w64)
  145. myhost="w32"
  146. myhostsub="64"
  147. shift
  148. ;;
  149. --build-amd64)
  150. myhost="amd64"
  151. shift
  152. ;;
  153. --build*)
  154. fatal "**Error**: invalid build option $1"
  155. shift
  156. ;;
  157. *)
  158. ;;
  159. esac
  160. die_p
  161. # Source our configuration
  162. if [ -f "${tsdir}/autogen.rc" ]; then
  163. . "${tsdir}/autogen.rc"
  164. fi
  165. # Source optional site specific configuration
  166. if [ -f "$HOME/.gnupg-autogen.rc" ]; then
  167. info "sourcing extra definitions from $HOME/.gnupg-autogen.rc"
  168. . "$HOME/.gnupg-autogen.rc"
  169. fi
  170. # **** FIND VERSION ****
  171. # This is a helper for the configure.ac M4 magic
  172. # Called
  173. # ./autogen.sh --find-version PACKAGE MAJOR MINOR [MICRO]
  174. # returns a complete version string with automatic beta numbering.
  175. if [ "$myhost" = "find-version" ]; then
  176. package="$1"
  177. major="$2"
  178. minor="$3"
  179. micro="$4"
  180. case "$version_parts" in
  181. 2)
  182. matchstr1="$package-$major.[0-9]*"
  183. matchstr2="$package-$major-base"
  184. vers="$major.$minor"
  185. ;;
  186. *)
  187. matchstr1="$package-$major.$minor.[0-9]*"
  188. matchstr2="$package-$major.$minor-base"
  189. vers="$major.$minor.$micro"
  190. ;;
  191. esac
  192. beta=no
  193. if [ -e .git ]; then
  194. ingit=yes
  195. tmp=$(git describe --match "${matchstr1}" --long 2>/dev/null)
  196. if [ -n "$tmp" ]; then
  197. tmp=$(echo "$tmp"|awk -F- '$3!=0 && $3 !~ /^beta/ {print"-beta"$3}')
  198. else
  199. tmp=$(git describe --match "${matchstr2}" --long 2>/dev/null \
  200. | awk -F- '$4!=0{print"-beta"$4}')
  201. fi
  202. [ -n "$tmp" ] && beta=yes
  203. rev=$(git rev-parse --short HEAD | tr -d '\n\r')
  204. rvd=$((0x$(echo ${rev} | head -c 4)))
  205. else
  206. ingit=no
  207. beta=yes
  208. tmp="-unknown"
  209. rev="0000000"
  210. rvd="0"
  211. fi
  212. echo "$package-$vers$tmp:$beta:$ingit:$vers$tmp:$vers:$tmp:$rev:$rvd:"
  213. exit 0
  214. fi
  215. # **** end FIND VERSION ****
  216. if [ ! -f "$tsdir/build-aux/config.guess" ]; then
  217. fatal "$tsdir/build-aux/config.guess not found"
  218. exit 1
  219. fi
  220. build=`$tsdir/build-aux/config.guess`
  221. if [ $PRINT_BUILD = yes ]; then
  222. echo "$build"
  223. exit 0
  224. fi
  225. # ******************
  226. # W32 build script
  227. # ******************
  228. if [ "$myhost" = "w32" ]; then
  229. case $myhostsub in
  230. ce)
  231. w32root="$w32ce_root"
  232. [ -z "$w32root" ] && w32root="$HOME/w32ce_root"
  233. toolprefixes="$w32ce_toolprefixes arm-mingw32ce"
  234. extraoptions="$extraoptions $w32ce_extraoptions"
  235. ;;
  236. 64)
  237. w32root="$w64root"
  238. [ -z "$w32root" ] && w32root="$HOME/w64root"
  239. toolprefixes="$w64_toolprefixes x86_64-w64-mingw32"
  240. extraoptions="$extraoptions $w64_extraoptions"
  241. ;;
  242. *)
  243. [ -z "$w32root" ] && w32root="$HOME/w32root"
  244. toolprefixes="$w32_toolprefixes i686-w64-mingw32 i586-mingw32msvc"
  245. toolprefixes="$toolprefixes i386-mingw32msvc mingw32"
  246. extraoptions="$extraoptions $w32_extraoptions"
  247. ;;
  248. esac
  249. info "Using $w32root as standard install directory"
  250. replace_sysroot
  251. # Locate the cross compiler
  252. crossbindir=
  253. for host in $toolprefixes; do
  254. if ${host}-gcc --version >/dev/null 2>&1 ; then
  255. crossbindir=/usr/${host}/bin
  256. conf_CC="CC=${host}-gcc"
  257. break;
  258. fi
  259. done
  260. if [ -z "$crossbindir" ]; then
  261. fatal "cross compiler kit not installed"
  262. if [ -z "$myhostsub" ]; then
  263. info "Under Debian GNU/Linux, you may install it using"
  264. info " apt-get install mingw32 mingw32-runtime mingw32-binutils"
  265. fi
  266. die_p
  267. fi
  268. if [ $PRINT_HOST = yes ]; then
  269. echo "$host"
  270. exit 0
  271. fi
  272. if [ -f "$tsdir/config.log" ]; then
  273. if ! head $tsdir/config.log | grep "$host" >/dev/null; then
  274. fatal "Please run a 'make distclean' first"
  275. die_p
  276. fi
  277. fi
  278. $tsdir/configure --enable-maintainer-mode ${SILENT} \
  279. --prefix=${w32root} \
  280. --host=${host} --build=${build} SYSROOT=${w32root} \
  281. PKG_CONFIG_LIBDIR=${w32root} \
  282. ${configure_opts} ${extraoptions} "$@"
  283. rc=$?
  284. exit $rc
  285. fi
  286. # ***** end W32 build script *******
  287. # ***** AMD64 cross build script *******
  288. # Used to cross-compile for AMD64 (for testing)
  289. if [ "$myhost" = "amd64" ]; then
  290. [ -z "$amd64root" ] && amd64root="$HOME/amd64root"
  291. info "Using $amd64root as standard install directory"
  292. replace_sysroot
  293. toolprefixes="$amd64_toolprefixes x86_64-linux-gnu amd64-linux-gnu"
  294. # Locate the cross compiler
  295. crossbindir=
  296. for host in $toolprefixes ; do
  297. if ${host}-gcc --version >/dev/null 2>&1 ; then
  298. crossbindir=/usr/${host}/bin
  299. conf_CC="CC=${host}-gcc"
  300. break;
  301. fi
  302. done
  303. if [ -z "$crossbindir" ]; then
  304. echo "Cross compiler kit not installed" >&2
  305. echo "Stop." >&2
  306. exit 1
  307. fi
  308. if [ $PRINT_HOST = yes ]; then
  309. echo "$host"
  310. exit 0
  311. fi
  312. if [ -f "$tsdir/config.log" ]; then
  313. if ! head $tsdir/config.log | grep "$host" >/dev/null; then
  314. echo "Please run a 'make distclean' first" >&2
  315. exit 1
  316. fi
  317. fi
  318. $tsdir/configure --enable-maintainer-mode ${SILENT} \
  319. --prefix=${amd64root} \
  320. --host=${host} --build=${build} \
  321. ${configure_opts} ${extraoptions} "$@"
  322. rc=$?
  323. exit $rc
  324. fi
  325. # ***** end AMD64 cross build script *******
  326. # Grep the required versions from configure.ac
  327. autoconf_vers=`sed -n '/^AC_PREREQ(/ {
  328. s/^.*(\(.*\))/\1/p
  329. q
  330. }' ${configure_ac}`
  331. autoconf_vers_num=`echo "$autoconf_vers" | cvtver`
  332. automake_vers=`sed -n '/^min_automake_version=/ {
  333. s/^.*="\(.*\)"/\1/p
  334. q
  335. }' ${configure_ac}`
  336. automake_vers_num=`echo "$automake_vers" | cvtver`
  337. if [ -d "${tsdir}/po" ]; then
  338. gettext_vers=`sed -n '/^AM_GNU_GETTEXT_VERSION(/ {
  339. s/^.*\[\(.*\)])/\1/p
  340. q
  341. }' ${configure_ac}`
  342. gettext_vers_num=`echo "$gettext_vers" | cvtver`
  343. else
  344. gettext_vers="n/a"
  345. fi
  346. if [ -z "$autoconf_vers" -o -z "$automake_vers" -o -z "$gettext_vers" ]
  347. then
  348. echo "**Error**: version information not found in "\`${configure_ac}\'"." >&2
  349. exit 1
  350. fi
  351. if check_version $AUTOCONF $autoconf_vers_num $autoconf_vers ; then
  352. check_version $AUTOHEADER $autoconf_vers_num $autoconf_vers autoconf
  353. fi
  354. if check_version $AUTOMAKE $automake_vers_num $automake_vers; then
  355. check_version $ACLOCAL $automake_vers_num $autoconf_vers automake
  356. fi
  357. if [ "$gettext_vers" != "n/a" ]; then
  358. if check_version $GETTEXT $gettext_vers_num $gettext_vers; then
  359. check_version $MSGMERGE $gettext_vers_num $gettext_vers gettext
  360. fi
  361. fi
  362. if [ "$DIE" = "yes" ]; then
  363. cat <<EOF
  364. Note that you may use alternative versions of the tools by setting
  365. the corresponding environment variables; see README.GIT for details.
  366. EOF
  367. die_p
  368. fi
  369. # Check the git setup.
  370. if [ -d .git ]; then
  371. CP="cp -a"
  372. [ -z "${SILENT}" ] && CP="$CP -v"
  373. if [ -f .git/hooks/pre-commit.sample -a ! -f .git/hooks/pre-commit ] ; then
  374. [ -z "${SILENT}" ] && cat <<EOF
  375. *** Activating trailing whitespace git pre-commit hook. ***
  376. For more information see this thread:
  377. http://mail.gnome.org/archives/desktop-devel-list/2009-May/msg00084.html
  378. To deactivate this pre-commit hook again move .git/hooks/pre-commit
  379. and .git/hooks/pre-commit.sample out of the way.
  380. EOF
  381. $CP .git/hooks/pre-commit.sample .git/hooks/pre-commit
  382. chmod +x .git/hooks/pre-commit
  383. fi
  384. if [ "$gettext_vers" != "n/a" ]; then
  385. tmp=$(git config --get filter.cleanpo.clean)
  386. if [ "$tmp" != \
  387. "awk '/^\"POT-Creation-Date:/&&!s{s=1;next};!/^#: /{print}'" ]
  388. then
  389. info "*** Adding GIT filter.cleanpo.clean configuration."
  390. git config --add filter.cleanpo.clean \
  391. "awk '/^\"POT-Creation-Date:/&&!s{s=1;next};!/^#: /{print}'"
  392. fi
  393. fi
  394. if [ -f build-aux/git-hooks/commit-msg -a ! -f .git/hooks/commit-msg ] ; then
  395. [ -z "${SILENT}" ] && cat <<EOF
  396. *** Activating commit log message check hook. ***
  397. EOF
  398. $CP build-aux/git-hooks/commit-msg .git/hooks/commit-msg
  399. chmod +x .git/hooks/commit-msg
  400. fi
  401. fi
  402. aclocal_flags="-I m4"
  403. if [ -n "${extra_aclocal_flags}" ]; then
  404. aclocal_flags="${aclocal_flags} ${extra_aclocal_flags}"
  405. fi
  406. if [ -n "${ACLOCAL_FLAGS}" ]; then
  407. aclocal_flags="${aclocal_flags} ${ACLOCAL_FLAGS}"
  408. fi
  409. info "Running $ACLOCAL ${aclocal_flags} ..."
  410. $ACLOCAL ${aclocal_flags}
  411. info "Running autoheader..."
  412. $AUTOHEADER
  413. info "Running automake --gnu ..."
  414. $AUTOMAKE --gnu;
  415. info "Running autoconf${FORCE} ..."
  416. $AUTOCONF${FORCE}
  417. info "You may now run:${am_lf} ${final_info}"