-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
161 lines (128 loc) · 4.31 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
PROJECTS:= \
libyaul \
libtga \
libbcl \
libmic3d \
libfiber \
libmenu
include env.mk
THIS_ROOT:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
export THIS_ROOT
# $1 -> Project directory
# $2 -> Project name
define macro-generate-build-rule
.PHONY: $1-$2
$1-$2:
$(ECHO)mkdir -p $(YAUL_BUILD_ROOT)/$(YAUL_BUILD)
$(ECHO)printf -- "$(V_BEGIN_CYAN)$1$(V_END) $(V_BEGIN_GREEN)$2$(V_END)\n"
$(ECHO)($(MAKE) -C $1 -f $2.mk $2) || exit $${?}
endef
# $1 -> Project directory
# $2 -> Project name
define macro-generate-install-rule
.PHONY: $1-install-$2
$1-install-$2:
$(ECHO)mkdir -p $(YAUL_PREFIX)/lib
$(ECHO)mkdir -p $(YAUL_PREFIX)/include
$(ECHO)printf -- "$(V_BEGIN_CYAN)$1$(V_END) $(V_BEGIN_GREEN)install-$2$(V_END)\n"
$(ECHO)($(MAKE) -C $1 -f $2.mk install-$2) || exit $${?}
endef
# $1 -> Project directory
define macro-generate-generate-cdb-rule
.PHONY: $1-generate-cdb
$1-generate-cdb:
$(ECHO)($(MAKE) -C $1 -f release.mk generate-cdb) || exit $${?}
endef
# $1 ->
# $2 ->
define macro-generate-clean-rule
.PHONY: $1-clean-$2
$1-clean-$2: $(YAUL_BUILD_ROOT)/$(YAUL_BUILD)
$(ECHO)printf -- "$(V_BEGIN_CYAN)$1$(V_END) $(V_BEGIN_GREEN)clean-$2$(V_END)\n"
$(ECHO)($(MAKE) -C $1 -f $2.mk clean) || exit $${?}
endef
# No arguments
define macro-install
$(ECHO)mkdir -p $(YAUL_PREFIX)/lib
$(ECHO)mkdir -p $(YAUL_PREFIX)/include
$(ECHO)for project in $(PROJECTS); do \
printf -- "$(V_BEGIN_CYAN)$${project}$(V_END) $(V_BEGIN_GREEN)$@$(V_END)\n"; \
($(MAKE) -C $${project} -f $<.mk $@) || exit $${?}; \
done
endef
# $1 ->
# $2 ->
define macro-check-tool-chain
$(ECHO)for tool in $2; do \
printf -- "$(YAUL_INSTALL_ROOT)/bin/$1-$${tool}$(EXE_EXT)\n"; \
if [ ! -e $(YAUL_INSTALL_ROOT)/bin/$1-$${tool} ]; then \
printf -- "$1 tool-chain has not been installed properly (see build-scripts/)\n" >&2; \
exit 1; \
fi; \
done
endef
.PHONY: all \
check-tool-chain \
clean \
clean-debug \
clean-release \
clean-tools \
debug \
distclean \
generate-cdb \
install \
install-debug \
install-release \
install-tools \
list-targets \
release \
tools
all: release debug tools
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-build-rule,$(project),release)))
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-build-rule,$(project),debug)))
check-tool-chain:
@printf -- "$(V_BEGIN_YELLOW)tool-chain check$(V_END)\n"
$(call macro-check-tool-chain,$(YAUL_ARCH_SH_PREFIX),as ar ld nm objcopy objdump gcc g++)
release debug: $(YAUL_BUILD_ROOT)/$(YAUL_BUILD)
$(ECHO)for project in $(PROJECTS); do \
printf -- "$(V_BEGIN_CYAN)$${project}$(V_END) $(V_BEGIN_GREEN)$@$(V_END)\n"; \
($(MAKE) -C $${project} -f [email protected] $@) || exit $${?}; \
done
$(YAUL_BUILD_ROOT)/$(YAUL_BUILD):
@$(MAKE) -s check-tool-chain
$(ECHO)mkdir -p $@
install: install-release install-tools
install-release: release
$(call macro-install)
install-debug: debug
$(call macro-install)
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-install-rule,$(project),release)))
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-install-rule,$(project),debug)))
clean: clean-release clean-debug clean-tools
distclean:
$(ECHO)$(RM) -r $(YAUL_BUILD_ROOT)/$(YAUL_BUILD)
clean-release:
$(ECHO)for project in $(PROJECTS); do \
printf -- "$(V_BEGIN_CYAN)$${project}$(V_END) $(V_BEGIN_GREEN)$@$(V_END)\n"; \
($(MAKE) -C $${project} -f release.mk clean) || exit $${?}; \
done
clean-debug:
$(ECHO)for project in $(PROJECTS); do \
printf -- "$(V_BEGIN_CYAN)$${project}$(V_END) $(V_BEGIN_GREEN)$@$(V_END)\n"; \
($(MAKE) -C $${project} -f debug.mk clean) || exit $${?}; \
done
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-clean-rule,$(project),release)))
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-clean-rule,$(project),debug)))
tools:
$(ECHO)($(MAKE) -C tools all) || exit $${?}
install-tools: tools
$(ECHO)($(MAKE) -C tools install) || exit $${?}
clean-tools:
$(ECHO)($(MAKE) -C tools clean) || exit $${?}
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-generate-cdb-rule,$(project))))
generate-cdb: $(patsubst %,%-generate-cdb,$(PROJECTS))
list-targets:
@$(MAKE) -pRrq -f $(firstword $(MAKEFILE_LIST)) : 2>/dev/null | \
awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | \
sort | \
grep -E -v -e '^[^[:alnum:]]' -e '^$@$$'