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