Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compilation on Mac #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)))

Expand All @@ -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)
Expand Down
53 changes: 53 additions & 0 deletions Makefile.mac
Original file line number Diff line number Diff line change
@@ -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)

28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 20 additions & 0 deletions configure.ac.mac
Original file line number Diff line number Diff line change
@@ -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()








2 changes: 1 addition & 1 deletion prolog/clocations.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down