-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
executable file
·140 lines (114 loc) · 2.85 KB
/
setup.sh
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
#! /usr/bin/env bash
# Use this script to initialize common build configurations:
#
# Usage examples:
# ./setup.sh # `arch` debug
# ./setup.sh mybuild # `arch` debug build directory = "mybuild"
# ./setup.sh -c # `arch` debug, force clang compiler
# ./setup.sh -g # `arch` debug, force gcc compiler
# ./setup.sh -xr # x86_64 release
# ./setup.sh -xd # x86_64 debug
# ./setup.sh -ar # armv7l release
# ./setup.sh -arf # armv7l FINAL release
# ./setup.sh -ad # armv7l debug
# Part of the rsked project. Copyright 2020 Steven A. Harp
print_usage()
{
cat <<EOF
Usage: ./setup.sh [-d|-r] [-a|-x] [-c|-g] [builddir]"
This script will invoke meson to prepare a build directory.
Without arguments, will prepare a build directory for a debug
build on the native architecture using gcc.
Options:
-a
build for armv7l architecture
-d
select a debug build
-c
use the clang compiler
-f
mark this as an official release for packaging
-g
use the gcc compiler
- n
include the NRSC5 radio player
-r
select a release build
-R
select a release build but do not strip binaries
-x
build for x86_64 architecture
builddir
optional name for the build directory
EOF
}
sCC=gcc
sCXX=g++
BTYPE='debug'
TMACH=$(arch)
NOSTRIP=false
FINAL=false
NRSC5=false
while getopts ":acdfngrRx" opt ; do
case $opt in
a ) TMACH=armv7l ;;
c ) sCC=clang; sCXX=clang++ ;;
d ) BTYPE=debug ;;
f ) FINAL=true ;;
g ) sCC=gcc; sCXX=g++ ;;
n ) NRSC5=true ;;
r ) BTYPE=release ;;
R ) BTYPE=release ; NOSTRIP=true ;;
x ) TMACH=x86_64 ;;
\? ) print_usage
exit 1
esac
done
shift $(($OPTIND - 1))
if [[ $# > 1 ]]; then
echo "Invalid argument list."
print_usage
exit 1
fi
# to strip or not to strip...
#
if [[ $BTYPE = 'release' ]]; then
if [[ $NOSTRIP = 'false' ]]; then
STRIP=true
else
STRIP=false
fi
else
STRIP=false
fi
echo "Strip binaries: $STRIP"
# canonical place in most distros for jsoncpp
JSONCPP=/usr/include/jsoncpp
if [[ -e "$JSONCPP/json/json.h" ]]; then
echo "jsoncpp include directory is: $JSONCPP"
else
# Nix, e.g. will add it to CFLAG search path
echo "jsoncpp include directory TBD by environment"
JSONCPP=''
fi
if [[ $# == 1 ]]; then
BUILDDIR=$1
else
BUILDDIR="${BTYPE}-${TMACH}"
fi
if [[ -d $BUILDDIR ]]; then
echo "Error: build directory $BUILDDIR already exists"
exit 1
fi
echo "Setup for target-arch=$TMACH, build-type=$BTYPE in: $BUILDDIR"
echo "Compiler: $sCXX / $sCC"
#-----------------------------
CC=$sCC CXX=$sCXX \
meson setup --buildtype $BTYPE \
-Dprefix="$HOME" \
-Dtarget_machine=$TMACH \
-Ddatadir=.config \
-Dfinal=$FINAL \
-Dwith_nrsc5=$NRSC5 \
-Djsoncpp_inc="$JSONCPP" \
-Dstrip=$STRIP $BUILDDIR