blob: 14108da63356b0139f21f10450b1b8907b56044c [file] [log] [blame]
xNombre232e9ca2020-07-03 22:10:22 +02001#!/usr/bin/env bash
2set -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
13readonly CI_SCRIPTNAME="$(basename "$0")"
14readonly CI_SCRIPTDIR="$(cd "$(dirname "$0")" && pwd)"
15readonly CI_SRCDIR="$(dirname "$CI_SCRIPTDIR")"
16readonly CI_BUILDDIR="$CI_SRCDIR/out/autotools.build"
17readonly CI_INSTALLDIR="$CI_SRCDIR/out/autotools.install"
18
19function ci_info {
20 printf >&2 "%s: %s\\n" "$CI_SCRIPTNAME" "$*"
21}
22
23function ci_err {
24 printf >&2 "%s: error: %s\\n" "$CI_SCRIPTNAME" "$*"
25 exit 2
26}
27
28function ci_spawn {
29 printf >&2 "%s: executing:" "$CI_SCRIPTNAME"
30 printf >&2 " %q" "$@"
31 printf >&2 "\\n"
32 "$@"
33}
34
35function 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
57function 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
75ci_init_autotools
76[[ ! $* ]] || {
77 ci_info "note: this program accepts environment options only"
78 ci_err "unexpected command arguments: '$*'"
79}
80ci_build_autotools