Newer
Older
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
#!/bin/bash
#set -e
set -vx
function f_exit {
cd ${CURPWD}
unset TTCN_FILES
unset CC_FILES
unset CFG_FILES
unset EXECUTABLE
echo $1
exit $2
}
function f_usage {
echo "build.bash: This script import from External Disk the "
echo "Optional arguments:"
echo " prof: Generate a makefile including profiling options (e.g. ./build.bash prof)"
exit 0
}
clear
if [ "$1" == "help" ]
then
f_usage
fi
ATS_NAME=Mec
#CURPWD=`pwd`
if [ ! "${PWD##*/}" == "objs" ]
then
cd ../objs
if [ ! $? == 0 ]
then
echo "Please move to PROJECT/obj directory"
exit 1
fi
fi
# Remove everything
rm -fr ../objs/*.hh
rm -fr ../objs/*.cc
rm -fr ../objs/*.log
rm -fr ../objs/*.o
rm -fr ../objs/Makefile
# Remove useless files
find .. -type f -name "*~" -exec rm {} \;
find .. -type f -name "*.bak" -exec rm {} \;
find .. -type f -name "*.log" -exec rm {} \;
# Build JSON files if any and put them in objs directory
REFERENCES="LibCommon LibHttp LibMec LibMec/LocationAPI LibMec/RnisAPI LibMec/UEidentityAPI LibMec/BwManagementAPI"
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
for i in ${REFERENCES}
do
# TTCN code
for j in `find ${PATH_DEV_MEC}/src/$i/ttcn -type f -name "*.ttcn"`;
do
ln -sf $j ../ttcn/`basename $j`
done
# Include source code
files=`find ${PATH_DEV_MEC}/src/$i/include -type f`
if [ "${files}" != " " ]
then
for j in ${files};
do
ln -sf $j ../include/`basename $j`
done
fi
# CC source code
files=`find ${PATH_DEV_MEC}/src/$i/src -type f`
if [ "${files}" != " " ]
then
for j in ${files};
do
ln -sf $j ../src/`basename $j`
done
fi
done
# Generate the list of the TTCN-3 files
TTCN_FILES=`find .. -name '*.ttcn*'`
# Start ATS generation - Step 1
if [ "${OSTYPE}" == "cygwin" ]
then
rm ../bin/*.exe ../lib/*.dll
compiler.exe -b -e -f -g -l -L -M -n -O -t -r -R -U none -X ${TTCN_FILES} 2>&1 3>&1 | tee build.log
if [ "$?" == "1" ]
then
f_exit "Failed to compile ATS" 4
fi
else
compiler -b -e -f -g -l -L -M -n -O -t -r -R -U none -X ${TTCN_FILES} 2>&1 3>&1 | tee build.log
if [ "$?" == "1" ]
then
f_exit "Failed to generate ATS source code" 6
fi
fi
# Sart ATS generation - Step 2
# Create working variables
CC_FILES=`find ../src -name '*.c*'`
FWK_FILES=`find ${PATH_DEV_MEC}/framework/ -name '*.c*'`
CFG_FILES=`find ../etc -name '*.cfg'`
# Sart ATS generation - Step 3
if [ "${OSTYPE}" == "cygwin" ]
then
ttcn3_makefilegen.exe -d -f -g -m -M -R -U none -e Ats${ATS_NAME} ${TTCN_FILES} ${CC_FILES} ${FWK_FILES} ${CFG_FILES} | tee --append build.log
if [ "$?" == "1" ]
then
f_exit "Failed to compile ATS" 5
fi
else
ttcn3_makefilegen -d -f -g -m -M -R -U none -e Ats${ATS_NAME} ${TTCN_FILES} ${CC_FILES} ${FWK_FILES} ${CFG_FILES} | tee --append build.log
if [ "$?" == "1" ]
then
f_exit "Failed to generate ATS source code" 7
fi
fi
# Remove port skeletons to use src/<port skeletons>
for i in `ls ../include/*.hh`
do
if [ -f ./`basename $i` ]
then
rm ./`basename $i`
fi
done
for i in `ls ../src/*.cc`
do
if [ -f ./`basename $i` ]
then
rm ./`basename $i`
fi
done
# Check if Makefile was generated
if [ ! -f ./Makefile ]
then
f_exit "Failed to generate ATS source code" 8
fi
# Patch ATS generated files
#./bin/patch.bash 2>&1 3>&1 | tee --append build.log
# Add compiler/linker options
# -DASN_DISABLE_OER_SUPPORT is required for CAMCodec and DENMCodec
if [ "$1" == "prof" ]
then
if [ "${OSTYPE}" == "cygwin" ]
then
CXXFLAGS_DEBUG_MODE='s/-Wall/-pg -Wall -std=c++11 -fPIC -D_XOPEN_SOURCE=700 -DAS_USE_SSL -DENABLE_TRACE -pthreads -fstack-check -fstack-protector -fsanitize=leak -fsanitize=address -fno-omit-frame-pointer/g'
else
CXXFLAGS_DEBUG_MODE='s/-Wall/-pg -Wall -std=c++11 -fPIC -DAS_USE_SSL -DENABLE_TRACE -pthreads -fstack-check -fstack-protector -fsanitize=leak -fsanitize=address -fno-omit-frame-pointer/g'
fi
LDFLAGS_DEBUG_MODE='s/LDFLAGS = /LDFLAGS = -pg -pthread -fPIC -fstack-check -fstack-protector -fsanitize=leak -fsanitize=address -fno-omit-frame-pointer/g'
else
if [ "${OSTYPE}" == "cygwin" ]
then
CXXFLAGS_DEBUG_MODE='s/-Wall/-ggdb -O0 -Wall -std=c++11 -fPIC -DAS_USE_SSL -DENABLE_TRACE -D_XOPEN_SOURCE=700 -pthread -fstack-check -fstack-protector -fsanitize=leak -fsanitize=address -fno-omit-frame-pointer/g'
else
CXXFLAGS_DEBUG_MODE='s/-Wall/-ggdb -O0 -Wall -std=c++11 -fPIC -DAS_USE_SSL -DENABLE_TRACE -pthread -fstack-check -fstack-protector -fsanitize=leak -fsanitize=address -fno-omit-frame-pointer/g'
fi
LDFLAGS_DEBUG_MODE='s/LDFLAGS = /LDFLAGS = -g -pthread -fPIC -fstack-check -fstack-protector -fsanitize=leak -fsanitize=address -fno-omit-frame-pointer/g'
fi
ADD_INCLUDE='/CPPFLAGS = /a\\CPPFLAGS += -I/usr/local/share -I$(PATH_DEV_MEC)/include -I$(PATH_DEV_MEC)/framework/include -I../include -I../../LibMec/Common/include -I../../LibMec/include -I$(HOME_FRAMEWORKS)/osip/include -I$(HOME_INC) -I.'
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
204
205
206
207
208
209
210
211
212
213
214
215
216
ADD_LIBRARIES='s/LINUX_LIBS = -lxml2/LINUX_LIBS = -lrt -lxml2 -lpcap -lstdc++fs -lssl -L\$\(HOME_FRAMEWORKS\)\/osip\/src\/osipparser2\/\.libs -losipparser2/g'
sed --in-place "${CXXFLAGS_DEBUG_MODE}" ./Makefile
sed --in-place "${LDFLAGS_DEBUG_MODE}" ./Makefile
sed --in-place "${ADD_INCLUDE}" ./Makefile
sed --in-place "${ADD_LIBRARIES}" ./Makefile
# Update COMPILER_FLAGS
COMPILER_FLAGS='s/COMPILER_FLAGS = /COMPILER_FLAGS = -e -O /g'
sed --in-place "${COMPILER_FLAGS}" ./Makefile
# Update clean clause
CLEAN_LINE='s/$(RM) $(EXECUTABLE)/$(RM) ..\/bin\/$(EXECUTABLE) ..\/src\/*.o/g'
sed --in-place "${CLEAN_LINE}" ./Makefile
# Move binary file command
EXECUTABLE=MyExample
MV_CMD='s/all: $(TARGET) ;/all: $(TARGET) ; @if [ -f ..\/objs\/$(EXECUTABLE) ]; then mv ..\/objs\/$(EXECUTABLE) ..\/bin; fi ;/g'
sed --in-place "${MV_CMD}" ./Makefile
# Add run command
ADD_HOST='/PLATFORM = /aHOST=127.0.0.1'
ADD_PORT='/PLATFORM = /aPORT=12000'
sed --in-place "${ADD_PORT}" ./Makefile
sed --in-place "${ADD_HOST}" ./Makefile
ADD_RUN_LINE_1='$arun: all'
ADD_RUN_LINE_2='$a\\t@sudo LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) $(PWD)/../bin/$(EXECUTABLE) $(HOST) $(PORT)'
sed --in-place "${ADD_RUN_LINE_1}" ./Makefile
sed --in-place "${ADD_RUN_LINE_2}" ./Makefile
ADD_RUN_LINE_1='$arun_d: all'
ADD_RUN_LINE_2='$a\\t@gdb --args $(PWD)/../bin/$(EXECUTABLE) $(HOST) $(PORT)'
sed --in-place "${ADD_RUN_LINE_1}" ./Makefile
sed --in-place "${ADD_RUN_LINE_2}" ./Makefile
ADD_RUN_LINE_1='$arun_v: all'
ADD_RUN_LINE_2='$a\\t@sudo LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) valgrind -v --tool=memcheck --leak-check=yes --show-reachable=yes --track-fds=yes --run-cxx-freeres=yes $(PWD)/../bin/$(EXECUTABLE) $(HOST) $(PORT)'
sed --in-place "${ADD_RUN_LINE_1}" ./Makefile
sed --in-place "${ADD_RUN_LINE_2}" ./Makefile
# Add gendoc entry
ADD_RUN_LINE_1='$agendoc: ../docs/o2.cfg'
ADD_RUN_LINE_2='$a\\tdoxygen ../docs/o2.cfg'
sed --in-place "${ADD_RUN_LINE_1}" ./Makefile
sed --in-place "${ADD_RUN_LINE_2}" ./Makefile
# Build all
make all 2>&1 3>&1 | tee --append build.log
if [ "$?" == "1" ]
then
f_exit "Failed to generate ATS source code" 9
fi
export LD_LIBRARY_PATH=~/frameworks/osip/src/osipparser2/.libs:$LD_LIBRARY_PATH
../bin/Ats${ATS_NAME} -v
f_exit "Build done successfully" 0