• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# Copyright (c) 2017-2018 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
12DEFAULT_PREFIX="$HOME/ltp-install"
13DEFAULT_BUILD="native"
14DEFAULT_TREE="in"
15CONFIGURE_OPTS_IN_TREE="--with-open-posix-testsuite --with-realtime-testsuite"
16# TODO: open posix testsuite is currently broken in out-tree-build. Enable it once it's fixed.
17CONFIGURE_OPTS_OUT_TREE="--with-realtime-testsuite"
18MAKE_OPTS="-j$(getconf _NPROCESSORS_ONLN)"
19CC=gcc
20
21build_32()
22{
23	echo "===== 32-bit ${1}-tree build into $PREFIX ====="
24	build $1 CFLAGS="-m32" CXXFLAGS="-m32" LDFLAGS="-m32"
25}
26
27build_native()
28{
29	echo "===== native ${1}-tree build into $PREFIX ====="
30	build $1
31}
32
33build_cross()
34{
35	local host="${CC%-gcc}"
36	[ -n "$host" ] || \
37		{ echo "Missing CC variable, pass it with -c option." >&2; exit 1; }
38
39	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
56}
57
58build_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
64	mkdir -p $build
65	cd $build
66	run_configure $tree/configure $CONFIGURE_OPTS_OUT_TREE CC="$CC" $@
67
68	echo "=== build ==="
69	make $make_opts
70
71	echo "=== install ==="
72	make $make_opts DESTDIR="$PREFIX" SKIP_IDCHECK=1 install
73}
74
75build_in_tree()
76{
77	run_configure ./configure $CONFIGURE_OPTS_IN_TREE CC="$CC" --prefix=$PREFIX $@
78
79	echo "=== build ==="
80	make $MAKE_OPTS
81
82	echo "=== install ==="
83	make $MAKE_OPTS install
84}
85
86run_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
102usage()
103{
104	cat << EOF
105Usage:
106$0 [ -c CC ] [ -o TREE ] [ -p DIR ] [ -t TYPE ]
107$0 -h
108
109Options:
110-h       Print this help
111-c CC    Define compiler (\$CC variable)
112-o TREE  Specify build tree, default: $DEFAULT_TREE
113-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
121
122BUILD TREE:
123in       in-tree build
124out      out-of-tree build
125
126BUILD TYPES:
12732       32-bit in-tree build
128cross    cross-compile in-tree build (requires set compiler via -c switch)
129native   native in-tree build
130EOF
131}
132
133PREFIX="$DEFAULT_PREFIX"
134build="$DEFAULT_BUILD"
135tree="$DEFAULT_TREE"
136
137while getopts "c:ho:p:t:" opt; do
138	case "$opt" in
139	c) CC="$OPTARG";;
140	h) usage; exit 0;;
141	o) case "$OPTARG" in
142		in|out) tree="$OPTARG";;
143		*) echo "Wrong build tree '$OPTARG'" >&2; usage; exit 1;;
144		esac;;
145	p) PREFIX="$OPTARG";;
146	t) case "$OPTARG" in
147		32|cross|native) build="$OPTARG";;
148		*) echo "Wrong build type '$OPTARG'" >&2; usage; exit 1;;
149		esac;;
150	?) usage; exit 1;;
151	esac
152done
153
154cd `dirname $0`
155
156echo "=== ver_linux ==="
157./ver_linux
158echo
159
160echo "=== compiler version ==="
161$CC --version
162
163eval build_$build $tree
164