build_helper.smf 14.5 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
36
37
38
39
# 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

#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_fmt() {
40
  echo "Starting to install fmt"
gauthier's avatar
gauthier committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  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
59
60
    # Looks like since Nov 11 commits, we cannot build
    git checkout -f 1936dddc3c53c1c0db55a665cf419dc7a257ba62
Mohammed Ismail's avatar
Mohammed Ismail committed
61
    $CMAKE -DFMT_TEST=FALSE  .
gauthier's avatar
gauthier committed
62
63
64
65
66
67
68
    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
69
  echo "fmt installation complete"
gauthier's avatar
gauthier committed
70
71
  return 0
}
72

gauthier's avatar
gauthier committed
73
74
75
76
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_spdlog_from_git() {
77
  echo "Starting to install spdlog"
gauthier's avatar
gauthier committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  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
102

gauthier's avatar
gauthier committed
103
    git clone $GIT_URL
104
    cd spdlog && git checkout master
gauthier's avatar
gauthier committed
105
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
106
    # enable syslog, Useless (defined in SMF code)
107
    sed -i '/#define SPDLOG_ENABLE_SYSLOG/s/^\/\///g' include/spdlog/tweakme.h
gauthier's avatar
gauthier committed
108
109
    popd
  fi
110
  echo "spdlog installation complete"
gauthier's avatar
gauthier committed
111
112
113
  return 0
}

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
114
115
116
117
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_pistache_from_git() {
118
  echo "Starting to install pistache"
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
119
120
  if [ $1 -eq 0 ]; then
    read -p "Do you want to install Pistache ? <y/N> " prompt
121
    OPTION="-y"
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  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
146
    cd pistache && git checkout e18ed9baeb2145af6f9ea41246cf48054ffd9907
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
147
148
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    mkdir _build && cd _build
149
150
151
152
153
    $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
154
155
156
157
158
159
160
    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
161
  echo "pistache installation complete"
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
162
163
164
  return 0
}

165
166
167
168
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_nlohmann_from_git() {
169
  echo "Starting to install Nlohmann Json"
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
  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
200
    $CMAKE -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DJSON_BuildTests=OFF ..
201
202
203
204
205
206
207
    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
208
  echo "Nlohmann Json installation complete"
209
210
211
  return 0
}

212
213
214
215
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_nghttp2_from_git() {
216
  echo "Starting to install nghttp2"
217
218
  if [ $1 -eq 0 ]; then
    read -p "Do you want to install nghttp2 ? <y/N> " prompt
219
    OPTION=""
220
221
222
223
224
225
226
227
228
229
230
231
232
  else
    prompt='y'
    OPTION="-y"
  fi
  if [ $2 -eq 0 ]; then
    debug=0
  else
    debug=1
  fi


  if [[ $prompt =~ [yY](es)* ]]
  then
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
    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
254
255
      $CMAKE \
      make \
256
257
258
259
260
261
262
263
264
265
266
267
      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
268
269
    ret=$?;[[ $ret -ne 0 ]] && return $ret
   
270
271
272
273
    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
274
    if [[ $OPTION =~ [yY](es)* ]]
275
276
277
278
279
280
    then
      $SUDO rm -rf nghttp2
    fi

    git clone $GIT_URL
    cd nghttp2
281
    git checkout 43ba3125932c1d56addaeded2b7f62637af255cd
282
283
284
285
286
287
288
289
    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
290
    ./configure --enable-asio-lib --enable-lib-only
291
292
293
294
295
    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
296
297
    $SUDO ldconfig
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
298
299
    popd
  fi
300
  echo "nghttp2 installation complete"
301
  return 0  
302
}
303

gauthier's avatar
gauthier committed
304
305
306
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
307
check_install_smf_deps() {
gauthier's avatar
gauthier committed
308

309
  if [ $1 -gt 0 ]; then
gauthier's avatar
gauthier committed
310
311
312
313
314
315
316
317
318
319
320
321
322
323
    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 $?

324
  # prevent lock on /var/lib/dpkg/lock
gauthier's avatar
gauthier committed
325
326
327
328
329
330
331
  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
332

gauthier's avatar
gauthier committed
333
  update_package_db
334
335


gauthier's avatar
gauthier committed
336
337
338
339
340
341
342
343
344
345
346
347
348
349
  check_enable_epel_repos

  # Compilers, generators, ...
  if [[ $OS_DISTRO == "ubuntu" ]]; then
    PACKAGE_LIST="\
      autoconf \
      automake \
      bison \
      build-essential \
      cmake \
      daemon \
      doxygen \
      flex \
      gdb \
350
      wget \
gauthier's avatar
gauthier committed
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
      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
368

gauthier's avatar
gauthier committed
369
370
371
372
  # Libraries
  if [[ $OS_DISTRO == "ubuntu" ]]; then
    case "$(get_distribution_release)" in
      "ubuntu18.04")
373
374
375
        # 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
376
377
        $SUDO add-apt-repository ppa:mhier/libboost-latest --yes
        $SUDO $INSTALLER update
378
        specific_packages="libconfig++-dev"        
gauthier's avatar
gauthier committed
379
      ;;
380
381
382
      *)
        specific_packages="libconfig++-dev libasio-dev libboost-all-dev"
        ;;
gauthier's avatar
gauthier committed
383
384
385
386
    esac
    # removed libspdlog-dev
    PACKAGE_LIST="\
      $specific_packages \
387
      libboost1.67-dev \
gauthier's avatar
gauthier committed
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
      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
403
404
405
      nettle-dev \
      libcurl4 \
      net-tools \
406
      pkg-config \
407
      wget \
408
      libasan2"
gauthier's avatar
gauthier committed
409
410
411
412
413
414
415
416
417
418
  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
419
      libnghttp2 \
gauthier's avatar
gauthier committed
420
421
422
423
424
      libtool \
      libxml2 \
      libxml2-devel \
      openssl \
      check \
Mohammed Ismail's avatar
Mohammed Ismail committed
425
426
427
      nettle-devel \
      libcurl-devel \
      python2 \
428
429
      pkgconfig \
      libasan"
gauthier's avatar
gauthier committed
430
431
432
433
434
435
  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
436
  echo "distro libs installation complete"
437

gauthier's avatar
gauthier committed
438
  # Use fmt lib included in spdlog
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
439
440
  #install_fmt $1
  #ret=$?;[[ $ret -ne 0 ]] && return $ret
gauthier's avatar
gauthier committed
441

gauthier's avatar
gauthier committed
442
443
  install_spdlog_from_git $1 $2
  ret=$?;[[ $ret -ne 0 ]] && return $ret
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
444
  
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
445
446
447
  install_fb_folly_from_source $1 $2
  ret=$?;[[ $ret -ne 0 ]] && return $ret
  
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
448
449
  install_pistache_from_git $1 $2
  ret=$?;[[ $ret -ne 0 ]] && return $ret
450
451
452
  
  install_nlohmann_from_git $1 $2
  ret=$?;[[ $ret -ne 0 ]] && return $ret
453

454
455
  install_nghttp2_from_git $1 $2
  ret=$?;[[ $ret -ne 0 ]] && return $ret
456
  
gauthier's avatar
gauthier committed
457
458
459
460
461
  return 0
}
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
462
check_install_smf_min_deps() {
gauthier's avatar
gauthier committed
463

464
  if [ $1 -gt 0 ]; then
gauthier's avatar
gauthier committed
465
466
467
468
469
470
471
472
473
474
475
476
477
478
    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 $?

479
  # prevent lock on /var/lib/dpkg/lock
gauthier's avatar
gauthier committed
480
481
482
483
484
485
486
  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
487

gauthier's avatar
gauthier committed
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
  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
505

gauthier's avatar
gauthier committed
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551

  # 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
552
  echo "networking tools installation complete"
gauthier's avatar
gauthier committed
553
554
555
556
557

  return 0
}