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 mt,$(.TKIND)),)
|
---|
22 | .tmp += mt
|
---|
23 | else
|
---|
24 | .tmp += st
|
---|
25 | endif # neq ($(findstring mt,$(.TKIND)),)
|
---|
26 | ifneq ($(findstring prof,$(.TKIND)),)
|
---|
27 | .tmp += prof
|
---|
28 | endif # neq ($(findstring prof,$(.TKIND)),)
|
---|
29 | .TKIND := $(.tmp)
|
---|
30 | .TKIND.DIR := $(subst $(SPACE),-,$(.TKIND))/
|
---|
31 | .tmp :=
|
---|
32 |
|
---|
33 | # .TARG is same as .TARGET except that it has a st/ or mt/ prefix
|
---|
34 | .TARG := $(.TKIND.DIR)$(.TARGET)
|
---|
35 |
|
---|
36 | ifdef .INSDIR
|
---|
37 | DO.INSTALL += cp.exe $.$(.TARG) $(INS)$(.INSDIR)$(.TARGET)$(NL)
|
---|
38 | INSDIRS += $(INS)$(.INSDIR)
|
---|
39 | endif # def .INSDIR
|
---|
40 |
|
---|
41 | # If module has any source files, find respective object file names
|
---|
42 | # and directories where they will be built
|
---|
43 | ifdef .TSRC
|
---|
44 |
|
---|
45 | .OBJS := $(addprefix $.,$(call OBJFILE,$(.TSRC)))
|
---|
46 | .DIRS := $(sort $(dir $(.OBJS)))
|
---|
47 | TARGDIRS += $(.DIRS)
|
---|
48 |
|
---|
49 | $(.MODULE): $(.DIRS) $.$(.TARG)
|
---|
50 |
|
---|
51 | # Remove the names of files for which we already generated build rules
|
---|
52 | # so that we won't generate same rule twice. In general this is not very
|
---|
53 | # correct since two targets may want a object file compiled with different
|
---|
54 | # options (e.g. .TCF) but we assume that the developer knows what's doing.
|
---|
55 | ifndef BUILD.RULES
|
---|
56 | # We need BUILD.RULES to be a expand-value-on-assignment type variable,
|
---|
57 | # rather than expand-value-on-reference.
|
---|
58 | BUILD.RULES :=
|
---|
59 | endif
|
---|
60 | .TSRC := $(filter-out $(BUILD.RULES),$(join $(addsuffix :,$(.OBJS)),$(.TSRC)))
|
---|
61 | BUILD.RULES += $(.TSRC)
|
---|
62 | .TSRC := $(filter-out $(.OBJS),$(subst :, ,$(.TSRC)))
|
---|
63 |
|
---|
64 | #.TSRC := $(foreach x,$(.TSRC),$(if $(findstring $(call OBJFILE,$x):$x,$(BUILD.RULES)),,$x))
|
---|
65 | #BUILD.RULES += $(foreach x,$(.TSRC),$(if $(findstring $(call OBJFILE,$x):$x,$(BUILD.RULES)),,$(call OBJFILE,$x):$x))
|
---|
66 |
|
---|
67 | # Generate compilation rules for C files
|
---|
68 | RULES += $(foreach x,$(filter %.c,$(.TSRC)),\
|
---|
69 | $(call FECHO,_@,$$.$(call OBJFILE,$x): $x)$(NL)\
|
---|
70 | $(call FECHO,_@, $$(call DO.COMPILE.c,$(.TCF) $(.TCF.$x)))$(NL)\
|
---|
71 | )
|
---|
72 |
|
---|
73 | # Generate compilation rules for S files
|
---|
74 | RULES += $(foreach x,$(filter %.s,$(.TSRC)),\
|
---|
75 | $(call FECHO,_@,$$.$(call OBJFILE,$x): $x)$(NL)\
|
---|
76 | $(call FECHO,_@, $$(call DO.COMPILE.s,$(.TSF) $(.TSF.$x)))$(NL)\
|
---|
77 | )
|
---|
78 |
|
---|
79 | # Generate compilation rules for asm files
|
---|
80 | RULES += $(foreach x,$(filter %.asm,$(.TSRC)),\
|
---|
81 | $(call FECHO,_@,$$.$(call OBJFILE,$x): $x)$(NL)\
|
---|
82 | $(call FECHO,_@, $$(call DO.COMPILE.asm,$(.TAF) $(.TAF.$x)))$(NL)\
|
---|
83 | )
|
---|
84 |
|
---|
85 | endif # def .TSRC
|
---|
86 |
|
---|
87 | # Replace the special sequence in .TDEP @O@ with $.$(.TKIND.DIR)
|
---|
88 | .DEPS := $(subst @O@,$.$(.TKIND.DIR),$(.TDEP))
|
---|