a24ba14e19455b9c3a942114ddd0338c9565713d
[it/test.git] / simulators / e2sim / build_e2sim
1 #!/bin/bash
2 #
3 #
4 # Copyright 2019 AT&T Intellectual Property
5 # Copyright 2019 Nokia
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 # build utility for E2 Agent
20
21 set -e
22
23 E2SIM_DIR=$PWD
24 ASN1_C_DIR=$E2SIM_DIR/build/CMakeFiles/ASN1
25
26 source $E2SIM_DIR/tools/build_helper.bash
27
28 print_help()
29 {
30   echo "
31     This program installs E2 Simulator
32     You should have ubuntu 14.xx, updated, and the Linux kernel >= 3.14
33     The program is run by default with no option
34
35     Options
36     --clean
37        Erase all files to make a rebuild from start
38     -h
39        Print this help
40     "
41 }
42
43 generate_asn1c_codes()
44 {
45   X2AP_RELEASE="R14"
46   X2AP_ASN_FILES="x2ap-14.6.0.asn1"
47   ASN_SOURCE_X2AP=$E2SIM_DIR/src/X2AP/MESSAGES/ASN1/${X2AP_RELEASE}/${X2AP_ASN_FILES}
48
49   ASN_SOURCE_Pendulum=$E2SIM_DIR/src/ONS2019/pendulum.asn1
50
51   done_flag="$ASN1_C_DIR"/done
52
53   #-ot = older than, -nt = newer than
54
55   if [ "$done_flag" -ot $ASN_SOURCE_X2AP ] ; then
56     echo_info "Generate C codes for from source file"
57     #echo_info $ASN_SOURCE
58
59     rm -f "$ASN1_C_DIR"/*.c "$ASN1_C_DIR"/*.h
60     mkdir -p $ASN1_C_DIR
61     asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example \
62                 -fno-include-deps -D $ASN1_C_DIR $ASN_SOURCE_X2AP  \
63                 |& egrep -v "^Copied|^Compiled" | sort -u
64
65     asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example \
66                 -fno-include-deps -D $ASN1_C_DIR $ASN_SOURCE_Pendulum  \
67                 |& egrep -v "^Copied|^Compiled" | sort -u
68
69     echo_success "ASN1 C codes generated at: $ASN1_C_DIR"
70   fi
71   touch $done_flag
72 }
73
74 install_rmr()
75 {
76   echo_info "Will install rmr library"
77   /bin/bash rmr_interface/rmr_install.sh
78 }
79
80 compile_asn_api_lib()
81 {
82   echo_info "Will complie ASN1_API library"
83   # rm -rf build/libASN1_API.a
84   # rm -rf build/asn_x2ap.o
85   # rm -rf build/asn_e2ap.o
86
87   g++ -O3  -std=c++14 -Wall \
88     -I./src/ASN1/ -I./src/ASN1/asn/ -I./src/ASN1/generated/  \
89     -c src/ASN1/lib/asn_e2ap.cpp \
90     -o build/asn_e2ap.o
91     ar -crv build/libASN1_API.a build/asn_e2ap.o
92
93   g++ -O3  -std=c++14 -Wall \
94     -I./src/ASN1/ -I./src/ASN1/asn/ -I./src/ASN1/generated/  \
95     -c src/ASN1/lib/asn_x2ap.cpp \
96     -o build/asn_x2ap.o
97     ar -crv build/libASN1_API.a build/asn_x2ap.o
98 }
99
100 function main()
101 {
102
103   case "$1" in
104     --clean)
105       echo_info "Will clean all previously producted files under build/"
106       rm -rf $E2SIM_DIR/build
107       echo_success "Clean Done"
108       exit
109       ;;
110
111     "")
112       ;;
113
114     --rmr)
115       install_rmr
116       exit
117       ;;
118
119     --lib)
120       compile_asn_api_lib
121       exit
122       ;;
123
124     -h)
125       print_help
126       exit 1;;
127
128     *)
129       echo_error "Unknown option $1"
130       exit
131   esac
132
133   BUILD_DIR=$E2SIM_DIR/build
134   mkdir -p $BUILD_DIR
135   mkdir -p $BUILD_DIR/log
136
137   # generate_asn1c_codes #X2AP, pendulum
138
139   compile_asn_api_lib
140
141   echo_info "Will build e2sim"
142   cd $BUILD_DIR
143   rm -rf CMakeCache.txt
144   cmake ..
145   make -j`nproc`
146
147   echo_success "e2sim compiled"
148
149 }
150
151 main "$@"