Skip to content

Commit c57e930

Browse files
lanodanCeleste
and
Celeste
committed
Makefile: Allow building libquickjs as a shared library
Adapted from https://git.alpinelinux.org/aports/tree/community/quickjs/01-sharedlib.patch?id=27a8f649949c36bfc3e45854e08c48a8eb06e07c Co-authored-by: Celeste <[email protected]>
1 parent 3b45d15 commit c57e930

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ endif
3232
#CONFIG_WIN32=y
3333
# use link time optimization (smaller and faster executables but slower build)
3434
#CONFIG_LTO=y
35+
# also build libquickjs as a shared library
36+
#CONFIG_SHARED=y
3537
# consider warnings as errors (for development)
3638
#CONFIG_WERROR=y
3739
# force 32 bit build for some utilities
@@ -205,6 +207,10 @@ PROGS+=libquickjs.a
205207
ifdef CONFIG_LTO
206208
PROGS+=libquickjs.lto.a
207209
endif
210+
ifdef CONFIG_SHARED
211+
SO_VERSION=$(shell sed 's/-/./g' VERSION)
212+
PROGS+=libquickjs.so.$(SO_VERSION)
213+
endif
208214

209215
# examples
210216
ifeq ($(CROSS_PREFIX),)
@@ -289,6 +295,11 @@ libquickjs.a: $(patsubst %.o, %.nolto.o, $(QJS_LIB_OBJS))
289295
$(AR) rcs $@ $^
290296
endif # CONFIG_LTO
291297

298+
ifdef CONFIG_SHARED
299+
libquickjs.so.$(SO_VERSION): $(patsubst %.o, %.pic.o, $(QJS_LIB_OBJS))
300+
$(CC) -shared -Wl,-soname,$@ $(LDFLAGS) -o $@ $^
301+
endif # CONFIG_SHARED
302+
292303
repl.c: $(QJSC) repl.js
293304
$(QJSC) -c -o $@ -m repl.js
294305

@@ -362,6 +373,10 @@ install: all
362373
install -m644 libquickjs.a "$(DESTDIR)$(PREFIX)/lib/quickjs"
363374
ifdef CONFIG_LTO
364375
install -m644 libquickjs.lto.a "$(DESTDIR)$(PREFIX)/lib/quickjs"
376+
endif
377+
ifdef CONFIG_SHARED
378+
install -Dm755 libquickjs.so.$(SO_VERSION) "$(DESTDIR)$(PREFIX)/lib"
379+
ln -s libquickjs.so.$(SO_VERSION) "$(DESTDIR)$(PREFIX)/lib/libquickjs.so"
365380
endif
366381
mkdir -p "$(DESTDIR)$(PREFIX)/include/quickjs"
367382
install -m644 quickjs.h quickjs-libc.h "$(DESTDIR)$(PREFIX)/include/quickjs"

0 commit comments

Comments
 (0)