blob: 6dd7ddf93117abe7a4241ef5fe11c17e82f586a7 [file] [log] [blame]
Petr Vorelfa5b22d2017-10-04 12:22:58 +02001#!/bin/sh
2# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
3# 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"
13DEFAULT_BUILD="build_native"
14CONFIGURE_OPTS_IN_TREE="--with-open-posix-testsuite --with-realtime-testsuite"
Petr Vorelfa5b22d2017-10-04 12:22:58 +020015# TODO: open posix testsuite is currently broken in out-tree-build. Enable it once it's fixed.
16CONFIGURE_OPTS_OUT_TREE="--with-realtime-testsuite"
Petr Vorelfa5b22d2017-10-04 12:22:58 +020017MAKE_OPTS="-j$(getconf _NPROCESSORS_ONLN)"
Petr Vorel73e4ec42017-12-14 17:58:56 +010018CC=
Petr Vorelfa5b22d2017-10-04 12:22:58 +020019
20build_32()
21{
22 echo "===== 32-bit in-tree build into $PREFIX ====="
23 build_in_tree CFLAGS="-m32" CXXFLAGS="-m32" LDFLAGS="-m32"
24}
25
26build_native()
27{
Petr Vorel73e4ec42017-12-14 17:58:56 +010028 echo "===== native in-tree build into $PREFIX ====="
Petr Vorelfa5b22d2017-10-04 12:22:58 +020029 build_in_tree
30}
31
Petr Vorel29a9e7a2017-12-14 19:03:48 +010032build_cross()
33{
34 local host="${CC%-gcc}"
35 [ -n "$host" ] || \
36 { echo "Missing CC variable, pass it with -c option." >&2; exit 1; }
37
38 echo "===== cross-compile ${host} in-tree build into $PREFIX ====="
39 build_in_tree "--host=$host" CROSS_COMPILE="${host}-"
40}
41
Petr Vorelfa5b22d2017-10-04 12:22:58 +020042build_out_tree()
43{
44 local tree="$PWD"
45 local build="$tree/../ltp-build"
46 local make_opts="$MAKE_OPTS -C $build -f $tree/Makefile top_srcdir=$tree top_builddir=$build"
47
48 echo "===== native out-of-tree build into $PREFIX ====="
49 mkdir -p $build
50
51 echo "=== autotools ==="
52 make autotools
53
54 cd $build
Petr Vorel73e4ec42017-12-14 17:58:56 +010055 run_configure $tree/configure $CONFIGURE_OPTS_OUT_TREE CC="$CC"
Petr Vorelfa5b22d2017-10-04 12:22:58 +020056
57 make $make_opts
58 make $make_opts DESTDIR="$PREFIX" SKIP_IDCHECK=1 install
59}
60
61build_in_tree()
62{
63 echo "=== autotools ==="
64 make autotools
65
Petr Vorel73e4ec42017-12-14 17:58:56 +010066 run_configure ./configure $CONFIGURE_OPTS_IN_TREE CC="$CC" --prefix=$PREFIX $@
Petr Vorelfa5b22d2017-10-04 12:22:58 +020067
68 echo "=== build ==="
69 make $MAKE_OPTS
70
71 echo "=== install ==="
72 make $MAKE_OPTS install
73}
74
Petr Vorel73e4ec42017-12-14 17:58:56 +010075run_configure()
76{
77 local configure=$1
78 shift
79
80 echo "=== configure $configure $@ ==="
81 if ! $configure $@; then
82 echo "== ERROR: configure failed, config.log =="
83 cat config.log
84 exit 1
85 fi
86
87 echo "== include/config.h =="
88 cat include/config.h
89}
90
Petr Vorelfa5b22d2017-10-04 12:22:58 +020091usage()
92{
93 cat << EOF
94Usage:
Petr Vorel73e4ec42017-12-14 17:58:56 +010095$0 [ -c CC ] [ -p DIR ] [ -t TYPE ]
96$0 -h
Petr Vorelfa5b22d2017-10-04 12:22:58 +020097
98Options:
Petr Vorel73e4ec42017-12-14 17:58:56 +010099-h Print this help
100-c CC Define compiler (\$CC variable)
101-p DIR Change installation directory. For in-tree build is this value passed
102 to --prefix option of configure script. For out-of-tree build is this
103 value passed to DESTDIR variable (i.e. sysroot) of make install
104 target, which means that LTP will be actually installed into
105 DIR/PREFIX (i.e. DIR/opt/ltp).
106 Default for in-tree build: '$DEFAULT_PREFIX'
107 Default for out-of-tree build: '$DEFAULT_PREFIX/opt/ltp'
108-t TYPE Specify build type, default: $DEFAULT_BUILD
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200109
110BUILD TYPES:
Petr Vorel73e4ec42017-12-14 17:58:56 +010011132 32-bit in-tree build
Petr Vorel29a9e7a2017-12-14 19:03:48 +0100112cross cross-compile in-tree build (requires set compiler via -c switch)
Petr Vorel73e4ec42017-12-14 17:58:56 +0100113native native in-tree build
114out out-of-tree build
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200115EOF
116}
117
Petr Vorel73e4ec42017-12-14 17:58:56 +0100118PREFIX="$DEFAULT_PREFIX"
119build="$DEFAULT_BUILD"
120
121while getopts "c:hp:t:" opt; do
122 case "$opt" in
123 c) CC="$OPTARG";;
124 h) usage; exit 0;;
125 p) PREFIX="$OPTARG";;
126 t) case "$OPTARG" in
127 32) build="build_32";;
Petr Vorel29a9e7a2017-12-14 19:03:48 +0100128 cross) build="build_cross";;
Petr Vorel73e4ec42017-12-14 17:58:56 +0100129 native) build="build_native";;
130 out) build="build_out_tree";;
131 *) echo "Wrong build type '$OPTARG'" >&2; usage; exit 1;;
132 esac;;
133 ?) usage; exit 1;;
134 esac
135done
Petr Vorelfa5b22d2017-10-04 12:22:58 +0200136
137cd `dirname $0`
138$build