blob: 9335595cac69f440a4a33837ab241363fb40d158 [file] [log] [blame]
Petr Vorelfa5b22d2017-10-04 12:22:58 +02001#!/bin/sh
Petr Vorel3cfd5c62021-05-12 16:24:49 +02002# Copyright (c) 2017-2021 Petr Vorel <pvorel@suse.cz>
Petr Vorelfa5b22d2017-10-04 12:22:58 +02003# Script for travis builds.
4#
5# TODO: Implement comparison of installed files. List of installed files can
6# be used only for local builds as Travis currently doesn't support sharing
7# file between jobs, see
8# https://github.com/travis-ci/travis-ci/issues/6054
9
10set -e
11
Petr Vorel22850e42020-06-22 09:40:57 +020012CFLAGS="${CFLAGS:--Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=return-type -fno-common}"
Petr Vorel9039d442019-04-12 01:31:15 +020013CC="${CC:-gcc}"
14
Petr Vorel73e4ec42017-12-14 17:58:56 +010015DEFAULT_PREFIX="$HOME/ltp-install"
Petr Vorel612fd8b2018-01-26 19:34:20 +010016DEFAULT_BUILD="native"
17DEFAULT_TREE="in"
Petr Vorel3cfd5c62021-05-12 16:24:49 +020018CONFIGURE_OPTS_IN_TREE="--with-open-posix-testsuite --with-realtime-testsuite $CONFIGURE_OPT_EXTRA"
Petr Vorelfa5b22d2017-10-04 12:22:58 +020019# TODO: open posix testsuite is currently broken in out-tree-build. Enable it once it's fixed.
Petr Vorel3cfd5c62021-05-12 16:24:49 +020020CONFIGURE_OPTS_OUT_TREE="--with-realtime-testsuite $CONFIGURE_OPT_EXTRA"
Petr Vorelfa5b22d2017-10-04 12:22:58 +020021MAKE_OPTS="-j$(getconf _NPROCESSORS_ONLN)"
22
23build_32()
24{
Petr Vorelf32272e2020-12-03 12:26:41 +010025 local dir
26 local arch="$(uname -m)"
27
Petr Vorel612fd8b2018-01-26 19:34:20 +010028 echo "===== 32-bit ${1}-tree build into $PREFIX ====="
Petr Vorelf32272e2020-12-03 12:26:41 +010029
30 if [ -z "$PKG_CONFIG_LIBDIR" ]; then
31 if [ "$arch" != "x86_64" ]; then
32 echo "ERROR: auto-detection not supported platform $arch, export PKG_CONFIG_LIBDIR!"
33 exit 1
34 fi
35
36 for dir in /usr/lib/i386-linux-gnu/pkgconfig \
37 /usr/lib32/pkgconfig /usr/lib/pkgconfig; do
38 if [ -d "$dir" ]; then
39 PKG_CONFIG_LIBDIR="$dir"
40 break
41 fi
42 done
43 if [ -z "$PKG_CONFIG_LIBDIR" ]; then
44 echo "WARNING: PKG_CONFIG_LIBDIR not found, build might fail"
45 fi
46 fi
47
Petr Voreldba3b822019-08-02 15:17:50 +020048 CFLAGS="-m32 $CFLAGS" LDFLAGS="-m32 $LDFLAGS"
Petr Vorel1d5f1c82020-02-07 17:04:25 +010049 build $1 $2
Petr Vorelfa5b22d2017-10-04 12:22:58 +020050}
51
52build_native()
53{
Petr Vorel612fd8b2018-01-26 19:34:20 +010054 echo "===== native ${1}-tree build into $PREFIX ====="
Petr Vorel1d5f1c82020-02-07 17:04:25 +010055 build $1 $2
Petr Vorelfa5b22d2017-10-04 12:22:58 +020056}
57
Petr Vorel29a9e7a2017-12-14 19:03:48 +010058build_cross()
59{
Li Zhijian42626422021-01-11 11:07:04 +080060 local host=$(basename "${CC%-gcc}")
Petr Vorela622a1e2020-08-11 12:16:53 +020061 if [ "$host" = "gcc" ]; then
62 echo "Invalid CC variable for cross compilation: $CC (clang not supported)" >&2
63 exit 1
64 fi
Petr Vorel29a9e7a2017-12-14 19:03:48 +010065
Petr Vorel612fd8b2018-01-26 19:34:20 +010066 echo "===== cross-compile ${host} ${1}-tree build into $PREFIX ====="
Li Zhijian1dee7402021-01-11 11:07:03 +080067 build $1 $2 "--host=$host"
Petr Vorel612fd8b2018-01-26 19:34:20 +010068}
69
70build()
71{
72 local tree="$1"
Petr Vorel1d5f1c82020-02-07 17:04:25 +010073 local install="$2"
74 shift 2
Petr Vorel612fd8b2018-01-26 19:34:20 +010075
76 echo "=== autotools ==="
77 make autotools
78
79 if [ "$tree" = "in" ]; then
Petr Vorel1d5f1c82020-02-07 17:04:25 +010080 build_in_tree $install $@
Petr Vorel612fd8b2018-01-26 19:34:20 +010081 else
Petr Vorel1d5f1c82020-02-07 17:04:25 +010082 build_out_tree $install $@
Petr Vorel612fd8b2018-01-26 19:34:20 +010083 fi
Petr Vorel29a9e7a2017-12-14 19:03:48 +010084}
85
Petr Vorelfa5b22d2017-10-04 12:22:58 +020086build_out_tree()
87{
Petr Vorel1d5f1c82020-02-07 17:04:25 +010088 local install="$1"
89 shift
90
Petr Vorelfa5b22d2017-10-04 12:22:58 +020091 local tree="$PWD"
92 local build="$tree/../ltp-build"
93 local make_opts="$MAKE_OPTS -C $build -f $tree/Makefile top_srcdir=$tree top_builddir=$build"
94
Petr Vorelfa5b22d2017-10-04 12:22:58 +020095 mkdir -p $build
Petr Vorelfa5b22d2017-10-04 12:22:58 +020096 cd $build
Petr Voreldba3b822019-08-02 15:17:50 +020097 run_configure $tree/configure $CONFIGURE_OPTS_OUT_TREE $@
Petr Vorelfa5b22d2017-10-04 12:22:58 +020098
Petr Vorel612fd8b2018-01-26 19:34:20 +010099 echo "=== build ==="
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200100 make $make_opts
Petr Vorel612fd8b2018-01-26 19:34:20 +0100101
Petr Vorel1d5f1c82020-02-07 17:04:25 +0100102 if [ "$install" = 1 ]; then
103 echo "=== install ==="
104 make $make_opts DESTDIR="$PREFIX" SKIP_IDCHECK=1 install
105 else
106 echo "make install skipped, use -i to run it"
107 fi
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200108}
109
110build_in_tree()
111{
Petr Vorel1d5f1c82020-02-07 17:04:25 +0100112 local install="$1"
113 shift
114
Petr Voreldba3b822019-08-02 15:17:50 +0200115 run_configure ./configure $CONFIGURE_OPTS_IN_TREE --prefix=$PREFIX $@
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200116
117 echo "=== build ==="
118 make $MAKE_OPTS
119
Petr Vorel1d5f1c82020-02-07 17:04:25 +0100120 if [ "$install" = 1 ]; then
121 echo "=== install ==="
122 make $MAKE_OPTS install
123 else
124 echo "make install skipped, use -i to run it"
125 fi
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200126}
127
Petr Vorel73e4ec42017-12-14 17:58:56 +0100128run_configure()
129{
130 local configure=$1
131 shift
132
Petr Vorelf32272e2020-12-03 12:26:41 +0100133 export CC CFLAGS LDFLAGS PKG_CONFIG_LIBDIR
134 echo "CC='$CC' CFLAGS='$CFLAGS' LDFLAGS='$LDFLAGS' PKG_CONFIG_LIBDIR='$PKG_CONFIG_LIBDIR'"
Petr Voreldba3b822019-08-02 15:17:50 +0200135
Petr Vorel73e4ec42017-12-14 17:58:56 +0100136 echo "=== configure $configure $@ ==="
137 if ! $configure $@; then
138 echo "== ERROR: configure failed, config.log =="
139 cat config.log
140 exit 1
141 fi
142
143 echo "== include/config.h =="
144 cat include/config.h
145}
146
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200147usage()
148{
149 cat << EOF
150Usage:
Petr Vorel612fd8b2018-01-26 19:34:20 +0100151$0 [ -c CC ] [ -o TREE ] [ -p DIR ] [ -t TYPE ]
Petr Vorel73e4ec42017-12-14 17:58:56 +0100152$0 -h
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200153
154Options:
Petr Vorel73e4ec42017-12-14 17:58:56 +0100155-h Print this help
156-c CC Define compiler (\$CC variable)
Petr Vorel612fd8b2018-01-26 19:34:20 +0100157-o TREE Specify build tree, default: $DEFAULT_TREE
Petr Vorel73e4ec42017-12-14 17:58:56 +0100158-p DIR Change installation directory. For in-tree build is this value passed
159 to --prefix option of configure script. For out-of-tree build is this
160 value passed to DESTDIR variable (i.e. sysroot) of make install
161 target, which means that LTP will be actually installed into
162 DIR/PREFIX (i.e. DIR/opt/ltp).
163 Default for in-tree build: '$DEFAULT_PREFIX'
164 Default for out-of-tree build: '$DEFAULT_PREFIX/opt/ltp'
165-t TYPE Specify build type, default: $DEFAULT_BUILD
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200166
Petr Vorel612fd8b2018-01-26 19:34:20 +0100167BUILD TREE:
168in in-tree build
169out out-of-tree build
170
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200171BUILD TYPES:
Petr Vorelf32272e2020-12-03 12:26:41 +010017232 32-bit build (PKG_CONFIG_LIBDIR auto-detection for x86_64)
Petr Vorel31d69832020-12-03 11:04:31 +0100173cross cross-compile build (requires set compiler via -c switch)
174native native build
Petr Vorel3cfd5c62021-05-12 16:24:49 +0200175
176Default configure options:
177in-tree: $CONFIGURE_OPTS_IN_TREE
178out-of-tree $CONFIGURE_OPTS_OUT_TREE
179
180configure options can extend the default with \$CONFIGURE_OPT_EXTRA environment variable
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200181EOF
182}
183
Petr Vorel73e4ec42017-12-14 17:58:56 +0100184PREFIX="$DEFAULT_PREFIX"
185build="$DEFAULT_BUILD"
Petr Vorel612fd8b2018-01-26 19:34:20 +0100186tree="$DEFAULT_TREE"
Petr Vorel1d5f1c82020-02-07 17:04:25 +0100187install=0
Petr Vorel73e4ec42017-12-14 17:58:56 +0100188
Petr Vorel1d5f1c82020-02-07 17:04:25 +0100189while getopts "c:hio:p:t:" opt; do
Petr Vorel73e4ec42017-12-14 17:58:56 +0100190 case "$opt" in
191 c) CC="$OPTARG";;
192 h) usage; exit 0;;
Petr Vorel1d5f1c82020-02-07 17:04:25 +0100193 i) install=1;;
Petr Vorel612fd8b2018-01-26 19:34:20 +0100194 o) case "$OPTARG" in
195 in|out) tree="$OPTARG";;
196 *) echo "Wrong build tree '$OPTARG'" >&2; usage; exit 1;;
197 esac;;
Petr Vorel73e4ec42017-12-14 17:58:56 +0100198 p) PREFIX="$OPTARG";;
199 t) case "$OPTARG" in
Petr Vorel612fd8b2018-01-26 19:34:20 +0100200 32|cross|native) build="$OPTARG";;
Petr Vorel73e4ec42017-12-14 17:58:56 +0100201 *) echo "Wrong build type '$OPTARG'" >&2; usage; exit 1;;
202 esac;;
203 ?) usage; exit 1;;
204 esac
205done
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200206
207cd `dirname $0`
Petr Vorel24519c12018-12-18 10:31:51 +0100208
209echo "=== ver_linux ==="
210./ver_linux
211echo
212
213echo "=== compiler version ==="
214$CC --version
215
Petr Vorel1d5f1c82020-02-07 17:04:25 +0100216eval build_$build $tree $install