1 | # The common submakefile used for building all kinds of targets.
|
---|
2 |
|
---|
3 | ifdef .MODULE
|
---|
4 | # If this is the first target in this module, add it to global variables
|
---|
5 | ifeq ($(findstring $(.MODULE),$(MODULES)),)
|
---|
6 | .PHONY: $(.MODULE)
|
---|
7 | MODULES += $(.MODULE)
|
---|
8 | ifdef .MDESC
|
---|
9 | DO.HELP.MODULES += $(call ECHO, $(.MODULE) - $(.MDESC))$(NL)
|
---|
10 | .MDESC :=
|
---|
11 | endif # def .MDESC
|
---|
12 | ifdef .MDEP
|
---|
13 | $(.MODULE): $(.MDEP)
|
---|
14 | .MDEP :=
|
---|
15 | endif # def .MDEP
|
---|
16 | endif # eq ($(findstring $(.MODULE),$(MODULES)),)
|
---|
17 | endif # def .MODULE
|
---|
18 |
|
---|
19 | # Canonicalize target kind to the form objectformat-threadness{-profiling}
|
---|
20 | ifneq ($(findstring aout,$(.TKIND)),)
|
---|
21 | .tmp := aout
|
---|
22 | else
|
---|
23 | .tmp := omf
|
---|
24 | endif # neq ($(findstring aout,$(.TKIND)),)
|
---|
25 | ifneq ($(findstring prof,$(.TKIND)),)
|
---|
26 | .tmp += prof
|
---|
27 | endif # neq ($(findstring prof,$(.TKIND)),)
|
---|
28 | ifneq ($(findstring log,$(.TKIND)),)
|
---|
29 | .tmp += log
|
---|
30 | endif # neq ($(findstring log,$(.TKIND)),)
|
---|
31 | ifneq ($(findstring lazy,$(.TKIND)),)
|
---|
32 | .tmp += lazy
|
---|
33 | endif # neq ($(findstring log,$(.TKIND)),)
|
---|
34 | .TKIND := $(.tmp)
|
---|
35 | ifdef .TKVAR
|
---|
36 | .TKIND.DIR := $(subst $(SPACE),-,$(.TKIND))/$(.TKVAR)/
|
---|
37 | else
|
---|
38 | .TKIND.DIR := $(subst $(SPACE),-,$(.TKIND))/
|
---|
39 | endif
|
---|
40 | .DIRS :=
|
---|
41 |
|
---|
42 | ifdef .TARGET
|
---|
43 |
|
---|
44 | # .TARG is same as .TARGET except that it has a st/ or mt/ prefix
|
---|
45 | .TARG := $(.TKIND.DIR)$(.TARGET)
|
---|
46 | .DIRS += $.$(.TKIND.DIR)
|
---|
47 |
|
---|
48 | ifdef .INSDIR
|
---|
49 | ifndef .NOINST
|
---|
50 | INS.FILES += $(INS)$(.INSDIR)$(.TARGET)
|
---|
51 | $(INS)$(.INSDIR)$(.TARGET): $.$(.TARG)
|
---|
52 | $(call CP,$<,$@)
|
---|
53 | endif
|
---|
54 | endif # def .INSDIR
|
---|
55 |
|
---|
56 | # We know how to create dependency files for .c and .cpp files
|
---|
57 | .tmp := $(strip $(filter %.c,$(.TSRC)) $(filter %.cpp,$(.TSRC)))
|
---|
58 | ifdef .tmp
|
---|
59 | # Read the dependency file
|
---|
60 | -include $.$(.TKIND.DIR)dep-$(.TARGET).smak
|
---|
61 |
|
---|
62 | TARGDEPEND += $.$(.TKIND.DIR)dep-$(.TARGET).smak
|
---|
63 |
|
---|
64 | ifdef BUILD_DEPS
|
---|
65 | # How to build the dependency file
|
---|
66 | $.$(.TKIND.DIR)dep-$(.TARGET).smak: $(.tmp)
|
---|
67 | $(DO.DEPS)
|
---|
68 | endif # BUILD_DEPS
|
---|
69 | endif # def .tmp
|
---|
70 |
|
---|
71 | endif # def .TARGET
|
---|
72 |
|
---|
73 | # If module has any source files, find respective object file names
|
---|
74 | # and directories where they will be built
|
---|
75 | ifdef .TSRC
|
---|
76 |
|
---|
77 | .OBJS := $(addprefix $.,$(call OBJFILE,$(.TSRC)))
|
---|
78 | .DIRS += $(sort $(dir $(.OBJS)))
|
---|
79 |
|
---|
80 | # Remove the names of files for which we already generated build rules
|
---|
81 | # so that we won't generate same rule twice. In general this is not very
|
---|
82 | # correct since two targets may want a object file compiled with different
|
---|
83 | # options (e.g. .TCF) but we assume that the developer knows what's doing.
|
---|
84 | ifndef BUILD.RULES
|
---|
85 | # We need BUILD.RULES to be a expand-value-on-assignment type variable,
|
---|
86 | # rather than expand-value-on-reference.
|
---|
87 | BUILD.RULES :=
|
---|
88 | endif
|
---|
89 | .TSRC := $(filter-out $(BUILD.RULES),$(join $(addsuffix :,$(.OBJS)),$(.TSRC)))
|
---|
90 | BUILD.RULES += $(.TSRC)
|
---|
91 | .TSRC := $(filter-out $(.OBJS),$(subst :, ,$(.TSRC)))
|
---|
92 |
|
---|
93 | # Generate compilation rules for C files
|
---|
94 | $(foreach x,$(filter %.c,$(.TSRC)), $(eval $(call def_compile_c,$(x))))
|
---|
95 |
|
---|
96 | # Generate compilation rules for S files
|
---|
97 | $(foreach x,$(filter %.s %.S,$(.TSRC)), $(eval $(call def_compile_S,$(x))))
|
---|
98 |
|
---|
99 | # Generate compilation rules for asm files
|
---|
100 | $(foreach x,$(filter %.asm,$(.TSRC)), $(eval $(call def_compile_asm,$(x))))
|
---|
101 |
|
---|
102 | endif # def .TSRC
|
---|
103 |
|
---|
104 | # Add target directories to module dependencies and to overall list of dirs
|
---|
105 | ifneq ($(.DIRS),)
|
---|
106 | TARGDIRS += $(.DIRS)
|
---|
107 | ifdef .MODULE
|
---|
108 | $(.MODULE): $(.DIRS)
|
---|
109 | endif # def .MODULE
|
---|
110 | endif # neq ($(.DIRS),)
|
---|
111 |
|
---|
112 | # Add the target to the list of module dependencies
|
---|
113 | ifdef .TARGET
|
---|
114 | $(.MODULE): $.$(.TARG)
|
---|
115 | endif # def .TARGET
|
---|
116 |
|
---|
117 | # Replace the special sequence in .TDEP @O@ with $.$(.TKIND.DIR)
|
---|
118 | .DEPS := $(subst @O@,$.$(.TKIND.DIR),$(.TDEP))
|
---|