aboutsummaryrefslogtreecommitdiff
path: root/.private/ci-build.sh
blob: 33dfb3b9835e4f05b9a912205760222423df4799 (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
#!/bin/bash

set -e

builddir=
scriptdir=$(dirname $(readlink -f "$0"))
install=no
test=yes
asan=yes

while [ $# -gt 0 ]; do
	case "$1" in
	--build-dir)
		if [ $# -lt 2 ]; then
			echo "ERROR: missing argument for --build-dir option" >&2
			exit 1
		fi
		builddir=$2
		shift 2
		;;
	--install)
		install=yes
		shift
		;;
	--no-test)
		test=no
		shift
		;;
	--no-asan)
		asan=no
		shift
		;;
	--)
		shift
		break;
		;;
	*)
		echo "ERROR: Unexpected argument: $1" >&2
		exit 1
	esac
done

if [ -z "${builddir}" ]; then
	echo "ERROR: --build-dir option not specified" >&2
	exit 1
fi

if [ -e "${builddir}" ]; then
	echo "ERROR: directory entry named '${builddir}' already exists" >&2
	exit 1
fi

mkdir "${builddir}"
cd "${builddir}"

cflags="-O2"

# enable extra warnings
cflags+=" -Winline"
cflags+=" -Wmissing-include-dirs"
cflags+=" -Wnested-externs"
cflags+=" -Wpointer-arith"
cflags+=" -Wredundant-decls"
cflags+=" -Wswitch-enum"

# enable address sanitizer
if [ "${asan}" = "yes" ]; then
	cflags+=" -fsanitize=address"
fi

echo ""
echo "Configuring ..."
CFLAGS="${cflags}" CXXFLAGS="${cflags}" ../configure --enable-examples-build --enable-tests-build "$@"

echo ""
echo "Building ..."
make -j4 -k

if [ "${test}" = "yes" ]; then
	# Load custom shim for WebUSB tests that simulates Web environment.
	export NODE_OPTIONS="--require ${scriptdir}/../tests/webusb-test-shim/"
	if ! make check ; then
	    cat tests/test-suite.log
	    exit 1
	fi
fi

if [ "${install}" = "yes" ]; then
	echo ""
	echo "Installing ..."
	make install
fi