Skip to content

Useful variables for recipes

Schrijvers Luc edited this page Jun 23, 2022 · 37 revisions

For a list of all variables and where to use them, check Haikuporter Guidelines and Haikuporter Build-Recipes

$portVersion

For a non standard $portversion like this: 1.5.4~pl02 you need to adjust the SOURCE_URI and sometimes the SOURCE_DIR:

`SOURCE_URI="https://www.gnu.org/software/xorriso/xorriso-${portVersion/\~/.}.tar.gz"`

SOURCE_DIR = xorriso-1.5.4 then:

SOURCE_DIR="xorriso-${portVersion/\~pl02/}"

A bit more complex for slunkcrypt-2022_04_24.recipe, we need to change the _ to - in the recipe, the archive doesn't provide a top-levell directory so we need to leave SOURCE_DIR empty, gitLabDir and SLUNKCRYPT_VERSION are custom variables:

gitLabDir="da63740f538e552708ae712bcc157142"
SLUNKCRYPT_VERSION=`echo $portVersion | sed 's/\_/-/g'`
SOURCE_URI="$HOMEPAGE/uploads/$gitLabDir/slunkcrypt.$SLUNKCRYPT_VERSION.source.tar.gz"
CHECKSUM_SHA256="599be4f4a6767992731a671d534fdaa74919dc8c83a8204b0f92439b90f7b658"
SOURCE_DIR=""

$commandBinDir and $commandSuffix

On x86_gcc2 if primary doesn't build (!x86_gcc2) then move binaries to $prefix/bin instead of $binDir ($prefix/bin/x86) needs the adjustment in BUILD() too:

commandBinDir=$binDir
commandSuffix=$secondaryArchSuffix
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

BUILD()
	runConfigure --omit-dirs binDir ./configure \
		--bindir=$commandBinDir

for cmake:

BUILD()
	cmake -B build -S . \
	$cmakeDirArgs \
	-DCMAKE_INSTALL_BINDIR=$commandBinDir

$libVersion and $libVersionCompat

If libraries provide sonames declare them here and in PROVIDES="":

libVersion="0.1.1"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	fribidi$secondaryArchSuffix = $portVersion
	lib:libfribidi$secondaryArchSuffix = $libVersionCompat
	"

In packages with multiple libraries and different sonames you could use a bit more complex variant:

libcdioLibs="
	libcdio
	libcdioxx
	libiso9660
	libiso9660xx
	libudf
	"
libcdioVersion=18.0.0
libcdioxxVersion=1.0.0
libiso9660Version=11.0.0
libiso9660xxVersion=0.0.0
libudfVersion=0.0.0
for i in lib $libcdioLibs; do
	eval "${i}VersionCompat=\"\$${i}Version compat >= \${${i}Version%%.*}\""
done

PROVIDES="
	libcdio$secondaryArchSuffix = $portVersion
	lib:libcdio$secondaryArchSuffix = $libcdioVersionCompat
	lib:libcdio++$secondaryArchSuffix = $libcdioxxVersionCompat
	lib:libiso9660$secondaryArchSuffix = $libiso9660VersionCompat
	lib:libiso9660++$secondaryArchSuffix = $libiso9660xxVersionCompat
	lib:libudf$secondaryArchSuffix = $libudfVersionCompat
	"

Skip command provided in both PRIMARY and SECONDARY ARCHITECTURE

If a package builds for both gcc2 and gcc8 you might want to skip the commands for SECONDARY_ARCHITECTURE="":

if [ -z "$secondaryArchSuffix" ]; then
	PROVIDES="$PROVIDES
		cmd:cdda_player = $portVersion
		cmd:cd_drive = $portVersion
		cmd:cd_info = $portVersion
		cmd:cd_read = $portVersion
		cmd:iso_info = $portVersion
		cmd:iso_read = $portVersion
		cmd:mmc_tool = $portVersion
		"
fi

Also needs adjusting in INSTALL():

INSTALL()
	if [ -z "$secondaryArchSuffix" ]; then
		packageEntries tools \
			"$commandBinDir"
	fi


	if [ -n "$secondaryArchSuffix" ]; then
		rm -rf "$documentationDir" "$binDir"
	fi

Tools sub package PROVIDES_TOOLS=""

Sometimes you want the tools (commands in a subpackage, use $commandSuffix or $secondaryArchSuffix as needed:

if [ -z "$secondaryArchSuffix" ]; the
	PROVIDES_tools="
		fribidi${secondaryArchSuffix}_tools = $portVersion
		cmd:fribidi$commandSuffix = $portVersion
		"
	REQUIRES_tools="
		fribidi$secondaryArchSuffix == $portVersion base
		"
fi

Also needs adjustment in INSTALL(), use $commandBinDir or $binDir where needed

	packageEntries tools \
			"$commandBinDir"

defineDebugInfoPackage

Check in Terminal with readelf -S $libname | grep debug for debug info If they are provided move them into a debug package:

defineDebugInfoPackage roaraudio$secondaryArchSuffix \
	$libDir/libroar.so.$libVersion \
	$commandBinDir/roarbidir

defineDebugInfoPackage libde265$secondaryArchSuffix \
	$libDir/libde265.so.$libVersion \
	"$(getPackagePrefix tools)"/bin/acceleration_speed \

Add pkgconfig file

Sometimes ports don't provide pkgconfig files, these can be added to the INSTALL() part:

# Add pkgconfig file
mkdir -p $developLibDir/pkgconfig
cat > $developLibDir/pkgconfig/libargon2.pc << EOF
bindir=$prefix/bin
exec_prefix=$prefix
libdir=$libDir
includedir=$includeDir

Name: libargon2
Description: $SUMMARY
Version: $portVersion
Libs: -L$developLibDir -largon2
Cflags: -I$includeDir
EOF

fixPkgconfig

Sometimes fixPkgconfig alters the paths for the pkgconfig files, this is a fix for those:

INSTALL()
	# fixPkgconfig
	if [ -n "$secondaryArchSuffix" ]; then
		sed -i 's,\/headers/x86,\/headers/x86/sunpinyin-2.0,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/sunpinyin-2.0.pc
	else
		sed -i 's,\/headers,\/headers/sunpinyin-2.0,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/sunpinyin-2.0.pc
	fi

Some more information on using sed: https://www.geeksforgeeks.org/sed-command-in-linux-unix-with-examples/

Remove multiple libtool files in one go in INSTALL()

find "$libDir" -name '*.la' -delete

Post-install script

If you need to do some post install actions you can do this in a post-install script that will be executed when the package is installed

ADDITIONAL_FILES="fontconfig-reload-cache.sh"

POST_INSTALL_SCRIPTS="$relativePostInstallDir/fontconfig-reload-cache.sh"

mkdir -p $postInstallDir
cp -f $portDir/additional-files/fontconfig-reload-cache.sh $postInstallDir

In the script you can do a check if fc-cache is available and if so reload the fontconfig's chache (save this file as fontconfig-reload-cache.sh in additional-files):

#!sh

command -v fc-cache && fc-cache -f

finddir

If you need to point to a certain path, check finddir -l for available paths:

$(finddir B_SYSTEM_DEVELOP_DIRECTORY)/lib$secondaryArchSubDir

This points to /boot/system/develop/lib/x86 (secondary architecture on 32bit)