]> git.tdb.fi Git - ext/libpng.git/blob - ci/ci_autotools.sh
Import libpng 1.6.39
[ext/libpng.git] / ci / ci_autotools.sh
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-2022 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 CI_SCRIPTNAME="$(basename "$0")"
14 CI_SCRIPTDIR="$(cd "$(dirname "$0")" && pwd)"
15 CI_SRCDIR="$(dirname "$CI_SCRIPTDIR")"
16 CI_BUILDDIR="$CI_SRCDIR/out/autotools.build"
17 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     CI_SYSTEM_NAME="$(uname -s)"
37     CI_MACHINE_NAME="$(uname -m)"
38     CI_MAKE="${CI_MAKE:-make}"
39     # Set CI_CC to cc by default, if the cc command is available.
40     # The configure script defaults CC to gcc, which is not always a good idea.
41     [[ -x $(command -v cc) ]] && CI_CC="${CI_CC:-cc}"
42     # Ensure that the CI_ variables that cannot be customized reliably are not initialized.
43     [[ ! $CI_CONFIGURE_VARS ]] || ci_err "unexpected: \$CI_CONFIGURE_VARS='$CI_CONFIGURE_VARS'"
44     [[ ! $CI_MAKE_VARS ]] || ci_err "unexpected: \$CI_MAKE_VARS='$CI_MAKE_VARS'"
45 }
46
47 function ci_trace_autotools {
48     ci_info "## START OF CONFIGURATION ##"
49     ci_info "system name: $CI_SYSTEM_NAME"
50     ci_info "machine hardware name: $CI_MACHINE_NAME"
51     ci_info "source directory: $CI_SRCDIR"
52     ci_info "build directory: $CI_BUILDDIR"
53     ci_info "install directory: $CI_INSTALLDIR"
54     ci_info "environment option: \$CI_CONFIGURE_FLAGS: '$CI_CONFIGURE_FLAGS'"
55     ci_info "environment option: \$CI_MAKE: '$CI_MAKE'"
56     ci_info "environment option: \$CI_MAKE_FLAGS: '$CI_MAKE_FLAGS'"
57     ci_info "environment option: \$CI_CC: '$CI_CC'"
58     ci_info "environment option: \$CI_CC_FLAGS: '$CI_CC_FLAGS'"
59     ci_info "environment option: \$CI_CPP: '$CI_CPP'"
60     ci_info "environment option: \$CI_CPP_FLAGS: '$CI_CPP_FLAGS'"
61     ci_info "environment option: \$CI_AR: '$CI_AR'"
62     ci_info "environment option: \$CI_RANLIB: '$CI_RANLIB'"
63     ci_info "environment option: \$CI_LD: '$CI_LD'"
64     ci_info "environment option: \$CI_LD_FLAGS: '$CI_LD_FLAGS'"
65     ci_info "environment option: \$CI_SANITIZERS: '$CI_SANITIZERS'"
66     ci_info "environment option: \$CI_NO_TEST: '$CI_NO_TEST'"
67     ci_info "environment option: \$CI_NO_INSTALL: '$CI_NO_INSTALL'"
68     ci_info "environment option: \$CI_NO_CLEAN: '$CI_NO_CLEAN'"
69     ci_info "executable: \$CI_MAKE: $(command -V "$CI_MAKE")"
70     [[ $CI_CC ]] &&
71         ci_info "executable: \$CI_CC: $(command -V "$CI_CC")"
72     [[ $CI_CPP ]] &&
73         ci_info "executable: \$CI_CPP: $(command -V "$CI_CPP")"
74     [[ $CI_AR ]] &&
75         ci_info "executable: \$CI_AR: $(command -V "$CI_AR")"
76     [[ $CI_RANLIB ]] &&
77         ci_info "executable: \$CI_RANLIB: $(command -V "$CI_RANLIB")"
78     [[ $CI_LD ]] &&
79         ci_info "executable: \$CI_LD: $(command -V "$CI_LD")"
80     ci_info "## END OF CONFIGURATION ##"
81 }
82
83 function ci_build_autotools {
84     ci_info "## START OF BUILD ##"
85     # Export the configure build environment.
86     [[ $CI_CC ]] && ci_spawn export CC="$CI_CC"
87     [[ $CI_CC_FLAGS ]] && ci_spawn export CFLAGS="$CI_CC_FLAGS"
88     [[ $CI_CPP ]] && ci_spawn export CPP="$CI_CPP"
89     [[ $CI_CPP_FLAGS ]] && ci_spawn export CPPFLAGS="$CI_CPP_FLAGS"
90     [[ $CI_AR ]] && ci_spawn export AR="$CI_AR"
91     [[ $CI_RANLIB ]] && ci_spawn export RANLIB="$CI_RANLIB"
92     [[ $CI_LD ]] && ci_spawn export CPP="$CI_LD"
93     [[ $CI_LD_FLAGS ]] && ci_spawn export LDFLAGS="$CI_LD_FLAGS"
94     [[ $CI_SANITIZERS ]] && {
95         ci_spawn export CFLAGS="-fsanitize=$CI_SANITIZERS ${CFLAGS:-"-O2"}"
96         ci_spawn export LDFLAGS="-fsanitize=$CI_SANITIZERS $LDFLAGS"
97     }
98     # Build and install.
99     ci_spawn rm -fr "$CI_BUILDDIR" "$CI_INSTALLDIR"
100     ci_spawn mkdir -p "$CI_BUILDDIR"
101     ci_spawn cd "$CI_BUILDDIR"
102     ci_spawn "$CI_SRCDIR/configure" --prefix="$CI_INSTALLDIR" $CI_CONFIGURE_FLAGS
103     ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS
104     [[ $CI_NO_TEST ]] || ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS test
105     [[ $CI_NO_INSTALL ]] || ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS install
106     [[ $CI_NO_CLEAN ]] || ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS clean
107     [[ $CI_NO_CLEAN ]] || ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS distclean
108     ci_info "## END OF BUILD ##"
109 }
110
111 ci_init_autotools
112 ci_trace_autotools
113 [[ $# -eq 0 ]] || {
114     ci_info "note: this program accepts environment options only"
115     ci_err "unexpected command arguments: '$*'"
116 }
117 ci_build_autotools