1*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh 2*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) 2017-2021 Petr Vorel <[email protected]> 3*49cdfc7eSAndroid Build Coastguard Worker# Script for CI builds. 4*49cdfc7eSAndroid Build Coastguard Worker 5*49cdfc7eSAndroid Build Coastguard Workerset -e 6*49cdfc7eSAndroid Build Coastguard Worker 7*49cdfc7eSAndroid Build Coastguard WorkerCFLAGS="${CFLAGS:--Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=return-type -fno-common}" 8*49cdfc7eSAndroid Build Coastguard WorkerCC="${CC:-gcc}" 9*49cdfc7eSAndroid Build Coastguard Worker 10*49cdfc7eSAndroid Build Coastguard WorkerDEFAULT_PREFIX="$HOME/ltp-install" 11*49cdfc7eSAndroid Build Coastguard WorkerDEFAULT_BUILD="native" 12*49cdfc7eSAndroid Build Coastguard WorkerDEFAULT_TREE="in" 13*49cdfc7eSAndroid Build Coastguard Worker 14*49cdfc7eSAndroid Build Coastguard WorkerCONFIGURE_OPTS_IN_TREE="--with-open-posix-testsuite --with-realtime-testsuite $CONFIGURE_OPT_EXTRA" 15*49cdfc7eSAndroid Build Coastguard Worker# TODO: open posix testsuite is currently broken in out-tree-build. Enable it once it's fixed. 16*49cdfc7eSAndroid Build Coastguard WorkerCONFIGURE_OPTS_OUT_TREE="--with-realtime-testsuite $CONFIGURE_OPT_EXTRA" 17*49cdfc7eSAndroid Build Coastguard Worker 18*49cdfc7eSAndroid Build Coastguard WorkerSRC_DIR="$(cd $(dirname $0); pwd)" 19*49cdfc7eSAndroid Build Coastguard WorkerBUILD_DIR="$SRC_DIR/../ltp-build" 20*49cdfc7eSAndroid Build Coastguard Worker 21*49cdfc7eSAndroid Build Coastguard WorkerMAKE_OPTS="-j$(getconf _NPROCESSORS_ONLN)" 22*49cdfc7eSAndroid Build Coastguard WorkerMAKE_OPTS_OUT_TREE="$MAKE_OPTS -C $BUILD_DIR -f $SRC_DIR/Makefile top_srcdir=$SRC_DIR top_builddir=$BUILD_DIR" 23*49cdfc7eSAndroid Build Coastguard Worker 24*49cdfc7eSAndroid Build Coastguard Workerrun_configure() 25*49cdfc7eSAndroid Build Coastguard Worker{ 26*49cdfc7eSAndroid Build Coastguard Worker local configure="$1" 27*49cdfc7eSAndroid Build Coastguard Worker shift 28*49cdfc7eSAndroid Build Coastguard Worker 29*49cdfc7eSAndroid Build Coastguard Worker export CC CFLAGS LDFLAGS PKG_CONFIG_LIBDIR 30*49cdfc7eSAndroid Build Coastguard Worker echo "CC='$CC' CFLAGS='$CFLAGS' LDFLAGS='$LDFLAGS' PKG_CONFIG_LIBDIR='$PKG_CONFIG_LIBDIR'" 31*49cdfc7eSAndroid Build Coastguard Worker 32*49cdfc7eSAndroid Build Coastguard Worker echo "=== configure $configure $@ ===" 33*49cdfc7eSAndroid Build Coastguard Worker if ! $configure $@; then 34*49cdfc7eSAndroid Build Coastguard Worker echo "== ERROR: configure failed, config.log ==" 35*49cdfc7eSAndroid Build Coastguard Worker cat config.log 36*49cdfc7eSAndroid Build Coastguard Worker exit 1 37*49cdfc7eSAndroid Build Coastguard Worker fi 38*49cdfc7eSAndroid Build Coastguard Worker 39*49cdfc7eSAndroid Build Coastguard Worker echo "== include/config.h ==" 40*49cdfc7eSAndroid Build Coastguard Worker cat include/config.h 41*49cdfc7eSAndroid Build Coastguard Worker} 42*49cdfc7eSAndroid Build Coastguard Worker 43*49cdfc7eSAndroid Build Coastguard Workerconfigure_in_tree() 44*49cdfc7eSAndroid Build Coastguard Worker{ 45*49cdfc7eSAndroid Build Coastguard Worker run_configure ./configure $CONFIGURE_OPTS_IN_TREE --prefix=$prefix $@ 46*49cdfc7eSAndroid Build Coastguard Worker} 47*49cdfc7eSAndroid Build Coastguard Worker 48*49cdfc7eSAndroid Build Coastguard Workerconfigure_out_tree() 49*49cdfc7eSAndroid Build Coastguard Worker{ 50*49cdfc7eSAndroid Build Coastguard Worker mkdir -p $BUILD_DIR 51*49cdfc7eSAndroid Build Coastguard Worker cd $BUILD_DIR 52*49cdfc7eSAndroid Build Coastguard Worker run_configure $SRC_DIR/configure $CONFIGURE_OPTS_OUT_TREE $@ 53*49cdfc7eSAndroid Build Coastguard Worker} 54*49cdfc7eSAndroid Build Coastguard Worker 55*49cdfc7eSAndroid Build Coastguard Workerconfigure_32() 56*49cdfc7eSAndroid Build Coastguard Worker{ 57*49cdfc7eSAndroid Build Coastguard Worker local tree="$1" 58*49cdfc7eSAndroid Build Coastguard Worker local prefix="$2" 59*49cdfc7eSAndroid Build Coastguard Worker local arch="$(uname -m)" 60*49cdfc7eSAndroid Build Coastguard Worker local dir 61*49cdfc7eSAndroid Build Coastguard Worker 62*49cdfc7eSAndroid Build Coastguard Worker echo "===== 32-bit ${tree}-tree build into $prefix =====" 63*49cdfc7eSAndroid Build Coastguard Worker 64*49cdfc7eSAndroid Build Coastguard Worker if [ -z "$PKG_CONFIG_LIBDIR" ]; then 65*49cdfc7eSAndroid Build Coastguard Worker if [ "$arch" != "x86_64" ]; then 66*49cdfc7eSAndroid Build Coastguard Worker echo "ERROR: auto-detection not supported platform $arch, export PKG_CONFIG_LIBDIR!" 67*49cdfc7eSAndroid Build Coastguard Worker exit 1 68*49cdfc7eSAndroid Build Coastguard Worker fi 69*49cdfc7eSAndroid Build Coastguard Worker 70*49cdfc7eSAndroid Build Coastguard Worker for dir in /usr/lib/i386-linux-gnu/pkgconfig \ 71*49cdfc7eSAndroid Build Coastguard Worker /usr/lib32/pkgconfig /usr/lib/pkgconfig; do 72*49cdfc7eSAndroid Build Coastguard Worker if [ -d "$dir" ]; then 73*49cdfc7eSAndroid Build Coastguard Worker PKG_CONFIG_LIBDIR="$dir" 74*49cdfc7eSAndroid Build Coastguard Worker break 75*49cdfc7eSAndroid Build Coastguard Worker fi 76*49cdfc7eSAndroid Build Coastguard Worker done 77*49cdfc7eSAndroid Build Coastguard Worker if [ -z "$PKG_CONFIG_LIBDIR" ]; then 78*49cdfc7eSAndroid Build Coastguard Worker echo "WARNING: PKG_CONFIG_LIBDIR not found, build might fail" 79*49cdfc7eSAndroid Build Coastguard Worker fi 80*49cdfc7eSAndroid Build Coastguard Worker fi 81*49cdfc7eSAndroid Build Coastguard Worker 82*49cdfc7eSAndroid Build Coastguard Worker CFLAGS="-m32 $CFLAGS" LDFLAGS="-m32 $LDFLAGS" 83*49cdfc7eSAndroid Build Coastguard Worker 84*49cdfc7eSAndroid Build Coastguard Worker eval configure_${tree}_tree 85*49cdfc7eSAndroid Build Coastguard Worker} 86*49cdfc7eSAndroid Build Coastguard Worker 87*49cdfc7eSAndroid Build Coastguard Workerconfigure_native() 88*49cdfc7eSAndroid Build Coastguard Worker{ 89*49cdfc7eSAndroid Build Coastguard Worker local tree="$1" 90*49cdfc7eSAndroid Build Coastguard Worker local prefix="$2" 91*49cdfc7eSAndroid Build Coastguard Worker 92*49cdfc7eSAndroid Build Coastguard Worker echo "===== native ${tree}-tree build into $prefix =====" 93*49cdfc7eSAndroid Build Coastguard Worker eval configure_${tree}_tree 94*49cdfc7eSAndroid Build Coastguard Worker} 95*49cdfc7eSAndroid Build Coastguard Worker 96*49cdfc7eSAndroid Build Coastguard Workerconfigure_cross() 97*49cdfc7eSAndroid Build Coastguard Worker{ 98*49cdfc7eSAndroid Build Coastguard Worker local tree="$1" 99*49cdfc7eSAndroid Build Coastguard Worker local prefix="$2" 100*49cdfc7eSAndroid Build Coastguard Worker local host=$(basename "${CC%-gcc}") 101*49cdfc7eSAndroid Build Coastguard Worker 102*49cdfc7eSAndroid Build Coastguard Worker if [ "$host" = "gcc" ]; then 103*49cdfc7eSAndroid Build Coastguard Worker echo "Invalid CC variable for cross compilation: $CC (clang not supported)" >&2 104*49cdfc7eSAndroid Build Coastguard Worker exit 1 105*49cdfc7eSAndroid Build Coastguard Worker fi 106*49cdfc7eSAndroid Build Coastguard Worker 107*49cdfc7eSAndroid Build Coastguard Worker echo "===== cross-compile ${host} ${1}-tree build into $prefix =====" 108*49cdfc7eSAndroid Build Coastguard Worker eval configure_${tree}_tree "--host=$host" 109*49cdfc7eSAndroid Build Coastguard Worker} 110*49cdfc7eSAndroid Build Coastguard Worker 111*49cdfc7eSAndroid Build Coastguard Workerbuild_in_tree() 112*49cdfc7eSAndroid Build Coastguard Worker{ 113*49cdfc7eSAndroid Build Coastguard Worker make $MAKE_OPTS 114*49cdfc7eSAndroid Build Coastguard Worker} 115*49cdfc7eSAndroid Build Coastguard Worker 116*49cdfc7eSAndroid Build Coastguard Workerbuild_out_tree() 117*49cdfc7eSAndroid Build Coastguard Worker{ 118*49cdfc7eSAndroid Build Coastguard Worker cd $BUILD_DIR 119*49cdfc7eSAndroid Build Coastguard Worker make $MAKE_OPTS_OUT_TREE 120*49cdfc7eSAndroid Build Coastguard Worker} 121*49cdfc7eSAndroid Build Coastguard Worker 122*49cdfc7eSAndroid Build Coastguard Workertest_in_tree() 123*49cdfc7eSAndroid Build Coastguard Worker{ 124*49cdfc7eSAndroid Build Coastguard Worker make $1 125*49cdfc7eSAndroid Build Coastguard Worker} 126*49cdfc7eSAndroid Build Coastguard Worker 127*49cdfc7eSAndroid Build Coastguard Workertest_out_tree() 128*49cdfc7eSAndroid Build Coastguard Worker{ 129*49cdfc7eSAndroid Build Coastguard Worker cd $BUILD_DIR 130*49cdfc7eSAndroid Build Coastguard Worker make $MAKE_OPTS_OUT_TREE $1 131*49cdfc7eSAndroid Build Coastguard Worker} 132*49cdfc7eSAndroid Build Coastguard Worker 133*49cdfc7eSAndroid Build Coastguard Workerinstall_in_tree() 134*49cdfc7eSAndroid Build Coastguard Worker{ 135*49cdfc7eSAndroid Build Coastguard Worker make $MAKE_OPTS install 136*49cdfc7eSAndroid Build Coastguard Worker} 137*49cdfc7eSAndroid Build Coastguard Worker 138*49cdfc7eSAndroid Build Coastguard Workerinstall_out_tree() 139*49cdfc7eSAndroid Build Coastguard Worker{ 140*49cdfc7eSAndroid Build Coastguard Worker cd $BUILD_DIR 141*49cdfc7eSAndroid Build Coastguard Worker make $MAKE_OPTS_OUT_TREE DESTDIR="$prefix" SKIP_IDCHECK=1 install 142*49cdfc7eSAndroid Build Coastguard Worker} 143*49cdfc7eSAndroid Build Coastguard Worker 144*49cdfc7eSAndroid Build Coastguard Workerusage() 145*49cdfc7eSAndroid Build Coastguard Worker{ 146*49cdfc7eSAndroid Build Coastguard Worker cat << EOF 147*49cdfc7eSAndroid Build Coastguard WorkerUsage: 148*49cdfc7eSAndroid Build Coastguard Worker$0 [ -c CC ] [ -i ] [ -o TREE ] [ -p DIR ] [-r RUN ] [ -t TYPE ] 149*49cdfc7eSAndroid Build Coastguard Worker$0 -h 150*49cdfc7eSAndroid Build Coastguard Worker 151*49cdfc7eSAndroid Build Coastguard WorkerOptions: 152*49cdfc7eSAndroid Build Coastguard Worker-h Print this help 153*49cdfc7eSAndroid Build Coastguard Worker-c CC Define compiler (\$CC variable), needed only for configure step 154*49cdfc7eSAndroid Build Coastguard Worker-i Run 'make install', needed only for install step 155*49cdfc7eSAndroid Build Coastguard Worker-o TREE Specify build tree, default: $DEFAULT_TREE 156*49cdfc7eSAndroid Build Coastguard Worker-p DIR Change installation directory. For in-tree build is this value passed 157*49cdfc7eSAndroid Build Coastguard Worker to --prefix option of configure script. For out-of-tree build is this 158*49cdfc7eSAndroid Build Coastguard Worker value passed to DESTDIR variable (i.e. sysroot) of make install 159*49cdfc7eSAndroid Build Coastguard Worker target, which means that LTP will be actually installed into 160*49cdfc7eSAndroid Build Coastguard Worker DIR/PREFIX (i.e. DIR/opt/ltp). 161*49cdfc7eSAndroid Build Coastguard Worker Default for in-tree build: '$DEFAULT_PREFIX' 162*49cdfc7eSAndroid Build Coastguard Worker Default for out-of-tree build: '$DEFAULT_PREFIX/opt/ltp' 163*49cdfc7eSAndroid Build Coastguard Worker-r RUN Run only certain step (usable for CI), default: all 164*49cdfc7eSAndroid Build Coastguard Worker-t TYPE Specify build type, default: $DEFAULT_BUILD, only for configure step 165*49cdfc7eSAndroid Build Coastguard Worker 166*49cdfc7eSAndroid Build Coastguard WorkerTREE: 167*49cdfc7eSAndroid Build Coastguard Workerin in-tree build 168*49cdfc7eSAndroid Build Coastguard Workerout out-of-tree build 169*49cdfc7eSAndroid Build Coastguard Worker 170*49cdfc7eSAndroid Build Coastguard WorkerTYPES: 171*49cdfc7eSAndroid Build Coastguard Worker32 32-bit build (PKG_CONFIG_LIBDIR auto-detection for x86_64) 172*49cdfc7eSAndroid Build Coastguard Workercross cross-compile build (requires set compiler via -c switch) 173*49cdfc7eSAndroid Build Coastguard Workernative native build 174*49cdfc7eSAndroid Build Coastguard Worker 175*49cdfc7eSAndroid Build Coastguard WorkerRUN: 176*49cdfc7eSAndroid Build Coastguard Workerautotools run only 'make autotools' 177*49cdfc7eSAndroid Build Coastguard Workerconfigure run only 'configure' 178*49cdfc7eSAndroid Build Coastguard Workerbuild run only 'make' 179*49cdfc7eSAndroid Build Coastguard Workertest run only 'make test' (not supported for cross-compile build) 180*49cdfc7eSAndroid Build Coastguard Workertest-c run only 'make test-c' (not supported for cross-compile build) 181*49cdfc7eSAndroid Build Coastguard Workertest-shell run only 'make test-shell' (not supported for cross-compile build) 182*49cdfc7eSAndroid Build Coastguard Workerinstall run only 'make install' 183*49cdfc7eSAndroid Build Coastguard Worker 184*49cdfc7eSAndroid Build Coastguard WorkerDefault configure options: 185*49cdfc7eSAndroid Build Coastguard Workerin-tree: $CONFIGURE_OPTS_IN_TREE 186*49cdfc7eSAndroid Build Coastguard Workerout-of-tree $CONFIGURE_OPTS_OUT_TREE 187*49cdfc7eSAndroid Build Coastguard Worker 188*49cdfc7eSAndroid Build Coastguard Workerconfigure options can extend the default with \$CONFIGURE_OPT_EXTRA environment variable 189*49cdfc7eSAndroid Build Coastguard WorkerEOF 190*49cdfc7eSAndroid Build Coastguard Worker} 191*49cdfc7eSAndroid Build Coastguard Worker 192*49cdfc7eSAndroid Build Coastguard Workerprefix="$DEFAULT_PREFIX" 193*49cdfc7eSAndroid Build Coastguard Workerbuild="$DEFAULT_BUILD" 194*49cdfc7eSAndroid Build Coastguard Workertree="$DEFAULT_TREE" 195*49cdfc7eSAndroid Build Coastguard Workerinstall= 196*49cdfc7eSAndroid Build Coastguard Workerrun= 197*49cdfc7eSAndroid Build Coastguard Worker 198*49cdfc7eSAndroid Build Coastguard Workerwhile getopts "c:hio:p:r:t:" opt; do 199*49cdfc7eSAndroid Build Coastguard Worker case "$opt" in 200*49cdfc7eSAndroid Build Coastguard Worker c) CC="$OPTARG";; 201*49cdfc7eSAndroid Build Coastguard Worker h) usage; exit 0;; 202*49cdfc7eSAndroid Build Coastguard Worker i) install=1;; 203*49cdfc7eSAndroid Build Coastguard Worker o) case "$OPTARG" in 204*49cdfc7eSAndroid Build Coastguard Worker in|out) tree="$OPTARG";; 205*49cdfc7eSAndroid Build Coastguard Worker *) echo "Wrong build tree '$OPTARG'" >&2; usage; exit 1;; 206*49cdfc7eSAndroid Build Coastguard Worker esac;; 207*49cdfc7eSAndroid Build Coastguard Worker p) prefix="$OPTARG";; 208*49cdfc7eSAndroid Build Coastguard Worker r) case "$OPTARG" in 209*49cdfc7eSAndroid Build Coastguard Worker autotools|configure|build|test|test-c|test-shell|install) run="$OPTARG";; 210*49cdfc7eSAndroid Build Coastguard Worker *) echo "Wrong run type '$OPTARG'" >&2; usage; exit 1;; 211*49cdfc7eSAndroid Build Coastguard Worker esac;; 212*49cdfc7eSAndroid Build Coastguard Worker t) case "$OPTARG" in 213*49cdfc7eSAndroid Build Coastguard Worker 32|cross|native) build="$OPTARG";; 214*49cdfc7eSAndroid Build Coastguard Worker *) echo "Wrong build type '$OPTARG'" >&2; usage; exit 1;; 215*49cdfc7eSAndroid Build Coastguard Worker esac;; 216*49cdfc7eSAndroid Build Coastguard Worker ?) usage; exit 1;; 217*49cdfc7eSAndroid Build Coastguard Worker esac 218*49cdfc7eSAndroid Build Coastguard Workerdone 219*49cdfc7eSAndroid Build Coastguard Worker 220*49cdfc7eSAndroid Build Coastguard Workercd $SRC_DIR 221*49cdfc7eSAndroid Build Coastguard Worker 222*49cdfc7eSAndroid Build Coastguard Workerif [ -z "$run" -o "$run" = "autotools" ]; then 223*49cdfc7eSAndroid Build Coastguard Worker make autotools 224*49cdfc7eSAndroid Build Coastguard Workerfi 225*49cdfc7eSAndroid Build Coastguard Worker 226*49cdfc7eSAndroid Build Coastguard Workerif [ -z "$run" -o "$run" = "configure" ]; then 227*49cdfc7eSAndroid Build Coastguard Worker eval configure_$build $tree $prefix 228*49cdfc7eSAndroid Build Coastguard Workerfi 229*49cdfc7eSAndroid Build Coastguard Worker 230*49cdfc7eSAndroid Build Coastguard Workerif [ -z "$run" -o "$run" = "build" ]; then 231*49cdfc7eSAndroid Build Coastguard Worker echo "=== build ===" 232*49cdfc7eSAndroid Build Coastguard Worker eval build_${tree}_tree 233*49cdfc7eSAndroid Build Coastguard Workerfi 234*49cdfc7eSAndroid Build Coastguard Worker 235*49cdfc7eSAndroid Build Coastguard Workerif [ -z "$run" -o "$run" = "test" -o "$run" = "test-c" -o "$run" = "test-shell" ]; then 236*49cdfc7eSAndroid Build Coastguard Worker if [ "$build" = "cross" ]; then 237*49cdfc7eSAndroid Build Coastguard Worker echo "cross-compile build, skipping running tests" >&2 238*49cdfc7eSAndroid Build Coastguard Worker else 239*49cdfc7eSAndroid Build Coastguard Worker eval test_${tree}_tree $run 240*49cdfc7eSAndroid Build Coastguard Worker fi 241*49cdfc7eSAndroid Build Coastguard Workerfi 242*49cdfc7eSAndroid Build Coastguard Worker 243*49cdfc7eSAndroid Build Coastguard Workerif [ -z "$run" -o "$run" = "install" ]; then 244*49cdfc7eSAndroid Build Coastguard Worker if [ "$install" = 1 ]; then 245*49cdfc7eSAndroid Build Coastguard Worker eval install_${tree}_tree 246*49cdfc7eSAndroid Build Coastguard Worker else 247*49cdfc7eSAndroid Build Coastguard Worker echo "make install skipped, use -i to run it" 248*49cdfc7eSAndroid Build Coastguard Worker fi 249*49cdfc7eSAndroid Build Coastguard Workerfi 250*49cdfc7eSAndroid Build Coastguard Worker 251*49cdfc7eSAndroid Build Coastguard Workerexit $? 252