forked from Stratoscale/osmosis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.Makefile
120 lines (101 loc) · 3.82 KB
/
build.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
all: all-targets
CONFIGURATION ?= RELEASE
SHELL ?= /bin/bash
COMMON_CXXFLAGS = -Ic -Icpp -I/usr/include/python2.7 -Ibuild/cpp-netlib-0.13.0-final -std=gnu++0x -Werror -Wall -static
COMMON_CFLAGS = -Ic -Werror -Wall -static
DEBUG_CXXFLAGS = -ggdb -DDEBUG
DEBUG_CFLAGS = $(DEBUG_CXXFLAGS)
RELEASE_CXXFLAGS = -O3
RELEASE_CFLAGS = $(RELEASE_CXXFLAGS)
RELEASE_LDFLAGS = -O3
CXXFLAGS = $(COMMON_CXXFLAGS) $($(CONFIGURATION)_CXXFLAGS)
CFLAGS = $(COMMON_CFLAGS) $($(CONFIGURATION)_CFLAGS)
LDFLAGS = -L/usr/lib/x86_64-linux-gnu $($(CONFIGURATION)_LDFLAGS) -static
ifneq ($(PROFILE),)
CFLAGS += -pg
LDFLAGS += -pg
endif
STATIC_BOOST_LIBS_DIR = $(shell \
if [ -e /usr/lib/x86_64-linux-gnu/libboost_regex-mt.a ] || [ -e /usr/lib/x86_64-linux-gnu/libboost_regex.a ]; then \
echo /usr/lib/x86_64-linux-gnu; \
else \
if [ -e /usr/lib64/libboost_regex-mt.a ] || [ -e /usr/lib64/libboost_regex.a ]; then \
echo /usr/lib64; \
elif [ -e /usr/lib/libboost_regex.a ] ; then \
echo /usr/lib; \
else \
echo BOOST_STATIC_NOT_INSTALLED; \
fi; \
fi)
ifeq "$(STATIC_BOOST_LIBS_DIR)" "BOOST_STATIC_NOT_INSTALLED"
$(error BOOST static libraries were not found)
endif
BOOST_MT = $(shell if [ -e $(STATIC_BOOST_LIBS_DIR)/libboost_thread-mt.a ]; then echo '-mt'; fi)
include targets.Makefile
define template_per_OBJECT
-include $(1).deps
endef
#endef template_per_OBJECT
define template_per_TARGET
template_per_TARGET_target = $$(if $$(filter %.cpp,$$($(1))), \
$$(patsubst TARGET_%,build/cpp/%.bin,$(1)), \
$$(if $$(filter %.c,$$($(1))), \
$$(patsubst TARGET_%,build/c/%.bin,$(1)), \
$$(patsubst TARGET_%,build/%.bin,$(1))))
template_per_TARGET_objects = $$(patsubst build/%.cp,build/%.o, $$(patsubst build/%.cxx,build/%.o, $$(patsubst c/%.c,build/c/%.o, $$(patsubst cpp/%.cpp,build/cpp/%.o,$$($(1))))))
all-targets: $$(template_per_TARGET_target)
$$(template_per_TARGET_target): $$(template_per_TARGET_objects) $$($$(patsubst TARGET_%,%,$(1))_TP_OBJECTS)
$$(foreach object,$$(template_per_TARGET_objects), \
$$(eval $$(call template_per_OBJECT,$$(object))) \
)
endef
#endef template_per_TARGET
$(foreach target,$(filter TARGET_%, $(.VARIABLES)), \
$(eval $(call template_per_TARGET,$(target))) \
)
define template_per_SHAREDLIBRARY
template_per_SHAREDLIBRARY_target = $$(if $$(filter %.cpp,$$($(1))), \
$$(patsubst SHAREDLIBRARY_%,build/cpp/%.so,$(1)), \
$$(patsubst SHAREDLIBRARY_%,build/c/%.so,$(1)))
template_per_SHAREDLIBRARY_objects = $$(patsubst build/%.cp,build/%.o, $$(patsubst build/%.cxx,build/%.o, $$(patsubst c/%.c,build/c/%.o, $$(patsubst cpp/%.cpp,build/cpp/%.o,$$($(1))))))
all-targets: $$(template_per_SHAREDLIBRARY_target)
$$(template_per_SHAREDLIBRARY_target): $$(template_per_SHAREDLIBRARY_objects)
$$(foreach object,$$(template_per_SHAREDLIBRARY_objects), \
$$(eval $$(call template_per_OBJECT,$$(object))) \
)
endef
#endef template_per_SHAREDLIBRARY
$(foreach target,$(filter SHAREDLIBRARY_%, $(.VARIABLES)), \
$(eval $(call template_per_SHAREDLIBRARY,$(target))) \
)
ifeq ($(V),1)
Q =
SWALLOW_STDOUT =
else
Q = @
SWALLOW_STDOUT = > /dev/null
endif
build/cpp/%.o: cpp/%.cpp
@mkdir -p $(@D)
@echo 'C++ ' $@
$(Q)g++ $(CXXFLAGS) $($(subst /,_,$(subst .,_,$*))_o_CFLAGS) -MMD -MF [email protected] -c $< -o $@
build/c/%.o: c/%.c
@mkdir -p $(@D)
@echo 'C ' $@
$(Q)gcc $(CFLAGS) $($(subst /,_,$(subst .,_,$*))_o_CFLAGS) -MMD -MF [email protected] -c $< -o $@
build/cpp/%.bin:
@mkdir -p $(@D)
@echo 'LINK++ ' $@
$(Q)g++ $(LDFLAGS) -o $@ $^ $($*_LDFLAGS) $($*_LIBRARIES)
build/c/%.bin:
@mkdir -p $(@D)
@echo 'LINK ' $@
$(Q)gcc $(LDFLAGS) -o $@ $^ $($*_LDFLAGS) $($*_LIBRARIES)
build/cpp/%.so:
@mkdir -p $(@D)
@echo 'LINK++ ' $@
$(Q)g++ -shared $(LDFLAGS) -o $@ $^ $($*_LDFLAGS) $($*_LIBRARIES)
build/c/%.so:
@mkdir -p $(@D)
@echo 'LINK ' $@
$(Q)gcc -shared $(LDFLAGS) -o $@ $^ $($*_LDFLAGS) $($*_LIBRARIES)