File PKGBUILD of Package bcunit

# Fix for error: bsdtar: Failed to set default locale
# LANG=en_US.UTF-8 # not available, use C or POSIX
LANG=C
LC_ALL=${LANG}
# 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=bcunit
pkgname=bcunit
pkgver=5.4.42
pkgrel=1
pkgdesc="Lightweight system for writing, administering, and running unit tests in C"
arch=(x86_64)
url="https://github.com/BelledonneCommunications/${_pkgname}"
license=(LGPL)
conflicts=('bcunit')
provides=('bcmunit')
depends=(glibc)
makedepends=('cmake' 'git' 'tar' 'procps-ng' 'bc' 'cpio' 'gzip')
source=("${_pkgname}-${pkgver}.tar.bz2")
sha256sums=('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}
_installToDir=${_pkgdir}/usr



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
  echo "--- Entering section prepare() ---"
  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
  uploaddir=/usr/src/packages/SOURCES
  sourcedir=/usr/src/packages/BUILD/${_pkgname}/src/${_pkgname}-${pkgver}
  # builddir is already defined as
  # builddir=/usr/src/packages/BUILD/${_pkgname}/build
  _builddir=${sourcedir}/OUTPUT
  # --- End Variables ---
  # Test if section prepare() is run:
  mkdir -p -v "${_builddir}"
  echo "Written from section prepare $(date) ." > ${_builddir}/testFile.txt
  # --- Apply patches ---"
  # ${srcdir}=/usr/src/packages/BUILD/bcmatroska2/src
  # patch file: /usr/src/packages/BUILD/bcmatroska2/src/${_pkgname}-0001-fix.patch
  cd "$sourcedir"
  # patch --forward --strip=1 --input="${srcdir}/${_pkgname}-0001-fix.patch"
  # or
  # patch --forward --strip=1 --input="${uploaddir}/${_pkgname}-0001-fix.patch"
  echo
  echo "--- Exiting section prepare() ---"
  echo
}



build() {
  echo
  echo
  echo
  echo
  echo "--- Entering section build() ---"
  echo
  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"
  echo "_numberOfProcessorsOnMachine=$_numberOfProcessorsOnMachine"
  echo "_wantedJobs=$_wantedJobs"
  echo "_jobsIget=$_jobsIget"
  echo "--- End machine data we are building on ---"
  echo
  echo
  echo
  echo
  echo
  echo
  # --- Start Variables ---
  uploaddir=/usr/src/packages/SOURCES
  sourcedir=/usr/src/packages/BUILD/${_pkgname}/src/${_pkgname}-${pkgver}
  builddir=/usr/src/packages/BUILD/${_pkgname}/build
  _builddir=${sourcedir}/OUTPUT
  # --- 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
  # --- Create missing directories ---
  if [ ! -d "${builddir}" ]; then
    mkdir -p -v "${builddir}"
    echo
    echo "Created directory:"
    echo "    ${builddir}"
    echo
  else
    echo "${builddir} already exists. Doing nothing."
  fi   
  if [ ! -d "${_builddir}" ]; then
    mkdir -p -v "${_builddir}"
    echo
    echo "Created directory:"
    echo "    ${_builddir}"
    echo
  else
    echo "${_builddir} already exists. Doing nothing."
  fi
  echo "--- Start print variables ---"
  echo uploaddir=$uploaddir
  echo sourcedir=$sourcedir
  echo \${srcdir}=${srcdir}
  echo builddir=$builddir
  echo \${builddir}=${builddir}
  echo \${_builddir}=${_builddir}
  echo "--- End print variables ---"
  echo
  echo
  echo
  # Test if section prepare() was run:
  if [ -f "${_builddir}/testFile.txt" ]; then
    echo
    echo "This is a test if the section prepare() was run:"
    echo "================================================"
    echo
    echo "cat ${_builddir}/testFile.txt"
    cat ${_builddir}/testFile.txt  
    echo
  else
    echo
    echo "This is a test if the section prepare() was run:"
    echo "================================================"
    echo
    echo "Does not exist:"
    echo "    ${_builddir}/testFile.txt"
    echo "-----------------------------"
    ls -al ${_builddir}
    echo "-----------------------------"
    echo
  fi
  echo
  echo "Current directory:"
  echo "    $(pwd)"
  echo
  echo
  echo "--- List files ---"
  # Stops makepkg:
  # find /usr/src/packages/BUILD 2>/dev/null
  find ${sourcedir} 2>/dev/null
  echo "--- End list files ---"
  echo
  echo "Current directory:"
  echo "    $(pwd)"
  echo
  echo "--- Start apply patches ---"
  cd "$sourcedir"
  echo
  echo "Current directory:"
  echo "    $(pwd)"
  echo
  #
  # 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 in PKGBUILD 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
  echo "The patches are here:"
  echo "    \${uploaddir}=${uploaddir}"
  echo "-----------------------------"
  ls -al ${_uploaddir}
  echo "-----------------------------"
  echo
  echo "Change directory to where the sources have been extracted:"
  cd ${_sourcedir}
  echo
  echo "Current directory:"
  echo "    $(pwd)"
  echo
  echo "Patching now..."
  patch --forward --strip=1 --input="${uploaddir}/bcunit-link-ncurses.patch"
  patch --forward --strip=1 --input="${uploaddir}/bcunit-ncurses6.patch"
  patch --forward --strip=1 --input="${uploaddir}/bcunit-sover.patch"
  patch --forward --strip=1 --input="${uploaddir}/set_current_version.patch"
  echo "Patching finished."
  echo
  echo "--- End apply patches ---"
  echo
  echo
  echo "--- List files ---"
  ## Searching directory 'pkg' will cause error,
  ## so this code will stop makepkg execution:
  ##     find /usr/src/packages/BUILD 2>/dev/null
  ## This works:
  ls -al /usr/src/packages/BUILD
  find ${srcdir} 2>/dev/null
  echo "--- End list files ---"
  echo
  echo "Current directory:"
  echo "    $(pwd)"
  echo
  # -DENABLE_STATIC=OFF \
  # -DENABLE_DOC=ON
  cmake -S "${_sourcedir}" -B "${_builddir}" \
    -DCMAKE_INSTALL_PREFIX=/usr
  cmake --build "${_builddir}"
  echo
  echo "Current directory:"
  echo "    pwd=$(pwd)"
  echo
  echo "--- Show what was built ---"
  find ${builddir} 2>/dev/null
  echo "--- End show what was built ---"
  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
  # --- Start Variables ---
  # sourcedir=/usr/src/packages/BUILD/${pkgname}/src/${pkgname}-${pkgver}
  # builddir=/usr/src/packages/BUILD/${pkgname}/build
  # builddir=${sourcedir}/OUTPUT
  # installToDir=${pkgdir}/usr
  # --- 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 \${installToDir}=${installToDir}
  echo \${_installToDir}=${_installToDir}
  echo \${pkgdir}=${pkgdir}   
  echo "--- End print variables ---"
  _installToDir=${pkgdir}/usr
  builddir=/usr/src/packages/BUILD/${_pkgname}/build
  sourcedir=/usr/src/packages/BUILD/${_pkgname}/src/${_pkgname}-${pkgver}
  _builddir=${sourcedir}/OUTPUT
  echo builddir=$builddir
  echo sourcedir=$sourcedir
  echo \${srcdir}=${srcdir}
  echo \${builddir}=${builddir}
  echo \${_builddir}=${_builddir}
  echo \${_installToDir}=${_installToDir}
  echo
  echo "Current directory:"
  echo "    $(pwd)"
  echo
  rm -rvf "$pkgdir"; mkdir -pv "$pkgdir"
  #
  # Change directory to where the build files are:
  # cd "${builddir}"
  cd "${_builddir}"
  #
  echo
  echo "Current directory:"
  echo "    $(pwd)"
  echo
  echo "--- trying: cmake --install . --strip --config RelWithDebInfo --prefix ${_installToDir} ---"
  cmake --install . --strip --config RelWithDebInfo --prefix "${_installToDir}"
  echo
  echo
  echo "--- List packaged files ---"
  find ${pkgdir}
  echo "--- End list packaged files ---"
  echo
  echo
  echo
  echo "--- Exiting section package() ---"
  echo
  echo
  echo
  echo
}
openSUSE Build Service is sponsored by