diff --git a/Makefile b/Makefile index f3f2143..75cc85c 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,9 @@ -LD=$(SWIPL)-ld -LDSOFLAGS=-Wall -shared -O2 -gdwarf-2 -g3 -CC=gcc +LDSOFLAGS += -Wall -shared -O2 -gdwarf-2 -g3 -L/usr/local/opt/libffi/lib/ ${SWISOLIB} MAKE=make PACKSODIR=lib/$(SWIARCH) FFI4PL=lib/$(SWIARCH)/ffi4pl.$(SOEXT) LIBS=-lffi -CFLAGS=-shared -fPIC +CFLAGS += -shared -fPIC -I/usr/local/Cellar/libffi/3.2.1/lib/libffi-3.2.1/include TESTS=test_mode test_marshall test_enum test_struct test_union test_funcptr TESTSO=$(addprefix test/$(SWIARCH)/, $(addsuffix .$(SOEXT), $(TESTS))) @@ -21,7 +19,7 @@ endif $(FFI4PL): c/ffi4pl.c c/cmemory.c Makefile mkdir -p $(PACKSODIR) - $(LD) $(LDSOFLAGS) -o $@ c/ffi4pl.c $(LIBS) + $(CC) $(CFLAGS) $(LDSOFLAGS) -o $@ c/ffi4pl.c $(LIBS) test/$(SWIARCH)/%.$(SOEXT): test/%.c mkdir -p test/$(SWIARCH) diff --git a/Makefile.mac b/Makefile.mac new file mode 100644 index 0000000..75cc85c --- /dev/null +++ b/Makefile.mac @@ -0,0 +1,53 @@ +LDSOFLAGS += -Wall -shared -O2 -gdwarf-2 -g3 -L/usr/local/opt/libffi/lib/ ${SWISOLIB} +MAKE=make +PACKSODIR=lib/$(SWIARCH) +FFI4PL=lib/$(SWIARCH)/ffi4pl.$(SOEXT) +LIBS=-lffi +CFLAGS += -shared -fPIC -I/usr/local/Cellar/libffi/3.2.1/lib/libffi-3.2.1/include +TESTS=test_mode test_marshall test_enum test_struct test_union test_funcptr +TESTSO=$(addprefix test/$(SWIARCH)/, $(addsuffix .$(SOEXT), $(TESTS))) + +all: env $(FFI4PL) + +ifeq ($(SOEXT),) +env:: + @echo "Please use . buildenv.sh to setup the environment" + @exit 1 +else +env:: +endif + +$(FFI4PL): c/ffi4pl.c c/cmemory.c Makefile + mkdir -p $(PACKSODIR) + $(CC) $(CFLAGS) $(LDSOFLAGS) -o $@ c/ffi4pl.c $(LIBS) + +test/$(SWIARCH)/%.$(SOEXT): test/%.c + mkdir -p test/$(SWIARCH) + $(CC) $(CFLAGS) -o $@ $< + +$(TESTSO): env + + +tags: + etags c/*.[ch] + +check: $(TESTSO) + $(SWIPL) -q -g test_cmem -t halt test/test_cmem.pl + $(SWIPL) -q -g test_mode -t halt test/test_mode.pl + $(SWIPL) -q -g test_marshall -t halt test/test_marshall.pl + $(SWIPL) -q -g test_enum -t halt test/test_enum.pl + $(SWIPL) -q -g test_struct -t halt test/test_struct.pl + $(SWIPL) -q -g test_union -t halt test/test_union.pl + $(SWIPL) -q -g test_funcptr -t halt test/test_funcptr.pl + $(SWIPL) -q -g test_qsort -t halt test/test_qsort.pl + $(SWIPL) -q -g test_libc -t halt test/test_libc.pl + +install:: + +clean: + rm -f *~ + rm -f test/*.$(SOEXT) + +distclean: clean + rm -f $(FFI4PL) + diff --git a/README.md b/README.md index e5b9358..f9239f5 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,34 @@ A = 66197957. https://github.com/JanWielemaker/ffi/wiki/files/ffi4swipl-windows.zip - Requires SWI-Prolog 7.7.10 or later. +### Mac installation + + - MacOS (at least Mojave 10.14.3) includes an outdated version of libffi + - A more recent version must be installed with Homebrew or MacPort. + - With Homebrew the command is + ```{prolog} + brew install libffi + ``` + - Go to the `ffi` pack directory + - Execute the shell command + ```{bash} + export C_INCLUDE_PATH=/usr/local/Cellar/libffi/3.2.1/lib/libffi-3.2.1/include + ``` + - Use `configure.ac.mac` and `Makefile.mac` : + - move them to `configure.ac` and `Makefile` + ```{bash} + mv configure.ac.mac configure.ac + mv Makefile.mac Makefile + ``` + - Run + ```{bash} + source buildenv.sh + autoconf + source configure + make + ``` + + ## Documentation There is not yet public documentation. With all proper tools installed diff --git a/configure.ac b/configure.ac index 505c974..d4936d7 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ AC_CONFIG_HEADER(config.h) AC_PROG_CC -AC_CHECK_HEADERS(ffi.h ffi/ffi.h) +AC_CHECK_HEADERS(ffi.h) AC_CHECK_HEADERS(dlfcn.h) AC_OUTPUT() diff --git a/configure.ac.mac b/configure.ac.mac new file mode 100644 index 0000000..d4936d7 --- /dev/null +++ b/configure.ac.mac @@ -0,0 +1,20 @@ +dnl Process this file with autoconf to produce a configure script. + +AC_INIT(pack.pl) +AC_PREREQ([2.50]) +AC_CONFIG_HEADER(config.h) + +AC_PROG_CC + +AC_CHECK_HEADERS(ffi.h) +AC_CHECK_HEADERS(dlfcn.h) + +AC_OUTPUT() + + + + + + + + diff --git a/prolog/clocations.pl b/prolog/clocations.pl index 381b959..1634f4d 100644 --- a/prolog/clocations.pl +++ b/prolog/clocations.pl @@ -109,7 +109,7 @@ % concrete file. The hook is tried as first option by c_lib_path/2. c_lib_path(Name, Path, Options) :- - ffi:library_path_hook(Name, Path, +Options), + ffi:library_path_hook(Name, Path, Options), !. c_lib_path(Name, Path, Options) :- atomic(Name),