-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
71 lines (50 loc) · 2.49 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
BUILDDIR := ./build
TARGET := realsimgear
SOURCES = realsimgear.c
LIBS = -llua5.1
INCLUDES = \
-ISDK/CHeaders/XPLM \
-ISDK/CHeaders/Widgets \
-I/usr/include/lua5.1
DEFINES = -DXPLM200=1 -DXPLM210=1 -DXPLM300=1 -DXPLM301=1 -DXPLM302=1 -DXPLM303=1 -DAPL=0 -DIBM=0 -DLIN=1
############################################################################
CSOURCES := $(filter %.c, $(SOURCES))
CDEPS64 := $(patsubst %.c, $(BUILDDIR)/obj64/%.cdep, $(CSOURCES))
COBJECTS64 := $(patsubst %.c, $(BUILDDIR)/obj64/%.o, $(CSOURCES))
ALL_DEPS64 := $(sort $(CDEPS64) $(CXXDEPS64))
ALL_OBJECTS64 := $(sort $(COBJECTS64) $(CXXOBJECTS64))
CFLAGS := $(DEFINES) $(INCLUDES) -Wall -Wextra -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_OBJECTS) $(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 -g -m64 -static-libgcc -shared -rdynamic -nodefaultlibs -undefined_warning -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 $@)
gcc -g $(CFLAGS) -m64 -c $< -o $@
gcc -g $(CFLAGS) -MM -MT $@ -o $(@:.o=.cdep) $<
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)