2 # * LTO - Link time optimization [default=0]
3 # * ASAN - Address sanitizer [default=0]
4 # * UBSAN - Undefined behavior sanitizer [default=0]
5 # * DEBUG - Debug build [default=0]
6 # * UNUSED - Remove unused references [default=1]
7 # * SRCDIR - Out of tree builds [default=./]
15 # Determine if we're building for Windows or not so we can set the right file
16 # extensions for the binaries and exclude the testsuite because it doesn't build
18 ifeq ($(OS),Windows_NT)
24 TESTSUITE := testsuite
30 # Build artifact directories
34 # Collect all the source files for GMQCC.
50 # Collect all the source files for QCVM.
55 # Collect all the source files for TESTSUITE.
67 CXXFLAGS += -Wno-parentheses
68 CXXFLAGS += -Wno-class-memaccess
69 CXXFLAGS += -Wno-implicit-fallthrough
70 CXXFLAGS += -std=c++11
72 # Disable some unneeded features.
73 CXXFLAGS += -fno-exceptions
75 CXXFLAGS += -fno-asynchronous-unwind-tables
77 # Give each function and data it's own section so the linker can remove unused
78 # references to each, producing smaller, tighter binaries.
80 CXXFLAGS += -ffunction-sections
81 CXXFLAGS += -fdata-sections
84 # Enable link-time optimizations if requested.
90 # Ensure there is a frame-pointer in debug builds.
91 CXXFLAGS += -fno-omit-frame-pointer
93 # Disable all optimizations in debug builds.
96 # Enable debug symbols.
99 # Disable all the stack protection features in release builds.
100 CXXFLAGS += -fno-stack-protector
101 CXXFLAGS += -fno-stack-check
103 # Disable frame pointer in release builds when AddressSanitizer isn't present.
105 CXXFLAGS += -fno-omit-frame-pointer
107 CXXFLAGS += -fomit-frame-pointer
110 # Highest optimization flag in release builds.
114 # Sanitizer selection
116 CXXFLAGS += -fsanitize=address
119 CXXFLAGS += -fsanitize=undefined
133 # Remove unreferenced sections
135 LDFLAGS += -Wl,--gc-sections
138 # Enable link-time optimizations if request.
143 # Sanitizer selection
145 LDFLAGS += -fsanitize=address
148 LDFLAGS += -fsanitize=undefined
151 # Strip the binaries when not a debug build
152 ifneq (,$(findstring -g,$(CXXFLAGS)))
158 all: $(GMQCC) $(QCVM) $(TESTSUITE)
160 # Build artifact directories.
166 $(OBJDIR)/%.o: %.cpp $(DEPDIR)/%.d | $(OBJDIR) $(DEPDIR)
167 $(CXX) -MT $@ $(DEPFLAGS) -MF $(DEPDIR)/$*.Td $(CXXFLAGS) -c -o $@ $<
168 @mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d
170 $(GMQCC): $(filter %.o,$(GSRCS:%.cpp=$(OBJDIR)/%.o))
171 $(CXX) $^ $(LDFLAGS) -o $@
174 $(QCVM): $(filter %.o,$(QSRCS:%.cpp=$(OBJDIR)/%.o))
175 $(CXX) $^ $(LDFLAGS) -o $@
178 $(TESTSUITE): $(filter %.o,$(TSRCS:%.cpp=$(OBJDIR)/%.o))
179 $(CXX) $^ $(LDFLAGS) -o $@
182 # Determine if the tests should be run.
185 RUNTESTS := ./$(TESTSUITE)
188 test: $(QCVM) $(TESTSUITE)
192 rm -rf $(DEPDIR) $(OBJDIR)
194 .PHONY: test clean $(DEPDIR) $(OBJDIR)
197 $(filter %.d,$(GSRCS:%.cpp=$(DEPDIR)/%.d)):
198 include $(wildcard $@)
200 $(filter %.d,$(QSRCS:%.cpp=$(DEPDIR)/%.d)):
201 include $(wildcard $@)
203 $(filter %.d,$(TSRCS:%.cpp=$(DEPDIR)/%.d)):
204 include $(wildcard $@)