build_helper.amf 12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
################################################################################
# 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
################################################################################
dukl's avatar
dukl committed
21

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

35 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
#-------------------------------------------------------------------------------
#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 $BOOST_URL 
    tar --bzip2 -xf boost_1_66_0.tar.bz2 
66
    cp -fR boost_1_66_0/boost /usr/include
67 68 69 70 71 72 73
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    popd
  fi
  return 0
}


Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
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
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_cpprestsdk_from_git() {
  if [ $1 -eq 0 ]; then
    read -p "Do you want to install C++ REST SDK ? <y/N> " prompt
    OPTION="-y"
  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/Microsoft/cpprestsdk.git
    echo "Install C++ REST SDK from $GIT_URL"
    pushd $OPENAIRCN_DIR/build/ext
    echo "Downloading C++ REST SDK"
    if [[ $OPTION =~ -[yY](es)* ]]
    then
      $SUDO rm -rf cpprestsdk
    fi

    git clone $GIT_URL
    cd cpprestsdk
    git submodule update --init
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    mkdir _build && cd _build
    $CMAKE -G Ninja .. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=OFF -DBUILD_SAMPLES=OFF
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    $SUDO ninja install 
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    $SUDO ldconfig -v
    popd
  fi
  return 0
}

dukl's avatar
dukl committed
118 119 120
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
121 122 123 124 125 126 127 128
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
dukl's avatar
dukl committed
129

130 131 132 133 134 135 136 137 138 139
  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
140 141
    # Looks like since Nov 11 commits, we cannot build
    git checkout -f 1936dddc3c53c1c0db55a665cf419dc7a257ba62
Mohammed Ismail's avatar
Mohammed Ismail committed
142
    $CMAKE -DFMT_TEST=FALSE  .
143 144 145 146 147 148 149 150 151 152 153 154 155 156
    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
}

#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_spdlog_from_git() {
dukl's avatar
dukl committed
157
  if [ $1 -eq 0 ]; then
158
    read -p "Do you want to install spdlog ? <y/N> " prompt
dukl's avatar
dukl committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172
    OPTION=""
  else
    prompt='y'
    OPTION="-y"
  fi
  if [ $2 -eq 0 ]; then
    debug=0
  else
    debug=1
  fi


  if [[ $prompt =~ [yY](es)* ]]
  then
173 174
    GIT_URL=https://github.com/gabime/spdlog.git
    echo "Install spdlog from $GIT_URL"
dukl's avatar
dukl committed
175
    pushd $OPENAIRCN_DIR/build/ext
176
    echo "Downloading spdlog"
dukl's avatar
dukl committed
177 178
    if [[ $OPTION =~ -[yY](es)* ]]
    then
179
      $SUDO rm -rf spdlog
dukl's avatar
dukl committed
180 181 182
    fi

    git clone $GIT_URL
183
    cd spdlog && git checkout master
dukl's avatar
dukl committed
184
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
185 186
    # enable syslog, Useless (defined in SMF code)
    sed -i '/#define SPDLOG_ENABLE_SYSLOG/s/^\/\///g' include/spdlog/tweakme.h
dukl's avatar
dukl committed
187 188 189 190 191 192 193 194 195 196 197
    popd
  fi
  return 0
}

#-------------------------------------------------------------------------------
#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
198
    OPTION="-y"
dukl's avatar
dukl committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
  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
223
    cd pistache && git checkout e18ed9baeb2145af6f9ea41246cf48054ffd9907
dukl's avatar
dukl committed
224 225
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    mkdir _build && cd _build
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
226 227 228 229 230
    $CMAKE -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release \
        -DPISTACHE_BUILD_EXAMPLES=false \
        -DPISTACHE_BUILD_TESTS=false \
        -DPISTACHE_BUILD_DOCS=false \
        .. 
dukl's avatar
dukl committed
231 232 233 234 235 236 237 238 239 240
    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
}

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


dukl's avatar
dukl committed
259 260
  if [[ $prompt =~ [yY](es)* ]]
  then
261 262
    GIT_URL=https://github.com/nlohmann/json.git
    echo "Install Nlohmann Json from $GIT_URL"
dukl's avatar
dukl committed
263
    pushd $OPENAIRCN_DIR/build/ext
264
    echo "Downloading Nlohmann"
dukl's avatar
dukl committed
265 266
    if [[ $OPTION =~ -[yY](es)* ]]
    then
267
      $SUDO rm -rf json
dukl's avatar
dukl committed
268
    fi
269

dukl's avatar
dukl committed
270
    git clone $GIT_URL
271 272 273 274
    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
275
    $CMAKE -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DJSON_BuildTests=OFF ..
276 277 278 279
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    make
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    $SUDO make install
dukl's avatar
dukl committed
280 281 282 283 284 285
    ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
    popd
  fi
  return 0
}

286 287 288
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
dukl's avatar
dukl committed
289 290
check_install_amf_deps(){

291 292
  var_ubuntu_18_04=0
  
dukl's avatar
dukl committed
293 294 295 296 297
  if [ $1 -gt 0 ]; then
    OPTION="-y"
  else 
    OPTION=""
  fi
298 299 300 301 302
  if [ $2 -eq 0 ]; then
    debug=0
  else
    debug=1
  fi
dukl's avatar
dukl committed
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328

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

  # prevent lock on /var/lib/dpkg/lock
  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

  update_package_db


  check_enable_epel_repos

  # Compilers, generators, ...
  if [[ $OS_DISTRO == "ubuntu" ]]; then
    PACKAGE_LIST="\
      autoconf \
      automake \
      bison \
      build-essential \
329
      $CMAKE \
dukl's avatar
dukl committed
330 331 332 333
      daemon \
      doxygen \
      flex \
      gdb \
334
      wget \
dukl's avatar
dukl committed
335 336 337 338 339
      git"
  elif [[ "$OS_BASEDISTRO" == "fedora" ]]; then
    PACKAGE_LIST="\
      autoconf \
      automake \
Mohammed Ismail's avatar
Mohammed Ismail committed
340
      gcc-c++ \
dukl's avatar
dukl committed
341 342
      bison \
      $CMAKE \
Mohammed Ismail's avatar
Mohammed Ismail committed
343
      make \
dukl's avatar
dukl committed
344 345 346 347 348 349 350 351 352 353
      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
kharade's avatar
kharade committed
354
  
dukl's avatar
dukl committed
355 356 357 358
  # Libraries
  if [[ $OS_DISTRO == "ubuntu" ]]; then
    case "$(get_distribution_release)" in
      "ubuntu18.04")
kharade's avatar
kharade committed
359 360 361 362 363
      # Currently Ubuntu18.04 has boost 1.65 as the latest
      # We need at least 1.66
      # PPA has 1.67
      $SUDO add-apt-repository ppa:mhier/libboost-latest --yes
      $SUDO $INSTALLER update
kharade's avatar
kharade committed
364
      #var_ubuntu_18_04=1 
365
      if [ $IS_CONTAINER -eq 0 ]; then
366
        specific_packages="libconfig++-dev libasio-dev libboost-all-dev mysql-server"
367
      else
kharade's avatar
kharade committed
368
        specific_packages="libconfig++-dev"
369
      fi
dukl's avatar
dukl committed
370
        ;;
371 372 373 374 375 376 377
      *)
      if [ $IS_CONTAINER -eq 0 ]; then
        specific_packages="libconfig++-dev libasio-dev libboost-all-dev mysql-server"
      else
        specific_packages="libconfig++-dev libasio-dev libboost-all-dev"
      fi
        ;;
dukl's avatar
dukl committed
378 379 380 381
    esac
    # removed libspdlog-dev
    PACKAGE_LIST="\
      $specific_packages \
kharade's avatar
kharade committed
382
      libboost1.67-dev \
dukl's avatar
dukl committed
383 384 385 386 387 388 389 390 391 392 393 394
      mysql-server \
      mysql-client \
      libmysqlclient-dev \
      guile-2.0-dev \
      libcurl4-gnutls-dev \
      libevent-dev \
      libgcrypt11-dev \
      libgmp-dev \
      libhogweed? \
      libidn2-0-dev \
      libidn11-dev \
      libpthread-stubs0-dev \
395
      libsctp-dev \
dukl's avatar
dukl committed
396 397 398 399 400 401 402 403 404
      libssl-dev \
      libtool \
      libxml2 \
      libxml2-dev \
      openssl \
      python \
      nettle-dev \
      libcurl4 \
      net-tools \
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
405 406
      pkg-config \
      ninja-build \
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
407
      wget \
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
408
      libasan2"
dukl's avatar
dukl committed
409 410 411
  elif [[ "$OS_BASEDISTRO" == "fedora" ]]; then
    PACKAGE_LIST="\
      guile-devel \
Mohammed Ismail's avatar
Mohammed Ismail committed
412 413 414
      mysql \
      mysql-devel \
      mysql-libs \
dukl's avatar
dukl committed
415 416 417 418 419 420 421 422 423 424 425 426
      libconfig-devel \
      libgcrypt-devel \
      gmp-devel \
      libidn-devel \
      lksctp-tools \
      lksctp-tools-devel \
      openssl-devel \
      libtool \
      libxml2 \
      libxml2-devel \
      openssl \
      check \
Mohammed Ismail's avatar
Mohammed Ismail committed
427 428 429
      nettle-devel \
      libcurl-devel \
      python2 \
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
430 431 432
      pkgconfig \
      ninja-build \
      libasan"
dukl's avatar
dukl committed
433 434 435 436 437 438
  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
439
 
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
440 441 442
  install_cpprestsdk_from_git $1 $2
  ret=$?;[[ $ret -ne 0 ]] && return $ret
  
443
  # Use fmt lib included in spdlog
kharade's avatar
kharade committed
444 445
  # install_fmt $1
  # ret=$?;[[ $ret -ne 0 ]] && return $ret
dukl's avatar
dukl committed
446 447 448 449 450 451 452 453 454 455 456 457 458

  install_spdlog_from_git $1 $2
  ret=$?;[[ $ret -ne 0 ]] && return $ret 

  install_fb_folly_from_source $1 $2
  ret=$?;[[ $ret -ne 0 ]] && return $ret

  install_pistache_from_git $1 $2
  ret=$?;[[ $ret -ne 0 ]] && return $ret

  install_nlohmann_from_git $1 $2
  ret=$?;[[ $ret -ne 0 ]] && return $ret 

459 460 461 462 463
  if [ $var_ubuntu_18_04 -ne 0 ]; then 
    install_boost_1_66 $1 $2
    ret=$?;[[ $ret -ne 0 ]] && return $ret
  fi
  
Raphael Defosseux's avatar
Raphael Defosseux committed
464
  $SUDO ldconfig
dukl's avatar
dukl committed
465 466 467
  return 0

}