-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.sh
executable file
·203 lines (187 loc) · 4.42 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash
set -e
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
SOURCE_PATH="$SCRIPT_PATH"
BUILD_PATH="$SOURCE_PATH/build"
CMAKE_BUILD_TYPE="-DCMAKE_BUILD_TYPE=Release"
CMAKE_COMPILER=""
BUILD_NAME_PREFIX=""
BUILD_NAME="release"
BUILD_NAME_SUFIX=""
CMAKE_ATTA_STATIC=""
BUILD_TYPE="default"
RUN_AFTER="false"
PROJECT_TO_RUN=""
INSTALL_AFTER="false"
NUM_JOBS=""
printHelp()
{
echo "Atta build script"
echo
echo "Usage: ./build.sh [option(s)]"
echo
echo "Options:"
echo
echo "-h or --help"
echo " This help menu"
echo
echo "-t or --type <option>"
echo " Which type of build."
echo " Valid options are: default, web, web_module, docs"
echo
echo "-d or --debug"
echo " Build with debug information."
echo
echo "-g or --gdb"
echo " Run with gdb."
echo
echo "-c or --compiler <name>"
echo " Select the compiler."
echo
echo "-j or --jobs <num_jobs>"
echo " Set number of jobs to use when building."
echo
echo "-s or --static <project_file>"
echo " Build statically linked to a project."
echo " The file should be a valid .atta"
echo
echo "-r or --run"
echo " Run after build."
echo
echo "-p or --project <project_file>"
echo " Specify project to run."
echo
echo "-i or --install"
echo " Install after build."
exit
}
buildDefault()
{
echo "---------- Building ----------"
# Build
cmake $CMAKE_BUILD_TYPE $CMAKE_COMPILER $CMAKE_ATTA_STATIC $SOURCE_PATH
make -j $NUM_JOBS
# Install
if [[ "$INSTALL_AFTER" == "true" ]]; then
echo "---------- Installing ----------"
sudo make install
fi
# Run
if [[ "$RUN_AFTER" == "true" ]]; then
echo "---------- Running ----------"
if [[ "$USE_GDB" == "true" ]]; then
gdb -ex r --args bin/atta $PROJECT_TO_RUN
else
bin/atta $PROJECT_TO_RUN
fi
fi
exit
}
buildWeb()
{
# Check if emscripten is installed
if ! command -v emcmake &> /dev/null
then
echo -e "\033[1m\033[31m[Error] \033[0m\033[31mEmscripten is not installed, please follow the instruction here: \033[37mhttps://emscripten.org/docs/getting_started/downloads.html"
exit
fi
CMAKE_MODULE="-DATTA_WEB_BUILD_MODULE=OFF"
if [[ "$BUILD_TYPE" == "web_module" ]]; then
CMAKE_MODULE="-DATTA_WEB_BUILD_MODULE=ON"
fi
# Build
echo "---------- Building web ----------"
emcmake cmake $CMAKE_MODULE $CMAKE_BUILD_TYPE $CMAKE_ATTA_STATIC $SOURCE_PATH
make -j $NUM_JOBS
# Run
if [[ "$RUN_AFTER" == "true" ]]; then
echo "---------- Running web ----------"
emrun bin/atta.html
fi
exit
}
buildDocs()
{
echo "---------- Building docs ----------"
cmake -ATTA_BUILD_DOCS=ON -DATTA_BUILD_TESTS=OFF $SOURCE_PATH
make -j $NUM_JOBS
exit
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
printHelp
;;
-d|--debug)
CMAKE_BUILD_TYPE="-DCMAKE_BUILD_TYPE=Debug"
BUILD_NAME="debug"
shift # past argument
;;
-g|--gdb)
USE_GDB="true"
RUN_AFTER="true"
shift # past argument
;;
-r|--run)
RUN_AFTER="true"
shift # past argument
;;
-j|--jobs)
NUM_JOBS="$2"
shift # past argument
shift # past value
;;
-p|--project)
PROJECT_TO_RUN="$2"
shift # past argument
shift # past value
;;
-i|--install)
INSTALL_AFTER="true"
shift # past argument
;;
-c|--compiler)
CMAKE_COMPILER="-DCMAKE_CXX_COMPILER=$2"
shift # past argument
shift # past vlaue
;;
-t|--type)
BUILD_TYPE="$2"
if [[ "$BUILD_TYPE" != "default" ]]; then
BUILD_NAME_PREFIX="$BUILD_TYPE-"
fi
shift # past argument
shift # past value
;;
-s|--static)
CMAKE_ATTA_STATIC="-DATTA_STATIC_PROJECT_FILE=$2"
BUILD_NAME_SUFIX="-static"
shift # past argument
shift # past value
;;
-*|--*)
echo "Unknown option $1"
exit
;;
esac
done
# Change to build directory
BUILD_PATH="$BUILD_PATH/$BUILD_NAME_PREFIX$BUILD_NAME$BUILD_NAME_SUFIX"
mkdir -p $BUILD_PATH && cd $BUILD_PATH
# Build
case $BUILD_TYPE in
default)
buildDefault
;;
web|web_module)
buildWeb
;;
docs)
buildDocs
;;
*)
echo "Unknown build type $BUILD_TYPE"
exit
;;
esac