3 #############################################################################
5 # Script meant to be used for Continuous Integration automation for POSIX
6 # systems. On GitHub, this is used by Ubuntu and MacOS builds.
8 #############################################################################
12 # This file has been put into the public domain.
13 # You can do whatever you want with this file.
15 #############################################################################
22 -c [crc32|crc64|sha256]
23 -d [encoders|decoders|bcj|delta|threads|shared|nls|small|ifunc|clmul|sandbox]
26 -n [ARTIFACTS_DIR_NAME]
30 # Absolute path of script directory
31 ABS_DIR
=$
(cd -- "$(dirname -- "$0")" && pwd)
33 # Default CLI option values
35 BUILD_SYSTEM
="autotools"
36 CHECK_TYPE
="crc32,crc64,sha256"
43 NATIVE_LANG_SUPPORT
="y"
48 SRC_DIR
="$ABS_DIR/../"
49 DEST_DIR
="$SRC_DIR/../xz_build"
51 ARTIFACTS_DIR_NAME
="output"
58 while getopts a
:b
:c
:d
:l
:n
:s
:p
:f
:h opt
; do
59 # b option can have either value "autotools" OR "cmake"
66 AUTOGEN_FLAGS
="$OPTARG"
72 *) echo "Invalid build system: $OPTARG"; exit 1;;
74 BUILD_SYSTEM
="$OPTARG"
76 c
) CHECK_TYPE
="$OPTARG"
78 # d options can be a comma separated list of things to disable at
81 for disable_arg
in $
(echo "$OPTARG" |
sed "s/,/ /g"); do
82 case "$disable_arg" in
83 encoders
) ENCODERS
="n" ;;
84 decoders
) DECODERS
="n" ;;
87 threads
) THREADS
="n" ;;
89 nls
) NATIVE_LANG_SUPPORT
="n";;
93 sandbox
) SANDBOX
="n";;
94 *) echo "Invalid disable value: $disable_arg"; exit 1 ;;
100 n
) ARTIFACTS_DIR_NAME
="$OPTARG"
118 # These two functions essentially implement the ternary "?" operator.
120 # First argument is option value ("y" or "n")
121 # Second argument is option to set if "y"
122 # Third argument is option to set if "n"
125 EXTRA_OPTIONS
="$EXTRA_OPTIONS $2"
127 EXTRA_OPTIONS
="$EXTRA_OPTIONS $3"
132 add_to_filter_list
() {
133 # First argument is option value ("y" or "n")
134 # Second argument is option to set if "y"
137 FILTER_LIST
="$FILTER_LIST$2"
146 if [ "$PHASE" = "all" ] ||
[ "$PHASE" = "build" ]
148 # Checksum options should be specified differently based on the
149 # build system. It must be calculated here since we won't know
150 # the build system used until all args have been parsed.
151 # Autotools - comma separated
152 # CMake - semi-colon separated
153 if [ "$BUILD_SYSTEM" = "autotools" ]
161 for crc
in $
(echo "$CHECK_TYPE" |
sed "s/,/ /g"); do
163 # Remove "crc32" from cmake build, if specified.
165 if [ "$BUILD_SYSTEM" = "cmake" ]
172 *) echo "Invalid check type: $crc"; exit 1 ;;
175 CHECK_TYPE_TEMP
="$CHECK_TYPE_TEMP$SEP$crc"
178 # Remove the first character from $CHECK_TYPE_TEMP since it will
179 # always be the delimiter.
180 CHECK_TYPE
="${CHECK_TYPE_TEMP:1}"
182 FILTER_LIST
="lzma1$SEP"lzma2
184 # Build based on arguments
187 # Generate configure option values
190 case $BUILD_SYSTEM in
194 # Run autogen.sh script if not already run
195 if [ ! -f configure
]
197 .
/autogen.sh
"$AUTOGEN_FLAGS"
202 add_to_filter_list
"$BCJ" ",x86,powerpc,ia64,arm,armthumb,arm64,sparc"
203 add_to_filter_list
"$DELTA" ",delta"
205 add_extra_option
"$ENCODERS" "--enable-encoders=$FILTER_LIST" "--disable-encoders"
206 add_extra_option
"$DECODERS" "--enable-decoders=$FILTER_LIST" "--disable-decoders"
207 add_extra_option
"$THREADS" "" "--disable-threads"
208 add_extra_option
"$SHARED" "" "--disable-shared"
209 add_extra_option
"$NATIVE_LANG_SUPPORT" "" "--disable-nls"
210 add_extra_option
"$SMALL" "--enable-small" ""
211 add_extra_option
"$IFUNC" "" "--disable-ifunc"
212 add_extra_option
"$CLMUL" "" "--disable-clmul-crc"
213 add_extra_option
"$SANDBOX" "" "--enable-sandbox=no"
215 # Run configure script
216 "$SRC_DIR"/configure
--enable-werror --enable-checks="$CHECK_TYPE" $EXTRA_OPTIONS --config-cache
224 add_to_filter_list
"$BCJ" ";x86;powerpc;ia64;arm;armthumb;arm64;sparc"
225 add_to_filter_list
"$DELTA" ";delta"
227 add_extra_option
"$THREADS" "-DENABLE_THREADS=ON" "-DENABLE_THREADS=OFF"
229 # Disable MicroLZMA if encoders are not configured.
230 add_extra_option
"$ENCODERS" "-DENCODERS=$FILTER_LIST" "-DENCODERS= -DMICROLZMA_ENCODER=OFF"
232 # Disable MicroLZMA and lzip decoders if decoders are not configured.
233 add_extra_option
"$DECODERS" "-DDECODERS=$FILTER_LIST" "-DDECODERS= -DMICROLZMA_DECODER=OFF -DLZIP_DECODER=OFF"
235 # CMake disables the shared library by default.
236 add_extra_option
"$SHARED" "-DBUILD_SHARED_LIBS=ON" ""
238 add_extra_option
"$SMALL" "-DHAVE_SMALL=ON" ""
240 # Remove old cache file to clear previous settings.
241 rm -f "CMakeCache.txt"
242 cmake
"$SRC_DIR/CMakeLists.txt" -B "$DEST_DIR" $EXTRA_OPTIONS -DADDITIONAL_CHECK_TYPES="$CHECK_TYPE" -G "Unix Makefiles"
243 cmake
--build "$DEST_DIR"
253 if [ "$PHASE" = "all" ] ||
[ "$PHASE" = "test" ]
255 case $BUILD_SYSTEM in
258 # If the tests fail, copy the test logs into the artifacts folder
263 mkdir
-p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
264 cp .
/tests
/*.log
"$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
274 mkdir
-p "$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"
275 cp .
/Testing
/Temporary
/*.log
"$SRC_DIR/build-aux/artifacts/$ARTIFACTS_DIR_NAME"