Skip to content

Commit

Permalink
lang/quickjs: Build shared libraries
Browse files Browse the repository at this point in the history
PR:		274681
Reported by:	Robert Clausecker <fuz@FreeBSD.org>
  • Loading branch information
yurivict committed Oct 24, 2023
1 parent 70ffe0b commit f847187
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 7 deletions.
5 changes: 2 additions & 3 deletions 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
Expand All @@ -10,16 +11,14 @@ 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 \
libgif.so:graphics/giflib \
libinotify.so:devel/libinotify \
libjanet.so:lang/janet \
libpng16.so:graphics/png \
libquickjs.so:lang/quickjs \
libsquirrel.so:lang/squirrel \
libunwind.so:devel/libunwind

Expand Down
4 changes: 4 additions & 0 deletions 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}
Expand All @@ -25,4 +26,7 @@ post-patch:
${WRKSRC}/Makefile
.endif

post-install:
${STRIP_CMD} ${STAGEDIR}${PREFIX}/lib/libquickjs.so

.include <bsd.port.post.mk>
71 changes: 71 additions & 0 deletions 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
11 changes: 11 additions & 0 deletions 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";
2 changes: 1 addition & 1 deletion lang/quickjs/pkg-plist
Expand Up @@ -3,4 +3,4 @@ bin/qjsc
bin/qjscalc
include/quickjs/quickjs-libc.h
include/quickjs/quickjs.h
lib/quickjs/libquickjs.a
lib/libquickjs.so
4 changes: 2 additions & 2 deletions www/edbrowse/Makefile
@@ -1,6 +1,7 @@
PORTNAME= edbrowse
DISTVERSIONPREFIX= v
DISTVERSION= 3.8.7
PORTREVISION= 1
CATEGORIES= www editors

MAINTAINER= alfix86@gmail.com
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion www/edbrowse/files/patch-src_makefile
Expand Up @@ -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

0 comments on commit f847187

Please sign in to comment.