SUMMARY="Larry Wall's Practical Extraction and Report Language"
DESCRIPTION="Perl was originally developed by Larry Wall in 1987 as a \
general-purpose Unix scripting language to make report processing easier.

Perl borrows features from other programming languages including C, shell \
scripting (sh), AWK, and sed. The language provides powerful text processing \
facilities without the arbitrary data-length limits of many contemporary Unix \
tools, facilitating easy manipulation of text files.

In addition to CGI, Perl is used for graphics programming, system \
administration, network programming, finance, bioinformatics, and other \
applications. Perl is nicknamed 'the Swiss Army chainsaw of scripting \
languages' because of its flexibility and power, and possibly also because of \
its perceived 'ugliness'."
HOMEPAGE="https://www.perl.org/"
COPYRIGHT="1993-2019 Larry Wall and others"
LICENSE="GNU GPL v1
	Artistic"
REVISION="1"
perlShortVersion="${portVersion%.*}"
SOURCE_URI="http://www.cpan.org/src/perl-$portVersion.tar.gz"
CHECKSUM_SHA256="03b693901cd8ae807231b1787798cf1f2e0b8a56218d07b7da44f784a7caeb2c"
PATCHES="perl-$portVersion.patchset"

ARCHITECTURES="all ?arm"

PROVIDES="
	# assume that any perl commands are backwards compatible to version 5.
	perl = $portVersion compat >= 5
	cmd:corelist = $portVersion compat >= 5
	cmd:cpan = $portVersion compat >= 5
	cmd:enc2xs = $portVersion compat >= 5
	cmd:encguess = $portVersion compat >= 5
	cmd:h2ph = $portVersion compat >= 5
	cmd:h2xs = $portVersion compat >= 5
	cmd:instmodsh = $portVersion compat >= 5
	cmd:json_pp = $portVersion compat >= 5
	cmd:libnetcfg = $portVersion compat >= 5
	cmd:perl = $portVersion compat >= 5
	cmd:perl$portVersion = $portVersion compat >= 5
	cmd:perlbug = $portVersion compat >= 5
	cmd:perldoc = $portVersion compat >= 5
	cmd:perlivp = $portVersion compat >= 5
	cmd:perlthanks = $portVersion compat >= 5
	cmd:piconv = $portVersion compat >= 5
	cmd:pl2pm = $portVersion compat >= 5
	cmd:pod2html = $portVersion compat >= 5
	cmd:pod2man = $portVersion compat >= 5
	cmd:pod2text = $portVersion compat >= 5
	cmd:pod2usage = $portVersion compat >= 5
	cmd:podchecker = $portVersion compat >= 5
	cmd:podselect = $portVersion compat >= 5
	cmd:prove = $portVersion compat >= 5
	cmd:ptar = $portVersion compat >= 5
	cmd:ptardiff = $portVersion compat >= 5
	cmd:ptargrep = $portVersion compat >= 5
	cmd:shasum = $portVersion compat >= 5
	cmd:splain = $portVersion compat >= 5
	cmd:streamzip = $portVersion compat >= 5
	cmd:xsubpp = $portVersion compat >= 5
	cmd:zipdetails = $portVersion compat >= 5
	# vendor_perl refers to the path to packaged perl modules, which includes
	# the short perl version, so it is backwards compatible up this one.
	vendor_perl = $perlShortVersion compat >= $perlShortVersion
	lib:libperl = $portVersion compat >= $perlShortVersion
	"
REQUIRES="
	haiku
	"

BUILD_REQUIRES="
	haiku_devel
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:gcc
	cmd:ld
	cmd:make
	cmd:sed
	cmd:grep
	"

perlArchName="$(uname -m)-haiku"

GLOBAL_WRITABLE_FILES="
	non-packaged/lib/perl5/site_perl/$perlShortVersion/sitecustomize.pl keep-old
	non-packaged/lib/perl5/site_perl/$perlShortVersion/$perlArchName directory keep-old
	"

BUILD_PACKAGE_ACTIVATION_PHASE=INSTALL

BUILD()
{
	./Configure \
		-Dprefix=$prefix \
		-Dprivlib=$prefix/lib/perl5/$portVersion \
		-Dsiteprefix=$prefix/non-packaged \
		-Dsitelib=$prefix/non-packaged/lib/perl5/site_perl/$perlShortVersion \
		-Dvendorprefix=$prefix \
		-Dvendorlib=$prefix/lib/perl5/vendor_perl/$perlShortVersion \
		-Dcf_email=zooey@hirschkaefer.de \
		-Uusenm -Duseshrplib -Uusemymalloc \
		-Dlibpth="$(finddir B_USER_DEVELOP_DIRECTORY)/lib $(finddir B_SYSTEM_DEVELOP_DIRECTORY)/lib" \
		-Dusrinc="$(finddir B_SYSTEM_DEVELOP_DIRECTORY)/headers/posix" \
		-Dlocinc="$(finddir B_USER_CONFIG_DIRECTORY)/develop/headers $(finddir B_SYSTEM_DEVELOP_DIRECTORY)/headers" \
		-Dlibc="'$(finddir B_SYSTEM_LIB_DIRECTORY)/libroot.so'" \
		-Dlibs=-lnetwork -Dcc=gcc -Dld=gcc \
		-Ud_link -Ddont_use_nlink -Ud_syserrlst \
		-Dldlibpthname=LIBRARY_PATH -Dstartperl="#! perl" \
		-Dccdlflags="-Wl,-fno-stack-protector,-rpath=$libDir/perl5/$portVersion/$perlArchName/CORE" \
		-Dusesitecustomize \
		-de

	# force-remove path from sed
	sed -i -e 's/LOC_SED\s*"\/bin\/sed/LOC_SED "sed/' config.h

	make $jobArgs
}

INSTALL()
{
	make install
	chmod a+x $binDir/{perl,perlthanks}

	# copy script into site_perl that takes care of massaging @INC into what we need.
	cp sitecustomize.pl $prefix/non-packaged/lib/perl5/site_perl/$perlShortVersion/
}

TEST()
{
#x86_64
#Failed 19 tests out of 2439, 99.22% okay.
#        ../cpan/ExtUtils-MakeMaker/t/INST.t
#        ../cpan/ExtUtils-MakeMaker/t/INST_PREFIX.t
#        ../cpan/ExtUtils-MakeMaker/t/MM_BeOS.t
#        ../cpan/IO-Socket-IP/t/11sockopts.t
#        ../cpan/IO-Socket-IP/t/18fdopen.t
#        ../cpan/IPC-SysV/t/msg.t
#        ../cpan/Socket/t/socketpair.t
#        ../cpan/Time-Piece/t/02core.t
#        ../cpan/version/t/07locale.t
#        ../dist/IO/t/cachepropagate-unix.t
#        ../dist/Net-Ping/t/010_pingecho.t
#        ../dist/Net-Ping/t/450_service.t
#        ../dist/PathTools/t/cwd_enoent.t
#        ../dist/Time-HiRes/t/stat.t
#        ../dist/Time-HiRes/t/utime.t
#        ../ext/POSIX/t/wrappers.t
#        io/socket.t
#        op/time.t
#        porting/regen.t

	make test
}
