• 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
12CFLAGS="${CFLAGS:--Werror=implicit-function-declaration -fno-common}"
13CC="${CC:-gcc}"
14
15DEFAULT_PREFIX="$HOME/ltp-install"
16DEFAULT_BUILD="native"
17DEFAULT_TREE="in"
18CONFIGURE_OPTS_IN_TREE="--with-open-posix-testsuite --with-realtime-testsuite"
19# TODO: open posix testsuite is currently broken in out-tree-build. Enable it once it's fixed.
20CONFIGURE_OPTS_OUT_TREE="--with-realtime-testsuite"
21MAKE_OPTS="-j$(getconf _NPROCESSORS_ONLN)"
22
23build_32()
24{
25	echo "===== 32-bit ${1}-tree build into $PREFIX ====="
26	CFLAGS="-m32 $CFLAGS" LDFLAGS="-m32 $LDFLAGS"
27	build $1 $2
28}
29
30build_native()
31{
32	echo "===== native ${1}-tree build into $PREFIX ====="
33	build $1 $2
34}
35
36build_cross()
37{
38	local host="${CC%-gcc}"
39	[ -n "$host" ] || \
40		{ echo "Missing CC variable, pass it with -c option." >&2; exit 1; }
41
42	echo "===== cross-compile ${host} ${1}-tree build into $PREFIX ====="
43	build $1 $2 "--host=$host" CROSS_COMPILE="${host}-"
44}
45
46build()
47{
48	local tree="$1"
49	local install="$2"
50	shift 2
51
52	echo "=== autotools ==="
53	make autotools
54
55	if [ "$tree" = "in" ]; then
56		build_in_tree $install $@
57	else
58		build_out_tree $install $@
59	fi
60}
61
62build_out_tree()
63{
64	local install="$1"
65	shift
66
67	local tree="$PWD"
68	local build="$tree/../ltp-build"
69	local make_opts="$MAKE_OPTS -C $build -f $tree/Makefile top_srcdir=$tree top_builddir=$build"
70
71	mkdir -p $build
72	cd $build
73	run_configure $tree/configure $CONFIGURE_OPTS_OUT_TREE $@
74
75	echo "=== build ==="
76	make $make_opts
77
78	if [ "$install" = 1 ]; then
79		echo "=== install ==="
80		make $make_opts DESTDIR="$PREFIX" SKIP_IDCHECK=1 install
81	else
82		echo "make install skipped, use -i to run it"
83	fi
84}
85
86build_in_tree()
87{
88	local install="$1"
89	shift
90
91	run_configure ./configure $CONFIGURE_OPTS_IN_TREE --prefix=$PREFIX $@
92
93	echo "=== build ==="
94	make $MAKE_OPTS
95
96	if [ "$install" = 1 ]; then
97		echo "=== install ==="
98		make $MAKE_OPTS install
99	else
100		echo "make install skipped, use -i to run it"
101	fi
102}
103
104run_configure()
105{
106	local configure=$1
107	shift
108
109	export CC CFLAGS LDFLAGS
110	echo "CC='$CC' CFLAGS='$CFLAGS' LDFLAGS='$LDFLAGS'"
111
112	echo "=== configure $configure $@ ==="
113	if ! $configure $@; then
114		echo "== ERROR: configure failed, config.log =="
115		cat config.log
116		exit 1
117	fi
118
119	echo "== include/config.h =="
120	cat include/config.h
121}
122
123usage()
124{
125	cat << EOF
126Usage:
127$0 [ -c CC ] [ -o TREE ] [ -p DIR ] [ -t TYPE ]
128$0 -h
129
130Options:
131-h       Print this help
132-c CC    Define compiler (\$CC variable)
133-o TREE  Specify build tree, default: $DEFAULT_TREE
134-p DIR   Change installation directory. For in-tree build is this value passed
135         to --prefix option of configure script. For out-of-tree build is this
136         value passed to DESTDIR variable (i.e. sysroot) of make install
137         target, which means that LTP will be actually installed into
138         DIR/PREFIX (i.e. DIR/opt/ltp).
139         Default for in-tree build: '$DEFAULT_PREFIX'
140         Default for out-of-tree build: '$DEFAULT_PREFIX/opt/ltp'
141-t TYPE  Specify build type, default: $DEFAULT_BUILD
142
143BUILD TREE:
144in       in-tree build
145out      out-of-tree build
146
147BUILD TYPES:
14832       32-bit in-tree build
149cross    cross-compile in-tree build (requires set compiler via -c switch)
150native   native in-tree build
151EOF
152}
153
154PREFIX="$DEFAULT_PREFIX"
155build="$DEFAULT_BUILD"
156tree="$DEFAULT_TREE"
157install=0
158
159while getopts "c:hio:p:t:" opt; do
160	case "$opt" in
161	c) CC="$OPTARG";;
162	h) usage; exit 0;;
163	i) install=1;;
164	o) case "$OPTARG" in
165		in|out) tree="$OPTARG";;
166		*) echo "Wrong build tree '$OPTARG'" >&2; usage; exit 1;;
167		esac;;
168	p) PREFIX="$OPTARG";;
169	t) case "$OPTARG" in
170		32|cross|native) build="$OPTARG";;
171		*) echo "Wrong build type '$OPTARG'" >&2; usage; exit 1;;
172		esac;;
173	?) usage; exit 1;;
174	esac
175done
176
177cd `dirname $0`
178
179echo "=== ver_linux ==="
180./ver_linux
181echo
182
183echo "=== compiler version ==="
184$CC --version
185
186eval build_$build $tree $install
187