-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
174 lines (136 loc) · 4.11 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
#!/bin/bash
#-----------------------------#
# Libraries required to build #
# #
# suto apt-get install #
# #
# libx11-dev libgl-dev #
# libssl-dev #
# #
#-----------------------------#
#Setup Compiler Options Here
CPP=g++
GPP=g++
OUTPUT="test.elf"
#Debug Mode enables certain warnings, debug symbols, and address sanitization to help mediate memory address issues;
# turn off for best performance!
DEBUGMODE=0
LINK_ONLY=0
VERBOSE=0
ASYNC_BUILD=1
REBUILD_APPLICATION=1
SOURCE_DIRECTORY="src"
COMPILER_FLAGS=""
ADDITIONAL_LIBRARIES="-static-libstdc++ -lX11 -lGL -lpthread -lstdc++fs -lcrypto"
ADDITIONAL_LIBDIRS=""
ADDITIONAL_INCLUDEDIRS="-Iinclude -Ilibraries/librapidjson/include"
LINKER_FLAGS=""
OBJ_DIR=".objs64"
#Compilers older than GCC 10.2.0 need to use -std=c++2a
# -- Automatically determine G++ version and use correct flag --
echo "--------------------------------------------------"
echo "- Initializing MME Build Toolchain -"
echo "--------------------------------------------------"
CXX2A="-std=c++2a"
CXX20="-std=c++20"
if ! command -v $GPP &> /dev/null; then
echo "Could not find ${GPP}; You must install ${GPP} first using: apt install ${GPP}"
exit
fi
VERSION=$( $GPP -dumpspecs | grep *version: -s -A 1 | grep -v *version )
_VERSION=()
_IFS=$IFS;
IFS='.';
for vz in $VERSION; do
_VERSION+=( $vz )
done
IFS=$_IFS # restore previous IFS
HIGHER_VERSION=0
if [ ${_VERSION[0]} -eq 10 ]; then
if [ ${_VERSION[1]} -eq 2 ]; then
if [ ${_VERSION[2]} -ge 0 ]; then
HIGHER_VERSION=1
fi
elif [ ${_VERSION[1]} -ge 2 ]; then
HIGHER_VERSION=1
else
HIGHER_VERSION=0
fi
elif [ ${_VERSION[0]} -ge 10 ]; then
HIGHER_VERSION=1
else
HIGHER_VERSION=0
fi
if [ $HIGHER_VERSION -eq 1 ]; then
COMPILER_FLAGS+=" ${CXX20}"
else
COMPILER_FLAGS+=" ${CXX2A}"
fi
echo "| Using ${GPP} version ${VERSION} |"
echo "========================================="
if [ -f "$OUTPUT" ]; then
rm $OUTPUT
fi
if [ $LINK_ONLY -eq 0 ]; then
if [ $DEBUGMODE -eq 1 ]; then
DEBUG_INFO="-ggdb -g -fsanitize=address -Wshadow-compatible-local"
else
DEBUG_INFO="-s"
fi
if [ $REBUILD_APPLICATION -eq 1 ]; then
rm $OBJ_DIR/*.o
fi
if [ ! -d "$OBJ_DIR/" ]; then
echo "Creating Object Directory Structure..."
mkdir "$OBJ_DIR/"
fi
echo "Building API Files..."
procs=[]
n=0
cppfiles=$(find $SOURCE_DIRECTORY -type f -name "*.cpp")
for filename in $cppfiles; do
objfile="$(basename "$filename" .cpp).o"
#echo "Iterate: $filename"
#echo "objfile=$objfile"
if [ ! -f $OBJ_DIR/$objfile ]; then
echo "Building $objfile"
if [ $ASYNC_BUILD -eq 1 ]; then
$CPP $ADDITIONAL_INCLUDEDIRS $COMPILER_FLAGS $DEBUG_INFO -c $filename -o $OBJ_DIR/$objfile &
procs[${n-1}]=$!
else
$CPP $ADDITIONAL_INCLUDEDIRS $COMPILER_FLAGS $DEBUG_INFO -c $filename -o $OBJ_DIR/$objfile
fi
if [ $VERBOSE -eq 1 ]; then
echo "$CPP $ADDITIONAL_INCLUDEDIRS $COMPILER_FLAGS $DEBUG_INFO -c $filename -o $OBJ_DIR/$objfile"
fi
fi
n=$((n + 1))
done
for pid in ${procs[*]}; do
wait $pid
done
fi
# Linking
echo "Linking Executable..."
sleep 5 #sleep for 5 seconds to prevent any linkage issues
files=""
for filename in "$OBJ_DIR"/*.o; do
files="$files $filename"
done
if [ $DEBUGMODE -eq 1 ]; then
LINKER_FLAGS+=" -fsanitize=address"
fi
if [ $VERBOSE -eq 1 ]; then
echo "$GPP $LINKER_FLAGS $ADDITIONAL_LIBDIRS -o $OUTPUT $files $ADDITIONAL_LIBRARIES"
fi
$GPP $LINKER_FLAGS $ADDITIONAL_LIBDIRS -o $OUTPUT $files $ADDITIONAL_LIBRARIES
if [ -f "$OUTPUT" ]; then
echo "---------------------------"
echo "- MME Build Completed! -"
echo "---------------------------"
else
echo "-------------------------"
echo "- MME Build FAILED! -"
echo "- See Log For Details -"
echo "-------------------------"
fi