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-2018 Aubrey Jaffer, George Carrette, et al."
LICENSE="GNU LGPL v3"
REVISION="3"
SOURCE_URI="https://ftpmirror.gnu.org/guile/guile-$portVersion.tar.gz
	https://ftp.gnu.org/gnu/guile/guile-$portVersion.tar.gz"
CHECKSUM_SHA256="c3471fed2e72e5b04ad133bbaaf16369e8360283679bcf19800bc1b381024050"
PATCHES="guile1-$portVersion.patchset"
SOURCE_DIR="guile-$portVersion"

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="17.4.0"
libguileVers="${libguileVersion%.*}"
libguileVersionCompat="$libguileVersion compat >= ${libguileVersion%%.*}"
portVersionCompat="$portVersion compat >= ${portVersion%%.*}"
portVers="${portVersion%.*}"

PROVIDES="
	guile1$secondaryArchSuffix = $portVersionCompat
	lib:libguile$secondaryArchSuffix = $libguileVersionCompat
	lib:libguilereadline_v_17$secondaryArchSuffix = 17.0.3 compat >= 17
	lib:libguile_srfi_srfi_1_v_3$secondaryArchSuffix = 3.0.2 compat >= 3
	lib:libguile_srfi_srfi_13_14_v_3$secondaryArchSuffix = 3.0.1 compat >= 3
	lib:libguile_srfi_srfi_4_v_3$secondaryArchSuffix = 3.0.1 compat >= 3
	lib:libguile_srfi_srfi_60_v_2$secondaryArchSuffix = 2.0.2 compat >= 2
	"
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="
	guile1${secondaryArchSuffix}_tools = $portVersionCompat
	cmd:guile$commandSuffix = $portVersion
	cmd:guile_snarf$commandSuffix = $portVersion
	cmd:guile_tools$commandSuffix = $portVersion
	"
REQUIRES_tools="
	haiku$secondaryArchSuffix
	guile1$secondaryArchSuffix == $portVersion base
	lib:libgmp$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libltdl$secondaryArchSuffix
	"

PROVIDES_devel="
	guile1${secondaryArchSuffix}_devel = $portVersionCompat
	cmd:guile_config$commandSuffix = $portVersion
	devel:libguile$secondaryArchSuffix = $libguileVersionCompat
	devel:libguilereadline_v_17$secondaryArchSuffix = 17.0.3 compat >= 17
	devel:libguile_srfi_srfi_1_v_3$secondaryArchSuffix = 3.0.2 compat >= 3
	devel:libguile_srfi_srfi_13_14_v_3$secondaryArchSuffix = 3.0.1 compat >= 3
	devel:libguile_srfi_srfi_4_v_3$secondaryArchSuffix = 3.0.1 compat >= 3
	devel:libguile_srfi_srfi_60_v_2$secondaryArchSuffix = 2.0.2 compat >= 2
	"
REQUIRES_devel="
	guile1$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$secondaryArchSuffix
	cmd:pkg_config$secondaryArchSuffix
	cmd:sed
	"

defineDebugInfoPackage guile1$secondaryArchSuffix \
	$(getPackagePrefix tools)/"$relativeCommandBinDir"/guile \
	"$libDir"/libguile.so.$libguileVersion \
	"$libDir"/libguilereadline-v-17.so.17.0.3 \
	"$libDir"/libguile-srfi-srfi-1-v-3.so.3.0.2 \
	"$libDir"/libguile-srfi-srfi-13-14-v-3.so.3.0.1 \
	"$libDir"/libguile-srfi-srfi-4-v-3.so.3.0.1 \
	"$libDir"/libguile-srfi-srfi-60-v-2.so.2.0.2

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

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

	make $jobArgs
}

INSTALL()
{
	make install

	rm -f "$libDir"/charset.alias

	# remove libtool files
	rm -f "$libDir"/lib*.la
	rm -f "$libDir"/guile/$portVers/extensions/*.la

	prepareInstalledDevelLibs libguile \
		libguilereadline-v-17 \
		libguile-srfi-srfi-1-v-3 \
		libguile-srfi-srfi-13-14-v-3 \
		libguile-srfi-srfi-4-v-3 \
		libguile-srfi-srfi-60-v-2

	fixPkgconfig

	# add version-less symlinks of the libraries which are loaded dynamically
	ln -s libguilereadline-v-17.so.17.0.3 "$libDir"/libguilereadline-v-17.so
	ln -s libguile-srfi-srfi-1-v-3.so.3.0.2 "$libDir"/libguile-srfi-srfi-1-v-3.so
	ln -s libguile-srfi-srfi-60-v-2.so.2.0.2 "$libDir"/libguile-srfi-srfi-60-v-2.so

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

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

TEST()
{
	make check
}
