-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
include Makefile.$(ARCHDIR) | ||
|
||
ifeq ($(ARCHDIR), LinuxARM) | ||
# for LinuxARM, get MACHINE from the following command | ||
# ref: https://github.com/euslisp/EusLisp/blob/89481741541488226fd78a92b2a8d1244169dd7f/lisp/Makefile.LinuxARM#L39 | ||
MACHINE=$(shell uname -m | sed 's/\(armv[0-9]\).*/\1/') | ||
else ifeq ($(ARCHDIR), Darwin) | ||
# for Darwin, depends on OS_VERSION | ||
# ref: https://github.com/euslisp/EusLisp/blob/89481741541488226fd78a92b2a8d1244169dd7f/lisp/Makefile.Darwin#L45-L50 | ||
OS_VERSION=$(shell sw_vers -productVersion | sed s/\.[^.]*$$//) | ||
ifeq ($(OS_VERSION), 10.5) | ||
MACHINE=i386 | ||
else | ||
MACHINE=x86_64 | ||
endif | ||
else | ||
MACHINE=$(shell grep "MACHINE=" $(EUSDIR)/lisp/Makefile | cut -f2 -d=) | ||
endif | ||
|
||
CFLAGS=-I$(EUSDIR)/include -D$(ARCHDIR) -D$(MACHINE) | ||
LDFLAGS= | ||
|
||
SRC=testdefforeign.c | ||
OBJ=$(basename $(SRC)).o | ||
LIB=$(LPFX)$(basename $(SRC)).$(LSFX) | ||
|
||
$(LIB): $(OBJ) | ||
$(LD) $(SOFLAGS) $(OUTOPT)$(LIB) $(OBJ) $(LDFLAGS) | ||
|
||
$(OBJ): $(SRC) | ||
$(CC) $(CFLAGS) -DCOMPILE_LIB -c $(SRC) $(OBJOPT)$(OBJ) | ||
|
||
clean: | ||
rm -f $(LIB) $(OBJ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CC = c++ -O2 -falign-functions=4 | ||
OBJOPT = -o | ||
OUTOPT = -o | ||
LD = c++ -shared -falign-functions=4 | ||
EXELD = c++ -falign-functions=4 | ||
SOFLAGS = | ||
EXESFX = .exe | ||
LSFX = dll | ||
LPFX = lib | ||
LIBS = -L$(ARCHDIR) -lRAPID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CC = c++ -O2 -falign-functions=8 -fPIC -DDarwin -DGCC -I$(EUSDIR)/include | ||
OBJOPT = -o | ||
OUTOPT = -o | ||
LD = c++ | ||
SOFLAGS = -dynamiclib -flat_namespace -undefined suppress | ||
EXELD = c++ | ||
EXESFX = | ||
LSFX = so | ||
LPFX = lib | ||
LIBS = -L$(ARCHDIR) -lRAPID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
CC = c++ -O2 -DLinux -DGCC -I$(EUSDIR)/include | ||
OBJOPT = -o | ||
OUTOPT = -o | ||
LD = c++ | ||
SOFLAGS = -shared | ||
EXELD = c++ | ||
EXESFX = | ||
LSFX = so | ||
LPFX = lib | ||
LIBS = -L$(ARCHDIR) -lRAPID | ||
|
||
|
||
ifeq ($(shell /bin/uname -m), x86_64) | ||
CC += -m32 | ||
LD += -m32 | ||
EXELD += -m32 | ||
endif | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CC = c++ -O2 -falign-functions=8 -fPIC -DLinux -DGCC -I$(EUSDIR)/include | ||
OBJOPT = -o | ||
OUTOPT = -o | ||
LD = c++ | ||
SOFLAGS = -shared | ||
EXELD = c++ | ||
EXESFX = | ||
LSFX = so | ||
LPFX = lib | ||
LIBS = -L$(ARCHDIR) -lRAPID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CC = c++ -O2 -fPIC -falign-functions=4 -DLinux -DGCC -I$(EUSDIR)/include | ||
OBJOPT = -o | ||
OUTOPT = -o | ||
LD = c++ | ||
SOFLAGS = -shared | ||
EXELD = c++ | ||
EXESFX = | ||
LSFX = so | ||
LPFX = lib | ||
LIBS = -L$(ARCHDIR) -lRAPID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(require :unittest "lib/llib/unittest.l") | ||
|
||
(init-unit-test) | ||
|
||
(deftest test-defforeign | ||
(defvar *testforeign-lib* | ||
(load-foreign (format nil "~a/test/libtestdefforeign.so" (unix:getenv "EUSDIR")))) | ||
|
||
(defforeign test1 | ||
*testforeign-lib* | ||
"test1" | ||
(:integer :float) | ||
:float | ||
) | ||
|
||
(defforeign test2 | ||
*testforeign-lib* | ||
"test2" | ||
(:string) | ||
:float | ||
) | ||
|
||
(setq test1-result (test1 1 2.5)) | ||
(format t "test1: ~a~%" test1-result) | ||
(assert (= test1-result 3.5)) | ||
|
||
(setq test2-result (test2 (float-vector 1.0 2.5))) | ||
(format t "test2: ~a~%" test2-result) | ||
(assert (= test2-result 3.5)) | ||
) | ||
|
||
(eval-when | ||
(load eval) | ||
(run-all-tests) | ||
(exit)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// for eus.h | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <setjmp.h> | ||
#include <errno.h> | ||
#include <sstream> | ||
|
||
#define class eus_class | ||
#define throw eus_throw | ||
#define export eus_export | ||
#define vector eus_vector | ||
#define string eus_string | ||
#include <eus.h> // include eus.h just for eusfloat_t ... | ||
#undef class | ||
#undef throw | ||
#undef export | ||
#undef vector | ||
#undef string | ||
|
||
extern "C" { | ||
eusfloat_t test1(eusinteger_t v1, eusfloat_t v2) { | ||
printf("// v1: %d\n", (int)v1); | ||
printf("// v2: %f\n", v2); | ||
return v1 + v2; | ||
} | ||
|
||
eusfloat_t test2(eusfloat_t *v) { | ||
printf("// v[0]: %f\n", v[0]); | ||
printf("// v[1]: %f\n", v[1]); | ||
return v[0] + v[1]; | ||
} | ||
} |