xNombre | 232e9ca | 2020-07-03 22:10:22 +0200 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | set -e |
| 3 | |
| 4 | # ci_autotools.sh |
| 5 | # Continuously integrate libpng using the GNU Autotools. |
| 6 | # |
| 7 | # Copyright (c) 2019-2020 Cosmin Truta. |
| 8 | # |
| 9 | # This software is released under the libpng license. |
| 10 | # For conditions of distribution and use, see the disclaimer |
| 11 | # and license in png.h. |
| 12 | |
| 13 | readonly CI_SCRIPTNAME="$(basename "$0")" |
| 14 | readonly CI_SCRIPTDIR="$(cd "$(dirname "$0")" && pwd)" |
| 15 | readonly CI_SRCDIR="$(dirname "$CI_SCRIPTDIR")" |
| 16 | readonly CI_BUILDDIR="$CI_SRCDIR/out/autotools.build" |
| 17 | readonly CI_INSTALLDIR="$CI_SRCDIR/out/autotools.install" |
| 18 | |
| 19 | function ci_info { |
| 20 | printf >&2 "%s: %s\\n" "$CI_SCRIPTNAME" "$*" |
| 21 | } |
| 22 | |
| 23 | function ci_err { |
| 24 | printf >&2 "%s: error: %s\\n" "$CI_SCRIPTNAME" "$*" |
| 25 | exit 2 |
| 26 | } |
| 27 | |
| 28 | function ci_spawn { |
| 29 | printf >&2 "%s: executing:" "$CI_SCRIPTNAME" |
| 30 | printf >&2 " %q" "$@" |
| 31 | printf >&2 "\\n" |
| 32 | "$@" |
| 33 | } |
| 34 | |
| 35 | function ci_init_autotools { |
| 36 | # Initialize the CI_ variables with default values, where applicable. |
| 37 | CI_MAKE="${CI_MAKE:-make}" |
| 38 | [[ $(uname -s || echo unknown) == Darwin ]] && CI_CC="${CI_CC:-clang}" |
| 39 | # Print the CI_ variables. |
| 40 | ci_info "source directory: $CI_SRCDIR" |
| 41 | ci_info "build directory: $CI_BUILDDIR" |
| 42 | ci_info "install directory: $CI_INSTALLDIR" |
| 43 | ci_info "environment option: \$CI_CONFIGURE_FLAGS='$CI_CONFIGURE_FLAGS'" |
| 44 | ci_info "environment option: \$CI_MAKE='$CI_MAKE'" |
| 45 | ci_info "environment option: \$CI_MAKE_FLAGS='$CI_MAKE_FLAGS'" |
| 46 | ci_info "environment option: \$CI_CC='$CI_CC'" |
| 47 | ci_info "environment option: \$CI_CC_FLAGS='$CI_CC_FLAGS'" |
| 48 | ci_info "environment option: \$CI_SANITIZERS='$CI_SANITIZERS'" |
| 49 | ci_info "environment option: \$CI_NO_TEST='$CI_NO_TEST'" |
| 50 | ci_info "environment option: \$CI_NO_INSTALL='$CI_NO_INSTALL'" |
| 51 | ci_info "environment option: \$CI_NO_CLEAN='$CI_NO_CLEAN'" |
| 52 | # Avoid using the CI_ variables that cannot be customized reliably. |
| 53 | [[ ! $CI_CONFIGURE_VARS ]] || ci_err "unexpected: \$CI_CONFIGURE_VARS='$CI_CONFIGURE_VARS'" |
| 54 | [[ ! $CI_MAKE_VARS ]] || ci_err "unexpected: \$CI_MAKE_VARS='$CI_MAKE_VARS'" |
| 55 | } |
| 56 | |
| 57 | function ci_build_autotools { |
| 58 | # Export the configure build environment. |
| 59 | [[ $CI_CC ]] && ci_spawn export CC="$CI_CC" |
| 60 | [[ $CI_CC_FLAGS ]] && ci_spawn export CFLAGS="$CI_CC_FLAGS" |
| 61 | [[ $CI_SANITIZERS ]] && ci_spawn export CFLAGS="-fsanitize=$CI_SANITIZERS -O2 $CFLAGS" |
| 62 | # Build and install. |
| 63 | ci_spawn rm -fr "$CI_BUILDDIR" "$CI_INSTALLDIR" |
| 64 | ci_spawn mkdir -p "$CI_BUILDDIR" |
| 65 | ci_spawn cd "$CI_BUILDDIR" |
| 66 | ci_spawn "$CI_SRCDIR/configure" --prefix="$CI_INSTALLDIR" $CI_CONFIGURE_FLAGS |
| 67 | ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS |
| 68 | [[ $CI_NO_TEST ]] || ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS test |
| 69 | [[ $CI_NO_INSTALL ]] || ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS install |
| 70 | [[ $CI_NO_CLEAN ]] || ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS clean |
| 71 | [[ $CI_NO_CLEAN ]] || ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS distclean |
| 72 | ci_info "success!" |
| 73 | } |
| 74 | |
| 75 | ci_init_autotools |
| 76 | [[ ! $* ]] || { |
| 77 | ci_info "note: this program accepts environment options only" |
| 78 | ci_err "unexpected command arguments: '$*'" |
| 79 | } |
| 80 | ci_build_autotools |