forked from yaul-org/libyaul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
174 lines (139 loc) · 4.77 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
162
163
164
165
166
167
168
169
170
171
172
173
174
PROJECTS:= \
libyaul \
libbcl \
libtga
ifeq ($(strip $(INSTALL_ROOT)),)
$(error Undefined INSTALL_ROOT (install root directory))
endif
ifeq ($(strip $(BUILD_ROOT)),)
$(error Undefined BUILD_ROOT (build root directory))
endif
ifeq ($(strip $(BUILD)),)
$(error Undefined BUILD (build directory))
endif
THIS_ROOT:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
export THIS_ROOT
ifeq ($(strip $(SILENT)),1)
ECHO=@
else
ECHO=
endif
export ECHO
V_BEGIN_BLACK= [1;30m
V_BEGIN_RED= [1;31m
V_BEGIN_GREEN= [1;32m
V_BEGIN_YELLOW= [1;33m
V_BEGIN_BLUE= [1;34m
V_BEGIN_MAGENTA= [1;35m
V_BEGIN_CYAN= [1;36m
V_BEGIN_WHITE= [1;37m
V_END= [m
define macro-generate-build-rule
.PHONY: $1-$2
$1-$2:
mkdir -p $(BUILD_ROOT)/$(BUILD)
printf -- "$(V_BEGIN_CYAN)$1$(V_END) $(V_BEGIN_GREEN)$1$(V_END)\n"
($(MAKE) -C $1 $2) || exit $$?
endef
define macro-generate-install-rule
.PHONY: $1-$2
$1-$2:
$(ECHO)mkdir -p $(INSTALL_ROOT)/lib
$(ECHO)mkdir -p $(INSTALL_ROOT)/include
$(ECHO)printf -- "$(V_BEGIN_CYAN)$1$(V_END) $(V_BEGIN_GREEN)$1$(V_END)\n"
$(ECHO)($(MAKE) -C $1 $2) || exit $$?
endef
define macro-generate-clean-rule
.PHONY: $1-$2
$1-$2: $(BUILD_ROOT)/$(BUILD)
$(ECHO)printf -- "$(V_BEGIN_CYAN)$1$(V_END) $(V_BEGIN_GREEN)$1$(V_END)\n"
$(ECHO)($(MAKE) -C $1 $2) || exit $$?
endef
define macro-install
$(ECHO)mkdir -p $(INSTALL_ROOT)/lib
$(ECHO)mkdir -p $(INSTALL_ROOT)/include
$(ECHO)for project in $(PROJECTS); do \
printf -- "$(V_BEGIN_CYAN)$@$(V_END) $(V_BEGIN_GREEN)$$project$(V_END)\n"; \
($(MAKE) -C $$project $@) || exit $$?; \
done
endef
.PHONY: all \
release \
release-internal \
debug \
install \
install-release \
install-release-internal \
install-debug \
distclean \
clean \
clean-release \
clean-release-internal \
clean-debug \
examples \
clean-examples \
tools \
install-tools \
clean-tools \
list-targets \
check-tool-chain
all: release release-internal debug tools
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-build-rule,$(project),release)))
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-build-rule,$(project),release-internal)))
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-build-rule,$(project),debug)))
check-tool-chain:
@printf -- "$(V_BEGIN_YELLOW)tool-chain check$(V_END)\n"
$(ECHO)for tool_chain in "sh-elf" "m68k-elf"; do \
for tool in "as" "ar" "gcc" "g++" "ld" "nm" "objcopy" "objdump"; do \
printf -- "$(INSTALL_ROOT)/$${tool_chain}/bin/$${tool_chain}-$${tool}\n"; \
if [ ! -e $(INSTALL_ROOT)/$${tool_chain}/bin/$${tool_chain}-$${tool} ]; then \
printf -- "$${tool_chain} tool-chain has not been installed properly (see build-scripts/)\n" >&2; \
exit 1; \
fi; \
done; \
done
release release-internal debug: $(BUILD_ROOT)/$(BUILD)
$(ECHO)for project in $(PROJECTS); do \
printf -- "$(V_BEGIN_CYAN)$@$(V_END) $(V_BEGIN_GREEN)$$project$(V_END)\n"; \
($(MAKE) -C $$project $@) || exit $$?; \
done
$(BUILD_ROOT)/$(BUILD):
@$(MAKE) -s check-tool-chain
$(ECHO)mkdir -p $@
install: install-release install-tools
install-release: release
$(call macro-install)
install-release-internal: release-internal
$(call macro-install)
install-debug: debug
$(call macro-install)
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-install-rule,$(project),install-release)))
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-install-rule,$(project),install-release-internal)))
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-install-rule,$(project),install-debug)))
clean: clean-release clean-release-internal clean-debug clean-tools
distclean: clean-examples
$(ECHO)$(RM) -r $(BUILD_ROOT)/$(BUILD)
clean-release clean-release-internal clean-debug:
$(ECHO)for project in $(PROJECTS); do \
printf -- "$(V_BEGIN_CYAN)$@$(V_END) $(V_BEGIN_GREEN)$$project$(V_END)\n"; \
($(MAKE) -C $$project $@) || exit $$?; \
done
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-clean-rule,$(project),clean)))
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-clean-rule,$(project),clean-release)))
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-clean-rule,$(project),clean-release-internal)))
$(foreach project,$(PROJECTS),$(eval $(call macro-generate-clean-rule,$(project),clean-debug)))
examples:
$(ECHO)($(MAKE) -C examples all) || exit $$?
clean-examples:
$(ECHO)($(MAKE) -C examples clean) || exit $$?
tools:
$(ECHO)($(MAKE) -C tools all) || exit $$?
install-tools: tools
$(ECHO)($(MAKE) -C tools install) || exit $$?
clean-tools:
$(ECHO)($(MAKE) -C tools clean) || exit $$?
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 '^$@$$'