forked from VCVRack/Rack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.mk
90 lines (75 loc) · 2.23 KB
/
compile.mk
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
ifndef RACK_DIR
$(error RACK_DIR is not defined)
endif
include $(RACK_DIR)/arch.mk
OBJCOPY ?= objcopy
STRIP ?= strip
# Generate dependency files alongside the object files
FLAGS += -MMD -MP
# Debugger symbols. These are removed with `strip`.
FLAGS += -g
# Optimization
FLAGS += -O3 -march=nocona -funsafe-math-optimizations
# Warnings
FLAGS += -Wall -Wextra -Wno-unused-parameter
# C++ standard
CXXFLAGS += -std=c++11
# Architecture-independent flags
ifdef ARCH_LIN
FLAGS += -DARCH_LIN
CXXFLAGS += -Wsuggest-override
endif
ifdef ARCH_MAC
FLAGS += -DARCH_MAC
CXXFLAGS += -stdlib=libc++
LDFLAGS += -stdlib=libc++
MAC_SDK_FLAGS = -mmacosx-version-min=10.7
FLAGS += $(MAC_SDK_FLAGS)
LDFLAGS += $(MAC_SDK_FLAGS)
endif
ifdef ARCH_WIN
FLAGS += -DARCH_WIN
FLAGS += -D_USE_MATH_DEFINES
CXXFLAGS += -Wsuggest-override
endif
# Allow *appending* rather than prepending to common flags.
# This is useful to force-redefine compiler settings instead of merely setting defaults that may be overwritten.
FLAGS += $(EXTRA_FLAGS)
CFLAGS += $(EXTRA_CFLAGS)
CXXFLAGS += $(EXTRA_CXXFLAGS)
LDFLAGS += $(EXTRA_LDFLAGS)
# Apply FLAGS to language-specific flags
CFLAGS += $(FLAGS)
CXXFLAGS += $(FLAGS)
# Derive object files from sources and place them before user-defined objects
OBJECTS := $(patsubst %, build/%.o, $(SOURCES)) $(OBJECTS)
OBJECTS += $(patsubst %, build/%.bin.o, $(BINARIES))
DEPENDENCIES := $(patsubst %, build/%.d, $(SOURCES))
# Final targets
$(TARGET): $(OBJECTS)
$(CXX) -o $@ $^ $(LDFLAGS)
-include $(DEPENDENCIES)
build/%.c.o: %.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c -o $@ $<
build/%.cpp.o: %.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -c -o $@ $<
build/%.cc.o: %.cc
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -c -o $@ $<
build/%.m.o: %.m
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c -o $@ $<
build/%.bin.o: %
@mkdir -p $(@D)
ifdef ARCH_LIN
$(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
endif
ifdef ARCH_WIN
$(OBJCOPY) -I binary -O pe-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
endif
ifdef ARCH_MAC
@# Apple makes this needlessly complicated, so just generate a C file with an array.
xxd -i $< | $(CC) $(MAC_SDK_FLAGS) -c -o $@ -xc -
endif