diff options
Diffstat (limited to 'Shared.makefile')
-rw-r--r-- | Shared.makefile | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/Shared.makefile b/Shared.makefile new file mode 100644 index 0000000..492c05d --- /dev/null +++ b/Shared.makefile | |||
@@ -0,0 +1,115 @@ | |||
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) 2>/dev/null) $(shell which lua53.$(_SO) 2>/dev/null) $(shell which lua52.$(_SO) 2>/dev/null) $(shell which lua51$(_SO) 2>/dev/null)) | ||
34 | $(info detected LUA_LIBS as $(LUA_LIBS)) | ||
35 | else | ||
36 | LUA_FLAGS := -I "$(LUA_DEV)/include" | ||
37 | LUA_LIBS := "$(LUA_DEV)/lua5.1.dll" -lgcc | ||
38 | endif | ||
39 | LIBFLAG := -shared -Wl,-Map,lanes.map | ||
40 | else | ||
41 | # Autodetect LUA_FLAGS and/or LUA_LIBS | ||
42 | # | ||
43 | ifneq "$(shell which pkg-config)" "" | ||
44 | ifeq "$(shell pkg-config --exists luajit && echo 1)" "1" | ||
45 | LUA_FLAGS := $(shell pkg-config --cflags luajit) | ||
46 | LUA_LIBS := $(shell pkg-config --libs luajit) | ||
47 | # | ||
48 | # Debian: -I/usr/include/luajit-2.0 | ||
49 | # -lluajit-5.1 | ||
50 | else | ||
51 | ifeq "$(shell pkg-config --exists lua5.1 && echo 1)" "1" | ||
52 | LUA_FLAGS := $(shell pkg-config --cflags lua5.1) | ||
53 | LUA_LIBS := $(shell pkg-config --libs lua5.1) | ||
54 | # | ||
55 | # Ubuntu: -I/usr/include/lua5.1 | ||
56 | # -llua5.1 | ||
57 | else | ||
58 | ifeq "$(shell pkg-config --exists lua && echo 1)" "1" | ||
59 | LUA_FLAGS := $(shell pkg-config --cflags lua) | ||
60 | LUA_LIBS := $(shell pkg-config --libs lua) | ||
61 | # | ||
62 | # OS X fink with pkg-config: | ||
63 | # -I/sw/include | ||
64 | # -L/sw/lib -llua -lm | ||
65 | else | ||
66 | $(warning *** 'pkg-config' existed but did not know of 'lua[5.1]' - Good luck!) | ||
67 | LUA_FLAGS := | ||
68 | LUA_LIBS := -llua | ||
69 | endif | ||
70 | endif | ||
71 | endif | ||
72 | else | ||
73 | # No 'pkg-config'; try defaults | ||
74 | # | ||
75 | ifeq "$(shell uname -s)" "Darwin" | ||
76 | $(warning *** Assuming 'fink' at default path) | ||
77 | LUA_FLAGS := -I/sw/include | ||
78 | LUA_LIBS := -L/sw/lib -llua | ||
79 | else | ||
80 | $(warning *** Assuming an arbitrary Lua installation; try installing 'pkg-config') | ||
81 | LUA_FLAGS := | ||
82 | LUA_LIBS := -llua | ||
83 | endif | ||
84 | endif | ||
85 | endif | ||
86 | |||
87 | ifeq "$(shell uname -s)" "Darwin" | ||
88 | # Some machines need 'MACOSX_DEPLOYMENT_TARGET=10.3' for using '-undefined dynamic_lookup' | ||
89 | # (at least PowerPC running 10.4.11); does not harm the others | ||
90 | # | ||
91 | CC := MACOSX_DEPLOYMENT_TARGET=10.3 gcc | ||
92 | LIBFLAG := -bundle -undefined dynamic_lookup | ||
93 | endif | ||
94 | |||
95 | CFLAGS := -Wall -Werror $(OPT_FLAGS) $(LUA_FLAGS) | ||
96 | LIBS := | ||
97 | endif | ||
98 | |||
99 | #--- | ||
100 | # PThread platform specifics | ||
101 | # | ||
102 | ifeq "$(shell uname -s)" "Linux" | ||
103 | # -D_GNU_SOURCE needed for 'pthread_mutexattr_settype' | ||
104 | CFLAGS += -D_GNU_SOURCE -fPIC | ||
105 | |||
106 | # Use of -DUSE_PTHREAD_TIMEDJOIN is possible, but not recommended (slower & keeps threads | ||
107 | # unreleased somewhat longer) | ||
108 | #CFLAGS += -DUSE_PTHREAD_TIMEDJOIN | ||
109 | |||
110 | LIBS += -lpthread | ||
111 | endif | ||
112 | |||
113 | ifeq "$(shell uname -s)" "BSD" | ||
114 | LIBS += -lpthread | ||
115 | endif | ||