summaryrefslogtreecommitdiffstats
path: root/gis/therion/therion.SlackBuild
blob: f5290f853024166a46249f6c7e2ec2a1245a18f2 (plain)
#!/bin/bash

# Slackware build script for therion

# Copyright 2023-2024 Giancarlo Dessi, Cagliari, IT
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=therion
VERSION=${VERSION:-6.2.1}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i586 ;;
    arm*) ARCH=arm ;;
       *) ARCH=$( uname -m ) ;;
  esac
fi

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

# Features enabled by default
BUILDLOCH="" ; [ "${LOCH:-yes}" = "no" ] && BUILDLOCH=" -DBUILD_LOCH=OFF"
BUILDBOOK=" -DTHBOOK_FORMAT=3" ; [ "${BOOK:-yes}" = "no" ] && BUILDBOOK=" -DBUILD_THBOOK=OFF"
BUILDX=""; [ "${GUI:-yes}" = "no" ] && BUILDX=" -DBUILD_XTHERION=OFF"

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

if [ "$ARCH" = "i586" ]; then
  SLKCFLAGS="-O2 -march=i586 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
  LIBDIRSUFFIX="64"
else
  SLKCFLAGS="-O2"
  LIBDIRSUFFIX=""
fi

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION
tar xvf $CWD/$PRGNAM-$VERSION.tar.gz
cd $PRGNAM-$VERSION
chown -R root:root .
find -L . \
 \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
  -o -perm 511 \) -exec chmod 755 {} \; -o \
 \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
  -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;

mkdir -p build
cd build
  cmake -Wno-dev \
    -DCMAKE_C_FLAGS:STRING="$SLKCFLAGS" \
    -DCMAKE_CXX_FLAGS:STRING="$SLKCFLAGS" \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_SYSCONFDIR=/etc/therion \
    $BUILDLOCH \
    $BUILDBOOK \
    $BUILDX \
    -DCMAKE_BUILD_TYPE=Release ..
  make -j 10
  make install/strip DESTDIR=$PKG
cd ..

rm -f $PKG/{,usr/}lib${LIBDIRSUFFIX}/*.la

find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \
  | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true

find $PKG -name perllocal.pod -o -name ".packlist" -o -name "*.bs" | xargs rm -f || true

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a CHANGES COPYING README CONTRIBUTING.md $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

# make installs documentation generated by the build into two directories in /usr/share/doc
# we move this documentation in /usr/doc/therion-x.y.z
if [ "$BOOK" != "no" ] ; then
 mv $PKG/usr/share/doc/$PRGNAM/thbook.pdf $PKG/usr/doc/$PRGNAM-$VERSION
 rm -rf $PKG/usr/share/doc/$PRGNAM
 if [ "$LOCH" == "no" ] ; then
   rm -rf $PKG/usr/share
 fi
fi
if [ "$LOCH" != "no" ] ; then
 mv $PKG/usr/share/doc/therion-viewer $PKG/usr/doc/$PRGNAM-$VERSION
 rm -rf $PKG/usr/share/doc
fi

#Make and install a copy of the application icon in PNG format
mkdir -p $PKG/usr/share/icons/hicolor/32x32/apps
magick $TMP/$PRGNAM-$VERSION/therion.ico $PKG/usr/share/icons/hicolor/32x32/apps/therion.png

#Create a desktop entry
mkdir -p $PKG/usr/share/applications
cat << EOF > $PKG/usr/share/applications/therion.desktop
[Desktop Entry]
Type=Application
Name=Therion
GenericName=Cave survey software
GenericName[de]=Höhlenstudienprogramm
GenericName[es]=Programa de estudio de las cuevas
GenericName[fr]=Programme d'étude des grottes
GenericName[it]=Programma di studio delle grotte
GenericName[pt]=Programa de estudo de caverna
Comment=Process data from speleological surveys and generate maps and 3D models of caves
Comment[de]=Verarbeiten Sie speläologische Daten und erstellen Sie Höhlenkarten und 3D-Modelle
Comment[es]=Procese datos de estudios espeleológicos y genere mapas y modelos 3D de cuevas
Comment[fr]=Traiter données des relevés spéléologiques et générer cartes et modèles 3D de grottes
Comment[it]=Elabora dati di rilievi speleologici e genera mappe e modelli 3D delle grotte
Comment[pt]=Processar dados de levantamentos espeleológicos e gerar mapas e modelos 3D de cavernas
Exec=xtherion
Icon=/usr/share/icons/hicolor/32x32/apps/therion.png
Terminal=false
Categories=Education;Science;Geology;
StartupNotify=true
MimeType=text/x-th;text/x-th2;

EOF

# remove *.ini files, leave only *.ini.new
rm -f $PKG/etc/therion/*.ini

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE