# Maintainer: PktSurf <smlinux@pktsurf.in>
app=perl
version=5.24.3
build=1sml
homepage="https://www.perl.org/"
download="https://www.cpan.org/src/5.0/perl-$version.tar.xz"
desc="High-level, general-purpose, interpreted, dynamic programming language"
requires="db"

prepbuilddir() {
  mkandenterbuilddir
  rm -rf $app-$version

  tar xf $srcdir/$app-$version.tar.?z*
  cd $app-$version
  fixbuilddirpermissions
}

build() {
  # /usr/local/include directory, if it contains any headers, 
  # might interfere with the compile because our GCC toolchain looks into that directory, in which case we abort.
  if [ -d /usr/local/include ] ; then
    echo "/usr/local/include directory may cause this perl compilation to fail. Kindly remove it. Aborting!"
    exit 1
  fi

  sed '1i#define PERL_BUILD_DATE "01.01.18 00:00:00"' -i perl.c

  sed -e 's;myuname=`$u;myuname="linux host" #`$u;' \
    -e 's;cf_time=`;cf_time="01.01.18 00:00:00" #`;' \
    -e 's;cf_by=`;cf_by=user #`;' \
    -e "s;^myhostname='';myhostname=host;" \
    -e "s;^phostname='';phostname=host;" \
  -i Configure

  sed -i 's,-fstack-protector,-fnostack-protector,g' ./Configure

  ./Configure -des \
    -Accflags='$CFLAGS -D_BSD_SOURCE' \
    -Dprefix=/ \
    -Dvendorprefix=/ \
    -Dsitelib="/lib/perl5/site_perl" \
    -Dsitearch="/lib/perl5/site_perl" \
    -Darchlib="/lib/perl5/core_perl" \
    -Dprivlib="/lib/perl5/core_perl" \
    -Dvendorlib="/lib/perl5/vendor_perl" \
    -Dvendorarch="/lib/perl5/vendor_perl" \
    -Dscriptdir='/bin' \
    -Dbin='/bin' \
    -Duseshrplib \
    -Dusethreads \
    -Ubincompat5005 \
    -Uversiononly \
    -Dcc="$CC" 

  make
  make install DESTDIR=$pkg

  rm -f $pkg/*.0 

  cp Artistic $pkgdocs/LICENSE

  mkfinalpkg
}

sha512sums="
330bbcd4bc8fc25dd84f9170f8b56450fa3ab4cdd6f39ab85fbfc4b9b8b47c130f312839189f45e6e2d7ca557524a3ee2cbd06f4aeb3ac96b4dd4f70b466cec6  perl-5.24.3.tar.lz
"
