blob: ae3b86ff292dbcf26adadf8f3dc0ea5e27ec610c [file] [log] [blame]
Petr Vorelfa5b22d2017-10-04 12:22:58 +02001#!/bin/sh
Petr Vorel24519c12018-12-18 10:31:51 +01002# Copyright (c) 2017-2018 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 Vorel73e4ec42017-12-14 17:58:56 +010012DEFAULT_PREFIX="$HOME/ltp-install"
Petr Vorel612fd8b2018-01-26 19:34:20 +010013DEFAULT_BUILD="native"
14DEFAULT_TREE="in"
Petr Vorel73e4ec42017-12-14 17:58:56 +010015CONFIGURE_OPTS_IN_TREE="--with-open-posix-testsuite --with-realtime-testsuite"
Petr Vorelfa5b22d2017-10-04 12:22:58 +020016# TODO: open posix testsuite is currently broken in out-tree-build. Enable it once it's fixed.
17CONFIGURE_OPTS_OUT_TREE="--with-realtime-testsuite"
Petr Vorelfa5b22d2017-10-04 12:22:58 +020018MAKE_OPTS="-j$(getconf _NPROCESSORS_ONLN)"
Petr Vorel24519c12018-12-18 10:31:51 +010019CC=gcc
Petr Vorelfa5b22d2017-10-04 12:22:58 +020020
21build_32()
22{
Petr Vorel612fd8b2018-01-26 19:34:20 +010023 echo "===== 32-bit ${1}-tree build into $PREFIX ====="
24 build $1 CFLAGS="-m32" CXXFLAGS="-m32" LDFLAGS="-m32"
Petr Vorelfa5b22d2017-10-04 12:22:58 +020025}
26
27build_native()
28{
Petr Vorel612fd8b2018-01-26 19:34:20 +010029 echo "===== native ${1}-tree build into $PREFIX ====="
30 build $1
Petr Vorelfa5b22d2017-10-04 12:22:58 +020031}
32
Petr Vorel29a9e7a2017-12-14 19:03:48 +010033build_cross()
34{
35 local host="${CC%-gcc}"
36 [ -n "$host" ] || \
37 { echo "Missing CC variable, pass it with -c option." >&2; exit 1; }
38
Petr Vorel612fd8b2018-01-26 19:34:20 +010039 echo "===== cross-compile ${host} ${1}-tree build into $PREFIX ====="
40 build $1 "--host=$host" CROSS_COMPILE="${host}-"
41}
42
43build()
44{
45 local tree="$1"
46 shift
47
48 echo "=== autotools ==="
49 make autotools
50
51 if [ "$tree" = "in" ]; then
52 build_in_tree $@
53 else
54 build_out_tree $@
55 fi
Petr Vorel29a9e7a2017-12-14 19:03:48 +010056}
57
Petr Vorelfa5b22d2017-10-04 12:22:58 +020058build_out_tree()
59{
60 local tree="$PWD"
61 local build="$tree/../ltp-build"
62 local make_opts="$MAKE_OPTS -C $build -f $tree/Makefile top_srcdir=$tree top_builddir=$build"
63
Petr Vorelfa5b22d2017-10-04 12:22:58 +020064 mkdir -p $build
Petr Vorelfa5b22d2017-10-04 12:22:58 +020065 cd $build
Petr Vorel612fd8b2018-01-26 19:34:20 +010066 run_configure $tree/configure $CONFIGURE_OPTS_OUT_TREE CC="$CC" $@
Petr Vorelfa5b22d2017-10-04 12:22:58 +020067
Petr Vorel612fd8b2018-01-26 19:34:20 +010068 echo "=== build ==="
Petr Vorelfa5b22d2017-10-04 12:22:58 +020069 make $make_opts
Petr Vorel612fd8b2018-01-26 19:34:20 +010070
71 echo "=== install ==="
Petr Vorelfa5b22d2017-10-04 12:22:58 +020072 make $make_opts DESTDIR="$PREFIX" SKIP_IDCHECK=1 install
73}
74
75build_in_tree()
76{
Petr Vorel73e4ec42017-12-14 17:58:56 +010077 run_configure ./configure $CONFIGURE_OPTS_IN_TREE CC="$CC" --prefix=$PREFIX $@
Petr Vorelfa5b22d2017-10-04 12:22:58 +020078
79 echo "=== build ==="
80 make $MAKE_OPTS
81
82 echo "=== install ==="
83 make $MAKE_OPTS install
84}
85
Petr Vorel73e4ec42017-12-14 17:58:56 +010086run_configure()
87{
88 local configure=$1
89 shift
90
91 echo "=== configure $configure $@ ==="
92 if ! $configure $@; then
93 echo "== ERROR: configure failed, config.log =="
94 cat config.log
95 exit 1
96 fi
97
98 echo "== include/config.h =="
99 cat include/config.h
100}
101
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200102usage()
103{
104 cat << EOF
105Usage:
Petr Vorel612fd8b2018-01-26 19:34:20 +0100106$0 [ -c CC ] [ -o TREE ] [ -p DIR ] [ -t TYPE ]
Petr Vorel73e4ec42017-12-14 17:58:56 +0100107$0 -h
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200108
109Options:
Petr Vorel73e4ec42017-12-14 17:58:56 +0100110-h Print this help
111-c CC Define compiler (\$CC variable)
Petr Vorel612fd8b2018-01-26 19:34:20 +0100112-o TREE Specify build tree, default: $DEFAULT_TREE
Petr Vorel73e4ec42017-12-14 17:58:56 +0100113-p DIR Change installation directory. For in-tree build is this value passed
114 to --prefix option of configure script. For out-of-tree build is this
115 value passed to DESTDIR variable (i.e. sysroot) of make install
116 target, which means that LTP will be actually installed into
117 DIR/PREFIX (i.e. DIR/opt/ltp).
118 Default for in-tree build: '$DEFAULT_PREFIX'
119 Default for out-of-tree build: '$DEFAULT_PREFIX/opt/ltp'
120-t TYPE Specify build type, default: $DEFAULT_BUILD
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200121
Petr Vorel612fd8b2018-01-26 19:34:20 +0100122BUILD TREE:
123in in-tree build
124out out-of-tree build
125
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200126BUILD TYPES:
Petr Vorel73e4ec42017-12-14 17:58:56 +010012732 32-bit in-tree build
Petr Vorel29a9e7a2017-12-14 19:03:48 +0100128cross cross-compile in-tree build (requires set compiler via -c switch)
Petr Vorel73e4ec42017-12-14 17:58:56 +0100129native native in-tree build
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200130EOF
131}
132
Petr Vorel73e4ec42017-12-14 17:58:56 +0100133PREFIX="$DEFAULT_PREFIX"
134build="$DEFAULT_BUILD"
Petr Vorel612fd8b2018-01-26 19:34:20 +0100135tree="$DEFAULT_TREE"
Petr Vorel73e4ec42017-12-14 17:58:56 +0100136
Petr Vorel612fd8b2018-01-26 19:34:20 +0100137while getopts "c:ho:p:t:" opt; do
Petr Vorel73e4ec42017-12-14 17:58:56 +0100138 case "$opt" in
139 c) CC="$OPTARG";;
140 h) usage; exit 0;;
Petr Vorel612fd8b2018-01-26 19:34:20 +0100141 o) case "$OPTARG" in
142 in|out) tree="$OPTARG";;
143 *) echo "Wrong build tree '$OPTARG'" >&2; usage; exit 1;;
144 esac;;
Petr Vorel73e4ec42017-12-14 17:58:56 +0100145 p) PREFIX="$OPTARG";;
146 t) case "$OPTARG" in
Petr Vorel612fd8b2018-01-26 19:34:20 +0100147 32|cross|native) build="$OPTARG";;
Petr Vorel73e4ec42017-12-14 17:58:56 +0100148 *) echo "Wrong build type '$OPTARG'" >&2; usage; exit 1;;
149 esac;;
150 ?) usage; exit 1;;
151 esac
152done
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200153
154cd `dirname $0`
Petr Vorel24519c12018-12-18 10:31:51 +0100155
156echo "=== ver_linux ==="
157./ver_linux
158echo
159
160echo "=== compiler version ==="
161$CC --version
162
Petr Vorel612fd8b2018-01-26 19:34:20 +0100163eval build_$build $tree