forked from CaioIcy/sdl2-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·137 lines (111 loc) · 2.79 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
#!/bin/bash
set -o posix
function attention_echo {
echo -e "\n******************************************"
echo -e "*\t$1 *"
echo -e "******************************************\n"
}
# Default project name (no spaces)
NAME_PROJECT="Default_Project_Name"
# If there is a T_NAME_PROJECT, assign it to NAME_PROJECT
if [ ! -z $T_NAME_PROJECT ]
then
NAME_PROJECT=${T_NAME_PROJECT}
else
attention_echo "No T_NAME_PROJECT set"
echo "Using '$NAME_PROJECT' as project name"
fi
# Run with timed run or not
TIMED_RUN="OFF"
# If there is a T_DO_TIMED_RUN, assign it to TIMED_RUN
if [ ! -z $T_DO_TIMED_RUN ]
then
TIMED_RUN=${T_DO_TIMED_RUN}
fi
attention_echo "TIMED_RUN='$TIMED_RUN'"
# The possible arguments to pass to this script
ARG_BUILD_DEBUG="debug"
ARG_BUILD_RELEASE="release"
ARG_CLEAN="clean"
# Some directories
DIR_PROJECT_ROOT=$(dirname "$(readlink -f $0)")
DIR_BUILD=${DIR_PROJECT_ROOT}/build
function build {
prepare_build
# Target is for DEBUG
if [ $1 == "Do${ARG_BUILD_DEBUG}" ]
then
attention_echo "Using CMake (build mode Debug)"
cmake -DSH_NAME_PROJECT=${NAME_PROJECT}\
-DCMAKE_BUILD_TYPE=Debug\
-DMY_TIMED_RUN_ENABLED=${TIMED_RUN}\
${DIR_PROJECT_ROOT} || exit $?
# Target is for RELEASE
elif [ $1 == "Do${ARG_BUILD_RELEASE}" ]
then
attention_echo "Using CMake (build mode Release)"
cmake -DSH_NAME_PROJECT=${NAME_PROJECT}\
-DCMAKE_BUILD_TYPE=Release\
-DMY_TIMED_RUN_ENABLED=${TIMED_RUN}\
${DIR_PROJECT_ROOT} || exit $?
# Invalid target for argument
else
attention_echo "Invalid parameter of '$1'"
exit 1
fi
attention_echo "Running the makefile"
make || exit $?
# Copy the executable to root, instead of copying the entire assets folder to build/src/
cp ./src/*_exec ../
popd
success_exit
}
function usage {
echo "The correct usage of this script:"
echo -e "\t./build.sh ${ARG_BUILD_DEBUG}"
echo -e "\t./build.sh ${ARG_BUILD_RELEASE}"
echo -e "\t./build.sh ${ARG_CLEAN}"
exit 2
}
function prepare_build {
# Clean the build folder first
rm -f ${DIR_BUILD}/CMakeCache.txt
mkdir -p ${DIR_BUILD} || exit $?
pushd ${DIR_BUILD}
}
function clean {
echo "Cleaning build/ folder..."
rm -rf build/
success_exit
}
function success_exit {
attention_echo "Finished build script"
exit 0
}
#########################################
################ "Main" #################
#########################################
attention_echo "Beggining build script"
# If the first argument is not empty
if [ ! -z $1 ]
then
# Target build is for DEBUG
if [ $1 == "${ARG_BUILD_DEBUG}" ]
then
build "Do${ARG_BUILD_DEBUG}"
# Target build is for RELEASE
elif [ $1 == "${ARG_BUILD_RELEASE}" ]
then
build "Do${ARG_BUILD_RELEASE}"
# Clean the workspace
elif [ $1 == "${ARG_CLEAN}" ]
then
clean
# Improper usage
else
usage
fi
# If the first argument is empty
else
usage
fi