| [94] | 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 | 
|---|
| [148] | 12 | ifdef .MDEP | 
|---|
|  | 13 | $(.MODULE): $(.MDEP) | 
|---|
|  | 14 | .MDEP := | 
|---|
|  | 15 | endif # def .MDEP | 
|---|
| [94] | 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)),) | 
|---|
| [1157] | 28 | ifneq ($(findstring log,$(.TKIND)),) | 
|---|
|  | 29 | .tmp += log | 
|---|
|  | 30 | endif # neq ($(findstring log,$(.TKIND)),) | 
|---|
| [1562] | 31 | ifneq ($(findstring lazy,$(.TKIND)),) | 
|---|
|  | 32 | .tmp += lazy | 
|---|
|  | 33 | endif # neq ($(findstring log,$(.TKIND)),) | 
|---|
| [94] | 34 | .TKIND := $(.tmp) | 
|---|
| [885] | 35 | ifdef .TKVAR | 
|---|
|  | 36 | .TKIND.DIR := $(subst $(SPACE),-,$(.TKIND))/$(.TKVAR)/ | 
|---|
|  | 37 | else | 
|---|
| [94] | 38 | .TKIND.DIR := $(subst $(SPACE),-,$(.TKIND))/ | 
|---|
| [885] | 39 | endif | 
|---|
| [156] | 40 | .DIRS := | 
|---|
| [94] | 41 |  | 
|---|
| [123] | 42 | ifdef .TARGET | 
|---|
|  | 43 |  | 
|---|
| [94] | 44 | # .TARG is same as .TARGET except that it has a st/ or mt/ prefix | 
|---|
|  | 45 | .TARG := $(.TKIND.DIR)$(.TARGET) | 
|---|
| [156] | 46 | .DIRS += $.$(.TKIND.DIR) | 
|---|
| [94] | 47 |  | 
|---|
|  | 48 | ifdef .INSDIR | 
|---|
| [578] | 49 | ifndef .NOINST | 
|---|
| [236] | 50 | INS.FILES += $(INS)$(.INSDIR)$(.TARGET) | 
|---|
|  | 51 | $(INS)$(.INSDIR)$(.TARGET): $.$(.TARG) | 
|---|
|  | 52 | $(call CP,$<,$@) | 
|---|
| [578] | 53 | endif | 
|---|
| [94] | 54 | endif # def .INSDIR | 
|---|
|  | 55 |  | 
|---|
| [123] | 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 |  | 
|---|
| [94] | 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))) | 
|---|
| [156] | 78 | .DIRS += $(sort $(dir $(.OBJS))) | 
|---|
| [94] | 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 | 
|---|
| [894] | 94 | $(foreach x,$(filter %.c,$(.TSRC)), $(eval $(call def_compile_c,$(x)))) | 
|---|
| [94] | 95 |  | 
|---|
|  | 96 | # Generate compilation rules for S files | 
|---|
| [2011] | 97 | $(foreach x,$(filter %.s %.S,$(.TSRC)), $(eval $(call def_compile_S,$(x)))) | 
|---|
| [94] | 98 |  | 
|---|
|  | 99 | # Generate compilation rules for asm files | 
|---|
| [894] | 100 | $(foreach x,$(filter %.asm,$(.TSRC)), $(eval $(call def_compile_asm,$(x)))) | 
|---|
| [94] | 101 |  | 
|---|
|  | 102 | endif # def .TSRC | 
|---|
|  | 103 |  | 
|---|
| [156] | 104 | # Add target directories to module dependencies and to overall list of dirs | 
|---|
|  | 105 | ifneq ($(.DIRS),) | 
|---|
|  | 106 | TARGDIRS += $(.DIRS) | 
|---|
| [148] | 107 | ifdef .MODULE | 
|---|
| [156] | 108 | $(.MODULE): $(.DIRS) | 
|---|
|  | 109 | endif # def .MODULE | 
|---|
|  | 110 | endif # neq ($(.DIRS),) | 
|---|
| [148] | 111 |  | 
|---|
| [156] | 112 | # Add the target to the list of module dependencies | 
|---|
|  | 113 | ifdef .TARGET | 
|---|
|  | 114 | $(.MODULE): $.$(.TARG) | 
|---|
|  | 115 | endif # def .TARGET | 
|---|
|  | 116 |  | 
|---|
| [94] | 117 | # Replace the special sequence in .TDEP @O@ with $.$(.TKIND.DIR) | 
|---|
|  | 118 | .DEPS := $(subst @O@,$.$(.TKIND.DIR),$(.TDEP)) | 
|---|