-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·126 lines (106 loc) · 3.35 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
#!/bin/bash
# exit immediately on errors
set -e
# read arguments
ACTION="$1"
COMMAND="$2"
ARG_OP="$2"
ARG_NUM="$3"
# parameter expansion - to clear white space
ACTION=${ACTION/ //}
COMMAND=${COMMAND/ //}
# get working dir
DIR_WORK=$(cd $(dirname "$0") && pwd)
# test application
APP=rng-enigma-app
# delete during pruning
ARTIFACTS="dieharder.bin dieharder.txt enigma.txt"
# helper functions
help () {
echo "USAGE: enter a command, no command defaults to 'build'"
echo " build -- call 'lib cmake; lib make; app cmake; app make'"
echo " clean -- call 'lib clean; app clean'"
echo " purge -- call 'lib purge; app purge'"
echo " expunge -- call 'clean; purge'"
echo " run -- run the test executable with ARG_OP and ARG_NUM"
echo " lib cmake -- call 'cmake'"
echo " lib make -- call 'make; make install'"
echo " lib clean -- call 'make clean'"
echo " lib purge -- purge all artifacts"
echo " app cmake -- call 'cmake'"
echo " app make -- call 'make'"
echo " app clean -- call 'make clean'"
echo " app purge -- purge all artifacts"
echo " help -- print this help"
}
action() {
local PROJ=$1
local CMD=$2
local DIR=""
local ACTION_ING=""
local ACTION_ED=""
local INST=""
local PURGE=""
case "$PROJ" in
"lib") DIR="library" ; INST="make install" ; PURGE="cd $DIR_WORK/$DIR/lib ; find . ! -name '.gitignore' -delete" ;;
"app") DIR="application" ; PURGE="cd $DIR_WORK/$DIR/bin ; rm -f ${ARTIFACTS}" ;;
*) echo "ERROR: argument proj '${PROJ}' is not supported" ; exit 1 ;;
esac
case "$CMD" in
"cmake") ACTION_ING="CMaking" ; ACTION_ED="CMaked" ;;
"make") ACTION_ING="Making" ; ACTION_ED="Maked" ;;
"clean") ACTION_ING="Cleaning" ; ACTION_ED="Cleaned" ;;
"purge") ACTION_ING="Purging" ; ACTION_ED="Purged" ; ;;
*) echo "ERROR: argument command '${CMD}' is not supported" ; exit 2 ;;
esac
cd $DIR_WORK/$DIR/build
echo "++ ${ACTION_ING} the ${DIR} project ..."
case "$CMD" in
"cmake") cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ../. ;;
"make") make ; eval $INST ;;
"clean") make clean ;;
"purge") find . ! -name '.gitignore' -delete ; eval $PURGE ;;
esac
echo "++ ${ACTION_ED} the ${DIR} project."
}
# compound commands
build() {
action lib cmake
action lib make
action app cmake
action app make
}
clean() {
action lib clean
action app clean
}
purge() {
action lib purge
action app purge
}
expunge() {
clean
purge
}
run() {
cd $DIR_WORK/application/bin
if [[ -e ${APP} ]]
then
./${APP} $ARG_OP $ARG_NUM
else
echo "ERROR: missing executable '${APP}'"
exit 3
fi
}
# action
case "$ACTION" in
"build") build ; exit 0 ;;
"clean") clean ; exit 0 ;;
"purge") purge ; exit 0 ;;
"expunge") expunge ; exit 0 ;;
"run") run ; exit 0 ;;
"help") help ; exit 0 ;;
"lib"|"app") action "$ACTION" "$COMMAND" ; exit 0 ;;
"") build ; exit 0 ;;
*) echo "ERROR: command '${ACTION}' is not supported" ; help ; exit 4 ;;
esac