[72] | 1 | # $Id: footer.kmk 72 2004-05-30 06:16:41Z bird $
|
---|
| 2 | ## @file
|
---|
| 3 | #
|
---|
| 4 | # kBuild - File included at top of makefile.
|
---|
| 5 | #
|
---|
| 6 | # Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
|
---|
| 7 | #
|
---|
| 8 | #
|
---|
| 9 | # This file is part of kBuild.
|
---|
| 10 | #
|
---|
| 11 | # kBuild is free software; you can redistribute it and/or modify
|
---|
| 12 | # it under the terms of the GNU General Public License as published by
|
---|
| 13 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 14 | # (at your option) any later version.
|
---|
| 15 | #
|
---|
| 16 | # kBuild is distributed in the hope that it will be useful,
|
---|
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | # GNU General Public License for more details.
|
---|
| 20 | #
|
---|
| 21 | # You should have received a copy of the GNU General Public License
|
---|
| 22 | # along with kBuild; if not, write to the Free Software
|
---|
| 23 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 24 | #
|
---|
| 25 | #
|
---|
| 26 |
|
---|
| 27 | ifndef __footer_kmk__
|
---|
| 28 | # start-of-file-content
|
---|
| 29 |
|
---|
| 30 | #
|
---|
| 31 | # Variables.
|
---|
| 32 | #
|
---|
| 33 |
|
---|
| 34 | # all targets.
|
---|
| 35 | ALL_TARGETS := $(LIBRARIES) $(PROGRAMS) $(DLLS) $(DRIVERS) $(OTHERS)
|
---|
| 36 |
|
---|
| 37 | # all of a type
|
---|
| 38 | _OBJS :=
|
---|
| 39 | _LIBS :=
|
---|
| 40 | _DLLS :=
|
---|
| 41 | _EXES :=
|
---|
| 42 | _DIRS :=
|
---|
| 43 |
|
---|
| 44 | # all objs of a specific target
|
---|
| 45 | define def_objs_var
|
---|
| 46 | _OBJS_$1 :=
|
---|
| 47 | endef
|
---|
| 48 | $(foreach target, $(ALL_TARGETS), $(eval _OBJS_$(target) := ))
|
---|
| 49 |
|
---|
| 50 | #
|
---|
| 51 | # Include templates
|
---|
| 52 | #
|
---|
| 53 | _TEMPLATES := $(TEMPLATE)
|
---|
| 54 | define def_templates
|
---|
| 55 | ifdef $(target)_TEMPLATE
|
---|
| 56 | _TEMPLATES += $($(target)_TEMPLATE)
|
---|
| 57 | endif
|
---|
| 58 | endef
|
---|
| 59 | $(foreach target, $(ALL_TARGETS), $(eval $(def_templates)))
|
---|
| 60 | _TEMPLATES := $(sort $(_TEMPLATES))
|
---|
| 61 | # $ (warning dbg: _TEMPLATES=$(_TEMPLATES))
|
---|
| 62 |
|
---|
| 63 | define def_templates_include
|
---|
| 64 | ifndef TEMPLATE_$(template)
|
---|
| 65 | include $(firstword $(wildcard $(PATH_KBUILD)/templates/$(template).kmk))
|
---|
| 66 | endif
|
---|
| 67 | endef
|
---|
| 68 | $(foreach template, $(_TEMPLATES), $(eval $(def_templates)))
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | #
|
---|
| 72 | # Common Inheritance
|
---|
| 73 | #
|
---|
| 74 |
|
---|
| 75 | ## Inherit defaults property
|
---|
| 76 | # @param $(prop) Property name
|
---|
| 77 | # @param $(target) Target name.
|
---|
| 78 | define def_inherit_defaults_one
|
---|
| 79 | ifndef $1_$(prop)
|
---|
| 80 | ifdef $(prop)
|
---|
| 81 | $1_$(prop) := $($(prop))
|
---|
| 82 | endif
|
---|
| 83 | endif
|
---|
| 84 | endef
|
---|
| 85 |
|
---|
| 86 | ## Inherit default properties for one target.
|
---|
| 87 | # A bit tricky this one, but it depends a bit on whether or not TEMPLATE
|
---|
| 88 | # is inherited from the default properties.
|
---|
| 89 | # @param $(target) Target name
|
---|
| 90 | define def_inherit_defaults
|
---|
| 91 | ifdef $(target)_TEMPLATE
|
---|
| 92 | ifndef TEMPLATE_$($(target)_TEMPLATE)_TOOL
|
---|
| 93 | $(foreach prop, TOOL, $(eval $(def_inherit_defaults_one)))
|
---|
| 94 | endif
|
---|
| 95 | ifndef TEMPLATE_$($(target)_TEMPLATE)_SDKS
|
---|
| 96 | $(foreach prop, SDKS, $(eval $(def_inherit_defaults_one)))
|
---|
| 97 | endif
|
---|
| 98 | else
|
---|
| 99 | $(foreach prop, TEMPLATE TOOL SDKS, $(eval $(def_inherit_defaults_one)))
|
---|
| 100 | endif
|
---|
| 101 | endef
|
---|
| 102 | # Inherit default properties.
|
---|
| 103 | $(foreach target, $(ALL_TARGETS), $(eval $(def_inherit_defaults)))
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | ## Inherit one template property.
|
---|
| 107 | # @param $(prop) Property name
|
---|
| 108 | # @param $(target) Target name
|
---|
| 109 | define def_inherit_template_one
|
---|
| 110 | ifndef $(target)_$(prop)
|
---|
| 111 | ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
|
---|
| 112 | $(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
|
---|
| 113 | endif
|
---|
| 114 | endif
|
---|
| 115 | endef
|
---|
| 116 |
|
---|
| 117 | ## Inherit template properties for on target.
|
---|
| 118 | # @param $(target) Target name.
|
---|
| 119 | define def_inherit_template
|
---|
| 120 | $(foreach prop,TOOL SDKS DEFS INCS COPTS CFLAGS CDEFS CINCS CXXOPTS CXXFLAGS CXXDEFS CXXINCS ASOPTS ASFLAGS ASDEFS ASINCS, \
|
---|
| 121 | $(eval $(def_inherit_template_one)))
|
---|
| 122 | endef
|
---|
| 123 | # Inherit template properties
|
---|
| 124 | $(foreach target, $(ALL_TARGETS), $(eval $(def_inherit_template)))
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 | #
|
---|
| 129 | # Include tools
|
---|
| 130 | #
|
---|
| 131 | _TOOLS := $(TOOL)
|
---|
| 132 | define def_tools_target_source
|
---|
| 133 | #$ (warning dbg: src=$(source))
|
---|
| 134 | $(foreach tool,$($(source)_TOOL) $($(target)_$(source)_TOOL),\
|
---|
| 135 | $(eval _TOOLS += $(tool)))
|
---|
| 136 | endef
|
---|
| 137 | define def_tools_target
|
---|
| 138 | #$ (warning dbg: trg=$(target))
|
---|
| 139 | $(foreach tool, $($(target)_TOOL), $(eval _TOOLS += $(tool)))
|
---|
| 140 | $(foreach source, $($(target)_SOURCES), $(eval $(def_tools_target_source)))
|
---|
| 141 | endef
|
---|
| 142 | $(foreach target, $(ALL_TARGETS), $(eval $(def_tools_target)))
|
---|
| 143 | _TOOLS := $(sort $(_TOOLS))
|
---|
| 144 | #$ (warning dbg: _TOOLS=$(_TOOLS))
|
---|
| 145 |
|
---|
| 146 | define def_tools_include
|
---|
| 147 | ifndef TOOL_$(tool)
|
---|
| 148 | include $(firstword $(wildcard $(PATH_KBUILD)/tools/$(tool).kmk))
|
---|
| 149 | endif
|
---|
| 150 | endef
|
---|
| 151 | $(foreach tool, $(_TOOLS), $(eval $(def_tools_include)))
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 | #
|
---|
| 155 | # Include SDKs
|
---|
| 156 | #
|
---|
| 157 | _SDKS := $(SDKS)
|
---|
| 158 | define def_sdks_target_source
|
---|
| 159 | $(foreach sdk, $($(source)_SDKS) $($(target)_$(source)_SDKS), \
|
---|
| 160 | $(eval _SDKS += $(sdk)))
|
---|
| 161 | endef
|
---|
| 162 | define def_sdks_target
|
---|
| 163 | $(foreach sdk, $($(target)_SDKS), $(eval _SDKS += $(sdk)))
|
---|
| 164 | $(foreach source, $($(target)_SOURCES), $(eval $(def_sdks_target_source)))
|
---|
| 165 | endef
|
---|
| 166 | $(foreach target, $(ALL_TARGETS), $(eval $(def_sdks_target)))
|
---|
| 167 | _SDKS := $(sort $(_SDKS))
|
---|
| 168 | #$ (warning dbg: _SDKS=$(_SDKS))
|
---|
| 169 |
|
---|
| 170 | define def_sdks_include
|
---|
| 171 | ifndef SDK_$(sdk)
|
---|
| 172 | include $(firstword $(wildcard $(PATH_KBUILD)/sdks/$(sdk).kmk))
|
---|
| 173 | endif
|
---|
| 174 | endef
|
---|
| 175 | $(foreach sdk, $(_SDKS), $(eval $(def_sdk)))
|
---|
| 176 |
|
---|
| 177 |
|
---|
| 178 | #
|
---|
| 179 | # LIBRARIES
|
---|
| 180 | #
|
---|
| 181 |
|
---|
| 182 | ## Figure out the tool for a source
|
---|
| 183 | # @param $1 source file
|
---|
| 184 | # @param $2 normalized main target
|
---|
| 185 | _SOURCE_TOOL = $(firstword $($1_$2_TOOL) $($1_TOOL) $($2_TOOL))
|
---|
| 186 | ## Figure out where to put object files.
|
---|
| 187 | # @param $1 source file
|
---|
| 188 | # @param $2 normalized main target
|
---|
| 189 | _OBJECT_BASE = $(PATH_TARGET)/$(2)/$(basename $1)
|
---|
| 190 |
|
---|
| 191 | ## Library (one).
|
---|
| 192 | # @param $(lib) Library name
|
---|
| 193 | define def_lib
|
---|
| 194 | #$ (warning dbg: Processing library $(target))
|
---|
| 195 |
|
---|
| 196 | # C++ sources
|
---|
| 197 | #$(foreach o, $(filter %.cpp,$($1_SOURCES)), $(eval $(call def_lib_cxx,$1,$o)))
|
---|
| 198 | #$(foreach o, $(filter %.cxx,$($1_SOURCES)), $(eval $(call def_lib_cxx,$1,$o)))
|
---|
| 199 | #$(foreach o, $(filter %.cc, $($1_SOURCES)), $(eval $(call def_lib_cxx,$1,$o)))
|
---|
| 200 |
|
---|
| 201 | # C sources
|
---|
| 202 | $(foreach source, $(filter %.c, $($(target)_SOURCES)), \
|
---|
| 203 | $(eval $(call TOOL_$(call _SOURCE_TOOL,$(source),$(target))_COMPILE_C,$(call _OBJECT_BASE,$(source),$(target)),$(source),$(target)) ) )
|
---|
| 204 |
|
---|
| 205 | ## ASM sources
|
---|
| 206 | #$(foreach o, $(filter %.asm,$($1_SOURCES)), $(eval $(call def_lib_asm,$1,$o)))
|
---|
| 207 |
|
---|
| 208 | # library
|
---|
| 209 | #$$(PATH_TARGET)/$1$(SUFF_LIB): \
|
---|
| 210 | # $$(PATH_TARGET) \
|
---|
| 211 | # $$(_OBJS_$1)
|
---|
| 212 | # $$(AR) $($1_ARFLAGS) $(ARFLAGS) $(AROUT)$$(@:/=\) $$(_OBJS_$1)
|
---|
| 213 | #
|
---|
| 214 | _OBJS += $(_OBJS_$(target))
|
---|
| 215 | _LIBS += $(PATH_TARGET)/$1$(SUFF_LIB)
|
---|
| 216 | endef
|
---|
| 217 |
|
---|
| 218 | # Process libraries
|
---|
| 219 | $(foreach target, $(LIBRARIES), $(eval $(def_lib)))
|
---|
| 220 |
|
---|
| 221 |
|
---|
| 222 |
|
---|
| 223 | #
|
---|
| 224 | # PROGRAMS
|
---|
| 225 | #
|
---|
| 226 |
|
---|
| 227 |
|
---|
| 228 |
|
---|
| 229 | #
|
---|
| 230 | # DLLS
|
---|
| 231 | #
|
---|
| 232 |
|
---|
| 233 |
|
---|
| 234 |
|
---|
| 235 | #
|
---|
| 236 | # DRIVERS
|
---|
| 237 | #
|
---|
| 238 |
|
---|
| 239 |
|
---|
| 240 |
|
---|
| 241 | #
|
---|
| 242 | # OTHERS
|
---|
| 243 | #
|
---|
| 244 |
|
---|
| 245 |
|
---|
| 246 |
|
---|
| 247 | #
|
---|
| 248 | # DOCS
|
---|
| 249 | #
|
---|
| 250 |
|
---|
| 251 |
|
---|
| 252 | #
|
---|
| 253 | # Directories.
|
---|
| 254 | #
|
---|
| 255 | _DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(dir $(_OBJS) $(_LIBS) $(_EXES) $(_DLLS))))
|
---|
| 256 |
|
---|
| 257 | define def_createdir
|
---|
| 258 | $(dirfile):
|
---|
| 259 | $(MKDIR) -p $$(@D)
|
---|
| 260 | echo dir_created > $$@
|
---|
| 261 | endef
|
---|
| 262 |
|
---|
| 263 | $(foreach dirfile,$(_DIRFILES),$(eval $(def_createdir)))
|
---|
| 264 |
|
---|
| 265 | #
|
---|
| 266 | # THE MAIN RULES
|
---|
| 267 | #
|
---|
| 268 | all_recursive:
|
---|
| 269 |
|
---|
| 270 |
|
---|
| 271 | objs: $(_OBJS)
|
---|
| 272 |
|
---|
| 273 |
|
---|
| 274 | # end-of-file-content
|
---|
| 275 | __footer_kmk__ := 1
|
---|
| 276 | endif # __footer_kmk__
|
---|