1#!/bin/bash 2 3set -e 4 5builddir= 6scriptdir=$(dirname $(readlink -f "$0")) 7install=no 8test=yes 9asan=yes 10 11while [ $# -gt 0 ]; do 12 case "$1" in 13 --build-dir) 14 if [ $# -lt 2 ]; then 15 echo "ERROR: missing argument for --build-dir option" >&2 16 exit 1 17 fi 18 builddir=$2 19 shift 2 20 ;; 21 --install) 22 install=yes 23 shift 24 ;; 25 --no-test) 26 test=no 27 shift 28 ;; 29 --no-asan) 30 asan=no 31 shift 32 ;; 33 --) 34 shift 35 break; 36 ;; 37 *) 38 echo "ERROR: Unexpected argument: $1" >&2 39 exit 1 40 esac 41done 42 43if [ -z "${builddir}" ]; then 44 echo "ERROR: --build-dir option not specified" >&2 45 exit 1 46fi 47 48if [ -e "${builddir}" ]; then 49 echo "ERROR: directory entry named '${builddir}' already exists" >&2 50 exit 1 51fi 52 53mkdir "${builddir}" 54cd "${builddir}" 55 56cflags="-O2" 57 58# enable extra warnings 59cflags+=" -Winline" 60cflags+=" -Wmissing-include-dirs" 61cflags+=" -Wnested-externs" 62cflags+=" -Wpointer-arith" 63cflags+=" -Wredundant-decls" 64cflags+=" -Wswitch-enum" 65 66# enable address sanitizer 67if [ "${asan}" = "yes" ]; then 68 cflags+=" -fsanitize=address" 69fi 70 71echo "" 72echo "Configuring ..." 73CFLAGS="${cflags}" CXXFLAGS="${cflags}" ../configure --enable-examples-build --enable-tests-build "$@" 74 75echo "" 76echo "Building ..." 77make -j4 -k 78 79if [ "${test}" = "yes" ]; then 80 # Load custom shim for WebUSB tests that simulates Web environment. 81 export NODE_OPTIONS="--require ${scriptdir}/../tests/webusb-test-shim/" 82 if ! make check ; then 83 cat tests/test-suite.log 84 exit 1 85 fi 86fi 87 88if [ "${install}" = "yes" ]; then 89 echo "" 90 echo "Installing ..." 91 make install 92fi 93