aboutsummaryrefslogtreecommitdiff
path: root/build.sh
blob: c6d146335e7de7bfb22812fb56ed3bf354e0f606 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/sh
# Copyright (c) 2017-2018 Petr Vorel <pvorel@suse.cz>
# Script for travis builds.
#
# TODO: Implement comparison of installed files. List of installed files can
# be used only for local builds as Travis currently doesn't support sharing
# file between jobs, see
# https://github.com/travis-ci/travis-ci/issues/6054

set -e

CFLAGS="${CFLAGS:--Werror=implicit-function-declaration}"
CC="${CC:-gcc}"

DEFAULT_PREFIX="$HOME/ltp-install"
DEFAULT_BUILD="native"
DEFAULT_TREE="in"
CONFIGURE_OPTS_IN_TREE="--with-open-posix-testsuite --with-realtime-testsuite"
# TODO: open posix testsuite is currently broken in out-tree-build. Enable it once it's fixed.
CONFIGURE_OPTS_OUT_TREE="--with-realtime-testsuite"
MAKE_OPTS="-j$(getconf _NPROCESSORS_ONLN)"

build_32()
{
	echo "===== 32-bit ${1}-tree build into $PREFIX ====="
	CFLAGS="-m32 $CFLAGS" LDFLAGS="-m32 $LDFLAGS"
	build $1
}

build_native()
{
	echo "===== native ${1}-tree build into $PREFIX ====="
	build $1
}

build_cross()
{
	local host="${CC%-gcc}"
	[ -n "$host" ] || \
		{ echo "Missing CC variable, pass it with -c option." >&2; exit 1; }

	echo "===== cross-compile ${host} ${1}-tree build into $PREFIX ====="
	build $1 "--host=$host" CROSS_COMPILE="${host}-"
}

build()
{
	local tree="$1"
	shift

	echo "=== autotools ==="
	make autotools

	if [ "$tree" = "in" ]; then
		build_in_tree $@
	else
		build_out_tree $@
	fi
}

build_out_tree()
{
	local tree="$PWD"
	local build="$tree/../ltp-build"
	local make_opts="$MAKE_OPTS -C $build -f $tree/Makefile top_srcdir=$tree top_builddir=$build"

	mkdir -p $build
	cd $build
	run_configure $tree/configure $CONFIGURE_OPTS_OUT_TREE $@

	echo "=== build ==="
	make $make_opts

	echo "=== install ==="
	make $make_opts DESTDIR="$PREFIX" SKIP_IDCHECK=1 install
}

build_in_tree()
{
	run_configure ./configure $CONFIGURE_OPTS_IN_TREE --prefix=$PREFIX $@

	echo "=== build ==="
	make $MAKE_OPTS

	echo "=== install ==="
	make $MAKE_OPTS install
}

run_configure()
{
	local configure=$1
	shift

	export CC CFLAGS LDFLAGS
	echo "CC='$CC' CFLAGS='$CFLAGS' LDFLAGS='$LDFLAGS'"

	echo "=== configure $configure $@ ==="
	if ! $configure $@; then
		echo "== ERROR: configure failed, config.log =="
		cat config.log
		exit 1
	fi

	echo "== include/config.h =="
	cat include/config.h
}

usage()
{
	cat << EOF
Usage:
$0 [ -c CC ] [ -o TREE ] [ -p DIR ] [ -t TYPE ]
$0 -h

Options:
-h       Print this help
-c CC    Define compiler (\$CC variable)
-o TREE  Specify build tree, default: $DEFAULT_TREE
-p DIR   Change installation directory. For in-tree build is this value passed
         to --prefix option of configure script. For out-of-tree build is this
         value passed to DESTDIR variable (i.e. sysroot) of make install
         target, which means that LTP will be actually installed into
         DIR/PREFIX (i.e. DIR/opt/ltp).
         Default for in-tree build: '$DEFAULT_PREFIX'
         Default for out-of-tree build: '$DEFAULT_PREFIX/opt/ltp'
-t TYPE  Specify build type, default: $DEFAULT_BUILD

BUILD TREE:
in       in-tree build
out      out-of-tree build

BUILD TYPES:
32       32-bit in-tree build
cross    cross-compile in-tree build (requires set compiler via -c switch)
native   native in-tree build
EOF
}

PREFIX="$DEFAULT_PREFIX"
build="$DEFAULT_BUILD"
tree="$DEFAULT_TREE"

while getopts "c:ho:p:t:" opt; do
	case "$opt" in
	c) CC="$OPTARG";;
	h) usage; exit 0;;
	o) case "$OPTARG" in
		in|out) tree="$OPTARG";;
		*) echo "Wrong build tree '$OPTARG'" >&2; usage; exit 1;;
		esac;;
	p) PREFIX="$OPTARG";;
	t) case "$OPTARG" in
		32|cross|native) build="$OPTARG";;
		*) echo "Wrong build type '$OPTARG'" >&2; usage; exit 1;;
		esac;;
	?) usage; exit 1;;
	esac
done

cd `dirname $0`

echo "=== ver_linux ==="
./ver_linux
echo

echo "=== compiler version ==="
$CC --version

eval build_$build $tree