From 90f05487b5e04f7daba842c0fdafc5f532c6bdd2 Mon Sep 17 00:00:00 2001 From: John Sebastian Peterson Date: Wed, 26 Mar 2025 04:22:38 +1100 Subject: [PATCH] shared lib and config file this will give packet manager the files they need export PREFIX=/usr export LIBDIR=lib/$HOST export CFLAGS=-DNDEBUG static libs can't be used in the context of a packet system that has to consider storage and download size and battery driven computers several thousand metres from the antenna . I am writing this from a hill overlooking south east Tasmania. It is impossible to store or download anything twice . if you add this to your bashrc you can store the library in separate files in the same folder export LD_LIBRARY_PATH=. mashing everything into the same ELF is a disaster it has no internal structure it is impossible to undo the mess. there are other bundle formats that allow extract the contents into separate files. you have to use flat pack or something else to bundle program files into a single runnable file # android bionic bug this uncovered a bug in /system/bin/linker64 or bionic dlopen that I was not aware of . the only solution I found was to not use bionic I have no clue what they are up to half of the time only problem is all system drivers are bionic and can't be loaded from non bionic aapps. I currently only need the library for elinks export LD_DEBUG=libs <- not implemented in bionic qjs-shared examples/test_fib.js perror=No such file or directory ReferenceError: could not load module filename 'examples/fib.so' as shared library export LD_LIBRARY_PATH=$(pwd):$(pwd)/examples/fib.so WARNING: linker: Warning: "/data/data/com.termux/files/home/quickjs/examples/fib.so" is not a directory (ignoring) $PREFIX/glibc/bash export PATH=$PREFIX/glibc/bin:$PATH export CFLAGS=-D__ANDROID__ ... Hello World fib(10)= 55 # to-do qjsc -shared this creates a large file from libquickjs.a qjsc examples/hello.js ls -sh a.out 4.1M a.out I would like to build a small file directly from JS compiler. a program that prints hello should not be four million bytes in a single file. it is impossible to inspect a compiled blob of code ELF format has no concept of internal objects everything is mashed into the text object. it is better to store the library in the same folder as the program --- Makefile | 21 +++++++++++++++++++++ quickjs.pc.in | 10 ++++++++++ 2 files changed, 31 insertions(+) create mode 100644 quickjs.pc.in diff --git a/Makefile b/Makefile index 3655b29de..7e42fa2a8 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,7 @@ endif # installation directory PREFIX?=/usr/local +LIBDIR?=lib # use the gprof profiler #CONFIG_PROFILE=y @@ -194,6 +195,7 @@ endif endif PROGS=qjs$(EXE) qjsc$(EXE) run-test262 +PROGS+=libquickjs.so quickjs.pc qjs-shared$(EXE) qjsc-shared$(EXE) ifneq ($(CROSS_PREFIX),) QJSC_CC=gcc QJSC=./host-qjsc @@ -237,6 +239,7 @@ ifndef CONFIG_WIN32 LIBS+=-ldl -lpthread endif LIBS+=$(EXTRA_LIBS) +LIBS_SHARED=-L. -lquickjs $(LIBS) $(OBJDIR): mkdir -p $(OBJDIR) $(OBJDIR)/examples $(OBJDIR)/tests @@ -244,12 +247,18 @@ $(OBJDIR): qjs$(EXE): $(QJS_OBJS) $(CC) $(LDFLAGS) $(LDEXPORT) -o $@ $^ $(LIBS) +qjs-shared$(EXE): $(OBJDIR)/qjs.o $(OBJDIR)/repl.o + $(CC) $(LDFLAGS) $(LDEXPORT) -o $@ $^ $(LIBS_SHARED) + qjs-debug$(EXE): $(patsubst %.o, %.debug.o, $(QJS_OBJS)) $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) qjsc$(EXE): $(OBJDIR)/qjsc.o $(QJS_LIB_OBJS) $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) +qjsc-shared$(EXE): $(OBJDIR)/qjsc.o + $(CC) $(LDFLAGS) $(LDEXPORT) -o $@ $^ $(LIBS_SHARED) + fuzz_eval: $(OBJDIR)/fuzz_eval.o $(OBJDIR)/fuzz_common.o libquickjs.fuzz.a $(CC) $(CFLAGS_OPT) $^ -o fuzz_eval $(LIB_FUZZING_ENGINE) @@ -284,6 +293,15 @@ else LTOEXT= endif +quickjs.pc: quickjs.pc.in + cp $^ $@ + sed -i s,@prefix@,$(PREFIX),g $@ + sed -i s,@libdir@,$(PREFIX)/$(LIBDIR),g $@ + sed -i s,@version@,$(shell cat VERSION),g $@ + +libquickjs.so: $(patsubst %.o, %.pic.o, $(QJS_LIB_OBJS)) + $(CC) $(LDFLAGS) $(LDEXPORT) -shared -o $@ $^ + libquickjs$(LTOEXT).a: $(QJS_LIB_OBJS) $(AR) rcs $@ $^ @@ -361,8 +379,11 @@ install: all ifdef CONFIG_LTO install -m644 libquickjs.lto.a "$(DESTDIR)$(PREFIX)/lib/quickjs" endif + install -m777 libquickjs.so "$(DESTDIR)$(PREFIX)/$(LIBDIR)" mkdir -p "$(DESTDIR)$(PREFIX)/include/quickjs" install -m644 quickjs.h quickjs-libc.h "$(DESTDIR)$(PREFIX)/include/quickjs" + mkdir -p "$(DESTDIR)$(PREFIX)/$(LIBDIR)/pkgconfig" + install -m644 quickjs.pc "$(DESTDIR)$(PREFIX)/$(LIBDIR)/pkgconfig" ############################################################################### # examples diff --git a/quickjs.pc.in b/quickjs.pc.in new file mode 100644 index 000000000..0f8a2674b --- /dev/null +++ b/quickjs.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +libdir=@libdir@ +includedir=${prefix}/include + +Name: quickjs +Description: JavaScript interpreting +URL: https://github.com/bellard/quickjs +Version: @version@ +Libs: -L${libdir} -lquickjs +Cflags: -I${includedir}