forked from Elektro-Volk/luamod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
126 lines (98 loc) · 3.09 KB
/
Makefile
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
HLSDK = include/hlsdk
HLSDK_XASH3D = include/hlsdk-xash3d
METAMOD = include/metamod
LUA = luajit/src
ifeq "$(TARGET)" "win32"
OS=windows
SHLIBEXT=dll
else
OS=linux
SHLIBEXT=so
endif
DLL_SRCDIR=src
DLLNAME=luamod_mm
LUAMOD_VERMAIN = 0.3.9
LUAMOD_BRANCH = dev
LUAMOD_GIT_COMMIT := $(firstword $(shell git rev-parse --short=6 HEAD) unknown)
CC?=gcc
CXX?=g++
# Lto enabled by default for luamod dll and luajit
LTO?=1
ARCH=$(shell uname -m)
COMPILER_VER_CC = $(shell $(CC) -dumpversion)
COMPILER_VER_CXX = $(shell $(CXX) -dumpversion)
ifeq (, $(findstring "g++", $(shell $(CXX) --version)))
# Disable lto if g++ 4.* and 5.*
GCC_DISABLE_LTO := $(shell expr `$(CXX) -dumpversion | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/'` \>= 505000)
ifeq "$(GCC_DISABLE_LTO)" "1"
LTO = 0
endif
endif
OPT_CFLAGS = -O2 -fno-stack-protector
BASE_CFLAGS = -D__USE_GNU -std=gnu++11 -DLUAMOD_VERSION=\"$(LUAMOD_VERSION)\" -DLUAMOD_BRANCH=\"$(LUAMOD_BRANCH)\" -fPIC -Wall
ifeq ($(LTO), 1)
CFLAGS += -flto
LDFLAGS += -flto
LUA_CFLAGS += -flto
LUA_LDFLAGS += -flto
endif
ifeq ($(ARCH), x86_64)
ARCH = i686
ARCH_CFLAGS += -m32 -march=i686 -msse -msse2 -mfpmath=sse
LUA_CFLAGS += -m32
LUA_LDFLAGS += -m32
else ifeq ($(ARCH), aarch64)
ARCH_CFLAGS += -march=native
XASH3D = 1
else ifeq ( , $(findstring arm,$(ARCH_UNAME)) )
ARCH_CFLAGS += -march=native
XASH3D = 1
endif
ifeq ($(DEBUG),1)
BUILD_TYPE = debug
BUILD_TYPE_CFLAGS = -g -DDEBUG
else
BUILD_TYPE = release
BUILD_TYPE_CFLAGS = -DNDEBUG
endif
ifeq ($(XASH3D), 1)
BUILD_TYPE_CFLAGS += -DXASH3D
HLSDK = $(HLSDK_XASH3D)
endif
ifeq ($(REHLDS_SUPPORT),1)
ifeq ($(XASH3D), 1)
$(error "XASH3D does support REHLDS api")
else
BUILD_TYPE_CFLAGS += -DREHLDS_SUPPORT
endif
endif
LUAMOD_VERSION := $(LUAMOD_VERMAIN)-$(BUILD_TYPE)-$(LUAMOD_GIT_COMMIT)
DLL_OBJDIR = $(BUILD_TYPE).$(OS).$(ARCH)
CFLAGS += $(BUILD_TYPE_CFLAGS) $(BASE_CFLAGS) $(OPT_CFLAGS) $(ARCH_CFLAGS)
INCLUDE=-I. -I$(DLL_SRCDIR) -I$(DLL_SRCDIR)/lua -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine \
-I$(HLSDK)/game_shared -I$(HLSDK)/pm_shared -I$(HLSDK)/public -I$(METAMOD) -I$(LUA)
LDFLAGS += -L $(LUA) -lluajit -shared
DO_CC=$(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $<
DO_CXX=$(CXX) $(CFLAGS) $(INCLUDE) -o $@ -c $<
$(DLL_OBJDIR)/%.o: $(DLL_SRCDIR)/%.cpp
$(DO_CXX)
SRC = $(wildcard src/*.cpp) $(wildcard src/lua/*.cpp)
OBJ := $(SRC:src/%.cpp=$(DLL_OBJDIR)/%.o)
$(DLLNAME)_$(ARCH).$(SHLIBEXT) : lua neat depend $(OBJ)
$(CXX) $(CFLAGS) $(OBJ) $(LDFLAGS) -o $(DLL_OBJDIR)/$@
neat:
@mkdir -p $(DLL_OBJDIR)
@mkdir -p $(DLL_OBJDIR)/lua/
$(DLL_OBJDIR): neat
clean: depend
-rm -f $(OBJ)
-rm -f $(DLL_OBJDIR)/$(DLLNAME)_$(ARCH).$(SHLIBEXT)
-rm -f $(DLL_OBJDIR)/Rules.depend
cd $(LUA) && $(MAKE) BUILDMODE=static clean
lua: $(LUA)/libluajit.a
$(LUA)/libluajit.a: $(LUA)/*.h $(LUA)/*.c
cd $(LUA) && $(MAKE) BUILDMODE=static CFLAGS="$(LUA_CFLAGS)" LDFLAGS="$(LUA_LDFLAGS)"
depend: $(DLL_OBJDIR)/Rules.depend
$(DLL_OBJDIR)/Rules.depend: $(SRCFILES) $(DLL_OBJDIR)
$(CXX) -MM $(INCLUDE) $(SRC) $(CFLAGS) | sed "s;\(^[^ ]*\):\(.*\);$(DLL_OBJDIR)/\1:\2;" > $@
include $(DLL_OBJDIR)/Rules.depend