4 # ci_verify_configure.sh
5 # Continuously integrate libpng using the configure script.
7 # Copyright (c) 2019-2023 Cosmin Truta.
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.
13 CI_SCRIPTNAME="$(basename "$0")"
14 CI_SCRIPTDIR="$(cd "$(dirname "$0")" && pwd)"
15 CI_SRCDIR="$(dirname "$CI_SCRIPTDIR")"
16 CI_BUILDDIR="$CI_SRCDIR/out/ci_verify_configure.build"
17 CI_INSTALLDIR="$CI_SRCDIR/out/ci_verify_configure.install"
20 printf >&2 "%s: %s\\n" "$CI_SCRIPTNAME" "$*"
24 printf >&2 "%s: error: %s\\n" "$CI_SCRIPTNAME" "$*"
29 printf >&2 "%s: executing:" "$CI_SCRIPTNAME"
35 function ci_init_configure_build {
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'"
47 function ci_trace_configure_build {
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")"
71 ci_info "executable: \$CI_CC: $(command -V "$CI_CC")"
73 ci_info "executable: \$CI_CPP: $(command -V "$CI_CPP")"
75 ci_info "executable: \$CI_AR: $(command -V "$CI_AR")"
77 ci_info "executable: \$CI_RANLIB: $(command -V "$CI_RANLIB")"
79 ci_info "executable: \$CI_LD: $(command -V "$CI_LD")"
80 ci_info "## END OF CONFIGURATION ##"
83 function ci_cleanup_old_configure_build {
84 [[ ! -e $CI_BUILDDIR ]] ||
85 ci_spawn rm -fr "$CI_BUILDDIR"
86 [[ ! -e $CI_INSTALLDIR ]] ||
87 ci_spawn rm -fr "$CI_INSTALLDIR"
90 function ci_build_configure {
91 ci_info "## START OF BUILD ##"
92 # Export the configure build environment.
93 [[ $CI_CC ]] && ci_spawn export CC="$CI_CC"
94 [[ $CI_CC_FLAGS ]] && ci_spawn export CFLAGS="$CI_CC_FLAGS"
95 [[ $CI_CPP ]] && ci_spawn export CPP="$CI_CPP"
96 [[ $CI_CPP_FLAGS ]] && ci_spawn export CPPFLAGS="$CI_CPP_FLAGS"
97 [[ $CI_AR ]] && ci_spawn export AR="$CI_AR"
98 [[ $CI_RANLIB ]] && ci_spawn export RANLIB="$CI_RANLIB"
99 [[ $CI_LD ]] && ci_spawn export CPP="$CI_LD"
100 [[ $CI_LD_FLAGS ]] && ci_spawn export LDFLAGS="$CI_LD_FLAGS"
101 [[ $CI_SANITIZERS ]] && {
102 ci_spawn export CFLAGS="-fsanitize=$CI_SANITIZERS ${CFLAGS:-"-O2"}"
103 ci_spawn export LDFLAGS="-fsanitize=$CI_SANITIZERS $LDFLAGS"
106 ci_spawn mkdir -p "$CI_BUILDDIR"
107 ci_spawn cd "$CI_BUILDDIR"
108 ci_spawn "$CI_SRCDIR/configure" --prefix="$CI_INSTALLDIR" $CI_CONFIGURE_FLAGS
109 ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS
110 [[ $CI_NO_TEST ]] || ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS test
111 [[ $CI_NO_INSTALL ]] || ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS install
112 [[ $CI_NO_CLEAN ]] || ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS clean
113 [[ $CI_NO_CLEAN ]] || ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS distclean
114 ci_info "## END OF BUILD ##"
119 ci_info "note: this program accepts environment options only"
120 ci_err "unexpected command arguments: '$*'"
122 ci_init_configure_build
123 ci_trace_configure_build
124 ci_cleanup_old_configure_build