-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
169 lines (144 loc) · 3.86 KB
/
build.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
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
#!/bin/bash
# ==============================================================================
# We like clean code
set -o errexit
set -o nounset
# ==============================================================================
# Constants
PROGRAM=`basename $0`
# Default parameters
DEBUG_DEF="false"
BUILDTYPE_DEF="Release"
# Real parameters
DEBUG=$DEBUG_DEF
BUILDTYPE=$BUILDTYPE_DEF
EXTRA_ARGS=
# ==============================================================================
# ------------------------------------------------------------------------------
debug_guard() {
[ "$DEBUG" = "true" ] && "$@" || :
}
# ------------------------------------------------------------------------------
echo_err() {
echo $@ >&2
}
# ------------------------------------------------------------------------------
usage()
{
cat << EOF
usage: $PROGRAM [-h] [-d] [BUILDTYPE}
Builds SODUCO programs.
POSITIONAL PARAMETERS:
BUILDTYPE
Type of build to generate. Must be either "Release" or "Debug".
[default: $BUILDTYPE_DEF]
OPTIONS:
-h Show this message
-d Activate debug mode
[default: $DEBUG_DEF]
EOF
}
# ------------------------------------------------------------------------------
# Build programs
# $1: debug type (mandatory) - should be either Debug or Release
build()
{
echo_err "Recreating build dir"
rm -rf build && mkdir build && cd build
echo_err "conan: install deps"
conan install -u .. --build pylene --build missing
echo_err "cmake: generate build scripts"
cmake .. --preset default
echo_err "cmake: launch build"
cmake --build . --config $1
echo_err "cpack: create artefacts"
cpack -G ZIP -G TGZ .
echo_err "**********************"
echo_err "BUILD COMPLETE"
echo_err "**********************"
}
# ------------------------------------------------------------------------------
parseargs()
{
# Get option(s)
while getopts “hd” OPTION
do
case $OPTION in
h)
usage
exit 1
;;
d)
DEBUG="true"
;;
?)
usage
exit
;;
esac
done
# Get positional parameter(s)
shift $((OPTIND-1))
if [ $# -eq 0 ]
then
debug_guard echo_err "No positional parameter was provided."
echo_err "No build type provided. Defaulting to \"$BUILDTYPE_DEF\""
BUILDTYPE=$BUILDTYPE_DEF
elif [ $# -eq 1 ]
then
BUILDTYPE=$1
elif [ $# -gt 1 ]
then
EXTRA_ARGS=$@
else
# Should never happen
debug_guard echo_err "BUG in positional argument processing."
fi
}
# ------------------------------------------------------------------------------
checkargs()
{
if [ ! -z "$EXTRA_ARGS" ]
then
echo_err "ERROR: extra parameters were detected"
echo_err "$EXTRA_ARGS"
echo_err "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
usage
exit 1
fi
if [ -z "$BUILDTYPE" ]
then
BUILDTYPE=$BUILDTYPE_DEF
elif [ "release" = $(echo $BUILDTYPE | tr '[:upper:]' '[:lower:]') ]
then
BUILDTYPE="Release"
elif [ "debug" = $(echo $BUILDTYPE | tr '[:upper:]' '[:lower:]') ]
then
BUILDTYPE="Debug"
else
echo_err "Unknown build type. Got \"$BUILDTYPE\" but expecting \"Release\" or \"Debug\"."
echo_err "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
usage
exit 2
fi
}
# ------------------------------------------------------------------------------
main()
{
# Parse command line (forward args)
parseargs $@
if [ "$DEBUG" = "true" ]
then
set -o verbose
set -o xtrace
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
fi
echo_err "BUILDTYPE: $BUILDTYPE"
# Check the options
checkargs
# Run if everything's allright.
build "$BUILDTYPE"
}
# ==============================================================================
# Call entry point (forward args)
main $@