File PKGBUILD of Package bctoolbox

# Get some information about the machine we are building on:
_numberOfProcessorsOnMachine=$(nproc)
_wantedJobs=$(echo "1.25*${_numberOfProcessorsOnMachine}" | bc -l)
_jobsIget=$(echo ${_wantedJobs} | awk '{print int($1+0.5)}')
_TOTAL_DISK=$(df -h --total | awk 'END{print $2}')
_FREEMEM=$(free --mega)
_TOTAL_MEM=$(free --total --mega | xargs | awk '{print $19"MB"}')
_TOTAL_RAM=$(free --total --mega | xargs | awk '{print $8"MB"}')
_TOTAL_SWAP=$(free --total --mega | xargs | awk '{print $15"MB"}')
pkgname=bctoolbox
_pkgname=bctoolbox
pkgver=5.4.42
pkgrel=1
pkgdesc="Utilities library for Belledonne Communications software"
arch=('x86_64')
url="https://gitlab.linphone.org/BC/public/${_pkgname}"
license=('GPL3')
#conflicts=('bctoolbox' 'mbedtls')
conflicts=('mbedtls2')
provides=('bctoolbox=$pkgver')
depends=('bcunit>=5.3.5' 'mbedtls' 'glibc')
#optional makedepends: 'libdecaf' (not available in OBS)
#makedepends=('cmake' 'git' 'tar' 'lsb-release' 'bcunit' 'libsrtp' 'procps-ng' 'gcc11')
makedepends=('cmake' 'git' 'tar' 'lsb-release' 'bcunit' 'libsrtp' 'procps-ng' 'bc' 
     'gcc' 'libdecaf' 'sed' 'gzip' 'mbedtls')    
source=(${_pkgname}-${pkgver}.tar.bz2)
#   ${_pkgname}-fix-pkgconfig.patch)
sha256sums=('SKIP')
#   'SKIP')
_uploaddir=/usr/src/packages/SOURCES
_sourcedir=/usr/src/packages/BUILD/${pkgname}/src/${pkgname}-${pkgver}
# srcdir is already defined as
# ${srcdir}=/usr/src/packages/BUILD/${pkgname}/src
_builddir=/usr/src/packages/BUILD/${pkgname}/build
_pkgdir=/usr/src/packages/BUILD/${pkgname}/pkg/${pkgname}
# Package files will be installed in:
_installToDir=${_pkgdir}



prepare() {
  echo "--- Entering section prepare() ---"
  # OBS build service may not always work as expected for Archlinux
  echo
  echo "--- It seems that OBS makepkg runs section prepare()"
  echo "--- but the output from this section is not visible in the log"
  echo "--- which makes it difficult to see what went wrong."
  echo "--- For visibility, move code to the build() section below."  
  echo
  # --- Start Variables ---
  # uploaddir=/usr/src/packages/SOURCES
  # sourcedir=/usr/src/packages/BUILD/${pkgname}/src/${pkgname}-${pkgver}
  # srcdir is already defined as
  # ${srcdir}=/usr/src/packages/BUILD/${pkgname}/src
  # builddir=/usr/src/packages/BUILD/${pkgname}/build
  # builddir=${sourcedir}/OUTPUT
  # --- End Variables ---
  #
  # Test if section prepare() is run by OBS build service:
  mkdir -p -v "${_builddir}"
  echo "Written from section prepare $(date) ." > ${_builddir}/testFile.txt
  #
  echo pwd=$(pwd)
  # Move patching to build() section for verbose log output
  # echo patch -d ${_sourcedir} -p1 < ${pkgname}-fix-pkgconfig.patch
  # echo patch -d "${_sourcedir}" --forward --strip=1 --input="${srcdir}/fix.patch"
  # echo patch -d "${_sourcedir}" --forward --strip=1 --input="${_uploaddir}/fix.patch"
  # patch -d "${_sourcedir}" --forward --strip=1 --input="${srcdir}/${pkgname}-fix-pkgconfig.patch"
  # patch -d "${_sourcedir}" --forward --strip=1 --input="${_uploaddir}/${pkgname}-fix-pkgconfig.patch"
  # patch -d "${_sourcedir}" --forward --strip=1 --input="${srcdir}/gcc9-stringop-bogus-warning.patch" 
  # patch -d "${_sourcedir}" --forward --strip=1 --input="${_uploaddir}/gcc9-stringop-bogus-warning.patch"
  # patch -d "${_sourcedir}" --forward --strip=1 --input="${_uploaddir}/bctoolbox-0001-set-current-version.patch"
  echo "--- Exiting section prepare() ---" 
}



build() {
  echo
  echo
  echo
  echo
  echo "--- Entering section build() ---"
  echo
  echo
  echo
  echo
  echo "--- Machine data we are building on ---"
  echo "Total disk: $_TOTAL_DISK"
  echo "Output of free -h:"
  echo "$_FREEMEM"
  echo "Total memory: $_TOTAL_MEM"
  echo "Total RAM: $_TOTAL_RAM"
  echo "Total SWAP: $_TOTAL_SWAP"archlinux 
  echo "_numberOfProcessorsOnMachine=$_numberOfProcessorsOnMachine"
  echo "_wantedJobs=$_wantedJobs"
  echo "_jobsIget=$_jobsIget"
  echo "--- End machine data we are building on ---"
  echo "--- Show files ---"
  find
  echo "--- End show files ---"
  # --- Start Variables ---
  # uploaddir=/usr/src/packages/SOURCES
  # sourcedir=/usr/src/packages/BUILD/${pkgname}/src/${pkgname}-${pkgver}
  sourcedir=/usr/src/packages/BUILD/${_pkgname}/src/${_pkgname}-${pkgver}
  # builddir=/usr/src/packages/BUILD/${pkgname}/build
  builddir=/usr/src/packages/BUILD/${_pkgname}/build
  # --- End Variables ---
  echo "--- Start print variables ---"
  echo \${uploaddir}=$uploaddir  
  echo \${_uploaddir}=$_uploaddir
  echo \${sourcedir}=$sourcedir
  echo \${_sourcedir}=$_sourcedir  
  echo \${srcdir}=${srcdir}
  echo \${builddir}=${builddir}
  echo \${_builddir}=${_builddir}
  echo "--- End print variables ---"
  echo pwd=$(pwd)
  # Test if section prepare() was run:
  if [ -f "${_builddir}/testFile.txt" ]; then
    echo "This is a test if the section prepare() was run:"
    echo "================================================"
    echo
    cat ${_builddir}/testFile.txt  
    echo
  fi
  #
  echo "--- Start apply patches ---"
  #
  # ${srcdir}=/usr/src/packages/BUILD/${_pkgname}/src
  # patch file: /usr/src/packages/BUILD/${_pkgname}/src/myFixErrorDuringCompilation.patch
  #
  cd "$sourcedir"
  #
  # myPatchFileOne=myFixErrorDuringCompilation.patch
  # myPatchFileTwo=
  # myPatchFileThree=
  # patch --forward --strip=1 --input="${srcdir}/${myPatchFileOne}"
  # patch --forward --strip=1 --input="${srcdir}/${myPatchFileTwo}"
  # patch --forward --strip=1 --input="${srcdir}/${myPatchFileThree}"
  #
  echo "--- Patches are in the following directory: ---"
  echo
  echo "    uploaddir=/usr/src/packages/SOURCES"
  echo
  echo "-----------------------------"
  ls -al ${uploaddir}
  echo "-----------------------------"
  echo
  echo "and in the following directory"
  echo "if you did not forget to put patches as sources like this:"
  echo
  echo "    source=('src.tar.xx'"
  echo "            'fix-0001.patch'"
  echo "            'fix-0002.patch'"
  echo "    )"
  echo
  echo "    \${srcdir}=${srcdir}"
  echo
  echo "-----------------------------"
  ls -al ${srcdir}
  echo "-----------------------------"
  echo  
  # /usr/src/packages/SOURCES/fix-0000.patch
  # /usr/src/packages/SOURCES/fix-0001.patch
  #
  # Apply patches the following way:
  # patch --forward --strip=1 --input="${uploaddir}/fix-0000.patch"
  # patch --forward --strip=1 --input="${uploaddir}/fix-0001.patch"
  #
  # or if you prefer:
  #
  # patch --forward --strip=1 --input="${srcdir}/fix-0000.patch"
  # patch --forward --strip=1 --input="${srcdir}/fix-0001.patch"
  echo "--- End apply patches ---"
  echo
  echo
  echo
  echo
  echo
  echo
  echo
  echo
  echo
  builddir=/usr/src/packages/BUILD/${_pkgname}/build
  sourcedir=/usr/src/packages/BUILD/${_pkgname}/src/${_pkgname}-${pkgver}
  echo builddir=$builddir
  echo sourcedir=$sourcedir
  echo \${srcdir}=${srcdir}
  echo \${_builddir}=${_builddir}
  echo pwd=$(pwd)  
  
  echo "--- Start apply patches ---"
  # ${srcdir}=/usr/src/packages/BUILD/${_pkgname}/src
  # patch file: /usr/src/packages/BUILD/${_pkgname}/src/myFixErrorDuringCompilation.patch
  cd "$sourcedir"
  # myPatchFileOne=myFixErrorDuringCompilation.patch
  # myPatchFileTwo=
  # myPatchFileThree=
  # patch --forward --strip=1 --input="${srcdir}/${myPatchFileOne}"
  # patch --forward --strip=1 --input="${srcdir}/${myPatchFileTwo}"
  # patch --forward --strip=1 --input="${srcdir}/${myPatchFileThree}"
  # Moved patching to prepare() section
  # patch --forward --strip=1 --input="${uploaddir}/bctoolbox-fix-pkgconfig.patch"
  # patch --forward --strip=1 --input="${uploaddir}/gcc9-stringop-bogus-warning.patch"  
  echo "--- End apply patches ---"
  #
  #
  # the modern CMake (3.14) build procedure:
  # cmake -S . -B build
  # cmake --build build
  # cmake --build build -t test
  #
  # the old way:
  mkdir -pv "${builddir}"
  cd "${builddir}"
  echo Line 51: changed to \${builddir}
  echo pwd=$(pwd)
  #
  # Configure with cmake:
  #
  # To fix:
  # CMake cannot find imported location bcunit:
  #   IMPORTED_LOCATION not set for imported target "bcunit".
  # That maybe means that "/usr/lib/libbcunit.so" is not connected to "bcunit"
  # How to tell CMake the bcunit cmake files are in:
  # /usr/share/BCUnit/cmake/     ?
  # CMake cannot find Decaf and asks for variable Decaf_DIR
  #   -- Could NOT find Decaf (missing: Decaf_DIR)
  # Decaf is in:
  # /usr/share/decaf/cmake/
  #
  ls -al /usr/share/decaf/cmake
  ls -al /usr/share/BCUnit/cmake
  #sed -i 's/find_package(BcUnit/find_package(BCUnit/g' ${sourcedir}/CMakeLists.txt
  #
  #
  # Explanation to the CMake options below:
  # =================================
  # Note: CMake command with options can be optimized.
  #
  # Archlinux compilation fails
  # 
  # CMake Error in /usr/src/packages/BUILD/bctoolbox/build/CMakeFiles/CMakeTmp/CMakeLists.txt:
  # IMPORTED_LOCATION not set for imported target "bcunit".
  # Researching the cause seems to boil down to the test parts.
  # Disabling TEST_COMPONENT and TESTS produces a successful build.
  #
  # Setting CMAKE_PREFIX_PATH or CMAKE_SHARED_LINKER_FLAGS does not seem to help CMake
  # find libbcunit.so
  #
  export CFLAGS=$(echo "$CFLAGS -Wno-error=maybe-uninitialized -Wno-error=unused-parameter")
  export CXXFLAGS=$(echo "$CXXFLAGS -Wno-error=maybe-uninitialized -Wno-error=unused-parameter")
  #
  # mbedtls2 v2.28.0 support
  # need fix for no mbedtls v3.x.y support
  #
  #  -DCMAKE_SHARED_LINKER_FLAGS="${CMAKE_SHARED_LINKER_FLAGS} -L/usr/lib/libbcunit.so" \
  #  -DCMAKE_PREFIX_PATH="\${CMAKE_PREFIX_PATH};/usr/share/BCUnit/cmake/;/usr/share/decaf/cmake/;/usr/lib/" \
  #  -DBCUnit_DIR=/usr/share/BCUnit/cmake/ \
  #  -DENABLE_DOC=ON     \
  # tester code not compiling well
  cmake "${sourcedir}" \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_PARALLEL_LEVEL=${_jobsIget} \
    -DDecaf_DIR=/usr/share/decaf/cmake/ \
    -DENABLE_STATIC=OFF \
    -DENABLE_TESTS_COMPONENT=OFF \
    -DENABLE_UNIT_TESTS=OFF \
    -DENABLE_TESTS=OFF \
    -DENABLE_MBEDTLS=OFF \
    -DENABLE_OPENSSL=YES \
    -DENABLE_STRICT=OFF
  #cmake -S ${sourcedir} -B ${builddir} -DENABLE_STATIC=OFF -DENABLE_DOC=ON
  # build the traditional way:
  echo cmake --build . --parallel ${_jobsIget}
  cmake --build . --parallel ${_jobsIget}
  echo pwd=$(pwd)
  find ${builddir} 2>/dev/null
  echo
  echo
  echo
  echo
  echo "--- Exiting section build() ---"
  echo
  echo
  echo
  echo
}



package() {
  echo
  echo
  echo
  echo
  echo "--- Entering section package() ---"
  echo
  echo
  echo
  echo
  builddir=/usr/src/packages/BUILD/${_pkgname}/build
  srcdir=/usr/src/packages/BUILD/${_pkgname}/src/${_pkgname}-${pkgver}
  echo "--- Start print variables ---"
  echo \${uploaddir}=$uploaddir  
  echo \${_uploaddir}=$_uploaddir
  echo \${sourcedir}=$sourcedir
  echo \${_sourcedir}=$_sourcedir  
  echo \${srcdir}=${srcdir}
  echo \${builddir}=${builddir}
  echo \${_builddir}=${_builddir}
  echo \${installToDir}=${installToDir}
  echo \${_installToDir}=${_installToDir}
  echo \${pkgdir}=${pkgdir}   
  echo "--- End print variables ---"
  echo pwd=$(pwd)
  # cd build
  cd ${builddir}
  echo pwd=$(pwd)
  rm -rf "$pkgdir"
  mkdir -p "$pkgdir"
  #cmake --install . --config RelWithDebInfo --prefix "$pkgdir" --strip
  #make install DESTDIR="$pkgdir"
  make DESTDIR="$pkgdir" install
  find "$pkgdir" -exec strip -s {} \;
  echo "--- Start of investigation ---"
  echo Try to find out what causes:
  echo WARNING: Package contains reference to \$srcdir
  cd "${srcdir}/.."
  echo pwd=$(pwd)
  echo grep -R "$PWD/src" pkg/ 2>/dev/null
  # Unfortunately it creates an error once it
  # finds a directory which root owns... so this approach does not work on OBS.
  # grep -R "$PWD/src" pkg/ 2>/dev/null
  echo "--- End of investigation ---"
  echo "--- List packaged files ---"
  find ${pkgdir}
  echo "--- End list packaged files ---"
  echo
  echo
  echo
  echo
  echo "--- Exiting section package() ---"
  echo
  echo
  echo
  echo
}
openSUSE Build Service is sponsored by