-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
102 lines (75 loc) · 3.58 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
BUILDDIR := ./build
SRC_BASE := .
SOURCES := $(wildcard *.cpp)
TARGETS := $(patsubst %.cpp,$(BUILDDIR)/%/64/lin.xpl,$(SOURCES))
HINTFILE := $(HOME)/.x-plane/x-plane_install_11.txt
XP11INST := $(shell cat $(HINTFILE))
# You can symlink "SDK" to your SDK, otherwise this will be downloaded:
SDK_DOWNLOAD := XPSDK301.zip
SDK_DOWNLOAD_URL := http://developer.x-plane.com/wp-content/plugins/code-sample-generation/sample_templates/$(SDK_DOWNLOAD)
FILE_TO_PROMPT_SDK_DL := SDK/CHeaders/XPLM/XPLMPlugin.h
LIBS =
INCLUDES = \
-I$(SRC_BASE)/SDK/CHeaders/XPLM \
-I$(SRC_BASE)/SDK/CHeaders/Widgets
DEFINES = -DXPLM200=1 -DXPLM210=1 -DXPLM300=1 -DXPLM301=1 -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
# Secondary tells make that the .o files are to be kept - they are secondary derivatives, not just
# temporary build products.
.SECONDARY: $(ALL_OBJECTS) $(ALL_OBJECTS64) $(ALL_DEPS)
all: $(TARGETS)
install: $(TARGETS)
@if [ -f "$(XP11INST)/X-Plane-x86_64" ]; then \
for p in $(patsubst %.cpp,%,$(SOURCES)); do mkdir -p "$(XP11INST)/Resources/plugins/$$p/64"; cp -v $(BUILDDIR)/$$p/64/lin.xpl "$(XP11INST)/Resources/plugins/$$p/64/"; done; \
else echo "X-Plane 11 not detected, please write $(HINTFILE) or edit Makefile"; \
fi
# Target rules - these just induce the right .xpl files.
$(BUILDDIR)/%/64/lin.xpl: $(BUILDDIR)/obj64/%.o
@echo Linking $@
mkdir -p $(dir $@)
gcc -m64 -static-libgcc -shared -Wl,--version-script=exports.txt -o $@ $< $(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 $(FILE_TO_PROMPT_SDK_DL)
mkdir -p $(dir $@)
g++ $(CFLAGS) -m64 -c $< -o $@
g++ $(CFLAGS) -MM -MT $@ -o $(@:.o=.cdep) $<
$(BUILDDIR)/obj64/%.o : %.cpp $(FILE_TO_PROMPT_SDK_DL)
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)
# Auto-download SDK
$(SDK_DOWNLOAD):
wget $(SDK_DOWNLOAD_URL)
$(FILE_TO_PROMPT_SDK_DL): $(SDK_DOWNLOAD)
unzip $<
touch $@