forked from aeroc7/XLua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·93 lines (66 loc) · 2.82 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
BUILDDIR := ./build
SRC_BASE := .
TARGET := xlua
SOURCES = \
src/xlua.cpp \
src/lua_helpers.cpp \
src/module.cpp \
src/xpcommands.cpp \
src/xpdatarefs.cpp \
src/xpfuncs.cpp \
src/xptimers.cpp
LIBS = -lluajit
INCLUDES = \
-I$(SRC_BASE)/lua_sdk \
-I$(SRC_BASE)/SDK/CHeaders/XPLM \
-I$(SRC_BASE)/SDK/CHeaders/Widgets
DEFINES = -DAPL=0 -DIBM=0 -DLIN=1
############################################################################
VPATH = $(SRC_BASE)
CSOURCES := $(filter %.c, $(SOURCES))
CXXSOURCES := $(filter %.cpp, $(SOURCES))
CDEPS64 := $(patsubst %.c, $(BUILDDIR)/obj64/%.cdep, $(CSOURCES))
CXXDEPS64 := $(patsubst %.cpp, $(BUILDDIR)/obj64/%.cppdep, $(CXXSOURCES))
COBJECTS64 := $(patsubst %.c, $(BUILDDIR)/obj64/%.o, $(CSOURCES))
CXXOBJECTS64 := $(patsubst %.cpp, $(BUILDDIR)/obj64/%.o, $(CXXSOURCES))
ALL_DEPS64 := $(sort $(CDEPS64) $(CXXDEPS64))
ALL_OBJECTS64 := $(sort $(COBJECTS64) $(CXXOBJECTS64))
CFLAGS := $(DEFINES) $(INCLUDES) -fPIC -fvisibility=hidden
# Phony directive tells make that these are "virtual" targets, even if a file named "clean" exists.
.PHONY: all clean $(TARGET)
# Secondary tells make that the .o files are to be kept - they are secondary derivatives, not just
# temporary build products.
.SECONDARY: $(ALL_OBJECTS64) $(ALL_DEPS)
# Target rules - these just induce the right .xpl files.
$(TARGET): $(BUILDDIR)/$(TARGET)/64/lin.xpl
$(BUILDDIR)/$(TARGET)/64/lin.xpl: $(ALL_OBJECTS64)
@echo Linking $@
mkdir -p $(dir $@)
gcc -Llua_sdk -m64 -static-libgcc -shared -Wl,--version-script=exports.txt -o $@ $(ALL_OBJECTS64) $(LIBS)
# Compiler rules
# What does this do? It creates a dependency file where the affected
# files are BOTH the .o itself and the cdep we will output. The result
# goes in the cdep. Thus:
# - if the .c itself is touched, we remake the .o and the cdep, as expected.
# - If any header file listed in the cdep turd is changed, rebuild the .o.
$(BUILDDIR)/obj64/%.o : %.c
mkdir -p $(dir $@)
g++ $(CFLAGS) -m64 -c $< -o $@
g++ $(CFLAGS) -MM -MT $@ -o $(@:.o=.cdep) $<
$(BUILDDIR)/obj64/%.o : %.cpp
mkdir -p $(dir $@)
g++ $(CFLAGS) -m64 -c $< -o $@
g++ $(CFLAGS) -MM -MT $@ -o $(@:.o=.cppdep) $<
clean:
@echo Cleaning out everything.
rm -rf $(BUILDDIR)
# Include any dependency turds, but don't error out if they don't exist.
# On the first build, every .c is dirty anyway. On future builds, if the
# .c changes, it is rebuilt (as is its dep) so who cares if dependencies
# are stale. If the .c is the same but a header has changed, this
# declares the header to be changed. If a primary header includes a
# utility header and the primary header is changed, the dependency
# needs a rebuild because EVERY header is included. And if the secondary
# header is changed, the primary header had it before (and is unchanged)
# so that is in the dependency file too.
-include $(ALL_DEPS64)