git: f84718746122 - main - lang/quickjs: Build shared libraries

From: Yuri Victorovich <yuri_at_FreeBSD.org>
Date: Tue, 24 Oct 2023 00:35:08 UTC
The branch main has been updated by yuri:

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

commit f8471874612278840b3db3076f3982cf5e259cc3
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2023-10-24 00:23:21 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2023-10-24 00:34:53 +0000

    lang/quickjs: Build shared libraries
    
    PR:             274681
    Reported by:    Robert Clausecker <fuz@FreeBSD.org>
---
 emulators/tic-80/Makefile             |  5 +--
 lang/quickjs/Makefile                 |  4 ++
 lang/quickjs/files/patch-Makefile     | 71 +++++++++++++++++++++++++++++++++++
 lang/quickjs/files/patch-qjsc.c       | 11 ++++++
 lang/quickjs/pkg-plist                |  2 +-
 www/edbrowse/Makefile                 |  4 +-
 www/edbrowse/files/patch-src_makefile |  2 +-
 7 files changed, 92 insertions(+), 7 deletions(-)

diff --git a/emulators/tic-80/Makefile b/emulators/tic-80/Makefile
index 9bf65216ab11..a16e780407f1 100644
--- a/emulators/tic-80/Makefile
+++ b/emulators/tic-80/Makefile
@@ -1,6 +1,7 @@
 PORTNAME=	TIC-80
 DISTVERSIONPREFIX=	v
 DISTVERSION=	1.1.2736
+PORTREVISION=	1
 CATEGORIES=	emulators games
 
 MAINTAINER=	fuz@FreeBSD.org
@@ -10,9 +11,6 @@ WWW=		https://tic80.com
 LICENSE=	MIT
 LICENSE_FILE=	${WRKSRC}/LICENSE
 
-# only available as a static library
-# bump TIC-80 when quickjs is updated!
-BUILD_DEPENDS=	quickjs>0:lang/quickjs
 LIB_DEPENDS=	libasound.so:audio/alsa-lib \
 		libcurl.so:ftp/curl \
 		libdbus-1.so:devel/dbus \
@@ -20,6 +18,7 @@ LIB_DEPENDS=	libasound.so:audio/alsa-lib \
 		libinotify.so:devel/libinotify \
 		libjanet.so:lang/janet \
 		libpng16.so:graphics/png \
+		libquickjs.so:lang/quickjs \
 		libsquirrel.so:lang/squirrel \
 		libunwind.so:devel/libunwind
 
diff --git a/lang/quickjs/Makefile b/lang/quickjs/Makefile
index 19a6a9630c59..1fbef10941d2 100644
--- a/lang/quickjs/Makefile
+++ b/lang/quickjs/Makefile
@@ -1,5 +1,6 @@
 PORTNAME=	quickjs
 DISTVERSION=	2021.03.27
+PORTREVISION=	1
 CATEGORIES=	lang devel
 MASTER_SITES=	https://bellard.org/${PORTNAME}/
 DISTNAME=	${PORTNAME}-${DISTVERSION:S/./-/g}
@@ -25,4 +26,7 @@ post-patch:
 		${WRKSRC}/Makefile
 .endif
 
+post-install:
+	${STRIP_CMD} ${STAGEDIR}${PREFIX}/lib/libquickjs.so
+
 .include <bsd.port.post.mk>
diff --git a/lang/quickjs/files/patch-Makefile b/lang/quickjs/files/patch-Makefile
new file mode 100644
index 000000000000..f7bd7b4b90a4
--- /dev/null
+++ b/lang/quickjs/files/patch-Makefile
@@ -0,0 +1,71 @@
+--- Makefile.orig	2023-10-23 23:26:12 UTC
++++ Makefile
+@@ -76,6 +76,7 @@ ifdef CONFIG_CLANG
+   HOST_CC=clang
+   CC=$(CROSS_PREFIX)clang
+   CFLAGS=-g -Wall -MMD -MF $(OBJDIR)/$(@F).d
++  CFLAGS += -fPIC
+   CFLAGS += -Wextra
+   CFLAGS += -Wno-sign-compare
+   CFLAGS += -Wno-missing-field-initializers
+@@ -156,9 +157,9 @@ endif
+ ifdef CONFIG_M32
+ PROGS+=qjs32 qjs32_s
+ endif
+-PROGS+=libquickjs.a
++PROGS+=libquickjs.so
+ ifdef CONFIG_LTO
+-PROGS+=libquickjs.lto.a
++PROGS+=libquickjs.lto.so
+ endif
+ 
+ # examples
+@@ -235,12 +236,12 @@ else
+ LTOEXT=
+ endif
+ 
+-libquickjs$(LTOEXT).a: $(QJS_LIB_OBJS)
+-	$(AR) rcs $@ $^
++libquickjs$(LTOEXT).so: $(QJS_LIB_OBJS)
++	$(CC) -shared $(LDFLAGS) -o $@ $^
+ 
+ ifdef CONFIG_LTO
+-libquickjs.a: $(patsubst %.o, %.nolto.o, $(QJS_LIB_OBJS))
+-	$(AR) rcs $@ $^
++libquickjs.so: $(patsubst %.o, %.nolto.o, $(QJS_LIB_OBJS))
++	$(CC) -shared $(LDFLAGS) -o $@ $^
+ endif # CONFIG_LTO
+ 
+ repl.c: $(QJSC) repl.js
+@@ -311,10 +312,10 @@ install: all
+ 	$(STRIP) qjs qjsc
+ 	install -m755 qjs qjsc "$(DESTDIR)$(prefix)/bin"
+ 	ln -sf qjs "$(DESTDIR)$(prefix)/bin/qjscalc"
+-	mkdir -p "$(DESTDIR)$(prefix)/lib/quickjs"
+-	install -m644 libquickjs.a "$(DESTDIR)$(prefix)/lib/quickjs"
++	mkdir -p "$(DESTDIR)$(prefix)/lib"
++	install -m644 libquickjs.so "$(DESTDIR)$(prefix)/lib"
+ ifdef CONFIG_LTO
+-	install -m644 libquickjs.lto.a "$(DESTDIR)$(prefix)/lib/quickjs"
++	install -m644 libquickjs.lto.so "$(DESTDIR)$(prefix)/lib"
+ endif
+ 	mkdir -p "$(DESTDIR)$(prefix)/include/quickjs"
+ 	install -m644 quickjs.h quickjs-libc.h "$(DESTDIR)$(prefix)/include/quickjs"
+@@ -347,7 +348,7 @@ HELLO_MODULE_SRCS=examples/hello_module.js
+ HELLO_MODULE_OPTS=-fno-string-normalize -fno-map -fno-promise -fno-typedarray \
+            -fno-typedarray -fno-regexp -fno-json -fno-eval -fno-proxy \
+            -fno-date -m
+-examples/hello_module: $(QJSC) libquickjs$(LTOEXT).a $(HELLO_MODULE_SRCS)
++examples/hello_module: $(QJSC) libquickjs$(LTOEXT).so $(HELLO_MODULE_SRCS)
+ 	$(QJSC) $(HELLO_MODULE_OPTS) -o $@ $(HELLO_MODULE_SRCS)
+ 
+ # use of an external C module (static compilation)
+@@ -355,7 +356,7 @@ examples/hello_module: $(QJSC) libquickjs$(LTOEXT).a $
+ test_fib.c: $(QJSC) examples/test_fib.js
+ 	$(QJSC) -e -M examples/fib.so,fib -m -o $@ examples/test_fib.js
+ 
+-examples/test_fib: $(OBJDIR)/test_fib.o $(OBJDIR)/examples/fib.o libquickjs$(LTOEXT).a
++examples/test_fib: $(OBJDIR)/test_fib.o $(OBJDIR)/examples/fib.o libquickjs$(LTOEXT).so
+ 	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
+ 
+ examples/fib.so: $(OBJDIR)/examples/fib.pic.o
diff --git a/lang/quickjs/files/patch-qjsc.c b/lang/quickjs/files/patch-qjsc.c
new file mode 100644
index 000000000000..292f0af889fd
--- /dev/null
+++ b/lang/quickjs/files/patch-qjsc.c
@@ -0,0 +1,11 @@
+--- qjsc.c.orig	2023-10-23 23:25:39 UTC
++++ qjsc.c
+@@ -446,7 +446,7 @@ static int output_executable(const char *out_filename,
+     if (dynamic_export)
+         *arg++ = "-rdynamic";
+     *arg++ = cfilename;
+-    snprintf(libjsname, sizeof(libjsname), "%s/libquickjs%s%s.a",
++    snprintf(libjsname, sizeof(libjsname), "%s/libquickjs%s%s.so",
+              lib_dir, bn_suffix, lto_suffix);
+     *arg++ = libjsname;
+     *arg++ = "-lm";
diff --git a/lang/quickjs/pkg-plist b/lang/quickjs/pkg-plist
index 1a1306ba137d..5a70bf083b2b 100644
--- a/lang/quickjs/pkg-plist
+++ b/lang/quickjs/pkg-plist
@@ -3,4 +3,4 @@ bin/qjsc
 bin/qjscalc
 include/quickjs/quickjs-libc.h
 include/quickjs/quickjs.h
-lib/quickjs/libquickjs.a
+lib/libquickjs.so
diff --git a/www/edbrowse/Makefile b/www/edbrowse/Makefile
index 78300980d355..c8274684bdb0 100644
--- a/www/edbrowse/Makefile
+++ b/www/edbrowse/Makefile
@@ -1,6 +1,7 @@
 PORTNAME=	edbrowse
 DISTVERSIONPREFIX=	v
 DISTVERSION=	3.8.7
+PORTREVISION=	1
 CATEGORIES=	www editors
 
 MAINTAINER=	alfix86@gmail.com
@@ -10,9 +11,8 @@ WWW=		https://edbrowse.org/
 LICENSE=	GPLv2
 LICENSE_FILE=	${WRKSRC}/COPYING
 
-BUILD_DEPENDS=	${LOCALBASE}/include/quickjs/quickjs.h:lang/quickjs \
-		${LOCALBASE}/lib/quickjs/libquickjs.a:lang/quickjs
 LIB_DEPENDS=	libcurl.so:ftp/curl \
+		libquickjs.so:lang/quickjs \
 		libodbc.so:databases/unixODBC \
 		libpcre2-8.so:devel/pcre2
 
diff --git a/www/edbrowse/files/patch-src_makefile b/www/edbrowse/files/patch-src_makefile
index d891514900c6..1d08660a15dd 100644
--- a/www/edbrowse/files/patch-src_makefile
+++ b/www/edbrowse/files/patch-src_makefile
@@ -14,7 +14,7 @@
  
  # LDFLAGS for quickjs loading.
 -QUICKJS_LDFLAGS = $(QUICKJS_DIR)/libquickjs.a -ldl
-+QUICKJS_LDFLAGS = /usr/local/lib/quickjs/libquickjs.a -ldl
++QUICKJS_LDFLAGS = -lquickjs
  ifeq ($(shell uname),Linux)
  	QUICKJS_LDFLAGS += -latomic
  endif