Hi,

HashLink has instructions for embedding [1], however the referenced
src/main.c relies on other parts like hlmodule.h/module.c that are not
part of the normal install of libhl.so.X.Y. This diff builds a second
shared object libhl_module.so.0.0 which is basically bin/hl without
main(). It also installs hlmodule.h and its required header opcodes.h.

This way I can embed hashlink and for example make use of unveil(2).
I have a project (in alpha stage) that makes use of this [2].

While here, I think it makes sense to group the hashlink headers in
/usr/local/include/hl/ directory to not keep polluting include/ with
poorly named header files and even hlc_main.c which is installed with
those by default.

Interested in if there is some potential problem with this port
adjustment that I'm overlooking...

[1] https://github.com/HaxeFoundation/hashlink/wiki/Embedding-HashLink
[2] https://github.com/rfht/rigg

Index: Makefile
===================================================================
RCS file: /cvs/ports/lang/hashlink/Makefile,v
retrieving revision 1.14
diff -u -p -r1.14 Makefile
--- Makefile    3 Sep 2023 05:25:20 -0000       1.14
+++ Makefile    17 Sep 2023 22:42:43 -0000
@@ -10,9 +10,10 @@ DISTNAME =   hashlink-${V}
 GH_ACCOUNT =   HaxeFoundation
 GH_PROJECT =   hashlink
 GH_TAGNAME =   ${V}
-REVISION =     1
+REVISION =     2
 
-SHARED_LIBS =  hl      1.0     # 1.12
+SHARED_LIBS += hl              1.0     # 1.12
+SHARED_LIBS += hl_module       0.0     # 1.13
 
 CATEGORIES =   lang
 HOMEPAGE =     https://hashlink.haxe.org/
Index: patches/patch-Makefile
===================================================================
RCS file: /cvs/ports/lang/hashlink/patches/patch-Makefile,v
retrieving revision 1.7
diff -u -p -r1.7 patch-Makefile
--- patches/patch-Makefile      4 Jan 2023 20:40:47 -0000       1.7
+++ patches/patch-Makefile      17 Sep 2023 22:42:43 -0000
@@ -3,36 +3,49 @@ add versioning to libhl
 {CFLAGS} -> (CFLAGS) to not get picked up by SUBST_CMD
 remove Linux's 32-/64-bit detection
 remove Darwin detection in install target (breaks 'make fake')
+build libhl_module.so and install hl/hl_module.h and hl/opcodes.h
+install headers (and hlc_main.c) in include/hl/
 
 Index: Makefile
 --- Makefile.orig
 +++ Makefile
-@@ -1,6 +1,4 @@
+@@ -1,20 +1,19 @@
  
 -LBITS := $(shell getconf LONG_BIT)
 -MARCH ?= $(LBITS)
  PREFIX ?= /usr/local
  INSTALL_DIR ?= $(PREFIX)
  INSTALL_BIN_DIR ?= $(PREFIX)/bin
-@@ -9,12 +7,12 @@ INSTALL_INCLUDE_DIR ?= $(PREFIX)/include
+ INSTALL_LIB_DIR ?= $(PREFIX)/lib
+-INSTALL_INCLUDE_DIR ?= $(PREFIX)/include
++INSTALL_INCLUDE_DIR ?= $(PREFIX)/include/hl
  
  LIBS=fmt sdl ssl openal ui uv mysql sqlite
  
 -CFLAGS = -Wall -O3 -I src -msse2 -mfpmath=sse -std=c11 -D LIBHL_EXPORTS
 -LFLAGS = -L. -lhl
-+CFLAGS = ${CFLAGS} -I src -I${LOCALBASE}/include -I${X11BASE}/include 
-std=c11 -I include -I include/pcre -I include/mikktspace -I include/minimp3 -D 
LIBHL_EXPORTS
-+LFLAGS = -L. -L${LOCALBASE} -lhl
++CFLAGS = -O2 -pipe   -I src -I/usr/local/include -I/usr/X11R6/include 
-std=c11 -I include -I include/pcre -I include/mikktspace -I include/minimp3 -D 
LIBHL_EXPORTS
++LFLAGS = -L. -L/usr/local -lhl
  EXTRA_LFLAGS ?=
 -LIBFLAGS =
 -HLFLAGS = -ldl
 -LIBEXT = so
-+LIBFLAGS = -L${LOCALBASE}/lib -L${X11BASE}/lib
++LIBFLAGS = -L/usr/local/lib -L/usr/X11R6/lib
 +HLFLAGS =
 +LIBEXT = so.${LIBhl_VERSION}
++LIBEXT_MODULE = so.${LIBhl_module_VERSION}
  LIBTURBOJPEG = -lturbojpeg
  
  PCRE_FLAGS = -I include/pcre
-@@ -105,16 +103,9 @@ LIB += ${HL_DEBUG}
+@@ -32,6 +31,7 @@ STD = src/std/array.o src/std/buffer.o src/std/bytes.o
+       src/std/track.o
+ 
+ HL = src/code.o src/jit.o src/main.o src/module.o src/debugger.o src/profile.o
++HL_MODULE = src/code.o src/jit.o src/module.o src/debugger.o src/profile.o
+ 
+ FMT_INCLUDE = -I include/mikktspace -I include/minimp3
+ 
+@@ -105,16 +105,9 @@ LIB += ${HL_DEBUG}
  else
  
  # Linux
@@ -50,15 +63,28 @@ Index: Makefile
  LIBOPENAL = -lopenal
  LIBOPENGL = -lGL
  RELEASE_NAME = linux
-@@ -133,7 +124,6 @@ endif
- all: libhl hl libs
+@@ -130,17 +123,18 @@ ifdef DEBUG
+ CFLAGS += -g
+ endif
+ 
+-all: libhl hl libs
++all: libhl libhl_module hl libs
  
  install:
 -      $(UNAME)==Darwin && ${MAKE} uninstall
        mkdir -p $(INSTALL_BIN_DIR)
        cp hl $(INSTALL_BIN_DIR)
        mkdir -p $(INSTALL_LIB_DIR)
-@@ -149,46 +139,46 @@ uninstall:
+       cp *.hdll $(INSTALL_LIB_DIR)
+       cp libhl.${LIBEXT} $(INSTALL_LIB_DIR)
++      cp libhl_module.${LIBEXT_MODULE} $(INSTALL_LIB_DIR)
+       mkdir -p $(INSTALL_INCLUDE_DIR)
+       cp src/hl.h src/hlc.h src/hlc_main.c $(INSTALL_INCLUDE_DIR)
++      cp src/hlmodule.h src/opcodes.h $(INSTALL_INCLUDE_DIR)
+ 
+ uninstall:
+       rm -f $(INSTALL_BIN_DIR)/hl $(INSTALL_LIB_DIR)/libhl.${LIBEXT} 
$(INSTALL_LIB_DIR)/*.hdll
+@@ -149,46 +143,49 @@ uninstall:
  libs: $(LIBS)
  
  ./include/pcre/%.o: include/pcre/%.c
@@ -81,6 +107,9 @@ Index: Makefile
 -      ${CC} ${CFLAGS} -o hl ${HL} ${LFLAGS} ${EXTRA_LFLAGS} ${HLFLAGS}
 +      ${CC} $(CFLAGS) -o hl ${HL} ${LFLAGS} ${EXTRA_LFLAGS} ${HLFLAGS}
  
++libhl_module: ${HL_MODULE}
++      ${CC} -o libhl_module.${LIBEXT_MODULE} ${LIBFLAGS} -shared ${HL_MODULE} 
-lm
++
  libs/fmt/%.o: libs/fmt/%.c
 -      ${CC} ${CFLAGS} -o $@ -c $< ${FMT_INCLUDE}
 +      ${CC} $(CFLAGS) -o $@ -c $< ${FMT_INCLUDE}
@@ -119,7 +148,7 @@ Index: Makefile
  
  mesa:
        (cd libs/mesa && ${MAKE})
-@@ -249,7 +239,7 @@ codesign_osx:
+@@ -249,7 +246,7 @@ codesign_osx:
  .SUFFIXES : .c .o
  
  .c.o :
Index: pkg/PLIST
===================================================================
RCS file: /cvs/ports/lang/hashlink/pkg/PLIST,v
retrieving revision 1.3
diff -u -p -r1.3 PLIST
--- pkg/PLIST   18 Dec 2022 18:26:46 -0000      1.3
+++ pkg/PLIST   17 Sep 2023 22:42:43 -0000
@@ -1,9 +1,13 @@
 @bin bin/hl
-include/hl.h
-include/hlc.h
-include/hlc_main.c
+include/hl/
+include/hl/hl.h
+include/hl/hlc.h
+include/hl/hlc_main.c
+include/hl/hlmodule.h
+include/hl/opcodes.h
 @bin lib/fmt.hdll
 @lib lib/libhl.so.${LIBhl_VERSION}
+@lib lib/libhl_module.so.${LIBhl_module_VERSION}
 @bin lib/mysql.hdll
 @bin lib/openal.hdll
 @bin lib/sdl.hdll

Reply via email to