3 # Copyright (C) 2003, 2014 g10 Code GmbH
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.
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.
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.
20 configure_ac="configure.ac"
23 awk 'NR==1 {split($NF,A,".");X=1000000*A[1]+1000*A[2]+A[3];print X;exit 0}'
27 if [ $(( `("$1" --version || echo "0") | cvtver` >= $2 )) = 1 ]; then
30 echo "**Error**: "\`$1\'" not installed or too old." >&2
31 echo ' Version '$3' or newer is required.' >&2
32 [ -n "$4" ] && echo ' Note that this is part of '\`$4\''.' >&2
38 echo "autogen.sh:" "$*" >&2
43 if [ -z "${SILENT}" ]; then
44 echo "autogen.sh:" "$*" >&2
49 if [ "$DIE" = "yes" ]; then
50 echo "autogen.sh: Stop." >&2
56 configure_opts=$(echo $configure_opts | sed "s#@SYSROOT@#${w32root}#g")
57 extraoptions=$(echo $extraoptions | sed "s#@SYSROOT@#${w32root}#g")
60 # Allow to override the default tool names
61 AUTOCONF=${AUTOCONF_PREFIX}${AUTOCONF:-autoconf}${AUTOCONF_SUFFIX}
62 AUTOHEADER=${AUTOCONF_PREFIX}${AUTOHEADER:-autoheader}${AUTOCONF_SUFFIX}
64 AUTOMAKE=${AUTOMAKE_PREFIX}${AUTOMAKE:-automake}${AUTOMAKE_SUFFIX}
65 ACLOCAL=${AUTOMAKE_PREFIX}${ACLOCAL:-aclocal}${AUTOMAKE_SUFFIX}
67 GETTEXT=${GETTEXT_PREFIX}${GETTEXT:-gettext}${GETTEXT_SUFFIX}
68 MSGMERGE=${GETTEXT_PREFIX}${MSGMERGE:-msgmerge}${GETTEXT_SUFFIX}
76 tsdir=$(cd "${tmp}"; pwd)
79 if [ -n "${AUTOGEN_SH_SILENT}" ]; then
82 if test x"$1" = x"--help"; then
83 echo "usage: ./autogen.sh [--silent] [--force] [--build-TYPE] [ARGS]"
86 if test x"$1" = x"--silent"; then
90 if test x"$1" = x"--force"; then
94 if test x"$1" = x"--print-host"; then
98 if test x"$1" = x"--print-build"; then
104 # Reject unsafe characters in $HOME, $tsdir and cwd. We consider spaces
105 # as unsafe because it is too easy to get scripts wrong in this regard.
109 *[\;\\\"\#\$\&\'\`$am_lf\ \ ]*)
110 fatal "unsafe working directory name" ;;
113 *[\;\\\"\#\$\&\'\`$am_lf\ \ ]*)
114 fatal "unsafe source directory: \`$tsdir'" ;;
117 *[\;\\\"\#\$\&\'\`$am_lf\ \ ]*)
118 fatal "unsafe home directory: \`$HOME'" ;;
123 # List of variables sourced from autogen.rc. The strings '@SYSROOT@' in
124 # these variables are replaced by the actual system root.
127 # List of optional variables sourced from autogen.rc and ~/.gnupg-autogen.rc
135 # End list of optional variables sourced from ~/.gnupg-autogen.rc
136 # What follows are variables which are sourced but default to
137 # environment variables or lacking them hardcoded values.
143 # Convenience option to use certain configure options for some hosts.
148 myhost="find-version"
171 fatal "**Error**: invalid build option $1"
188 # Source our configuration
189 if [ -f "${tsdir}/autogen.rc" ]; then
190 . "${tsdir}/autogen.rc"
193 # Source optional site specific configuration
194 if [ -f "$HOME/.gnupg-autogen.rc" ]; then
195 info "sourcing extra definitions from $HOME/.gnupg-autogen.rc"
196 . "$HOME/.gnupg-autogen.rc"
200 # **** FIND VERSION ****
201 # This is a helper for the configure.ac M4 magic
203 # ./autogen.sh --find-version PACKAGE MAJOR MINOR [MICRO]
204 # returns a complete version string with automatic beta numbering.
205 if [ "$myhost" = "find-version" ]; then
211 case "$version_parts" in
213 matchstr1="$package-$major.[0-9]*"
214 matchstr2="$package-$major-base"
218 matchstr1="$package-$major.$minor.[0-9]*"
219 matchstr2="$package-$major.$minor-base"
220 vers="$major.$minor.$micro"
227 tmp=$(git describe --match "${matchstr1}" --long 2>/dev/null)
228 if [ -n "$tmp" ]; then
229 tmp=$(echo "$tmp"|awk -F- '$3!=0 && $3 !~ /^beta/ {print"-beta"$3}')
231 tmp=$(git describe --match "${matchstr2}" --long 2>/dev/null \
232 | awk -F- '$4!=0{print"-beta"$4}')
234 [ -n "$tmp" ] && beta=yes
235 rev=$(git rev-parse --short HEAD | tr -d '\n\r')
236 rvd=$((0x$(echo ${rev} | head -c 4)))
245 echo "$package-$vers$tmp:$beta:$ingit:$vers$tmp:$vers:$tmp:$rev:$rvd:"
248 # **** end FIND VERSION ****
251 # This is a helper for the code coverage collection
253 # ./autogen.sh --coverage lcov gcov [dirs...]
254 if [ "$myhost" = "coverage" ]; then
262 while [ x"$1" != "x" ]; do
264 $LCOV --gcov-tool $GCOV \
265 --base-directory "$BASE"/"$P" \
267 --output-file coverage.info.`basename "$P"` \
268 --capture --no-checksum --compat-libtool \
269 --rc lcov_branch_coverage=1
270 COVINFO="$COVINFO -a coverage.info."`basename "$P"`
274 $LCOV $COVINFO --base-directory "$BASE" --output-file coverage.info \
276 --rc lcov_branch_coverage=1
280 # **** end COVERAGE ****
282 # **** COVERAGE_REPORT ****
283 # This is a helper for the code coverage report
285 # ./autogen.sh --report lcov genhtml [exclude...]
286 if [ "$myhost" = "report" ]; then
292 while [ x"$1" != "x" ]; do
294 $LCOV --remove coverage.info "$P" -o coverage.info \
295 --rc lcov_branch_coverage=1
299 LANG=C $GENHTML --output-directory coveragereport --title "Code Coverage" \
300 --legend --show-details coverage.info \
301 --rc lcov_branch_coverage=1
305 # **** end COVERAGE_REPORT ****
307 if [ ! -f "$tsdir/build-aux/config.guess" ]; then
308 fatal "$tsdir/build-aux/config.guess not found"
311 build=`$tsdir/build-aux/config.guess`
312 if [ $PRINT_BUILD = yes ]; then
322 if [ "$myhost" = "w32" ]; then
325 w32root="$w32ce_root"
326 [ -z "$w32root" ] && w32root="$HOME/w32ce_root"
327 toolprefixes="$w32ce_toolprefixes arm-mingw32ce"
328 extraoptions="$extraoptions $w32ce_extraoptions"
332 [ -z "$w32root" ] && w32root="$HOME/w64root"
333 toolprefixes="$w64_toolprefixes x86_64-w64-mingw32"
334 extraoptions="$extraoptions $w64_extraoptions"
337 [ -z "$w32root" ] && w32root="$HOME/w32root"
338 toolprefixes="$w32_toolprefixes i686-w64-mingw32 i586-mingw32msvc"
339 toolprefixes="$toolprefixes i386-mingw32msvc mingw32"
340 extraoptions="$extraoptions $w32_extraoptions"
343 info "Using $w32root as standard install directory"
346 # Locate the cross compiler
348 for host in $toolprefixes; do
349 if ${host}-gcc --version >/dev/null 2>&1 ; then
350 crossbindir=/usr/${host}/bin
351 conf_CC="CC=${host}-gcc"
355 if [ -z "$crossbindir" ]; then
356 fatal "cross compiler kit not installed"
357 if [ -z "$myhostsub" ]; then
358 info "Under Debian GNU/Linux, you may install it using"
359 info " apt-get install mingw32 mingw32-runtime mingw32-binutils"
363 if [ $PRINT_HOST = yes ]; then
368 if [ -f "$tsdir/config.log" ]; then
369 if ! head $tsdir/config.log | grep "$host" >/dev/null; then
370 fatal "Please run a 'make distclean' first"
375 $tsdir/configure --enable-maintainer-mode ${SILENT} \
376 --prefix=${w32root} \
377 --host=${host} --build=${build} SYSROOT=${w32root} \
378 ${configure_opts} ${extraoptions} "$@"
382 # ***** end W32 build script *******
384 # ***** AMD64 cross build script *******
385 # Used to cross-compile for AMD64 (for testing)
386 if [ "$myhost" = "amd64" ]; then
387 [ -z "$amd64root" ] && amd64root="$HOME/amd64root"
388 info "Using $amd64root as standard install directory"
391 toolprefixes="$amd64_toolprefixes x86_64-linux-gnu amd64-linux-gnu"
393 # Locate the cross compiler
395 for host in $toolprefixes ; do
396 if ${host}-gcc --version >/dev/null 2>&1 ; then
397 crossbindir=/usr/${host}/bin
398 conf_CC="CC=${host}-gcc"
402 if [ -z "$crossbindir" ]; then
403 echo "Cross compiler kit not installed" >&2
407 if [ $PRINT_HOST = yes ]; then
412 if [ -f "$tsdir/config.log" ]; then
413 if ! head $tsdir/config.log | grep "$host" >/dev/null; then
414 echo "Please run a 'make distclean' first" >&2
419 $tsdir/configure --enable-maintainer-mode ${SILENT} \
420 --prefix=${amd64root} \
421 --host=${host} --build=${build} \
422 ${configure_opts} ${extraoptions} "$@"
426 # ***** end AMD64 cross build script *******
429 # Grep the required versions from configure.ac
430 autoconf_vers=`sed -n '/^AC_PREREQ(/ {
434 autoconf_vers_num=`echo "$autoconf_vers" | cvtver`
436 automake_vers=`sed -n '/^min_automake_version=/ {
440 automake_vers_num=`echo "$automake_vers" | cvtver`
442 if [ -d "${tsdir}/po" ]; then
443 gettext_vers=`sed -n '/^AM_GNU_GETTEXT_VERSION(/ {
447 gettext_vers_num=`echo "$gettext_vers" | cvtver`
452 if [ -z "$autoconf_vers" -o -z "$automake_vers" -o -z "$gettext_vers" ]
454 echo "**Error**: version information not found in "\`${configure_ac}\'"." >&2
459 if check_version $AUTOCONF $autoconf_vers_num $autoconf_vers ; then
460 check_version $AUTOHEADER $autoconf_vers_num $autoconf_vers autoconf
462 if check_version $AUTOMAKE $automake_vers_num $automake_vers; then
463 check_version $ACLOCAL $automake_vers_num $autoconf_vers automake
465 if [ "$gettext_vers" != "n/a" ]; then
466 if check_version $GETTEXT $gettext_vers_num $gettext_vers; then
467 check_version $MSGMERGE $gettext_vers_num $gettext_vers gettext
471 if [ "$DIE" = "yes" ]; then
474 Note that you may use alternative versions of the tools by setting
475 the corresponding environment variables; see README.GIT for details.
481 # Check the git setup.
484 [ -z "${SILENT}" ] && CP="$CP -v"
485 if [ -f .git/hooks/pre-commit.sample -a ! -f .git/hooks/pre-commit ] ; then
486 [ -z "${SILENT}" ] && cat <<EOF
487 *** Activating trailing whitespace git pre-commit hook. ***
488 For more information see this thread:
489 http://mail.gnome.org/archives/desktop-devel-list/2009-May/msg00084html
490 To deactivate this pre-commit hook again move .git/hooks/pre-commit
491 and .git/hooks/pre-commit.sample out of the way.
493 $CP .git/hooks/pre-commit.sample .git/hooks/pre-commit
494 chmod +x .git/hooks/pre-commit
497 if [ "$gettext_vers" != "n/a" ]; then
498 tmp=$(git config --get filter.cleanpo.clean)
500 "awk '/^\"POT-Creation-Date:/&&!s{s=1;next};!/^#: /{print}'" ]
502 info "*** Adding GIT filter.cleanpo.clean configuration."
503 git config --add filter.cleanpo.clean \
504 "awk '/^\"POT-Creation-Date:/&&!s{s=1;next};!/^#: /{print}'"
507 if [ -f build-aux/git-hooks/commit-msg -a ! -f .git/hooks/commit-msg ] ; then
508 [ -z "${SILENT}" ] && cat <<EOF
509 *** Activating commit log message check hook. ***
511 $CP build-aux/git-hooks/commit-msg .git/hooks/commit-msg
512 chmod +x .git/hooks/commit-msg
516 aclocal_flags="-I m4"
517 if [ -n "${extra_aclocal_flags}" ]; then
518 aclocal_flags="${aclocal_flags} ${extra_aclocal_flags}"
520 if [ -n "${ACLOCAL_FLAGS}" ]; then
521 aclocal_flags="${aclocal_flags} ${ACLOCAL_FLAGS}"
523 info "Running $ACLOCAL ${aclocal_flags} ..."
524 $ACLOCAL ${aclocal_flags}
525 info "Running autoheader..."
527 info "Running automake --gnu ..."
529 info "Running autoconf${FORCE} ..."
532 info "You may now run:${am_lf} ${final_info}"