aboutsummaryrefslogtreecommitdiff
path: root/src/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'src/Makefile')
-rw-r--r--src/Makefile176
1 files changed, 176 insertions, 0 deletions
diff --git a/src/Makefile b/src/Makefile
new file mode 100644
index 0000000..a17e9cd
--- /dev/null
+++ b/src/Makefile
@@ -0,0 +1,176 @@
1#
2# Lanes/src/Makefile
3#
4# make [LUA=... LUAC=...] Manual build
5# make LUAROCKS=1 CFLAGS=... LIBFLAG=... LUA=... LUAC=... LuaRocks automated build
6#
7
8MODULE=lanes
9
10SRC=lanes.c threading.c tools.c
11
12OBJ=$(SRC:.c=.o)
13
14# LuaRocks gives 'LIBFLAG' from the outside
15#
16LIBFLAG=-shared
17
18OPT_FLAGS=-O2
19 # -O0 -g
20
21LUA=lua
22LUAC=luac
23
24_SO=.so
25ifeq "$(findstring MINGW32,$(shell uname -s))" "MINGW32"
26 _SO=.dll
27endif
28
29ifeq "$(LUAROCKS)" ""
30 ifeq "$(findstring MINGW32,$(shell uname -s))" "MINGW32"
31 # MinGW MSYS on Windows
32 #
33 # - 'lua' and 'luac' expected to be on the path
34 # - %LUA_DEV% must lead to include files and libraries (Lua for Windows >= 5.1.3.14)
35 # - %MSCVR80% must be the full pathname of 'msvcr80.dll'
36 #
37 ifeq "$(LUA_DEV)" ""
38 $(error LUA_DEV not defined - try i.e. 'make LUA_DEV=/c/Program\ Files/Lua/5.1')
39 endif
40 ifeq "$(MSVCR80)" ""
41 MSVCR80:=$(LUA_DEV)/install/support/Microsoft.VC80.CRT.SP1/MSVCR80.DLL
42 ifneq '$(shell test -f "$(MSVCR80)" && echo found)' 'found'
43 $(error MSVCR80 not defined - set it to full path of msvcr80.dll')
44 endif
45 $(warning MSVCR80=$(MSVCR80))
46 endif
47 LUA_FLAGS:=-I "$(LUA_DEV)/include"
48 LUA_LIBS:="$(LUA_DEV)/lua5.1.dll" -lgcc -lmsvcr80 "$(MSVCR80)"
49 LIBFLAG=-shared -Wl,-Map,lanes.map
50 else
51 # Autodetect LUA_FLAGS and/or LUA_LIBS
52 #
53 ifneq "$(shell which pkg-config)" ""
54 ifeq "$(shell pkg-config --exists lua5.1 && echo 1)" "1"
55 LUA_FLAGS:=$(shell pkg-config --cflags lua5.1)
56 LUA_LIBS:=$(shell pkg-config --libs lua5.1)
57 #
58 # Ubuntu: -I/usr/include/lua5.1
59 # -llua5.1
60 else
61 ifeq "$(shell pkg-config --exists lua && echo 1)" "1"
62 LUA_FLAGS:=$(shell pkg-config --cflags lua)
63 LUA_LIBS:=$(shell pkg-config --libs lua)
64 #
65 # OS X fink with pkg-config:
66 # -I/sw/include
67 # -L/sw/lib -llua -lm
68 else
69 $(warning *** 'pkg-config' existed but did not know of 'lua[5.1]' - Good luck!)
70 LUA_FLAGS:=
71 LUA_LIBS:=-llua
72 endif
73 endif
74 else
75 # No 'pkg-config'; try defaults
76 #
77 ifeq "$(shell uname -s)" "Darwin"
78 $(warning *** Assuming 'fink' at default path)
79 LUA_FLAGS:=-I/sw/include
80 LUA_LIBS:=-L/sw/lib -llua
81 else
82 $(warning *** Assuming an arbitrary Lua installation; try installing 'pkg-config')
83 LUA_FLAGS:=
84 LUA_LIBS:=-llua
85 endif
86 endif
87 endif
88
89 ifeq "$(shell uname -s)" "Darwin"
90 # Some machines need 'MACOSX_DEPLOYMENT_TARGET=10.3' for using '-undefined dynamic_lookup'
91 # (at least PowerPC running 10.4.11); does not harm the others
92 #
93 CC = MACOSX_DEPLOYMENT_TARGET=10.3 gcc
94 LIBFLAG = -bundle -undefined dynamic_lookup
95 endif
96
97 CFLAGS=-Wall -Werror $(OPT_FLAGS) $(LUA_FLAGS)
98 LIBS=$(LUA_LIBS)
99endif
100
101#---
102# PThread platform specifics
103#
104ifeq "$(shell uname -s)" "Linux"
105 # -D_GNU_SOURCE needed for 'pthread_mutexattr_settype'
106 CFLAGS += -D_GNU_SOURCE -fPIC
107
108 # Use of -DUSE_PTHREAD_TIMEDJOIN is possible, but not recommended (slower & keeps threads
109 # unreleased somewhat longer)
110 #CFLAGS += -DUSE_PTHREAD_TIMEDJOIN
111
112 LIBS += -lpthread
113endif
114
115ifeq "$(shell uname -s)" "BSD"
116 LIBS += -lpthread
117endif
118
119#---
120all: lua51-$(MODULE)$(_SO)
121
122%.o: %.c *.h Makefile
123
124# Note: Don't put $(LUA_LIBS) ahead of $^; MSYS will not like that (I think)
125#
126lua51-$(MODULE)$(_SO): $(OBJ)
127 $(CC) $(LIBFLAG) $(LIBS) $^ $(LUA_LIBS) -o $@
128
129clean:
130 -rm -rf lua51-$(MODULE)$(_SO) *.lch *.o *.tmp *.map
131
132lanes.o: keeper.lch
133
134# Note: 'luac -o -' could be used on systems other than Windows (where pipes
135# are binary). We need to support MinGW as well, so a temporary file.
136#
137%.lch: %.lua
138 $(LUAC) -o $@.tmp $<
139 $(LUA) ../tools/bin2c.lua $@.tmp -o $@
140 -rm $@.tmp
141
142#---
143# NSLU2 "slug" Linux ARM
144#
145nslu2:
146 $(MAKE) all CFLAGS="$(CFLAGS) -I/opt/include -L/opt/lib -D_GNU_SOURCE -lpthread"
147
148#---
149# Cross compiling to Win32 (MinGW on OS X Intel)
150#
151# Point WIN32_LUA51 to an extraction of LuaBinaries dll8 and dev packages.
152#
153# Note: Only works on platforms with same endianess (i.e. not from PowerPC OS X,
154# since 'luac' uses the host endianess)
155#
156# EXPERIMENTAL; NOT TESTED OF LATE.
157#
158MINGW_GCC=mingw32-gcc
159 # i686-pc-mingw32-gcc
160
161win32: $(WIN32_LUA51)/include/lua.h
162 $(MAKE) build CC=$(MINGW_GCC) \
163 LUA_FLAGS=-I$(WIN32_LUA51)/include \
164 LUA_LIBS="-L$(WIN32_LUA51) -llua51" \
165 _SO=.dll \
166 SO_FLAGS=-shared \
167 LUA=lua51 \
168 LUAC=luac51
169
170$(WIN32_LUA51)/include/lua.h:
171 @echo "Usage: make win32 WIN32_LUA51=<path of extracted LuaBinaries dll8 and dev packages>"
172 @echo " [MINGW_GCC=...mingw32-gcc]"
173 @false
174
175.PROXY: all clean nslu2 win32
176