File PKGBUILD of Package bcmatroska2

# 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=bcmatroska2
_pkgname=bcmatroska2
pkgver=5.3.5
pkgrel=1
pkgdesc="C Library to Deal with Matroska Files"
arch=('x86_64')
url="https://github.com/BelledonneCommunications/bcmatroska2"
license=('GPL2')
conflicts=('bcmatroska2')
provides=('bcmatroska2')
depends=(glibc)
makedepends=('cmake' 'git' 'tar' 'procps-ng' 'bc' 'cpio' 'gzip' 'bctoolbox>=5.3.5' 
             libdecaf)
source=("${_pkgname}-${pkgver}.tar.bz2")
sha1sums=('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}
  # builddir is already defined as
  # 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
  #
  # --- 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"
  # patch -d "$sourcedir" --forward --strip=1 --input="${srcdir}/${_pkgname}-0001-fix.patch"
  # or
  # patch -d "$sourcedir" --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
  # --- 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 "This is a test if the section prepare() was run:"
    echo "================================================"
    echo
    cat ${_builddir}/testFile.txt  
    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
  echo "Patching now..."
  # Uncomment and adapt below:
  # patch --forward --strip=1 --input="${uploaddir}/${_pkgname}-0001.patch"
  # patch --forward --strip=1 --input="${uploaddir}/${_pkgname}-0002.patch"
  # patch --forward --strip=1 --input="${uploaddir}/${_pkgname}-0003.patch"
  echo "Patching finished."
  echo
  echo "--- End apply patches ---"
  echo
  echo
  echo "--- List files ---"
  # This stops makepkg because it cannot handle errors.
  # Directory 'pkg' will cause error, so this cannot be done:
  #     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
  #
  # The modern CMake (3.14) build procedure:
  # cmake -S . -B build
  # cmake --build build
  # cmake --build build -t test
  #
  # The old way:
  # Uncomment the following where needed:
  # mkdir -pv "${builddir}"
  # cd "${builddir}"
  # echo "Changed to \${builddir}"
  # echo "Current directory:"
  # echo "    $(pwd)"
  # #
  # # Configure with cmake:
  # #
  # echo cmake "${sourcedir}" -DENABLE_STATIC=OFF -DENABLE_DOC=ON
  # cmake "${sourcedir}" -DENABLE_STATIC=OFF -DENABLE_DOC=ON
  # # cmake -S ${sourcedir} -B ${builddir} -DENABLE_STATIC=OFF -DENABLE_DOC=ON
  # #
  # # Build the traditional way:
  # #
  # echo cmake --build .
  # cmake --build .
  # find ${builddir} 2>/dev/null
  # echo "--- Exiting section build() ---"
  # echo
  # Configure with cmake:
  # cmake -S ${sourcedir} -B ${builddir} -DENABLE_STATIC=OFF -DENABLE_DOC=ON
  # Special recipe for bcmatroska2:
  #
  # Decide where to build:
  cd "${builddir}"
  # cd "${_builddir}"
  #
  echo
  echo "Current directory:"
  echo "    $(pwd)"
  echo
  echo "Opting for not including static library in package and creating doc."
  # -DCMAKE_SHARED_LINKER_FLAGS="-Wl,-rpath,%{ldaplibdir},-lssl,-lcrypto,-lsasl2" \
  # -Wl,--as-needed
  echo cmake "${sourcedir}" \
    -DCMAKE_BUILD_PARALLEL_LEVEL=${_jobsIget} \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DENABLE_STATIC=OFF \
    -DENABLE_DOC=ON
  cmake "${sourcedir}" \
    -DCMAKE_BUILD_PARALLEL_LEVEL=${_jobsIget} \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DENABLE_STATIC=OFF \
    -DENABLE_DOC=ON
  #
  # or:
  # 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
  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
  _installToDir=${pkgdir}/usr
  builddir=/usr/src/packages/BUILD/${_pkgname}/build
  sourcedir=/usr/src/packages/BUILD/${_pkgname}/src/${_pkgname}-${pkgver}
  _builddir=${sourcedir}/OUTPUT
  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
  echo "Current directory:"
  echo "    $(pwd)"
  echo
  rm -rf "$pkgdir"
  mkdir -p "$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