build_helper.smf 15 KB
Newer Older
gauthier's avatar
gauthier committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
################################################################################
# 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
# the OAI Public License, Version 1.1  (the "License"); you may not use this file
# 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
################################################################################

22
# file build_helper.smf
gauthier's avatar
gauthier committed
23
24
25
26
27
28
29
30
31
32
33
34
35
# brief
# author Laurent Thomas, Lionel GAUTHIER
#
#######################################
################################
# include helper functions
################################
SCRIPT=$(readlink -f ${BASH_SOURCE})
THIS_SCRIPT_PATH=`dirname $SCRIPT`
source $THIS_SCRIPT_PATH/build_helper
source $THIS_SCRIPT_PATH/build_helper.libconfig
source $THIS_SCRIPT_PATH/build_helper.fb_folly

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
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_boost_1_66() {
  if [ $1 -eq 0 ]; then
    read -p "Do you want to install Boost version 1.66.0 ? <y/N> " prompt
    OPTION=""
  else
    prompt='y'
    OPTION="-y"
  fi
  if [ $2 -eq 0 ]; then
    debug=0
  else
    debug=1
  fi

  if [[ $prompt =~ [yY](es)* ]]
  then
    BOOST_URL=https://boostorg.jfrog.io/artifactory/main/release/1.66.0/source/boost_1_66_0.tar.bz2
    echo "Install Boost from $BOOST_URL"
    pushd $OPENAIRCN_DIR/build/ext
    echo "Downloading Boost 1.66.0"
    if [[ $OPTION =~ -[yY](es)* ]]
    then
      $SUDO rm -rf boost
    fi

    #git clone $GIT_URL
    wget --quiet --tries=3 --retry-connrefused $BOOST_URL 
    tar --bzip2 -xf boost_1_66_0.tar.bz2 
    cp -fR boost_1_66_0/boost /usr/include
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    popd
  fi
  return 0
}
73

gauthier's avatar
gauthier committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_fmt() {
  if [ $1 -eq 0 ]; then
    read -p "Do you want to install open-source formatting library for C++ ? <y/N> " prompt
    OPTION=""
  else
    prompt='y'
    OPTION="-y"
  fi

  echo "Install fmt from source"

  if [[ $prompt =~ [yY](es)* ]]
  then
    cd /tmp
    echo "Downloading fmt"
    $SUDO rm -rf /tmp/fmt*
    git clone https://github.com/fmtlib/fmt.git
    ret=$?;[[ $ret -ne 0 ]] && return $ret
    cd fmt
96
97
    # Looks like since Nov 11 commits, we cannot build
    git checkout -f 1936dddc3c53c1c0db55a665cf419dc7a257ba62
Mohammed Ismail's avatar
Mohammed Ismail committed
98
    $CMAKE -DFMT_TEST=FALSE  .
gauthier's avatar
gauthier committed
99
100
101
102
103
104
105
106
107
    ret=$?;[[ $ret -ne 0 ]] && return $ret
    make -j `nproc`
    ret=$?;[[ $ret -ne 0 ]] && return $ret
    $SUDO make install
    cd /tmp
    rm -rf /tmp/fmt*
  fi
  return 0
}
108

gauthier's avatar
gauthier committed
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
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_spdlog_from_git() {
  if [ $1 -eq 0 ]; then
    read -p "Do you want to install spdlog ? <y/N> " prompt
    OPTION=""
  else
    prompt='y'
    OPTION="-y"
  fi
  if [ $2 -eq 0 ]; then
    debug=0
  else
    debug=1
  fi


  if [[ $prompt =~ [yY](es)* ]]
  then
    GIT_URL=https://github.com/gabime/spdlog.git
    echo "Install spdlog from $GIT_URL"
    pushd $OPENAIRCN_DIR/build/ext
    echo "Downloading spdlog"
    if [[ $OPTION =~ -[yY](es)* ]]
    then
      $SUDO rm -rf spdlog
    fi
137

gauthier's avatar
gauthier committed
138
    git clone $GIT_URL
139
    cd spdlog && git checkout master
gauthier's avatar
gauthier committed
140
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
141
    # enable syslog, Useless (defined in SMF code)
142
    sed -i '/#define SPDLOG_ENABLE_SYSLOG/s/^\/\///g' include/spdlog/tweakme.h
gauthier's avatar
gauthier committed
143
144
145
146
147
    popd
  fi
  return 0
}

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
148
149
150
151
152
153
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_pistache_from_git() {
  if [ $1 -eq 0 ]; then
    read -p "Do you want to install Pistache ? <y/N> " prompt
154
    OPTION="-y"
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
  else
    prompt='y'
    OPTION="-y"
  fi
  if [ $2 -eq 0 ]; then
    debug=0
  else
    debug=1
  fi


  if [[ $prompt =~ [yY](es)* ]]
  then
    GIT_URL=https://github.com/oktal/pistache.git
    echo "Install Pistache from $GIT_URL"
    pushd $OPENAIRCN_DIR/build/ext
    echo "Downloading Pistache"
    if [[ $OPTION =~ -[yY](es)* ]]
    then
      $SUDO rm -rf pistache
    fi

    git clone $GIT_URL
    git submodule update --init
179
    cd pistache && git checkout e18ed9baeb2145af6f9ea41246cf48054ffd9907
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
180
181
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    mkdir _build && cd _build
182
183
184
185
186
    $CMAKE -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release \
        -DPISTACHE_BUILD_EXAMPLES=false \
        -DPISTACHE_BUILD_TESTS=false \
        -DPISTACHE_BUILD_DOCS=false \
        .. 
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
187
188
189
190
191
192
193
194
195
196
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    make
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    $SUDO make install
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    popd
  fi
  return 0
}

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_nlohmann_from_git() {
  if [ $1 -eq 0 ]; then
    read -p "Do you want to install Nlohmann Json ? <y/N> " prompt
    OPTION=""
  else
    prompt='y'
    OPTION="-y"
  fi
  if [ $2 -eq 0 ]; then
    debug=0
  else
    debug=1
  fi


  if [[ $prompt =~ [yY](es)* ]]
  then
    GIT_URL=https://github.com/nlohmann/json.git
    echo "Install Nlohmann Json from $GIT_URL"
    pushd $OPENAIRCN_DIR/build/ext
    echo "Downloading Nlohmann"
    if [[ $OPTION =~ -[yY](es)* ]]
    then
      $SUDO rm -rf json
    fi

    git clone $GIT_URL
    git submodule update --init
    cd json && git checkout master
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    mkdir _build && cd _build
Mohammed Ismail's avatar
Mohammed Ismail committed
231
    $CMAKE -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DJSON_BuildTests=OFF ..
232
233
234
235
236
237
238
239
240
241
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    make
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    $SUDO make install
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    popd
  fi
  return 0
}

242
243
244
245
246
247
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_nghttp2_from_git() {
  if [ $1 -eq 0 ]; then
    read -p "Do you want to install nghttp2 ? <y/N> " prompt
248
    OPTION=""
249
250
251
252
253
254
255
256
257
258
259
260
261
  else
    prompt='y'
    OPTION="-y"
  fi
  if [ $2 -eq 0 ]; then
    debug=0
  else
    debug=1
  fi


  if [[ $prompt =~ [yY](es)* ]]
  then
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
    if [[ $OS_DISTRO == "ubuntu" ]]; then
      PACKAGE_LIST="\
      g++ \
      cmake \
      binutils \
      autoconf \
      automake \
      autotools-dev \
      libtool \
      pkg-config \
      zlib1g-dev \
      libcunit1-dev \
      libssl-dev \
      libxml2-dev libev-dev libevent-dev libjansson-dev libc-ares-dev \
      libjemalloc-dev libsystemd-dev cython python3-dev python-setuptools"
    elif [[ "$OS_BASEDISTRO" == "fedora" ]]; then
      PACKAGE_LIST="\
      gcc-c++ \
      binutils-devel \
      autoconf \
      automake \
Mohammed Ismail's avatar
Mohammed Ismail committed
283
284
      $CMAKE \
      make \
285
286
287
288
289
290
291
292
293
294
295
296
      libtool \
      pkg-config \
      zlib-devel \
      CUnit-devel \
      openssl-devel \
      libxml2-devel libev-devel libevent-devel jansson-devel c-ares-devel \
      jemalloc-devel systemd-devel python3-Cython python3-devel python3-setuptools"
    else
      echo_fatal "$OS_DISTRO is not a supported distribution."
    fi
    echo "Install build tools"
    $SUDO $INSTALLER install $OPTION $PACKAGE_LIST
297
298
    ret=$?;[[ $ret -ne 0 ]] && return $ret
   
299
300
301
302
    GIT_URL=https://github.com/nghttp2/nghttp2.git
    echo "Install nghttp2 from $GIT_URL"
    pushd $OPENAIRCN_DIR/build/ext
    echo "Downloading nghttp2"
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
303
    if [[ $OPTION =~ [yY](es)* ]]
304
305
306
307
308
309
    then
      $SUDO rm -rf nghttp2
    fi

    git clone $GIT_URL
    cd nghttp2
310
    git checkout 43ba3125932c1d56addaeded2b7f62637af255cd
311
312
313
314
315
316
317
318
    git submodule update --init
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    autoreconf -i
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    automake
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    autoconf
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
319
    ./configure --enable-asio-lib --enable-lib-only
320
321
322
323
324
325
326
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    make
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    $SUDO make install
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    popd
  fi
327
  return 0  
328
}
329

gauthier's avatar
gauthier committed
330
331
332
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
333
check_install_smf_deps() {
gauthier's avatar
gauthier committed
334

335
336
  var_ubuntu_18_04=0

337
  if [ $1 -gt 0 ]; then
gauthier's avatar
gauthier committed
338
339
340
341
342
343
344
345
346
347
348
349
350
351
    OPTION="-y"
  else
    OPTION=""
  fi
  if [ $2 -eq 0 ]; then
    debug=0
  else
    debug=1
  fi

  echo "Check supported distribution"
  check_supported_distribution
  [[ $? -ne 0 ]] && return $?

352
  # prevent lock on /var/lib/dpkg/lock
gauthier's avatar
gauthier committed
353
354
355
356
357
358
359
  if [[ $OS_DISTRO == "ubuntu" ]]; then
    #$SUDO systemctl mask apt-daily.service
    #$SUDO systemctl mask apt-daily.timer
    #$SUDO systemctl mask apt-daily-upgrade.service
    #$SUDO systemctl mask apt-daily-upgrade.timer
    $SUDO sed -i 's/1/0/g' /etc/apt/apt.conf.d/10periodic
  fi
360

gauthier's avatar
gauthier committed
361
  update_package_db
362
363


gauthier's avatar
gauthier committed
364
365
366
367
368
369
370
371
372
373
374
375
376
377
  check_enable_epel_repos

  # Compilers, generators, ...
  if [[ $OS_DISTRO == "ubuntu" ]]; then
    PACKAGE_LIST="\
      autoconf \
      automake \
      bison \
      build-essential \
      cmake \
      daemon \
      doxygen \
      flex \
      gdb \
378
      wget \
gauthier's avatar
gauthier committed
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
      git"
  elif [[ "$OS_BASEDISTRO" == "fedora" ]]; then
    PACKAGE_LIST="\
      autoconf \
      automake \
      bison \
      $CMAKE \
      doxygen \
      flex \
      gdb \
      git"
  else
    echo_fatal "$OS_DISTRO is not a supported distribution."
  fi
  echo "Install build tools"
  $SUDO $INSTALLER install $OPTION $PACKAGE_LIST
  ret=$?;[[ $ret -ne 0 ]] && return $ret
396

gauthier's avatar
gauthier committed
397
398
399
400
  # Libraries
  if [[ $OS_DISTRO == "ubuntu" ]]; then
    case "$(get_distribution_release)" in
      "ubuntu18.04")
401
402
403
        # Currently Ubuntu18.04 has boost 1.65 as the latest
        # We need at least 1.66
        # PPA has 1.67
Rohan's avatar
Rohan committed
404
405
406
        $SUDO add-apt-repository ppa:mhier/libboost-latest --yes
        $SUDO $INSTALLER update
        #var_ubuntu_18_04=1 
407
        specific_packages="libconfig++-dev"        
gauthier's avatar
gauthier committed
408
      ;;
409
410
411
      *)
        specific_packages="libconfig++-dev libasio-dev libboost-all-dev"
        ;;
gauthier's avatar
gauthier committed
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
    esac
    # removed libspdlog-dev
    PACKAGE_LIST="\
      $specific_packages \
      guile-2.0-dev \
      libcurl4-gnutls-dev \
      libevent-dev \
      libgcrypt11-dev \
      libgmp-dev \
      libhogweed? \
      libidn2-0-dev \
      libidn11-dev \
      libpthread-stubs0-dev \
      libssl-dev \
      libtool \
      libxml2 \
      libxml2-dev \
      openssl \
      python \
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
431
432
433
      nettle-dev \
      libcurl4 \
      net-tools \
434
      pkg-config \
435
      wget \
436
      libasan2"
gauthier's avatar
gauthier committed
437
438
439
440
441
442
443
444
445
446
  elif [[ "$OS_BASEDISTRO" == "fedora" ]]; then
    PACKAGE_LIST="\
      guile-devel \
      libconfig-devel \
      libgcrypt-devel \
      gmp-devel \
      libidn-devel \
      lksctp-tools \
      lksctp-tools-devel \
      openssl-devel \
Mohammed Ismail's avatar
Mohammed Ismail committed
447
      libnghttp2 \
gauthier's avatar
gauthier committed
448
449
450
451
452
      libtool \
      libxml2 \
      libxml2-devel \
      openssl \
      check \
Mohammed Ismail's avatar
Mohammed Ismail committed
453
454
455
      nettle-devel \
      libcurl-devel \
      python2 \
456
457
      pkgconfig \
      libasan"
gauthier's avatar
gauthier committed
458
459
460
461
462
463
  else
    echo_fatal "$OS_DISTRO is not a supported distribution."
  fi
  echo "Install distro libs"
  $SUDO $INSTALLER install $OPTION $PACKAGE_LIST
  ret=$?;[[ $ret -ne 0 ]] && return $ret
464

gauthier's avatar
gauthier committed
465
  # Use fmt lib included in spdlog
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
466
467
  #install_fmt $1
  #ret=$?;[[ $ret -ne 0 ]] && return $ret
gauthier's avatar
gauthier committed
468

gauthier's avatar
gauthier committed
469
470
  install_spdlog_from_git $1 $2
  ret=$?;[[ $ret -ne 0 ]] && return $ret
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
471
  
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
472
473
474
  install_fb_folly_from_source $1 $2
  ret=$?;[[ $ret -ne 0 ]] && return $ret
  
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
475
476
  install_pistache_from_git $1 $2
  ret=$?;[[ $ret -ne 0 ]] && return $ret
477
478
479
  
  install_nlohmann_from_git $1 $2
  ret=$?;[[ $ret -ne 0 ]] && return $ret
480

481
482
  install_nghttp2_from_git $1 $2
  ret=$?;[[ $ret -ne 0 ]] && return $ret
483
484
485
486
487
  
  if [ $var_ubuntu_18_04 -ne 0 ]; then 
    install_boost_1_66 $1 $2
    ret=$?;[[ $ret -ne 0 ]] && return $ret
  fi
488
   
gauthier's avatar
gauthier committed
489
490
491
492
493
  return 0
}
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
494
check_install_smf_min_deps() {
gauthier's avatar
gauthier committed
495

496
  if [ $1 -gt 0 ]; then
gauthier's avatar
gauthier committed
497
498
499
500
501
502
503
504
505
506
507
508
509
510
    OPTION="-y"
  else
    OPTION=""
  fi
  if [ $2 -eq 0 ]; then
    debug=0
  else
    debug=1
  fi

  echo "Check supported distribution"
  check_supported_distribution
  [[ $? -ne 0 ]] && return $?

511
  # prevent lock on /var/lib/dpkg/lock
gauthier's avatar
gauthier committed
512
513
514
515
516
517
518
  if [[ $OS_DISTRO == "ubuntu" ]]; then
    #$SUDO systemctl mask apt-daily.service
    #$SUDO systemctl mask apt-daily.timer
    #$SUDO systemctl mask apt-daily-upgrade.service
    #$SUDO systemctl mask apt-daily-upgrade.timer
    $SUDO sed -i 's/1/0/g' /etc/apt/apt.conf.d/10periodic
  fi
519

gauthier's avatar
gauthier committed
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
  update_package_db

  check_enable_epel_repos

  # Compilers, generators, ...
  if [[ $OS_DISTRO == "ubuntu" ]]; then
    PACKAGE_LIST="\
      gdb"
  elif [[ "$OS_BASEDISTRO" == "fedora" ]]; then
    PACKAGE_LIST="\
      gdb"
  else
    echo_fatal "$OS_DISTRO is not a supported distribution."
  fi
  echo "Install build tools"
  $SUDO $INSTALLER install $OPTION $PACKAGE_LIST
  ret=$?;[[ $ret -ne 0 ]] && return $ret
537

gauthier's avatar
gauthier committed
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588

  # Libraries
  if [[ $OS_DISTRO == "ubuntu" ]]; then
    case "$(get_distribution_release)" in
      "ubuntu18.04")
        specific_packages="libconfig++-dev libasio-dev libboost-all-dev"
      ;;
    esac
    # removed libspdlog-dev
    PACKAGE_LIST="\
      libtool"
  elif [[ "$OS_BASEDISTRO" == "fedora" ]]; then
    PACKAGE_LIST="\
      libtool"
  else
    echo_fatal "$OS_DISTRO is not a supported distribution."
  fi
  echo "Install distro libs"
  $SUDO $INSTALLER install $OPTION $PACKAGE_LIST
  ret=$?;[[ $ret -ne 0 ]] && return $ret

  # Networking
  if [[ $OS_DISTRO == "ubuntu" ]]; then
    case "$(get_distribution_release)" in
  "ubuntu18.04")
      specific_packages="iproute2"
      ;;
    esac
    PACKAGE_LIST="\
      $specific_packages \
      ethtool \
      iptables \
      vlan"
  elif [[ "$OS_BASEDISTRO" == "fedora" ]]; then
    PACKAGE_LIST="\
      ethtool \
      iperf \
      iproute \
      iptables \
      vconfig"
  else
    echo_fatal "$OS_DISTRO is not a supported distribution."
  fi
  echo "Install networking tools"
  $SUDO $INSTALLER install $OPTION $PACKAGE_LIST
  ret=$?;[[ $ret -ne 0 ]] && return $ret

  return 0
}