SUMMARY="A free COBOL compiler"
DESCRIPTION="GnuCOBOL (formerly OpenCOBOL) is a free COBOL compiler."
HOMEPAGE="https://www.gnu.org/software/gnucobol/"
COPYRIGHT="2001-2017 Free Software Foundation, Inc
	Keisuke Nishida
	Roger While
	Ron Norman
	Simon Sobisch
	Edward Hart
	Brian Tiffin
	Sergey Kashyrin
	Dave Pitts"
LICENSE="GNU GPL v3
	GNU LGPL v3
	GNU FDL v1.3"
REVISION="1"
SOURCE_URI="https://sourceforge.net/projects/open-cobol/files/gnu-cobol/$portVersion/gnucobol-$portVersion.tar.gz"
CHECKSUM_SHA256="925838decd65864b2aa3a4bf1385ce4bc708b942e05e8406945a730d7aab32cb"

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

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

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

PROVIDES="
	gnucobol$secondaryArchSuffix = $portVersion
	cmd:cobc$commandSuffix = $portVersion
	cmd:cobcrun$commandSuffix = $portVersion
	lib:libcob$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libdb$secondaryArchSuffix
	lib:libgmp$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libltdl$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix
	"

PROVIDES_devel="
	gnucobol${secondaryArchSuffix}_devel = $portVersion
	cmd:cob_config$commandSuffix
	devel:libcob$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	gnucobol$secondaryArchSuffix == $portVersion base
	devel:libdb$secondaryArchSuffix
	devel:libgmp$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libltdl$secondaryArchSuffix
	devel:libncurses$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libdb$secondaryArchSuffix
	devel:libgmp$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libltdl$secondaryArchSuffix
	devel:libncurses$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:awk
	cmd:bison
	cmd:find
	cmd:flex
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

TEST_REQUIRES="
	cmd:wget
	cmd:perl
	"

BUILD()
{
	autoreconf -vfi
	runConfigure --omit-dirs binDir ./configure \
		--bindir=$commandBinDir
	make $jobArgs
}

INSTALL()
{
	make install

	rm $libDir/*.la

	prepareInstalledDevelLib libcob

	# devel package
	packageEntries devel \
		$developDir \
		$commandBinDir/cob-config
}

TEST()
{
	export LIBRARY_PATH=$sourceDir/libcob/.libs:$LIBRARY_PATH
	make check
	# ERROR: 761 tests were run,
	# 9 failed (6 expected failures).
	# 5 tests were skipped.

	make test
	# this will download a testsuite for cobol85 (about 4MB)
	# all tests for cobol85 passed
}
