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