build_oai 33.4 KB
Newer Older
thomasl's avatar
thomasl committed
1
#!/bin/bash
2 3 4 5 6
#/*
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements.  See the NOTICE file distributed with
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
7
# * the OAI Public License, Version 1.1  (the "License"); you may not use this file
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# * except in compliance with the License.
# * You may obtain a copy of the License at
# *
# *      http://www.openairinterface.org/?page_id=698
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *-------------------------------------------------------------------------------
# * For more information about the OpenAirInterface (OAI) Software Alliance:
# *      contact@openairinterface.org
# */

23
# file build_oai
thomasl's avatar
thomasl committed
24 25 26
# brief OAI automated build tool that can be used to install, compile, run OAI.
# author  Navid Nikaein, Lionel GAUTHIER, Laurent Thomas

27
set -e
thomasl's avatar
thomasl committed
28

yilmazt's avatar
yilmazt committed
29
# Include helper functions
30 31
THIS_SCRIPT_PATH=$(dirname $(readlink -f "$0"))
source "$THIS_SCRIPT_PATH"/tools/build_helper
thomasl's avatar
thomasl committed
32

yilmazt's avatar
yilmazt committed
33
# Set environment variables (OPENAIR_HOME, ...)
34 35
set_openair_env

yilmazt's avatar
yilmazt committed
36
# Variables for UE data generation
37 38 39
gen_nvram_path=$OPENAIR_DIR/targets/bin
conf_nvram_path=$OPENAIR_DIR/openair3/NAS/TOOLS/ue_eurecom_test_sfr.conf

40
XFORMS="True"
41
SKIP_SHARED_LIB_FLAG="False"
42
PRINT_STATS="False"
laurent's avatar
laurent committed
43
DEADLINE_SCHEDULER_FLAG_USER=""
44
REL="Rel15"
45
HW="None"
46
TP="Ethernet"
Lionel Gauthier's avatar
Lionel Gauthier committed
47
EPC=0
48
VERBOSE_CI=0
49
VERBOSE_COMPILE=0
50 51
RUN_GROUP=0
TEST_CASE_GROUP=""
52
BUILD_DIR=ran_build
53
BUILD_DOXYGEN=0
54
BUILD_COVERITY_SCAN=0
Rohit Gupta's avatar
Rohit Gupta committed
55
DISABLE_HARDWARE_DEPENDENCY="False"
56
CMAKE_BUILD_TYPE="RelWithDebInfo"
57
CMAKE_CMD="$CMAKE"
58
NOAVX512="False"
59
BUILD_ECLIPSE=0
Guy De Souza's avatar
Guy De Souza committed
60
NR="False"
61
OPTIONAL_LIBRARIES="telnetsrv enbscope uescope nrscope"
62
RU=0
63 64
CMAKE_C_FLAGS=()
CMAKE_CXX_FLAGS=()
65

66
function print_help() {
Cedric Roux's avatar
Cedric Roux committed
67
  echo_info "
Robert Schmidt's avatar
Robert Schmidt committed
68 69 70 71 72
This script compiles OpenAirInterface Software, and can install dependencies
for a number of distributions (Ubuntu 18-22, Fedora, RHEL7/8).
Options:
--arch-native
   Passes -march=native to the compiler.
73
-c | --clean
Cedric Roux's avatar
Cedric Roux committed
74
   Erase all files to make a rebuild from start
75
-C | --clean-all
Cedric Roux's avatar
Cedric Roux committed
76
   Erase all files made by previous compilations, installations
77 78
--clean-kernel
   Erase previously installed features in kernel: iptables, drivers, ...
79 80
--cmake-opt
   Pass the supplied option verbatim to cmake.
81 82
-d | --build-dir
   Sets build directory (will be <oai-root>/cmake_targets/<build-dir>/build)
Lionel Gauthier's avatar
Lionel Gauthier committed
83
-I | --install-external-packages
84 85 86 87
   Installs required packages such as LibXML, asn1.1 compiler, freediameter, ...
   This option will require root password
--install-optional-packages
   Install useful but not mandatory packages such as valgrind
88 89 90
-i | --install-system-files
   Install OpenAirInterface required files in Linux system
   This option will require root password
91 92 93 94 95
-g | --run-with-gdb <Release | RelWithDebInfo | MinSizeRel | Debug
  specify the build mode used by cmake. defaults to Debug mode if -g is used alone, with no mode parameter
  if -g is not specifies, Release mode is used.
-G | --cmaketrace
   enable cmake debugging messages
96
--eNB
Guy De Souza's avatar
Guy De Souza committed
97
  Makes the LTE softmodem
hardy's avatar
hardy committed
98 99
--eNBocp
  Makes the OCP LTE softmodem
Robert Schmidt's avatar
Robert Schmidt committed
100
--gNB
Guy De Souza's avatar
Guy De Souza committed
101
  Makes the NR softmodem
102
--RU
103
  Makes the OAI RRU
104
--UE
105
   Makes the UE specific parts (ue_ip, usim, nvram) from the given configuration file
Robert Schmidt's avatar
Robert Schmidt committed
106 107
--nrUE
  Makes the NR UE softmodem
Cedric Roux's avatar
Cedric Roux committed
108 109 110 111
--UE-conf-nvram [configuration file]
   Specify conf_nvram_path (default \"$conf_nvram_path\")
--UE-gen-nvram [output path]
   Specify gen_nvram_path (default \"$gen_nvram_path\")
112
-w | --hardware
113
   EXMIMO, USRP, BLADERF, LMSSDR, IRIS, ADRV9371_ZC706, SIMU, AW2SORI, None (Default)
114
   Adds this RF board support (in external packages installation and in compilation)
Robert Schmidt's avatar
Robert Schmidt committed
115
-t | --transport
116
   Selects the transport protocol type, options: None, Ethernet, benetel4g, benetel5g
117
-P | --phy_simulators
118
   Makes the unitary tests Layer 1 simulators
119
-S | --core_simulators
120 121 122
   Makes the core security features unitary simulators
-s | --check
   runs a set of auto-tests based on simulators and several compilation tests
123 124
--run-group 
   runs only specified test cases specified here. This flag is only valid with -s
125 126
-V | --vcd
   Adds a debgging facility to the binary files: GUI with major internal synchronization events
Robert Schmidt's avatar
Robert Schmidt committed
127 128 129 130
-x | --xforms
   Will compile with software oscilloscope features
--verbose-ci
  Compile with verbose instructions in CI Docker env
131 132
--verbose-compile
   Shows detailed compilation instructions in makefile
133 134
--cflags_processor
   Manually Add CFLAGS of processor if they are not detected correctly by script. Only add these flags if you know your processor supports them. Example flags: -msse3 -msse4.1 -msse4.2 -mavx2
135 136
--build-doxygen
   Builds doxygen based documentation.
137 138
--build-coverity-scan
   Builds Coverity-Scan objects for upload
139
--disable-deadline
140 141
   Disables deadline scheduler of Linux kernel (>=3.14.x).
--enable-deadline
laurent's avatar
laurent committed
142
   Enable deadline scheduler of Linux kernel (>=3.14.x). 
143
--disable-cpu-affinity
144
   Disables CPU Affinity between UHD/TX/RX Threads (Valid only when deadline scheduler is disabled). By defaulT, CPU Affinity is enabled when not using deadline scheduler. It is enabled only with >2 CPUs. For eNB, CPU_0-> Device library (UHD), CPU_1->TX Threads, CPU_2...CPU_MAX->Rx Threads. For UE, CPU_0->Device Library(UHD), CPU_1..CPU_MAX -> All the UE threads
145
--enable-cpu-affinity
146 147
--disable-T-Tracer
   Disables the T tracer.
Rohit Gupta's avatar
Rohit Gupta committed
148 149
--disable-hardware-dependency
   Disable HW dependency during installation
150
--ue-autotest-trace
151
   Enable specific traces for UE autotest framework
gabrielC's avatar
gabrielC committed
152
--ue-trace
153
   Enable traces for UE debugging
gabrielC's avatar
gabrielC committed
154
--ue-timing
155 156 157
   Enable traces for timing
--uhd-images-dir
   Download UHD images in the indicated location
158
--build-eclipse
159
   Build eclipse project files.
160
--build-lib <libraries>
161
   Build optional shared library, <libraries> can be one or several of $OPTIONAL_LIBRARIES or \"all\"
162 163
--usrp-recplay
   Build for I/Q record-playback modes
164 165
--noavx512
   Build without AVX512 if it is present on CPU
166 167
-k | --skip-shared-libraries
   Skip build for shared libraries to reduce compilation time when building frequently for debugging purposes
Robert Schmidt's avatar
Robert Schmidt committed
168 169
--ninja
  Tell cmake to use the Ninja build system. Without, will generate make files
170 171
--sanitize
  Shortcut for usage of --sanitize-address --sanitize-undefined
Robert Schmidt's avatar
Robert Schmidt committed
172
--sanitize-address | -fsanitize=address
173 174 175
  Enable the address sanitizer on all targets
--sanitize-undefined | -fsanitize=undefined
  Enable the undefined behavior sanitizer on all targets
176 177
-h | --help
   Print this help
178

179
Usage (first build):
yilmazt's avatar
yilmazt committed
180 181
 NI/ETTUS B201  + COTS UE : ./build_oai -I -i --eNB -w USRP
Usage (regular):
182 183
 Eurecom EXMIMO + OAI ENB : ./build_oai --eNB  
 NI/ETTUS B201  + OAI ENB : ./build_oai --eNB -w USRP"
184 185 186 187
}


function main() {
188

189 190
  until [ -z "$1" ]
  do
191
    case "$1" in
192
       --arch-native)
193 194 195
            CMAKE_C_FLAGS+=("-march=native")
            CMAKE_CXX_FLAGS+=("-march=native")
            shift;;
196 197 198 199 200
       -c | --clean)
            CLEAN=1
            shift;;
       -C | --clean-all)
            CLEAN_ALL=1
thomasl's avatar
thomasl committed
201
            shift;;
202 203 204
       --clean-kernel)
            clean_kernel
            echo_info "Erased iptables config and removed modules from kernel"
thomasl's avatar
thomasl committed
205
            shift;;
206 207 208
       --cmake-opt)
            CMAKE_CMD="$CMAKE_CMD $2"
            shift 2;;
209 210
       -d | --build-dir)
            BUILD_DIR=$2
211
            shift 2;;
212
       -I | --install-external-packages)
213
            INSTALL_EXTERNAL=1
214
            echo_info "Will install external packages"
thomasl's avatar
thomasl committed
215
            shift;;
216
       --install-optional-packages)
thomasl's avatar
thomasl committed
217 218 219
            INSTALL_OPTIONAL=1
            echo_info "Will install optional packages"
            shift;;
220 221 222 223
       -i | --install-system-files)
            INSTALL_SYSTEM_FILES=1
            echo_info "Will copy OpenAirInterface files in Linux directories"
            shift;;
224
       -g | --run-with-gdb)
225 226 227 228 229 230 231 232 233 234
            case "$2" in
                "Release")
                    CMAKE_BUILD_TYPE="Release"
                    echo_info "Will Compile without gdb symbols and with compiler optimization"
                    CMAKE_CMD="$CMAKE_CMD -DCMAKE_BUILD_TYPE=Release"
                    shift
                    ;;
                "RelWithDebInfo")
                    CMAKE_BUILD_TYPE="RelWithDebInfo"
                    echo_info "Will Compile with gdb symbols"
235
                    CMAKE_CMD="$CMAKE_CMD -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=1"
236 237 238 239 240
                    shift
                    ;;
                "MinSizeRel")
                    CMAKE_BUILD_TYPE="MinSizeRel"
                    echo_info "Will Compile for minimal exec size"
241
                    CMAKE_CMD="$CMAKE_CMD -DCMAKE_BUILD_TYPE=MinSizeRel"
242
                    shift
243
                    ;;
244 245 246 247 248
                "Debug" | *)
                    CMAKE_BUILD_TYPE="Debug"
                    echo_info "Will Compile with gdb symbols and disable compiler optimization"
                    CMAKE_CMD="$CMAKE_CMD -DCMAKE_BUILD_TYPE=Debug"
                    if [ "$2" == "Debug" ] ; then
249
                        shift
250 251 252
                    fi
                    ;;
            esac
thomasl's avatar
thomasl committed
253
            shift;;
254
       -G | --cmaketrace)
255
            CMAKE_CMD="$CMAKE_CMD --trace-expand"
thomasl's avatar
thomasl committed
256
            shift;;
257 258 259 260
       --eNB)
            eNB=1
            echo_info "Will compile eNB"
            shift;;
hardy's avatar
hardy committed
261 262 263 264 265
       --eNBocp)
            eNBocp=1
            echo_info "Will compile OCP eNB"
            shift;;
      --gNB)
Guy De Souza's avatar
Guy De Souza committed
266 267 268
            gNB=1
            echo_info "Will compile gNB"
            shift;;
269
       --RU)
270
            RU=1
271 272
            echo_info "Will compile RRU"
	    shift;;
273
       -a | --agent)
Guy De Souza's avatar
Guy De Souza committed
274 275
            echo_info "FlexRAN support is always compiled into the eNB"
            shift;;
276 277 278 279
       --UE)
            UE=1
            echo_info "Will compile UE"
            shift;;
Guy De Souza's avatar
Guy De Souza committed
280 281
       --nrUE)
            nrUE=1
282
            rfsimNas=1
Guy De Souza's avatar
Guy De Souza committed
283 284
            echo_info "Will compile NR UE"
            shift;;
Xu Bo's avatar
Xu Bo committed
285
       --mu)
286
            CMAKE_CMD="$CMAKE_CMD -DUE_EXPANSION=True -DPRE_SCD_THREAD=True"
Xu Bo's avatar
Xu Bo committed
287 288
            echo_info "Will compile with UE_EXPANSION"
            shift;;
Cedric Roux's avatar
Cedric Roux committed
289
       --UE-conf-nvram)
290
            conf_nvram_path=$(readlink -f "$2")
Cedric Roux's avatar
Cedric Roux committed
291
            shift 2;;
292
       --UE-gen-nvram)
293
            gen_nvram_path=$(readlink -f "$2")
294
            shift 2;;
thomasl's avatar
thomasl committed
295
       -w | --hardware)
296 297 298 299 300
            # Use OAI_USRP as the key word USRP is used inside UHD driver           
            case "$2" in
                "EXMIMO")
                    HW="EXMIMO"
                    ;;
301
                "USRP" | "BLADERF" | "LMSSDR" | "IRIS" | "ADRV9371_ZC706" | "SIMU" | "AW2SORI")
302 303 304 305 306 307 308
                    HW="OAI_"$2
                    ;;
                "None")
                    HW="None"
                    ;;
                *)
                    echo_fatal "Unknown HW type $HW: exit..."
309
            esac
310 311 312
            echo_info "Setting hardware to: $HW"
            #CMAKE_CMD="$CMAKE_CMD -DRF_BOARD=\"${HW}\""
            CMAKE_CMD="$CMAKE_CMD -DRF_BOARD=${HW}"
thomasl's avatar
thomasl committed
313
            shift 2;;
314 315 316
       -t | --transport)
	    TP=$2
            shift 2;;
317
       -P | --phy_simulators)
thomasl's avatar
thomasl committed
318
            SIMUS_PHY=1
319 320
            echo_info "Will compile dlsim, ulsim, ..."
            shift;;
321
       -S | --core_simulators)
322 323 324
            SIMUS_CORE=1
            echo_info "Will compile security unitary tests"
            shift;;
thomasl's avatar
thomasl committed
325 326
       -s | --check)
            OAI_TEST=1
327
            echo_info "Will run auto-tests"
thomasl's avatar
thomasl committed
328
            shift;;
329 330 331 332 333
       --run-group)
            RUN_GROUP=1
            TEST_CASE_GROUP=$2
            echo_info "executing test cases only in group: $TEST_CASE_GROUP"
            shift 2;;
thomasl's avatar
thomasl committed
334
       -V | --vcd)
335
            echo_info "Setting gtk-wave output"
336
            CMAKE_CMD="$CMAKE_CMD -DENABLE_VCD_FIFO=True"
thomasl's avatar
thomasl committed
337
            EXE_ARGUMENTS="$EXE_ARGUMENTS -V"
thomasl's avatar
thomasl committed
338
            shift;;
thomasl's avatar
thomasl committed
339
       -x | --xforms)
340
            XFORMS=1
thomasl's avatar
thomasl committed
341
            EXE_ARGUMENTS="$EXE_ARGUMENTS -d"
342
            echo_info "Will generate the software oscilloscope features"
thomasl's avatar
thomasl committed
343
            shift;;
344
       --verbose-ci)
345
            VERBOSE_CI=1
346 347
            echo_info "Will compile with verbose instructions in CI Docker env"
            shift;;
348
       --verbose-compile)
349
            VERBOSE_COMPILE=1
350 351
            echo_info "Will compile with verbose instructions"
            shift;;
352
       --cflags_processor)
353 354
            CMAKE_CMD="$CMAKE_CMD -DCFLAGS_PROCESSOR_USER=\"$2\""
            echo_info "Setting CPU FLAGS from USER to: $2"
355
            shift 2;;
356
       --build-doxygen)
357
	        BUILD_DOXYGEN=1
358 359
            echo_info "Will build doxygen support"
            shift;;     
360
       --build-coverity-scan)
361
            BUILD_COVERITY_SCAN=1
362 363
            echo_info "Will build Coverity-Scan objects for upload"
            shift;;
364
       --disable-deadline)
365
            DEADLINE_SCHEDULER_FLAG_USER="False"
366
            CMAKE_CMD="$CMAKE_CMD -DDEADLINE_SCHEDULER=False"
367 368
            echo_info "Disabling the usage of deadline scheduler"
            shift 1;;
369
       --enable-deadline)
370
            DEADLINE_SCHEDULER_FLAG_USER="True"
371
            CMAKE_CMD="$CMAKE_CMD -DDEADLINE_SCHEDULER=True"
372 373
            echo_info "Enabling the usage of deadline scheduler"
            shift 1;;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
374 375
       --enable-cpu-affinity)
            CPU_AFFINITY_FLAG_USER="True"
376
            CMAKE_CMD="$CMAKE_CMD -DCPU_AFFINITY=True"
Florian Kaltenberger's avatar
Florian Kaltenberger committed
377 378
            echo_info "Enabling CPU Affinity (only valid when not using deadline scheduler)"
            shift 1;;
379 380
       --disable-cpu-affinity)
            CPU_AFFINITY_FLAG_USER="False"
381
            CMAKE_CMD="$CMAKE_CMD -DCPU_AFFINITY=False"
382 383
            echo_info "Disabling CPU Affinity (only valid when not using deadline scheduler)"
            shift 1;;
384
       --disable-T-Tracer)
385
            CMAKE_CMD="$CMAKE_CMD -DT_TRACER=False"
386
            echo_info "Disabling the T tracer"
387
            shift 1;;
388 389 390 391
       --disable-hardware-dependency)
            echo_info "Disabling hardware dependency for compiling software"
            DISABLE_HARDWARE_DEPENDENCY="True"
            shift 1;;
392
       --ue-autotest-trace)
393
            CMAKE_CMD="$CMAKE_CMD -DUE_AUTOTEST_TRACE=True"
394 395
            echo_info "Enabling autotest specific trace for UE"
            shift 1;;
396
       --ue-trace)
397
            CMAKE_CMD="$CMAKE_CMD -DUE_DEBUG_TRACE=False"
gabrielC's avatar
gabrielC committed
398 399
            echo_info "Enabling UE trace for debug"
            shift 1;;
400
       --ue-timing)
401
            CMAKE_CMD="$CMAKE_CMD -DUE_TIMING_TRACE=True"
gabrielC's avatar
gabrielC committed
402 403
            echo_info "Enabling UE timing trace"
            shift 1;;
404
       --uhd-images-dir)
405 406 407
            UHD_IMAGES_DIR=$2
            echo_info "Downloading UHD images in the indicated location"
            shift 2;;
408 409 410 411
       --build-eclipse)
            BUILD_ECLIPSE=1
            CMAKE_CMD="$CMAKE_CMD"' -DCMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT=TRUE -G"Eclipse CDT4 - Unix Makefiles"'
            echo_info "Enabling build eclipse project support"
oai's avatar
oai committed
412
            shift 1;;
413 414
       --build-lib) 
            BUILD_OPTLIB="" 
415 416 417 418 419
            if [  "$2" == "all" ] ; then
              BUILD_OPTLIB="$OPTIONAL_LIBRARIES"
              echo_info "Enabling build of all optional shared libraries ($OPTIONAL_LIBRARIES)" 
            else
              for alib in $2 ; do 
420
                for oklib in $OPTIONAL_LIBRARIES ; do
421 422 423 424 425
                  if [ "$alib" = "$oklib" ] ; then
                    BUILD_OPTLIB="$BUILD_OPTLIB $alib" 
                    echo_info "Enabling build of lib${alib}.so" 
                    fi   
                  done
426
                done
427 428 429
	          if [ "${BUILD_OPTLIB## }" != "$2" ] ; then
                 echo_fatal "Unknown optional library in $2, valid libraries are $OPTIONAL_LIBRARIES" 
              fi
430 431
            fi
            shift 2;;		
432 433 434 435
        --noavx512)
            NOAVX512="True"
            echo_info "Disabling AVX512"
            shift 1;;
436 437
        -k | --skip-shared-libraries)
            SKIP_SHARED_LIB_FLAG="True"
438
            echo_info "Skipping build of shared libraries, rfsimulator and transport protocol libraries"
439
            shift;;
440 441 442 443
        --ninja)
            CMAKE_CMD="$CMAKE_CMD -GNinja"
            MAKE_CMD=ninja
            shift;;
444 445 446
        --sanitize)
            CMAKE_CMD="$CMAKE_CMD -DSANITIZE_ADDRESS=True -DSANITIZE_UNDEFINED=True"
            shift;;
447
        --sanitize-address | -fsanitize=address)
448
            grep -sq "Ubuntu 18.04" /etc/os-release && echo_error "Bug in OS with this option, see CMakeLists.txt"
449 450
            CMAKE_CMD="$CMAKE_CMD -DSANITIZE_ADDRESS=True"
            shift;;
451 452 453
        --sanitize-undefined | -fundefined=address)
            CMAKE_CMD="$CMAKE_CMD -DSANITIZE_UNDEFINED=True"
            shift;;
thomasl's avatar
thomasl committed
454 455 456
        -h | --help)
            print_help
            exit 1;;
Lionel Gauthier's avatar
Lionel Gauthier committed
457
	*)
458 459
	    print_help
            echo_fatal "Unknown option $1"
thomasl's avatar
thomasl committed
460
            break;;
thomasl's avatar
thomasl committed
461
   esac
462
  done
463

yilmazt's avatar
yilmazt committed
464 465 466
  ###################################
  # Check if cov-build is installed #
  ###################################
467 468 469 470 471 472 473 474 475 476
  if [ "$BUILD_COVERITY_SCAN" == "1" ] ; then
      echo_info "Checking cov-build is installed"
      IS_INSTALLED=`which cov-build | grep -c cov-build || true`
      if [ $IS_INSTALLED -eq 1 ] ; then
          echo_info "Found cov-build"
      else
          echo_fatal "Did NOT find cov-build in PATH!"
      fi
  fi

yilmazt's avatar
yilmazt committed
477 478 479
  ########################################################
  # Check validity of HW and TP parameters for eNB / gNB #
  ########################################################
Aikaterini's avatar
Aikaterini committed
480
  # to be discussed
481
  
482
  if [ "$eNB" = "1" -o "$eNBocp" = "1" -o "$gNB" = "1" ] ; then
483
      if [ "$HW" = "None" -a  "$TP" = "None" ] ; then
yilmazt's avatar
yilmazt committed
484
	      echo_info "No local radio head and no transport protocol selected"
485
      fi
486
      if [ "$HW" = "None" ] ; then 
yilmazt's avatar
yilmazt committed
487
	      echo_info "No radio head has been selected (HW set to $HW)"	
488
      fi
489
      if [ "$TP" = "None" ] ; then
yilmazt's avatar
yilmazt committed
490
	      echo_info "No transport protocol has been selected (TP set to $TP)"	
491 492
      fi
  fi
root's avatar
root committed
493

494
  echo_info "RF HW set to $HW" 
495 496
  # If the user doesn't specify the Linux scheduler to use, we set a value
  if [ "$DEADLINE_SCHEDULER_FLAG_USER" = "" ]; then
yilmazt's avatar
yilmazt committed
497
      case "$HW" in
498
          "EXMIMO")
yilmazt's avatar
yilmazt committed
499 500
		      DEADLINE_SCHEDULER_FLAG_USER="True"
		      ;;
501
          *)
yilmazt's avatar
yilmazt committed
502 503 504
		      DEADLINE_SCHEDULER_FLAG_USER="False"
		      ;;
      esac
505 506
  fi

507
  #Disable CPU Affinity for deadline scheduler
laurent's avatar
laurent committed
508
  if [ "$DEADLINE_SCHEDULER_FLAG_USER" = "True" ] ; then 
509
     CPU_AFFINITY_FLAG_USER="False"
510
     CMAKE_CMD="$CMAKE_CMD -DCPU_AFFINITY=False"
511
  fi
512

laurent's avatar
laurent committed
513
  echo_info "Flags for Deadline scheduler: $DEADLINE_SCHEDULER_FLAG_USER"
514
  echo_info "Flags for CPU Affinity: $CPU_AFFINITY_FLAG_USER"
Aikaterini's avatar
Aikaterini committed
515

yilmazt's avatar
yilmazt committed
516 517 518
  #######################################################
  # Setting and printing OAI envs, we should check here #
  #######################################################
Lionel Gauthier's avatar
Lionel Gauthier committed
519

520
  echo_info "2. Setting the OAI PATHS ..."
thomasl's avatar
thomasl committed
521

522
  cecho "OPENAIR_DIR    = $OPENAIR_DIR" $green
thomasl's avatar
thomasl committed
523

524 525 526 527 528 529 530 531 532 533
  # for conf files copy in this bash script
  if [ -d /usr/lib/freeDiameter ]; then
    export FREEDIAMETER_PREFIX=/usr
  else
    if [ -d /usr/local/lib/freeDiameter ]; then
      export FREEDIAMETER_PREFIX=/usr/local
    else
      echo_warning "FreeDiameter prefix not found, install freeDiameter if EPC, HSS"
    fi
  fi
thomasl's avatar
thomasl committed
534

535 536 537 538
  if [ "$CLEAN_ALL" = "1" ] ; then
    clean_all_files
    echo_info "Erased all previously producted files"
  fi
539

540 541 542 543 544 545 546
  dbin=$OPENAIR_DIR/targets/bin
  dlog=$OPENAIR_DIR/cmake_targets/log
  mkdir -p $dbin $dlog

  if [ "$INSTALL_EXTERNAL" = "1" ] ; then
    echo_info "Installing packages"
    check_install_oai_software
547 548 549
    if [ "$HW" == "OAI_USRP" ] ; then
      echo_info "installing packages for USRP support"
      check_install_usrp_uhd_driver
550
      if [ ! -v BUILD_UHD_FROM_SOURCE ] && [ ! "$DISABLE_HARDWARE_DEPENDENCY" == "True" ]; then
551
        install_usrp_uhd_driver $UHD_IMAGES_DIR
552
      fi
553
    fi 
frobinet's avatar
frobinet committed
554 555 556 557
#    if [ "$HW" == "OAI_ADRV9371_ZC706" ] ; then
#      echo_info "\nInstalling packages for ADRV9371_ZC706 support"
#      check_install_libiio_driver
#    fi 
558
    if [ "$HW" == "OAI_BLADERF" ] ; then
559
      echo_info "installing packages for BLADERF support"
560
      check_install_bladerf_driver
561 562 563
      if [ ! "$DISABLE_HARDWARE_DEPENDENCY" == "True" ]; then
        flash_firmware_bladerf
      fi
564
    fi
565 566 567 568 569 570
    if [ "$HW" == "OAI_IRIS" ] ; then
      echo_info "installing packages for IRIS support"
      check_install_soapy
      #if [ ! "$DISABLE_HARDWARE_DEPENDENCY" == "True" ]; then
      #  flash_firmware_iris
      #fi
571
    fi
572
    echo_info "Installing protobuf/protobuf-c for flexran agent support"
573
    install_protobuf_c
574
    echo_success "protobuf/protobuf-c installation successful"
575 576 577 578 579 580 581
  fi

  if [ "$INSTALL_OPTIONAL" = "1" ] ; then
    echo_info "Installing optional packages"
    check_install_additional_tools
  fi

582 583
  execlist=""
  if [ "$eNB" = "1" ] ; then
584
      execlist="$execlist lte-softmodem"
585 586
  fi
  if [ "$eNBocp" = "1" ] ; then
hardy's avatar
hardy committed
587
      execlist="$execlist ocp-enb"
588 589
  fi
  if [ "$gNB" = "1" ] ; then
590
      execlist="$execlist nr-softmodem"
591 592
  fi
  if [ "$RU" = "1" ] ; then
593
      execlist="$execlist oairu"
594 595
  fi
  if [ "$UE" = 1 ] ; then
596
      execlist="$execlist lte-uesoftmodem"
597 598
  fi
  if [ "$nrUE" = 1 ] ; then
599
      execlist="$execlist nr-uesoftmodem"
600
  fi
601 602 603 604 605 606 607 608 609 610 611 612 613 614

  if [[ "$execlist" == "" && "$SIMUS_PHY" != "1" ]]; then
    echo_success "installing dependencies successful"
    exit
  fi

  echo_info "3. building the compilation directives ..."

  DIR=$OPENAIR_DIR/cmake_targets

  [ "$CLEAN" = "1" ] && rm -rf $DIR/$BUILD_DIR/build
  mkdir -p $DIR/$BUILD_DIR/build

  cd  $DIR/$BUILD_DIR/build
615 616
  if [[ ${#CMAKE_C_FLAGS[@]} > 0 ]]; then CMAKE_CMD="$CMAKE_CMD -DCMAKE_C_FLAGS=\"${CMAKE_C_FLAGS[*]}\""; fi
  if [[ ${#CMAKE_CXX_FLAGS[@]} > 0 ]]; then CMAKE_CMD="$CMAKE_CMD -DCMAKE_CXX_FLAGS=\"${CMAKE_CXX_FLAGS[*]}\""; fi
617
  CMAKE_CMD="$CMAKE_CMD -DNOAVX512=\"${NOAVX512[*]}\""
618
  echo_info "running $CMAKE_CMD"
619
  eval $CMAKE_CMD
620 621
  
  for f in $execlist ; do
622
      echo_info "Compiling $f..."
623
      compilations \
624
          $BUILD_DIR $f \
625 626 627 628 629 630 631
          $f $dbin/$f.$REL
  done
  
  
  # mandatory shared libraries common to UE and (e/g)NB
  
  if [ "$SKIP_SHARED_LIB_FLAG" = "False" ]; then
632
      echo_info "Building shared libraries common to UE and gNB"
633 634 635

      # configuration module libraries, one currently available, using libconfig
      config_libconfig_shlib=params_libconfig
636 637
      
      compilations \
638
          $BUILD_DIR $config_libconfig_shlib \
639 640
          lib$config_libconfig_shlib.so $dbin/lib$config_libconfig_shlib.so
      
641
      compilations \
642
          $BUILD_DIR coding \
643
          libcoding.so $dbin/libcoding.so
644
      
645
  fi
646
  
yilmazt's avatar
yilmazt committed
647
  if [ "$UE" = 1 ] ; then
648

649
    echo_info "Compiling UE specific part"
650 651 652 653 654

    if [ $IS_CONTAINER -eq 0 ]
    then
      echo_info "Building ue_ip module"
      compilations \
655
        $BUILD_DIR ue_ip \
656 657 658 659
        CMakeFiles/ue_ip/ue_ip.ko $dbin/ue_ip.ko
    else
      echo_info "Bypassing ue_ip build"
    fi #IS_CONTAINER
660

Lionel Gauthier's avatar
Lionel Gauthier committed
661 662
#    mkdir -p $DIR/at_commands/build
#    cd $DIR/at_commands/build
663
#    eval $CMAKE_CMD
Lionel Gauthier's avatar
Lionel Gauthier committed
664 665 666
#    compilations \
#      at_commands at_nas_ue \
#      at_nas_ue $dbin/at_nas_ue
667

Lionel Gauthier's avatar
Lionel Gauthier committed
668
    [ "$CLEAN" = "1" ] && rm -rf $DIR/nas_sim_tools/build
669 670
    mkdir -p $DIR/nas_sim_tools/build
    cd $DIR/nas_sim_tools/build
671

672
    eval $CMAKE_CMD ..
thomasl's avatar
thomasl committed
673
    compilations \
674 675
      nas_sim_tools usim \
      usim $dbin/usim
thomasl's avatar
thomasl committed
676
    compilations \
677 678
      nas_sim_tools nvram \
      nvram $dbin/nvram
thomasl's avatar
thomasl committed
679
    compilations \
680 681
      nas_sim_tools conf2uedata \
      conf2uedata $dbin/conf2uedata
682 683

    # generate USIM data
684
    if [ -f $dbin/conf2uedata ]; then
685
      install_nas_tools $conf_nvram_path $gen_nvram_path "$dlog/conf2uedata.txt"
686 687 688 689
      echo_info "Copying UE specific part to $DIR/$BUILD_DIR/build"
      cp -Rvf $dbin/.ue_emm.nvram0 $DIR/$BUILD_DIR/build
      cp -Rvf $dbin/.ue.nvram0 $DIR/$BUILD_DIR/build
      cp -Rvf $dbin/.usim.nvram0 $DIR/$BUILD_DIR/build
690 691 692
    else
      echo_warning "not generated UE NAS files: binaries not found"
    fi
693
  fi
thomasl's avatar
thomasl committed
694

695
  cd  $DIR/$BUILD_DIR/build
696
  
yilmazt's avatar
yilmazt committed
697 698 699
  ##################
  # PHY simulators #
  ##################
700
  if [ "$SIMUS_PHY" = "1" ] ; then
yilmazt's avatar
yilmazt committed
701
    echo_info "Compiling physical unitary tests simulators"
702
    # TODO: fix: dlsim_tm4 pucchsim prachsim pdcchsim pbchsim mbmssim
703
    simlist="dlsim ulsim ldpctest polartest smallblocktest nr_pbchsim nr_dlschsim nr_ulschsim nr_dlsim nr_ulsim nr_pucchsim nr_prachsim"
WANG Tsu-Han's avatar
WANG Tsu-Han committed
704
	# simlist="ldpctest"
705 706
    for f in $simlist ; do
      compilations \
laurent's avatar
laurent committed
707
        $BUILD_DIR $f \
yilmazt's avatar
yilmazt committed
708
	    $f $dbin/$f.$REL
709
    done
710
    compilations \
laurent's avatar
laurent committed
711
      $BUILD_DIR coding \
yilmazt's avatar
yilmazt committed
712
      libcoding.so $dbin/libcoding.so
713
  fi
thomasl's avatar
thomasl committed
714

yilmazt's avatar
yilmazt committed
715 716 717
  ###################
  # Core simulators #
  ###################
718
  if [ "$SIMUS_CORE" = "1" ] ; then
yilmazt's avatar
yilmazt committed
719
    echo_info "Compiling security unitary tests simulators"
720 721 722
    simlist="secu_knas_encrypt_eia1 secu_kenb aes128_ctr_encrypt aes128_ctr_decrypt secu_knas_encrypt_eea2 secu_knas secu_knas_encrypt_eea1 kdf aes128_cmac_encrypt secu_knas_encrypt_eia2"
    for f in $simlist ; do
      compilations \
laurent's avatar
laurent committed
723
	    $BUILD_DIR test_$f \
yilmazt's avatar
yilmazt committed
724
	    test_$f $dbin/test_$f.$REL
725 726
    done
  fi
thomasl's avatar
thomasl committed
727

yilmazt's avatar
yilmazt committed
728 729 730
  ####################################
  # EXMIMO drivers & firmware loader #
  ####################################
731
  if [ "$HW" = "EXMIMO" ] ; then
732 733
    echo_info "Compiling Express MIMO 2 board drivers"
    compilations \
734
      $BUILD_DIR openair_rf \
yilmazt's avatar
yilmazt committed
735
      CMakeFiles/openair_rf/openair_rf.ko $dbin/openair_rf.ko
736
    compilations \
737
	  $BUILD_DIR updatefw \
Lionel Gauthier's avatar
Lionel Gauthier committed
738
	  updatefw $dbin/updatefw
739
    echo_info "Compiling oarf tools. The logfile for compilation is here: $dlog/oarf.txt"
740 741
    make -C $OPENAIR_DIR/cmake_targets/$BUILD_DIR/build oarf > $dlog/oarf.txt 2>&1
    cp $OPENAIR_DIR/cmake_targets/$BUILD_DIR/build/*.oct $dbin
742
    if [ -s $dbin/oarf_config_exmimo.oct ] ; then
yilmazt's avatar
yilmazt committed
743
	  echo_success "oarf tools compiled"
744
    else
yilmazt's avatar
yilmazt committed
745
	  echo_error "oarf tools compilation failed"
746
    fi
747
    cp $OPENAIR_DIR/cmake_targets/tools/init_exmimo2 $dbin
748
  fi
749
  
yilmazt's avatar
yilmazt committed
750 751 752
  ######################
  # Optional libraries #
  ######################
753 754 755
  if [ ! -z "$BUILD_OPTLIB" ] ; then 
     for oklib in $BUILD_OPTLIB ; do
         compilations \
756
             $BUILD_DIR $oklib \
757
             lib${oklib}.so $dbin/lib${oklib}.so
758
     done
yilmazt's avatar
yilmazt committed
759 760 761 762 763
  fi
  
  ####################################################
  # Build RF device and transport protocol libraries #
  ####################################################
764
  if [ "$eNB" = "1" -o "$eNBocp" = "1" -o "$UE" = "1" -o "$gNB" = "1" -o "$RU" = "1"  -o "$nrUE" = "1" ] ; then
765

766
      # build RF device libraries
767
      if [ "$HW" != "None" ] ; then
yilmazt's avatar
yilmazt committed
768 769 770 771 772
          rm -f liboai_device.so
          rm -f $dbin/liboai_device.so

          # link liboai_device.so with the selected RF device library
          if [ "$HW" == "EXMIMO" ] ; then
773
              compilations \
774
                  $BUILD_DIR oai_exmimodevif \
775
                  liboai_exmimodevif.so $dbin/liboai_exmimodevif.so.$REL
yilmazt's avatar
yilmazt committed
776

777 778 779 780
              ln -sf liboai_exmimodevif.so liboai_device.so
              ln -sf $dbin/liboai_exmimodevif.so.$REL $dbin/liboai_device.so
              echo_info "liboai_device.so is linked to EXMIMO device library"
          elif [ "$HW" == "OAI_USRP" ] ; then
781
              compilations \
782
                  $BUILD_DIR oai_usrpdevif \
783
                  liboai_usrpdevif.so $dbin/liboai_usrpdevif.so.$REL
784

yilmazt's avatar
yilmazt committed
785 786 787 788 789 790
              ln -sf liboai_usrpdevif.so liboai_device.so
              ln -sf $dbin/liboai_usrpdevif.so.$REL $dbin/liboai_device.so
              echo_info "liboai_device.so is linked to USRP device library"        
          elif [ "$HW" == "OAI_BLADERF" ] ; then
              if [ -f "/usr/include/libbladeRF.h" ] ; then
                  compilations \
791
                      $BUILD_DIR oai_bladerfdevif \
yilmazt's avatar
yilmazt committed
792 793 794 795 796 797 798 799 800
                      liboai_bladerfdevif.so $dbin/liboai_bladerfdevif.so.$REL
              fi

              ln -sf liboai_bladerfdevif.so liboai_device.so
              ln -sf $dbin/liboai_bladerfdevif.so.$REL $dbin/liboai_device.so
              echo_info "liboai_device.so is linked to BLADERF device library"	 
          elif [ "$HW" == "OAI_LMSSDR" ] ; then
#              if [ -f "/usr/include/libbladeRF.h" ] ; then
                  compilations \
801
                      $BUILD_DIR oai_lmssdrdevif \
yilmazt's avatar
yilmazt committed
802 803
                      liboai_lmssdrdevif.so $dbin/liboai_lmssdrdevif.so.$REL
#              fi
804

yilmazt's avatar
yilmazt committed
805 806 807
              ln -sf liboai_lmssdrdevif.so liboai_device.so
              ln -sf $dbin/liboai_lmssdrdevif.so.$REL $dbin/liboai_device.so
              echo_info "liboai_device.so is linked to LMSSDR device library"	 
808
          elif [ "$HW" == "OAI_IRIS" ] ; then
yilmazt's avatar
yilmazt committed
809
              compilations \
810
                  $BUILD_DIR oai_irisdevif \
yilmazt's avatar
yilmazt committed
811
                  liboai_irisdevif.so $dbin/liboai_irisdevif.so.$REL
812 813 814 815

              ln -s liboai_irisdevif.so liboai_device.so
              ln -s $dbin/liboai_irisdevif.so.$REL $dbin/liboai_device.so
              echo_info "liboai_device.so is linked to IRIS device library"
yilmazt's avatar
yilmazt committed
816 817 818 819 820 821 822 823 824 825 826 827
          elif [ "$HW" == "OAI_ADRV9371_ZC706" ] ; then
              SYRIQ_KVER=$(uname -r)
              SYRIQ_KMAJ=$(echo $SYRIQ_KVER | sed -e 's/^\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*.*/\1/')
              SYRIQ_KMIN=$(echo $SYRIQ_KVER | sed -e 's/^[0-9][0-9]*\.\([0-9][0-9]*\)\.[0-9][0-9]*.*/\1/')
#              echo $SYRIQ_KMAJ$SYRIQ_KMIN
              if [ "$SYRIQ_KMAJ$SYRIQ_KMIN" == "319" ] || [ "$SYRIQ_KMAJ$SYRIQ_KMIN" == "410" ] || [ "$SYRIQ_KMAJ$SYRIQ_KMIN" == "415" ] ; then
#                  echo "Kernel $SYRIQ_KMAJ.$SYRIQ_KMIN detected"
                  ln -sf /usr/local/lib/syriq/libadrv9371zc706.so liboai_device.so
              else
                  echo_error "== FAILED == Unexpected Kernel $SYRIQ_KMAJ.$SYRIQ_KMIN"
              fi
              echo_info "liboai_device.so is linked to ADRV9371_ZC706 device library for Kernel $SYRIQ_KMAJ.$SYRIQ_KMIN"
828 829
          elif [ "$HW" == "OAI_AW2SORI" ] ; then
	      compilations \
830
		  $BUILD_DIR aw2sori_transpro \
831 832 833 834
                  libaw2sori_transpro.so $dbin/libaw2sori_transpro.so.$REL 

              ln -sf libaw2sori_transpro.so libthirdparty_transpro.so
              ln -sf $dbin/libaw2sori_transpro.so.$REL $dbin/libaw2sori_transpro.so
835
              echo_info "build libthirdparty_transpro.so for AW2SORI fronthaul"
836 837 838
          else
              echo_info "liboai_device.so is not linked to any device library"
          fi
839
      fi
840

yilmazt's avatar
yilmazt committed
841
      #build simulators devices
842
      if [ "$SKIP_SHARED_LIB_FLAG" = "False" ]; then
843 844
          echo_info "Compiling rfsimulator"
          compilations \
845
              $BUILD_DIR rfsimulator \
846
              librfsimulator.so $dbin/librfsimulator.so.$REL
847
      fi
848

yilmazt's avatar
yilmazt committed
849
      #build transport protocol libraries (currently only ETHERNET is available)
850
      if [ "$SKIP_SHARED_LIB_FLAG" = "False" ]; then
851 852 853
          echo_info "Building transport protocol libraries"
          rm -f liboai_transpro.so
          rm -f $dbin/liboai_transpro.so
854 855
	  if [ "$TP" == "Ethernet" ]; then
              compilations \
856
		  $BUILD_DIR oai_eth_transpro \
857 858 859 860 861 862 863
		  liboai_eth_transpro.so $dbin/liboai_eth_transpro.so.$REL
              ln -sf liboai_eth_transpro.so liboai_transpro.so
              ln -sf $dbin/liboai_eth_transpro.so.$REL $dbin/liboai_transpro.so
              echo_info "liboai_transpro.so is linked to ETHERNET transport"
	  fi
	  if [ "$TP" == "benetel4g" ]; then
              compilations \
864
		  $BUILD_DIR benetel_4g \
865 866 867 868 869 870 871
		  libbenetel_4g.so $dbin/libbenetel_4g.$REL
              ln -sf libbenetel_4g.so liboai_transpro.so
              ln -sf $dbin/libbenetel_4g.so.$REL $dbin/liboai_transpro.so
              echo_info "liboai_transpro.so is linked to BENETEL4G transport"
	  fi
	  if [ "$TP" == "benetel5g" ]; then
              compilations \
872
		  $BUILD_DIR benetel_5g \
873 874 875 876 877
		  libbenetel_5g.so $dbin/libbenetel_5g.$REL
              ln -sf libbenetel_5g.so liboai_transpro.so
              ln -sf $dbin/libbenetel_5g.so.$REL $dbin/liboai_transpro.so
              echo_info "liboai_transpro.so is linked to BENETEL4G transport"
	  fi
878
      fi
yilmazt's avatar
yilmazt committed
879
  fi
880

yilmazt's avatar
yilmazt committed
881 882 883 884
  ###################
  # Doxygen Support #
  ###################
  if [ "$BUILD_DOXYGEN" = "1" ] ; then
885
    doxygen_log=$OPENAIR_DIR/cmake_targets/log/doxygen.log
yilmazt's avatar
yilmazt committed
886 887 888
    echo_info "Building Doxygen based documentation. The documentation file is located here: $OPENAIR_DIR/targets/DOCS/html/index.html"
    echo_info "Doxygen generation log is located here: $doxygen_log"
    echo_info "Generating Doxygen files....please wait"
889 890 891 892
    (
    [ "$CLEAN" = "1" ] && rm -rf $OPENAIR_DIR/cmake_targets/doxygen/build
    mkdir -p $OPENAIR_DIR/cmake_targets/doxygen/build
    cd $OPENAIR_DIR/cmake_targets/doxygen/build
893
    eval $CMAKE_CMD ..
894 895
    make doc
    ) >& $doxygen_log
896 897
  fi

yilmazt's avatar
yilmazt committed
898 899 900 901
  ##############
  # Auto-tests #
  ##############
  if [ "$OAI_TEST" = "1" ] ; then
thomasl's avatar
thomasl committed
902
    echo_info "10. Running OAI pre commit tests (pre-ci) ..."
903 904 905 906
    echo_error "These scripts ASSUME that user is in /etc/sudoers and can execute commands without PASSWORD prompt"
    echo_error "Add the following lines in /etc/sudoers file to make your __user_name__ sudo without password prompt"
    echo_error " __your_user_name__ ALL = (ALL:ALL) NOPASSWD: ALL"
    echo_error " __your_user_name__ ALL = (ALL) NOPASSWD: ALL "
907 908
    echo_info "The log file for the autotest script for debugging is located here: $OPENAIR_DIR/cmake_targets/autotests/log/autotests.log "
    echo_info "The results of autotests results is located here: $OPENAIR_DIR/cmake_targets/autotests/log/results_autotests.xml "
yilmazt's avatar
yilmazt committed
909
    echo_info "You can hit CTRL-C at any time to terminate the autotests..."
910 911 912
    echo "Current User Name: $USER"
    read -s -p "Enter Password: " mypassword
    echo -e "\n"
913 914
    rm -fr $OPENAIR_DIR/cmake_targets/autotests/log
    mkdir -p $OPENAIR_DIR/cmake_targets/autotests/log
915
    if [ "$RUN_GROUP" -eq "1" ]; then
916
        $OPENAIR_DIR/cmake_targets/autotests/run_exec_autotests.bash -g "$TEST_CASE_GROUP" -p $mypassword >& $OPENAIR_DIR/cmake_targets/autotests/log/autotests.log &
917
    else
918
        $OPENAIR_DIR/cmake_targets/autotests/run_exec_autotests.bash -p $mypassword >& $OPENAIR_DIR/cmake_targets/autotests/log/autotests.log &
919
    fi
920
    wait
Lionel Gauthier's avatar
Lionel Gauthier committed
921
  else
thomasl's avatar
thomasl committed
922
    echo_info "10. Bypassing the Tests ..."
923
    echo_success "BUILD SHOULD BE SUCCESSFUL"
Lionel Gauthier's avatar
Lionel Gauthier committed
924
  fi
925

926 927 928
}

main "$@"