-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
84 lines (60 loc) · 2.92 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
MAKEFLAGS += --no-builtin-rules --warn-undefined-variables
CCFLAGS = -fpic -IlibMmkFormat/include -Wall -Wextra -Wpedantic -Werror -Wno-variadic-macros
# TODO:
# Thoroughly audit https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html for more warnings to turn on.
# Per-project include paths...?
# Disabled warnings:
# -Wvariadic-macros: Variadic macros are fundamental to libMmkFormat, as long as I want to have something C compatible.
ifeq ($(shell getconf LONG_BIT),32)
LOCAL_ARCH :=x86
else
LOCAL_ARCH :=x64
endif
# $(1) Compiler family (gcc, clang)
CXX_TOOLSET_gcc = g++
CXX_TOOLSET_clang = clang++
LXX_TOOLSET_gcc = $(CXX_TOOLSET_gcc)
LXX_TOOLSET_clang = $(CXX_TOOLSET_clang)
CCFLAGS_TOOLSET_gcc = -Wno-long-long
CCFLAGS_TOOLSET_clang = -Wno-c++11-long-long
# $(2) Arch (x86, x64)
CCFLAGS_ARCH_x86 = -m32
CCFLAGS_ARCH_x64 = -m64
LDFLAGS_ARCH_x86 = -m32
LDFLAGS_ARCH_x64 = -m64
# $(3) Build (debug, release)
CCFLAGS_BUILD_debug = -O0 -D_DEBUG
CCFLAGS_BUILD_release = -O3 -DNDEBUG
# $(4) Language (c++03, c++11, gnu++11)
define DEFINE_SINGLE_CONFIG
# No actual lib currently
# bin/$(1)-$(2)-$(3)-$(4)/libMmkFormat.so : $$(patsubst %.cpp,obj/$(1)-$(2)-$(3)-$(4)/%.o,$$(shell find libMmkFormat/ -type f -name '*.cpp'))
# @mkdir -p $$(dir $$@)
# $$(LXX_TOOLSET_$(1)) $$(LDFLAGS_ARCH_$(2)) -shared -L$$(dir $$@) $$(patsubst $$(dir $$@)lib%.so,-l%,$$(filter %.so,$$^)) $$^ -o $$@
#bin/$(1)-$(2)-$(3)-$(4)/mmkFormatTest : bin/$(1)-$(2)-$(3)-$(4)/libMmkFormat.so $$(patsubst %.cpp,obj/$(1)-$(2)-$(3)-$(4)/%.o,$$(shell find mmkFormatTest/ -type f -name '*.cpp'))
bin/$(1)-$(2)-$(3)-$(4)/mmkFormatTest : $$(patsubst %.cpp,obj/$(1)-$(2)-$(3)-$(4)/%.o,$$(shell find mmkFormatTest/ -type f -name '*.cpp'))
@mkdir -p $$(dir $$@)
$$(LXX_TOOLSET_$(1)) $$(LDFLAGS_ARCH_$(2)) -L$$(dir $$@) $$^ $$(patsubst $$(dir $$@)lib%.so,-l%,$$(filter %.so,$$^)) -o $$@
obj/$(1)-$(2)-$(3)-$(4)/%.o : %.cpp
@mkdir -p $$(dir $$@)
$$(CXX_TOOLSET_$(1)) -c $$^ $(CCFLAGS) $$(CCFLAGS_TOOLSET_$(1)) $$(CCFLAGS_ARCH_$(2)) $$(CCFLAGS_BUILD_$(3)) -std=$(4) -MMD -MF $$(patsubst %.o,%.d,$$@) -o $$@
-include obj$(1)-$(2)-$(3)-$(4)/%.d
ifeq ($(LOCAL_ARCH),$(2))
build-libs:: bin/$(1)-$(2)-$(3)-$(4)/libMmkFormat.so
build-tests:: bin/$(1)-$(2)-$(3)-$(4)/mmkFormatTest
run-tests:: bin/$(1)-$(2)-$(3)-$(4)/mmkFormatTest; LD_LIBRARY_PATH=$$(dir $$^) ./$$^
endif
endef
TOOLSETS := gcc clang
ARCHS := x86 x64
BUILDS := debug release
LANGS := c++03 c++11 gnu++11
default : run-tests
$(foreach toolset,$(TOOLSETS),$(foreach arch,$(ARCHS),$(foreach build,$(BUILDS),$(foreach lang,$(LANGS), $(eval $(call DEFINE_SINGLE_CONFIG,$(toolset),$(arch),$(build),$(lang)))))))
clean :
rm -f bin/**/*.so
rm -f bin/**/mmdebugtest
rm -f obj/**/*.o
rm -f obj/**/*.d
.PHONY : build-libs build-tests build-all run-tests default
.SUFFIXES: