summaryrefslogtreecommitdiff
path: root/plugins/MirLua/Modules/luaffi/src/Makefile
blob: 8477140a057ad60ed888f4f280b5da1db7a7885e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
.PHONY: all clean test

PKG_CONFIG=pkg-config
LUA=lua

LUA_CFLAGS=`$(PKG_CONFIG) --cflags lua5.2 2>/dev/null || $(PKG_CONFIG) --cflags lua`
SOCFLAGS=-fPIC
SOCC=$(CC) -shared $(SOCFLAGS)
CFLAGS=-fPIC -g -Wall -Werror $(LUA_CFLAGS) -fvisibility=hidden -Wno-unused-function --std=gnu99

MODNAME=ffi
MODSO=$(MODNAME).so

all:
	if [ `uname` = "Darwin" ]; then $(MAKE) macosx; else $(MAKE) posix; fi

test:
	if [ `uname` = "Darwin" ]; then $(MAKE) test_macosx; else $(MAKE) test_posix; fi

macosx:
	$(MAKE) posix "SOCC=MACOSX_DEPLOYMENT_TARGET=10.3 $(CC) -dynamiclib -single_module -undefined dynamic_lookup $(SOCFLAGS)"

test_macosx:
	$(MAKE) test_posix "SOCC=MACOSX_DEPLOYMENT_TARGET=10.3 $(CC) -dynamiclib -single_module -undefined dynamic_lookup $(SOCFLAGS)"

posix: $(MODSO) test_cdecl.so

clean:
	rm -f *.o *.so call_*.h

call_x86.h: call_x86.dasc dynasm/*.lua
	$(LUA) dynasm/dynasm.lua -LN -o $@ $<

call_x64.h: call_x86.dasc dynasm/*.lua
	$(LUA) dynasm/dynasm.lua -D X64 -LN -o $@ $<

call_x64win.h: call_x86.dasc dynasm/*.lua
	$(LUA) dynasm/dynasm.lua -D X64 -D X64WIN -LN -o $@ $<

%.o: %.c *.h dynasm/*.h call_x86.h call_x64.h call_x64win.h
	$(CC) $(CFLAGS) -o $@ -c $<

$(MODSO): ffi.o ctype.o parser.o call.o
	$(SOCC) $^ -o $@

test_cdecl.so: test.o
	$(SOCC) $^ -o $@

test_posix: test_cdecl.so $(MODSO)
	LD_LIBRARY_PATH=./ $(LUA) test.lua