-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.modules
86 lines (59 loc) · 1.38 KB
/
Makefile.modules
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
target := $(obj)
.PHONY: __modules
__modules: $(target)
@:
srctree := .
objtree := .
rootdir := $(if $(dir),src/$(dir),src)
include $(srctree)/Makefile.lib
include $(srctree)/auto.conf
#
# Printing linker command information for modules
#
CFLAGS += -DMODULE
quiet_cmd_cc_mod_c = CC [M] $@
cmd_cc_mod_c = $(CC) $(DEPFLAGS) -c $< -o $@ $(CFLAGS) $(c_flags) $(INCLUDE)
#
# Compiling modules
#
define build_mod
modname := $$(basename $(1))
objname := $$(modname).ebm
depfile := $$(modname).o.d
srcfile := $$(modname).c
c_flags := $(2)
ifneq (, $$(srcfile))
$(1): $$(srcfile)
$$(call cmd,cc_mod_c)
-include $$(depfile)
endif
endef
compile_module = $(foreach file,$(1),$(eval $(call build_mod,$(file),$(2))))
#
# Compile template
#
define build_target
$(1)-ccfl :=
$(1)-mods :=
$$(eval $$(call collect_target,$$(rootdir),$(1)))
$$(eval $$(call compile_module,$$($(1)-mods),$$($(1)-ccfl)))
endef
$(eval $(call build_target,$(target)))
#
# Printing linking command information
#
quiet_cmd_oc_mod = LD [M] $@
cmd_oc_mod = $(OBJCOPY) $(OBJCOPY_SECTION) $< $@
quiet_cmd_cp_mod = INSTALL build/modules/$(notdir $@)
cmd_cp_mod = $(CP) $(2) build/modules
#
# Linking binary files
#
mod_copy = $(foreach module,$(1),$(call cmd,cp_mod,$(basename $(module:./%=%))))
#
# Target building
#
%.ebm: %.o
$(call cmd,oc_mod,$@)
$(call cmd,cp_mod,$@)
$(target): $($(target)-mods:.o=.ebm)