• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# Copyright (c) 2017-2021 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:--Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=return-type -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 $CONFIGURE_OPT_EXTRA"
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 $CONFIGURE_OPT_EXTRA"
21MAKE_OPTS="-j$(getconf _NPROCESSORS_ONLN)"
22
23build_32()
24{
25	local dir
26	local arch="$(uname -m)"
27
28	echo "===== 32-bit ${1}-tree build into $PREFIX ====="
29
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
48	CFLAGS="-m32 $CFLAGS" LDFLAGS="-m32 $LDFLAGS"
49	build $1 $2
50}
51
52build_native()
53{
54	echo "===== native ${1}-tree build into $PREFIX ====="
55	build $1 $2
56}
57
58build_cross()
59{
60	local host=$(basename "${CC%-gcc}")
61	if [ "$host" = "gcc" ]; then
62		echo "Invalid CC variable for cross compilation: $CC (clang not supported)" >&2
63		exit 1
64	fi
65
66	echo "===== cross-compile ${host} ${1}-tree build into $PREFIX ====="
67	build $1 $2 "--host=$host"
68}
69
70build()
71{
72	local tree="$1"
73	local install="$2"
74	shift 2
75
76	echo "=== autotools ==="
77	make autotools
78
79	if [ "$tree" = "in" ]; then
80		build_in_tree $install $@
81	else
82		build_out_tree $install $@
83	fi
84}
85
86build_out_tree()
87{
88	local install="$1"
89	shift
90
91	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
95	mkdir -p $build
96	cd $build
97	run_configure $tree/configure $CONFIGURE_OPTS_OUT_TREE $@
98
99	echo "=== build ==="
100	make $make_opts
101
102	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
108}
109
110build_in_tree()
111{
112	local install="$1"
113	shift
114
115	run_configure ./configure $CONFIGURE_OPTS_IN_TREE --prefix=$PREFIX $@
116
117	echo "=== build ==="
118	make $MAKE_OPTS
119
120	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
126}
127
128run_configure()
129{
130	local configure=$1
131	shift
132
133	export CC CFLAGS LDFLAGS PKG_CONFIG_LIBDIR
134	echo "CC='$CC' CFLAGS='$CFLAGS' LDFLAGS='$LDFLAGS' PKG_CONFIG_LIBDIR='$PKG_CONFIG_LIBDIR'"
135
136	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
147usage()
148{
149	cat << EOF
150Usage:
151$0 [ -c CC ] [ -o TREE ] [ -p DIR ] [ -t TYPE ]
152$0 -h
153
154Options:
155-h       Print this help
156-c CC    Define compiler (\$CC variable)
157-o TREE  Specify build tree, default: $DEFAULT_TREE
158-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
166
167BUILD TREE:
168in       in-tree build
169out      out-of-tree build
170
171BUILD TYPES:
17232       32-bit build (PKG_CONFIG_LIBDIR auto-detection for x86_64)
173cross    cross-compile build (requires set compiler via -c switch)
174native   native build
175
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
181EOF
182}
183
184PREFIX="$DEFAULT_PREFIX"
185build="$DEFAULT_BUILD"
186tree="$DEFAULT_TREE"
187install=0
188
189while getopts "c:hio:p:t:" opt; do
190	case "$opt" in
191	c) CC="$OPTARG";;
192	h) usage; exit 0;;
193	i) install=1;;
194	o) case "$OPTARG" in
195		in|out) tree="$OPTARG";;
196		*) echo "Wrong build tree '$OPTARG'" >&2; usage; exit 1;;
197		esac;;
198	p) PREFIX="$OPTARG";;
199	t) case "$OPTARG" in
200		32|cross|native) build="$OPTARG";;
201		*) echo "Wrong build type '$OPTARG'" >&2; usage; exit 1;;
202		esac;;
203	?) usage; exit 1;;
204	esac
205done
206
207cd `dirname $0`
208
209echo "=== ver_linux ==="
210./ver_linux
211echo
212
213echo "=== compiler version ==="
214$CC --version
215
216eval build_$build $tree $install
217