SUMMARY="Libraries for GNU Ubiquitous Intelligent Language for Extensions"
SUMMARY_tools="Binaries for GNU Ubiquitous Intelligent Language for Extensions"
DESCRIPTION="Guile is a library designed to help programmers create flexible \
applications. Using Guile in an application allows programmers to write \
plug-ins, or modules (there are many names, but the concept is essentially \
the same) and users to use them to have an application fit their needs."
HOMEPAGE="https://www.gnu.org/software/guile/"
COPYRIGHT="1993-2020 Aubrey Jaffer, George Carrette, et al."
LICENSE="GNU LGPL v3"
REVISION="4"
SOURCE_URI="https://ftpmirror.gnu.org/guile/guile-$portVersion.tar.lz
	https://ftp.gnu.org/gnu/guile/guile-$portVersion.tar.lz"
CHECKSUM_SHA256="5de7c4d28fa25c232512a4d1e76e6152a721dde568a6b1310971e1ea49e18c46"
PATCHES="guile-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2 ?x86"
SECONDARY_ARCHITECTURES="x86"

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

libguileVersion="1.4.2"
libguileVersionCompat="$libguileVersion compat >= ${libguileVersion%%.*}"
portVersionCompat="$portVersion compat >= ${portVersion%%.*}"
portVers="${portVersion%.*}"

PROVIDES="
	guile$secondaryArchSuffix = $portVersionCompat
	lib:libguile_$portVers$secondaryArchSuffix = $libguileVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libffi$secondaryArchSuffix
	lib:libgc$secondaryArchSuffix
	lib:libgmp$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libltdl$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix
	lib:libreadline$secondaryArchSuffix
	lib:libunistring$secondaryArchSuffix
	"

PROVIDES_tools="
	guile${secondaryArchSuffix}_tools = $portVersionCompat
	cmd:guild$commandSuffix = $portVersion
	cmd:guile$commandSuffix = $portVersion
	cmd:guile_snarf$commandSuffix = $portVersion
	cmd:guile_tools$commandSuffix = $portVersion
	"
REQUIRES_tools="
	haiku$secondaryArchSuffix
	guile$secondaryArchSuffix == $portVersion base
	lib:libffi$secondaryArchSuffix
	lib:libgc$secondaryArchSuffix
	lib:libgmp$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libltdl$secondaryArchSuffix
	lib:libunistring$secondaryArchSuffix
	"

PROVIDES_devel="
	guile${secondaryArchSuffix}_devel = $portVersionCompat
	cmd:guile_config$commandSuffix = $portVersion
	devel:libguile_$portVers$secondaryArchSuffix = $libguileVersionCompat
	"
REQUIRES_devel="
	guile$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libffi$secondaryArchSuffix
	devel:libgc$secondaryArchSuffix
	devel:libgmp$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libltdl$secondaryArchSuffix
	devel:libncurses$secondaryArchSuffix
	devel:libreadline$secondaryArchSuffix
	devel:libunistring$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:gcc$secondaryArchSuffix
	cmd:gperf
	cmd:grep
	cmd:make
	cmd:ld
	cmd:pkg_config$secondaryArchSuffix
	cmd:sed
	"

defineDebugInfoPackage guile$secondaryArchSuffix \
	$(getPackagePrefix tools)/"$relativeCommandBinDir"/guile \
	"$libDir"/libguile-$portVers.so.$libguileVersion

BUILD()
{
	CPPFLAGS="-D_BSD_SOURCE" LIBS="-lbsd -lnetwork" \
	runConfigure --omit-dirs binDir ./configure\
		 --bindir=$commandBinDir\
		--with-threads

	# No MADV_DONTNEED, yet
	sed --in-place '/HAVE_SYS_MMAN_H/d' config.h

	make $jobArgs
}

INSTALL()
{
	make install

	rm -f "$libDir"/charset.alias
	rm -f "$libDir"/lib*.la
	rm -f "$libDir"/guile/$portVers/extensions/*.la
	rm -f "$libDir"/guile/$portVers/extensions/*.a

	prepareInstalledDevelLib libguile-$portVers

	fixPkgconfig

	packageEntries tools \
		"$commandBinDir"/guild \
		"$commandBinDir"/guile \
		"$commandBinDir"/guile-snarf \
		"$commandBinDir"/guile-tools \
		"$manDir"

	packageEntries devel \
		"$commandBinDir"/guile-config \
		"$dataDir"/aclocal \
		"$developDir"
}

TEST()
{
	make check
}
