-
Notifications
You must be signed in to change notification settings - Fork 0
/
compileApp.sh
executable file
·90 lines (76 loc) · 2.06 KB
/
compileApp.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
#! /bin/bash
# Build data
preCompilePackage="component_archive"
executableFilename="smallsh"
mainFilename="main.c"
testOutputFiles="
*.o
*.a
junk*
mytestresults
myModifiedTestresults
testfile.txt
~/testdir*"
# Components
declare -a componentList=(
"constants"
"ioHandlerMethods"
"subProcessHandlers"
"builtinFunctions"
"signalHandlers"
"activeProcessHandlers"
)
# Cleans previously compiled files and created folders
function preCompileClean() {
rm -rf $executableFilename *.o *.a $testOutputFiles
}
# Cleans space of temporary compile files
function postCompileClean() {
rm -f *.o *.a
}
function generatePrecompiledObject() {
gcc --std=gnu99 -c ${1}/${1}.c
}
function generateModuleObjectsAndArchive() {
# Stores object list
precompileObjectList=""
# Create precompiled objects and list
for component in ${componentList[@]}; do
precompileObjectList+=" ${component}.o"
generatePrecompiledObject $component
done
# Creates archive with objects
ar -r ${preCompilePackage}.a $precompileObjectList 2>/dev/null
}
# Compiles main
function compileMainAndArchive() {
gcc --std=gnu99 -o $executableFilename $mainFilename ${preCompilePackage}.a
}
function main() {
# Pre cleaning, removes leftovers from previous runs
preCompileClean
# Compilation step
generateModuleObjectsAndArchive
compileMainAndArchive
# Pre cleaning to eliminate temporary files
postCompileClean
# Handles parameters to execute.
# Param triggers:
# e -> run executable
# v -> run executable with valgrind leak analysis
# t -> run executable with testscript to stdout
# r -> run executable with testscript and send results to a report file
# c -> performs only cleaning of compilation files and creted test files
while getopts "evtrc" flag; do
case $flag in
e) ./$executableFilename ;;
v) valgrind ./$executableFilename ;;
t) ./p3testscript 2>&1 ;;
r) ./p3testscript >mytestresults 2>&1 ;;
c) preCompileClean && postCompileClean ;;
esac
shift
done
}
# Execute this script passing params to main
main "$@"