diff options
Diffstat (limited to 'Shared.mk')
-rw-r--r-- | Shared.mk | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/Shared.mk b/Shared.mk new file mode 100644 index 0000000..56c951c --- /dev/null +++ b/Shared.mk | |||
@@ -0,0 +1,114 @@ | |||
1 | CC= g++ -std=c++20 | ||
2 | |||
3 | # LuaRocks gives 'LIBFLAG' from the outside | ||
4 | # | ||
5 | LIBFLAG=-shared | ||
6 | |||
7 | OPT_FLAGS=-O2 | ||
8 | # -O0 -g | ||
9 | |||
10 | ifeq "$(findstring MINGW,$(shell uname -s))" "MINGW" | ||
11 | # MinGW MSYS on Windows | ||
12 | # | ||
13 | _SO=dll | ||
14 | _LUAEXT=.exe | ||
15 | TIME=timeit.exe | ||
16 | else | ||
17 | _SO=so | ||
18 | _LUAEXT= | ||
19 | endif | ||
20 | |||
21 | ifeq "$(LUAROCKS)" "" | ||
22 | ifeq "$(findstring MINGW,$(shell uname -s))" "MINGW" | ||
23 | # MinGW MSYS on Windows | ||
24 | # | ||
25 | # - 'lua' and 'luac' expected to be on the path | ||
26 | # - %LUA_DEV% must lead to include files and libraries (Lua for Windows >= 5.1.3.14) | ||
27 | # - %MSCVR80% must be the full pathname of 'msvcr80.dll' | ||
28 | # | ||
29 | ifeq "$(LUA_DEV)" "" | ||
30 | $(warning LUA_DEV not defined - try i.e. 'make LUA_DEV=/c/Program\ Files/Lua/5.1') | ||
31 | # this assumes Lua was built and installed from source and everything is located in default folders (/usr/local/include and /usr/local/bin) | ||
32 | LUA_FLAGS:=-I "/usr/local/include" | ||
33 | LUA_LIBS:=$(word 1,$(shell which lua54.$(_SO)) $(shell which lua53.$(_SO)) $(shell which lua52.$(_SO)) $(shell which lua51$(_SO))) | ||
34 | else | ||
35 | LUA_FLAGS:=-I "$(LUA_DEV)/include" | ||
36 | LUA_LIBS:="$(LUA_DEV)/lua5.1.dll" -lgcc | ||
37 | endif | ||
38 | LIBFLAG=-shared -Wl,-Map,lanes.map | ||
39 | else | ||
40 | # Autodetect LUA_FLAGS and/or LUA_LIBS | ||
41 | # | ||
42 | ifneq "$(shell which pkg-config)" "" | ||
43 | ifeq "$(shell pkg-config --exists luajit && echo 1)" "1" | ||
44 | LUA_FLAGS:=$(shell pkg-config --cflags luajit) | ||
45 | LUA_LIBS:=$(shell pkg-config --libs luajit) | ||
46 | # | ||
47 | # Debian: -I/usr/include/luajit-2.0 | ||
48 | # -lluajit-5.1 | ||
49 | else | ||
50 | ifeq "$(shell pkg-config --exists lua5.1 && echo 1)" "1" | ||
51 | LUA_FLAGS:=$(shell pkg-config --cflags lua5.1) | ||
52 | LUA_LIBS:=$(shell pkg-config --libs lua5.1) | ||
53 | # | ||
54 | # Ubuntu: -I/usr/include/lua5.1 | ||
55 | # -llua5.1 | ||
56 | else | ||
57 | ifeq "$(shell pkg-config --exists lua && echo 1)" "1" | ||
58 | LUA_FLAGS:=$(shell pkg-config --cflags lua) | ||
59 | LUA_LIBS:=$(shell pkg-config --libs lua) | ||
60 | # | ||
61 | # OS X fink with pkg-config: | ||
62 | # -I/sw/include | ||
63 | # -L/sw/lib -llua -lm | ||
64 | else | ||
65 | $(warning *** 'pkg-config' existed but did not know of 'lua[5.1]' - Good luck!) | ||
66 | LUA_FLAGS:= | ||
67 | LUA_LIBS:=-llua | ||
68 | endif | ||
69 | endif | ||
70 | endif | ||
71 | else | ||
72 | # No 'pkg-config'; try defaults | ||
73 | # | ||
74 | ifeq "$(shell uname -s)" "Darwin" | ||
75 | $(warning *** Assuming 'fink' at default path) | ||
76 | LUA_FLAGS:=-I/sw/include | ||
77 | LUA_LIBS:=-L/sw/lib -llua | ||
78 | else | ||
79 | $(warning *** Assuming an arbitrary Lua installation; try installing 'pkg-config') | ||
80 | LUA_FLAGS:= | ||
81 | LUA_LIBS:=-llua | ||
82 | endif | ||
83 | endif | ||
84 | endif | ||
85 | |||
86 | ifeq "$(shell uname -s)" "Darwin" | ||
87 | # Some machines need 'MACOSX_DEPLOYMENT_TARGET=10.3' for using '-undefined dynamic_lookup' | ||
88 | # (at least PowerPC running 10.4.11); does not harm the others | ||
89 | # | ||
90 | CC = MACOSX_DEPLOYMENT_TARGET=10.3 gcc | ||
91 | LIBFLAG = -bundle -undefined dynamic_lookup | ||
92 | endif | ||
93 | |||
94 | CFLAGS=-Wall -Werror $(OPT_FLAGS) $(LUA_FLAGS) | ||
95 | LIBS=$(LUA_LIBS) | ||
96 | endif | ||
97 | |||
98 | #--- | ||
99 | # PThread platform specifics | ||
100 | # | ||
101 | ifeq "$(shell uname -s)" "Linux" | ||
102 | # -D_GNU_SOURCE needed for 'pthread_mutexattr_settype' | ||
103 | CFLAGS += -D_GNU_SOURCE -fPIC | ||
104 | |||
105 | # Use of -DUSE_PTHREAD_TIMEDJOIN is possible, but not recommended (slower & keeps threads | ||
106 | # unreleased somewhat longer) | ||
107 | #CFLAGS += -DUSE_PTHREAD_TIMEDJOIN | ||
108 | |||
109 | LIBS += -lpthread | ||
110 | endif | ||
111 | |||
112 | ifeq "$(shell uname -s)" "BSD" | ||
113 | LIBS += -lpthread | ||
114 | endif | ||