git: 107c6a92bfe9 - main - lang/p5-JavaScript-QuickJS: Use lang/quickjs

From: Po-Chuan Hsieh <sunpoet_at_FreeBSD.org>
Date: Sun, 08 Sep 2024 18:43:20 UTC
The branch main has been updated by sunpoet:

URL: https://cgit.FreeBSD.org/ports/commit/?id=107c6a92bfe92bb68c55e95c32643db6f510dd2c

commit 107c6a92bfe92bb68c55e95c32643db6f510dd2c
Author:     Po-Chuan Hsieh <sunpoet@FreeBSD.org>
AuthorDate: 2024-09-08 18:17:58 +0000
Commit:     Po-Chuan Hsieh <sunpoet@FreeBSD.org>
CommitDate: 2024-09-08 18:37:12 +0000

    lang/p5-JavaScript-QuickJS: Use lang/quickjs
    
    - Bump PORTREVISION for dependency and package change
---
 lang/p5-JavaScript-QuickJS/Makefile                |  8 +-
 lang/p5-JavaScript-QuickJS/files/patch-Makefile.PL | 88 ++++++++++++++++++++++
 2 files changed, 95 insertions(+), 1 deletion(-)

diff --git a/lang/p5-JavaScript-QuickJS/Makefile b/lang/p5-JavaScript-QuickJS/Makefile
index 6e7bb99a21f3..5cc4c39203e9 100644
--- a/lang/p5-JavaScript-QuickJS/Makefile
+++ b/lang/p5-JavaScript-QuickJS/Makefile
@@ -14,14 +14,20 @@ LICENSE_COMB=	dual
 BUILD_DEPENDS=	p5-ExtUtils-MakeMaker-CPANfile>=0:devel/p5-ExtUtils-MakeMaker-CPANfile \
 		p5-File-Slurper>=0:devel/p5-File-Slurper \
 		p5-File-Which>=0:sysutils/p5-File-Which
+LIB_DEPENDS=	libquickjs.so:lang/quickjs
 TEST_DEPENDS=	p5-Test-Deep>=0:devel/p5-Test-Deep \
 		p5-Test-FailWarnings>=0:devel/p5-Test-FailWarnings \
 		p5-Test-Fatal>=0:devel/p5-Test-Fatal \
 		p5-Types-Serialiser>=0:devel/p5-Types-Serialiser
 
-USES=		gmake perl5
+USES=		perl5
 USE_PERL5=	configure
 
+post-patch:
+	@${REINPLACE_CMD} -e 's|%%LOCALBASE%%|${LOCALBASE}|' ${WRKSRC}/Makefile.PL
+# Clean up bundled libraries
+	@${RM} -r ${WRKSRC}/quickjs/
+
 post-install:
 	${STRIP_CMD} ${STAGEDIR}${PREFIX}/${SITE_ARCH_REL}/auto/JavaScript/QuickJS/QuickJS.so
 
diff --git a/lang/p5-JavaScript-QuickJS/files/patch-Makefile.PL b/lang/p5-JavaScript-QuickJS/files/patch-Makefile.PL
new file mode 100644
index 000000000000..99174c1a1b57
--- /dev/null
+++ b/lang/p5-JavaScript-QuickJS/files/patch-Makefile.PL
@@ -0,0 +1,88 @@
+--- Makefile.PL.orig	2024-02-12 06:16:14 UTC
++++ Makefile.PL
+@@ -13,24 +13,11 @@ use Cwd;
+ use File::Which;
+ use Cwd;
+ 
+-my $GMAKE_PATH = _find_gmake();
+-
+-if (!$GMAKE_PATH) {
+-    die "GNU Make ($Config{'gmake'}) is required.\n";
+-}
+-elsif (!-x $GMAKE_PATH) {
+-    if ($!) {
+-        die "Failed to detect if GNU Make ($GMAKE_PATH) is executable: $!\n";
+-    }
+-
+-    die "GNU Make ($GMAKE_PATH) is not executable.\n";
+-}
+-
+ my $ATOMIC_ENV_KEY = 'JS_QUICKJS_LINK_LIBATOMIC';
+ 
+ my $PERL_QJS_MAKEFILE_PATH = File::Spec->catfile( Cwd::getcwd(), 'Makefile.quickjs');
+ 
+-my $libpath = File::Spec->catfile('quickjs', 'libquickjs.a');
++my $libpath = File::Spec->catfile('%%LOCALBASE%%/lib', 'libquickjs.so');
+ 
+ # quickjs needs these; pre-5.20 perls didn’t include libpthread.
+ # Note that MSWin32, if given these, will try to compile them statically
+@@ -42,8 +29,6 @@ if (_need_librt()) {
+     push @libs, '-lrt';
+ }
+ 
+-_tweak_for_os();
+-
+ if (!_stdatomic_h_exists()) {
+     _avoid_stdatomic_h();
+ }
+@@ -54,13 +39,6 @@ mkdir( File::Spec->catdir( qw(quickjs .obj) ) );
+ #
+ mkdir( File::Spec->catdir( qw(quickjs .obj) ) );
+ 
+-make_libquickjs_makefile();
+-
+-# RaspiOS needs this; others may, too:
+-if (_should_link_libatomic()) {
+-    push @libs, '-latomic';
+-}
+-
+ WriteMakefile(
+     NAME              => 'JavaScript::QuickJS',
+     VERSION_FROM      => 'lib/JavaScript/QuickJS.pm', # finds $VERSION
+@@ -71,7 +49,7 @@ WriteMakefile(
+         ],
+       ) : ()
+     ),
+-    INC               => '-Wall --std=c99 -I.',
++    INC               => '-Wall --std=c99 -I. -I%%LOCALBASE%%/include',
+     LICENSE           => "perl_5",
+ 
+     PMLIBDIRS => ['lib'],
+@@ -224,8 +202,6 @@ sub _should_link_libatomic {
+     my $needs_libatomic;
+ 
+     eval {
+-        system $GMAKE_PATH, '-C', 'quickjs', '-f', $PERL_QJS_MAKEFILE_PATH, $rel_objpath;
+-        die if $?;
+         my $objbin = File::Slurper::read_binary($objpath);
+ 
+         $needs_libatomic = -1 != index($objbin, '__atomic_fetch_sub_');
+@@ -315,18 +291,5 @@ use Config;
+ package MY;
+ 
+ use Config;
+-
+-sub postamble {
+-
+-    # QuickJS requires GNU make.
+-    my $make = ($^O =~ m<bsd>i) ? $GMAKE_PATH : '$(MAKE)';
+-
+-    # The leading “+” is to ensure that parallel builds work properly.
+-    return <<"MAKE_FRAG"
+-
+-$libpath:
+-\t+$make -C quickjs -f '$PERL_QJS_MAKEFILE_PATH' libquickjs.a
+-MAKE_FRAG
+-}
+ 
+ 1;