]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - build/ci/build.sh
Update vendor/libarchive/dist to git b5818e39e128eca4951e2ab10467d4d850a2ba57
[FreeBSD/FreeBSD.git] / build / ci / build.sh
1 #!/bin/sh
2 #
3 # Automated build and test of libarchive on CI systems
4 #
5 # Variables that can be passed via environment:
6 # BS=                   # build system (autotools or cmake)
7 # BUILDDIR=             # build directory
8 # SRCDIR=               # source directory
9 # CONFIGURE_ARGS=       # configure arguments
10 # MAKE_ARGS=            # make arguments
11 # DEBUG=                # set -g -fsanitize=address flags
12
13 ACTIONS=
14 if [ -n "${BUILD_SYSTEM}" ]; then
15         BS="${BUILD_SYSTEM}"
16 fi
17
18 BS="${BS:-autotools}"
19 MAKE="${MAKE:-make}"
20 CMAKE="${CMAKE:-cmake}"
21 CURDIR=`pwd`
22 SRCDIR="${SRCDIR:-`pwd`}"
23 RET=0
24
25 usage () {
26         echo "Usage: $0 [-b autotools|cmake] [-a autogen|configure|build|test|install|distcheck ] [ -a ... ] [ -d builddir ] [-s srcdir ]"
27 }
28 inputerror () {
29         echo $1
30         usage
31         exit 1
32 }
33 while getopts a:b:d:s: opt; do
34         case ${opt} in
35                 a)
36                         case "${OPTARG}" in
37                                 autogen) ;;
38                                 configure) ;;
39                                 build) ;;
40                                 test) ;;
41                                 install) ;;
42                                 distcheck) ;;
43                                 *) inputerror "Invalid action (-a)" ;;
44                         esac
45                         ACTIONS="${ACTIONS} ${OPTARG}"
46                 ;;
47                 b) BS="${OPTARG}"
48                         case "${BS}" in
49                                 autotools) ;;
50                                 cmake) ;;
51                                 *) inputerror "Invalid build system (-b)" ;;
52                         esac
53                 ;;
54                 d)
55                         BUILDDIR="${OPTARG}"
56                 ;;
57                 s)
58                         SRCDIR="${OPTARG}"
59                         if [ ! -f "${SRCDIR}/build/version" ]; then
60                                 inputerror "Missing file: ${SRCDIR}/build/version"
61                         fi
62                 ;;
63         esac
64 done
65 if [ -z "${MAKE_ARGS}" ]; then
66         if [ "${BS}" = "autotools" ]; then
67                 MAKE_ARGS="V=1"
68         elif [ "${BS}" = "cmake" ]; then
69                 MAKE_ARGS="VERBOSE=1"
70         fi
71 fi
72 if [ -n "${DEBUG}" ]; then
73         if [ -n "${CFLAGS}" ]; then
74                 export CFLAGS="${CFLAGS} -g -fsanitize=address"
75         else
76                 export CFLAGS="-g -fsanitize=address"
77         fi
78         if ["${BS}" = "cmake" ]; then
79                 CONFIGURE_ARGS="${CONFIGURE_ARGS} -DCMAKE_C_CFLAGS=-g -fsanitize=address"
80         fi
81 fi
82 if [ -z "${ACTIONS}" ]; then
83         ACTIONS="autogen configure build test install"
84 fi
85 if [ -z "${BS}" ]; then
86         inputerror "Missing build system (-b) parameter"
87 fi
88 if [ -z "${BUILDDIR}" ]; then
89         BUILDDIR="${CURDIR}/build_ci/${BS}"
90 fi
91 mkdir -p "${BUILDDIR}"
92 for action in ${ACTIONS}; do
93         cd "${BUILDDIR}"
94         case "${action}" in
95                 autogen)
96                         case "${BS}" in
97                                 autotools)
98                                         cd "${SRCDIR}"
99                                         sh build/autogen.sh
100                                         RET="$?"
101                                 ;;
102                         esac
103                 ;;
104                 configure)
105                         case "${BS}" in
106                                 autotools) "${SRCDIR}/configure" ${CONFIGURE_ARGS} ;;
107                                 cmake) ${CMAKE} ${CONFIGURE_ARGS} "${SRCDIR}" ;;
108                         esac
109                         RET="$?"
110                 ;;
111                 build)
112                         ${MAKE} ${MAKE_ARGS}
113                         RET="$?"
114                 ;;
115                 test)
116                         case "${BS}" in
117                                 autotools)
118                                         ${MAKE} ${MAKE_ARGS} check LOG_DRIVER="${SRCDIR}/build/ci/test_driver"
119                                         ;;
120                                 cmake)
121                                         ${MAKE} ${MAKE_ARGS} test
122                                         ;;
123                         esac
124                         RET="$?"
125                         find ${TMPDIR:-/tmp} -path '*_test.*' -name '*.log' -print -exec cat {} \;
126                 ;;
127                 install)
128                         ${MAKE} ${MAKE_ARGS} install DESTDIR="${BUILDDIR}/destdir"
129                         RET="$?"
130                         cd ${BUILDDIR}/destdir && ls -lR .
131                 ;;
132                 distcheck)
133                         ${MAKE} ${MAKE_ARGS} distcheck
134                         RET="$?"
135                 ;;
136         esac
137         if [ "${RET}" != "0" ]; then
138                 exit "${RET}"
139         fi
140         cd "${CURDIR}"
141 done
142 exit "${RET}"