-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.sh
executable file
·166 lines (153 loc) · 5.58 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
#!/bin/bash
# default variables
APG_DIR=apg
EXAMPLES_DIR=examples
BUILD_DIR_DEBUG=Debug
BUILD_DIR_RELEASE=Release
TYPE_DEBUG=-DCMAKE_BUILD_TYPE=Debug
TYPE_RELEASE=-DCMAKE_BUILD_TYPE=Release
NAMES=(ex-apgex ex-api ex-ast ex-basic ex-conv ex-format ex-json ex-lines ex-msgs ex-odata ex-sip ex-trace ex-wide ex-xml)
NAMELEN=${#NAMES[@]}
FLAG_DEBUG=-d
FLAG_RELEASE=-r
HELP="--help"
CLEAN='--clean'
SOURCE=
BUILD=
TARGET=
CLEAN_FLAG=0
# modify these for different IDE or build system
IDE_DEBUG='-G "Eclipse CDT4 - Unix Makefiles"'
IDE_VERSION_DEBUG=4.16
IDE_RELEASE='Unix Makefiles'
IDE_VERSION_RELEASE=''
# release version is default
BUILD_DIR=${BUILD_DIR_RELEASE}
IDE=${IDE_RELEASE}
IDE_VERSION=${IDE_VERSION_RELEASE}
TYPE=${TYPE_RELEASE}
# display the targets and descriptions
targets(){
echo ' target - description'
echo ' ------ - -----------'
echo ' all - build all targets'
echo ' apg - build apg70, the APG Version 7.0 parser generator'
echo ' ex-apgex - examples of using the SABNF pattern-matching engine, apgex library'
echo " ex-api - examples of using the parser generator's Application Programming Interface (API) library"
echo ' ex-ast - examples of using the Abstract Syntax Tree (AST)'
echo ' ex-basic - illustrate the basics of creating and using a parser'
echo ' ex-conv - illustrate the use of the data conversion library'
echo ' ex-format - illustrate the use of the data (hexdump-like) foramatting library'
echo ' ex-json - illustrate the use of the JSON parser library'
echo ' ex-lines - illustrate the lines parsing library'
echo ' ex-msgs - illustrate the use of the message logging library'
echo ' ex-odata - run the OData test cases'
echo ' ex-sip - parsing and time test for the Session Initiation Protocol (SIP) "torture tests"'
echo ' ex-trace - illustrate parser tracing and parser, memory and vector statistics'
echo ' ex-wide - illustrate parsing of wide (32-bit) characters'
}
# display the help screen
help(){
echo 'NAME'
echo " build.sh - create executables and/or Eclipse projects for the"
echo " APG 7.0 parser generator and examples of its use"
echo ''
echo 'SYNOPSIS'
echo " ./build.sh [-r | -d |--help] target [--clean]"
echo ''
echo 'DESCRIPTION'
echo ' This script will generate make files for the APG 7.0 parser generator and any'
echo " or all of the supplied example applications."
echo ""
echo " In release mode (-r), Unix Makefiles are generated and optimized executables are built."
echo " For a different build system, modify IDE_RELEASE and IDE_VERSION_RELEASE."
echo ""
echo " In debug mode (-d) Eclipse, version 4.16, project files are generated."
echo " Open Eclipse and select"
echo " Project->import->General->Existing Projects into Workspace"
echo " and browse to the ./Debug directory. At this point you should be able to"
echo " import all of the built projects into Eclipse."
echo " For a different build system, modify IDE_DEBUG and IDE_VERSION_DEBUG."
echo ""
echo " -r (default) - release mode, generate a release build and compile the executables"
echo " -d - bebug mode, generate Eclipse project files"
echo ' --help - print this help screen'
echo ' --clean - in release mode if --clean is present, clean the target if previously built'
echo " - ignored in debug mode"
echo ""
targets
}
# generate and Eclipse target
build(){
if [ ${CLEAN_FLAG} -eq 1 ];then
eval "cmake --build $2 --target clean"
else
eval "cmake ${IDE} ${IDE_VERSION} ${TYPE} -S $1 -B $2"
if [ ${TYPE} == ${TYPE_RELEASE} ];then
eval "cmake --build $2"
fi
fi
}
# check for an argument
if [ $# -eq 0 ] || [ $1 == ${HELP} ]; then
help
exit 0
fi
# set up for release or debug build
if [ $1 == ${FLAG_DEBUG} ]; then
BUILD_DIR=${BUILD_DIR_DEBUG}
IDE=${IDE_DEBUG}
IDE_VERSION=${IDE_VERSION_DEBUG}
TYPE=${TYPE_DEBUG}
TARGET=$2
echo "Building DEBUG target ${TARGET}"
elif [ $1 == ${FLAG_RELEASE} ]; then
TARGET=$2
if [ "$3" == ${CLEAN} ]; then
CLEAN_FLAG=1
echo "cleaning RELEASE target ${TARGET}"
else
echo "Building RELEASE target ${TARGET}"
fi
else
TARGET=$1
if [ $2 == ${CLEAN} ]; then
CLEAN_FLAG=1
echo "cleaning RELEASE target ${TARGET}"
else
echo "Building RELEASE target ${TARGET}"
fi
fi
# the examples require an output directory
if [ ! -d ${EXAMPLES_DIR}/output ]; then
echo "No example output directory - creating"
echo "${EXAMPLES_DIR}/output"
eval "mkdir ${EXAMPLES_DIR}/output"
fi
# generate Makefiles and build all example executables
if [ ${TARGET} == "all" ]; then
build apg ${BUILD_DIR}/apg
for (( i=0; i<${NAMELEN}; i++))
do
build ${EXAMPLES_DIR}/${NAMES[$i]} ${BUILD_DIR}/${NAMES[$i]}
done
exit 0
fi
# generate and build special case of apg70 executable
if [ ${TARGET} == "apg" ]; then
build apg ${BUILD_DIR}/${APG_DIR}
exit 0
fi
# search the list of example names
# generate and build the example if found
for (( i=0; i<${NAMELEN}; i++))
do
if [ ${NAMES[$i]} == ${TARGET} ]; then
build ${EXAMPLES_DIR}/${TARGET} ${BUILD_DIR}/${TARGET}
exit 0
fi
done
# error on unrecognized argument
echo "Unrecognized target: ${TARGET}"
help
exit 1