[72] | 1 | # $Id: footer.kmk 76 2004-05-31 08:12:08Z 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.
|
---|
[73] | 32 | # (Some of these need initialization before including definitions using them.)
|
---|
[72] | 33 | #
|
---|
| 34 |
|
---|
| 35 | # all targets.
|
---|
| 36 | ALL_TARGETS := $(LIBRARIES) $(PROGRAMS) $(DLLS) $(DRIVERS) $(OTHERS)
|
---|
| 37 |
|
---|
[75] | 38 | # dependency files.
|
---|
| 39 | _DEPFILES :=
|
---|
| 40 |
|
---|
| 41 | # All kind of output files except for _OBJS and _DEPFILES.
|
---|
| 42 | # Compiling or linking definition outputting other things that $@ and any
|
---|
| 43 | # required dependency file must add those output files to this variable.
|
---|
| 44 | _OUT_FILES :=
|
---|
| 45 |
|
---|
[72] | 46 | # all of a type
|
---|
| 47 | _OBJS :=
|
---|
| 48 | _LIBS :=
|
---|
| 49 | _DLLS :=
|
---|
| 50 | _EXES :=
|
---|
| 51 | _DIRS :=
|
---|
| 52 |
|
---|
| 53 | # all objs of a specific target
|
---|
| 54 | define def_objs_var
|
---|
| 55 | _OBJS_$1 :=
|
---|
| 56 | endef
|
---|
| 57 | $(foreach target, $(ALL_TARGETS), $(eval _OBJS_$(target) := ))
|
---|
| 58 |
|
---|
[73] | 59 |
|
---|
[72] | 60 | #
|
---|
[73] | 61 | # Basic macros
|
---|
| 62 | #
|
---|
| 63 |
|
---|
| 64 | ## Figure out the tool for a source
|
---|
| 65 | # @param $1 source file
|
---|
| 66 | # @param $2 normalized main target
|
---|
[74] | 67 | _SOURCE_TOOL = $(firstword $($1_$2_TOOL) $($1_TOOL) $($2_TOOL) $(TOOL))
|
---|
[73] | 68 |
|
---|
| 69 | ## Figure out where to put object files.
|
---|
| 70 | # @param $1 source file
|
---|
| 71 | # @param $2 normalized main target
|
---|
| 72 | _OBJECT_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
|
---|
| 73 |
|
---|
| 74 | ## Figure out where to put object files.
|
---|
| 75 | # @param $1 real target name.
|
---|
| 76 | # @param $2 normalized main target
|
---|
| 77 | _TARGET_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | #
|
---|
[72] | 81 | # Include templates
|
---|
| 82 | #
|
---|
| 83 | _TEMPLATES := $(TEMPLATE)
|
---|
| 84 | define def_templates
|
---|
| 85 | ifdef $(target)_TEMPLATE
|
---|
| 86 | _TEMPLATES += $($(target)_TEMPLATE)
|
---|
| 87 | endif
|
---|
| 88 | endef
|
---|
| 89 | $(foreach target, $(ALL_TARGETS), $(eval $(def_templates)))
|
---|
| 90 | _TEMPLATES := $(sort $(_TEMPLATES))
|
---|
| 91 | # $ (warning dbg: _TEMPLATES=$(_TEMPLATES))
|
---|
| 92 |
|
---|
| 93 | define def_templates_include
|
---|
| 94 | ifndef TEMPLATE_$(template)
|
---|
| 95 | include $(firstword $(wildcard $(PATH_KBUILD)/templates/$(template).kmk))
|
---|
| 96 | endif
|
---|
| 97 | endef
|
---|
| 98 | $(foreach template, $(_TEMPLATES), $(eval $(def_templates)))
|
---|
| 99 |
|
---|
[74] | 100 |
|
---|
[72] | 101 | #
|
---|
| 102 | # Common Inheritance
|
---|
| 103 | #
|
---|
| 104 |
|
---|
| 105 | ## Inherit defaults property
|
---|
| 106 | # @param $(prop) Property name
|
---|
| 107 | # @param $(target) Target name.
|
---|
| 108 | define def_inherit_defaults_one
|
---|
[74] | 109 | ifndef $(target)_$(prop)
|
---|
[72] | 110 | ifdef $(prop)
|
---|
[74] | 111 | $(target)_$(prop) := $($(prop))
|
---|
[72] | 112 | endif
|
---|
| 113 | endif
|
---|
| 114 | endef
|
---|
| 115 |
|
---|
| 116 | ## Inherit default properties for one target.
|
---|
| 117 | # A bit tricky this one, but it depends a bit on whether or not TEMPLATE
|
---|
| 118 | # is inherited from the default properties.
|
---|
| 119 | # @param $(target) Target name
|
---|
| 120 | define def_inherit_defaults
|
---|
| 121 | ifdef $(target)_TEMPLATE
|
---|
| 122 | ifndef TEMPLATE_$($(target)_TEMPLATE)_TOOL
|
---|
| 123 | $(foreach prop, TOOL, $(eval $(def_inherit_defaults_one)))
|
---|
| 124 | endif
|
---|
| 125 | ifndef TEMPLATE_$($(target)_TEMPLATE)_SDKS
|
---|
| 126 | $(foreach prop, SDKS, $(eval $(def_inherit_defaults_one)))
|
---|
| 127 | endif
|
---|
| 128 | else
|
---|
| 129 | $(foreach prop, TEMPLATE TOOL SDKS, $(eval $(def_inherit_defaults_one)))
|
---|
| 130 | endif
|
---|
| 131 | endef
|
---|
| 132 | # Inherit default properties.
|
---|
| 133 | $(foreach target, $(ALL_TARGETS), $(eval $(def_inherit_defaults)))
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 | ## Inherit one template property.
|
---|
| 137 | # @param $(prop) Property name
|
---|
| 138 | # @param $(target) Target name
|
---|
| 139 | define def_inherit_template_one
|
---|
| 140 | ifndef $(target)_$(prop)
|
---|
| 141 | ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
|
---|
| 142 | $(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
|
---|
| 143 | endif
|
---|
| 144 | endif
|
---|
| 145 | endef
|
---|
| 146 |
|
---|
| 147 | ## Inherit template properties for on target.
|
---|
| 148 | # @param $(target) Target name.
|
---|
| 149 | define def_inherit_template
|
---|
| 150 | $(foreach prop,TOOL SDKS DEFS INCS COPTS CFLAGS CDEFS CINCS CXXOPTS CXXFLAGS CXXDEFS CXXINCS ASOPTS ASFLAGS ASDEFS ASINCS, \
|
---|
| 151 | $(eval $(def_inherit_template_one)))
|
---|
| 152 | endef
|
---|
| 153 | # Inherit template properties
|
---|
| 154 | $(foreach target, $(ALL_TARGETS), $(eval $(def_inherit_template)))
|
---|
| 155 |
|
---|
| 156 |
|
---|
| 157 |
|
---|
| 158 | #
|
---|
| 159 | # Include tools
|
---|
| 160 | #
|
---|
| 161 | _TOOLS := $(TOOL)
|
---|
| 162 | define def_tools_target_source
|
---|
| 163 | #$ (warning dbg: src=$(source))
|
---|
| 164 | $(foreach tool,$($(source)_TOOL) $($(target)_$(source)_TOOL),\
|
---|
| 165 | $(eval _TOOLS += $(tool)))
|
---|
| 166 | endef
|
---|
| 167 | define def_tools_target
|
---|
| 168 | #$ (warning dbg: trg=$(target))
|
---|
| 169 | $(foreach tool, $($(target)_TOOL), $(eval _TOOLS += $(tool)))
|
---|
| 170 | $(foreach source, $($(target)_SOURCES), $(eval $(def_tools_target_source)))
|
---|
| 171 | endef
|
---|
| 172 | $(foreach target, $(ALL_TARGETS), $(eval $(def_tools_target)))
|
---|
| 173 | _TOOLS := $(sort $(_TOOLS))
|
---|
| 174 | #$ (warning dbg: _TOOLS=$(_TOOLS))
|
---|
| 175 |
|
---|
| 176 | define def_tools_include
|
---|
| 177 | ifndef TOOL_$(tool)
|
---|
| 178 | include $(firstword $(wildcard $(PATH_KBUILD)/tools/$(tool).kmk))
|
---|
| 179 | endif
|
---|
| 180 | endef
|
---|
| 181 | $(foreach tool, $(_TOOLS), $(eval $(def_tools_include)))
|
---|
| 182 |
|
---|
| 183 |
|
---|
| 184 | #
|
---|
| 185 | # Include SDKs
|
---|
[73] | 186 | #
|
---|
[72] | 187 | _SDKS := $(SDKS)
|
---|
| 188 | define def_sdks_target_source
|
---|
| 189 | $(foreach sdk, $($(source)_SDKS) $($(target)_$(source)_SDKS), \
|
---|
| 190 | $(eval _SDKS += $(sdk)))
|
---|
| 191 | endef
|
---|
| 192 | define def_sdks_target
|
---|
| 193 | $(foreach sdk, $($(target)_SDKS), $(eval _SDKS += $(sdk)))
|
---|
| 194 | $(foreach source, $($(target)_SOURCES), $(eval $(def_sdks_target_source)))
|
---|
| 195 | endef
|
---|
| 196 | $(foreach target, $(ALL_TARGETS), $(eval $(def_sdks_target)))
|
---|
| 197 | _SDKS := $(sort $(_SDKS))
|
---|
| 198 | #$ (warning dbg: _SDKS=$(_SDKS))
|
---|
| 199 |
|
---|
| 200 | define def_sdks_include
|
---|
| 201 | ifndef SDK_$(sdk)
|
---|
| 202 | include $(firstword $(wildcard $(PATH_KBUILD)/sdks/$(sdk).kmk))
|
---|
| 203 | endif
|
---|
| 204 | endef
|
---|
| 205 | $(foreach sdk, $(_SDKS), $(eval $(def_sdk)))
|
---|
| 206 |
|
---|
[73] | 207 | #
|
---|
| 208 | # Object processing.
|
---|
| 209 | #
|
---|
[72] | 210 |
|
---|
[73] | 211 | ## Generic macro for processing C, C++ and Assembly sources.
|
---|
| 212 | # @param $(target) Normalized target name.
|
---|
| 213 | # @param $(source) Source file name.
|
---|
| 214 | # @param $(type) Source type. {C,CXX,AS}
|
---|
[72] | 215 | #
|
---|
[73] | 216 | # @remark I've no clue why I've to $(eval ..) everything in this define. MAKE bug?
|
---|
| 217 | define def_target_source_c_cpp_asm
|
---|
| 218 | #$ (warning dbg: def_target_source_c_cpp_asm: source=$(source) target=$(target) type=$(type))
|
---|
| 219 |
|
---|
| 220 | $(eval tool:=$(call _SOURCE_TOOL,$(source),$(target)))
|
---|
| 221 | $(eval defs :=\
|
---|
[74] | 222 | $(TOOL_$(tool)_$(type)DEFS)\
|
---|
| 223 | $(TOOL_$(tool)_$(type)DEFS.$(BUILD_TYPE))\
|
---|
| 224 | $(DEFS)\
|
---|
| 225 | $(DEFS.$(BUILD_TYPE))\
|
---|
| 226 | $($(target)_DEFS)\
|
---|
| 227 | $($(target)_DEFS.$(BUILD_TYPE))\
|
---|
| 228 | $($(target)_DEFS.$(BUILD_TARGET))\
|
---|
| 229 | $($(source)_DEFS)\
|
---|
| 230 | $($(source)_DEFS.$(BUILD_TYPE))\
|
---|
| 231 | $($(source)_DEFS.$(BUILD_TARGET))\
|
---|
[73] | 232 | $($(source)_$(type)DEFS)\
|
---|
[74] | 233 | $($(source)_$(type)DEFS.$(BUILD_TYPE))\
|
---|
| 234 | $($(source)_$(type)DEFS.$(BUILD_TARGET))\
|
---|
[73] | 235 | $($(target)_$(type)DEFS)\
|
---|
[74] | 236 | $($(target)_$(type)DEFS.$(BUILD_TYPE))\
|
---|
| 237 | $($(target)_$(type)DEFS.$(BUILD_TARGET))\
|
---|
| 238 | $($(target)_$(source)_DEFS)\
|
---|
| 239 | $($(target)_$(source)_DEFS.$(BUILD_TYPE))\
|
---|
| 240 | $($(target)_$(source)_DEFS.$(BUILD_TARGET))\
|
---|
| 241 | $($(target)_$(source)_$(type)DEFS)\
|
---|
| 242 | $($(target)_$(source)_$(type)DEFS.$(BUILD_TYPE))\
|
---|
| 243 | $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET))\
|
---|
[73] | 244 | )
|
---|
| 245 | $(eval incs :=\
|
---|
[74] | 246 | $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET))\
|
---|
| 247 | $($(target)_$(source)_$(type)INCS.$(BUILD_TYPE))\
|
---|
[73] | 248 | $($(target)_$(source)_$(type)INCS)\
|
---|
[74] | 249 | $($(target)_$(source)_INCS.$(BUILD_TARGET))\
|
---|
| 250 | $($(target)_$(source)_INCS.$(BUILD_TYPE))\
|
---|
[73] | 251 | $($(target)_$(source)_INCS)\
|
---|
[74] | 252 | $($(source)_$(type)INCS.$(BUILD_TARGET))\
|
---|
| 253 | $($(source)_$(type)INCS.$(BUILD_TYPE))\
|
---|
[73] | 254 | $($(source)_$(type)INCS)\
|
---|
[74] | 255 | $($(source)_INCS.$(BUILD_TARGET))\
|
---|
| 256 | $($(source)_INCS.$(BUILD_TYPE))\
|
---|
[73] | 257 | $($(source)_INCS)\
|
---|
[74] | 258 | $($(target)_$(type)INCS.$(BUILD_TARGET))\
|
---|
| 259 | $($(target)_$(type)INCS.$(BUILD_TYPE))\
|
---|
[73] | 260 | $($(target)_$(type)INCS)\
|
---|
[74] | 261 | $($(target)_INCS.$(BUILD_TARGET))\
|
---|
| 262 | $($(target)_INCS.$(BUILD_TYPE))\
|
---|
[73] | 263 | $($(target)_INCS)\
|
---|
[74] | 264 | $(INCS.$(BUILD_TARGET))\
|
---|
| 265 | $(INCS.$(BUILD_TYPE))\
|
---|
[73] | 266 | $(INCS)\
|
---|
[74] | 267 | $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET))\
|
---|
| 268 | $(TOOL_$(tool)_$(type)INCS.$(BUILD_TYPE))\
|
---|
[73] | 269 | $(TOOL_$(tool)_$(type)INCS)\
|
---|
| 270 | )
|
---|
| 271 | $(eval flags :=\
|
---|
| 272 | $(TOOL_$(tool)_$(type)FLAGS)\
|
---|
| 273 | $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TYPE))\
|
---|
[74] | 274 | $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET))\
|
---|
[73] | 275 | $($(type)FLAGS)\
|
---|
| 276 | $($(type)FLAGS.$(BUILD_TYPE))\
|
---|
[74] | 277 | $($(type)FLAGS.$(BUILD_TARGET))\
|
---|
[73] | 278 | $($(target)_$(type)FLAGS)\
|
---|
| 279 | $($(target)_$(type)FLAGS.$(BUILD_TYPE))\
|
---|
[74] | 280 | $($(target)_$(type)FLAGS.$(BUILD_TARGET))\
|
---|
[73] | 281 | $($(source)_$(type)FLAGS)\
|
---|
| 282 | $($(source)_$(type)FLAGS.$(BUILD_TYPE))\
|
---|
[74] | 283 | $($(source)_$(type)FLAGS.$(BUILD_TARGET))\
|
---|
[73] | 284 | $($(target)_$(source)_$(type)FLAGS)\
|
---|
| 285 | $($(target)_$(source)_$(type)FLAGS.$(BUILD_TYPE))\
|
---|
[74] | 286 | $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET))\
|
---|
[73] | 287 | )
|
---|
| 288 | $(eval outbase := $(call _OBJECT_BASE,$(source),$(target)))
|
---|
| 289 | $(eval dirdep := $(dir $(outbase)).dir_created)
|
---|
[74] | 290 | $(eval objsuff := $(firstword \
|
---|
| 291 | $($(target)_$(source)_OBJSUFF.$(BUILD_TARGET))\
|
---|
| 292 | $($(target)_$(source)_OBJSUFF)\
|
---|
| 293 | $($(source)_OBJSUFF.$(BUILD_TARGET))\
|
---|
| 294 | $($(source)_OBJSUFF)\
|
---|
| 295 | $($(target)_OBJSUFF.$(BUILD_TARGET))\
|
---|
| 296 | $($(target)_OBJSUFF)\
|
---|
| 297 | $(TOOL_$(tool)_$(type)OBJSUFF.$(BUILD_TARGET))\
|
---|
| 298 | $(TOOL_$(tool)_$(type)OBJSUFF)\
|
---|
| 299 | $(SUFF_OBJ)\
|
---|
| 300 | ))
|
---|
[73] | 301 | $(eval obj := $(outbase)$(objsuff))
|
---|
[74] | 302 | $(eval dep := $(outbase)$(SUFF_DEP))
|
---|
[73] | 303 |
|
---|
| 304 | #$ (warning dbg: target=$(target) source=$(source) tool=$(tool) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff))
|
---|
| 305 | $(eval $(TOOL_$(tool)_COMPILE_$(type)))
|
---|
| 306 |
|
---|
| 307 | $(eval _OBJS_$(target) += $(obj))
|
---|
| 308 | $(eval _DEPFILES += $(dep))
|
---|
| 309 |
|
---|
| 310 | endef
|
---|
| 311 |
|
---|
| 312 | ## Generic macro for processing all target sources.
|
---|
[74] | 313 | # @param $(target) Normalized target name.
|
---|
[73] | 314 | define def_target_sources
|
---|
| 315 | #$ (warning def_target_sources)
|
---|
| 316 | # C sources
|
---|
| 317 | $(foreach type,C,$(foreach source, $(filter %.c, $($(target)_SOURCES))\
|
---|
| 318 | ,$(eval $(def_target_source_c_cpp_asm)) ))
|
---|
| 319 |
|
---|
| 320 | # C++ sources
|
---|
| 321 | $(foreach type,CXX,$(foreach source, $(filter %.cpp, $($(target)_SOURCES)) $(filter %.cxx, $($(target)_SOURCES)) $(filter %.cc, $($(target)_SOURCES))\
|
---|
| 322 | ,$(eval $(def_target_source_c_cpp_asm)) ))
|
---|
| 323 |
|
---|
| 324 | # ASM sources
|
---|
| 325 | $(foreach type,AS,$(foreach source, $(filter %.asm, $($(target)_SOURCES)) $(filter %.s, $($(target)_SOURCES)) $(filter %.S, $($(target)_SOURCES))\
|
---|
| 326 | ,$(eval $(def_target_source_c_cpp_asm)) ))
|
---|
| 327 | endef
|
---|
| 328 |
|
---|
| 329 |
|
---|
| 330 | #
|
---|
[72] | 331 | # LIBRARIES
|
---|
[73] | 332 | #
|
---|
[72] | 333 |
|
---|
| 334 | ## Library (one).
|
---|
[74] | 335 | # @param $(target) Normalized library (target) name.
|
---|
[72] | 336 | define def_lib
|
---|
[73] | 337 | # source -> object
|
---|
| 338 | $(eval $(def_target_sources))
|
---|
[72] | 339 |
|
---|
[73] | 340 | # library
|
---|
| 341 | $(eval tool := $(firstword $($(target)_TOOL) $(TOOL)))
|
---|
[74] | 342 | $(eval flags :=\
|
---|
| 343 | $(TOOL_$(tool)_ARFLAGS)\
|
---|
| 344 | $(TOOL_$(tool)_ARFLAGS.$(BUILD_TYPE))\
|
---|
| 345 | $(ARFLAGS)\
|
---|
| 346 | $(ARFLAGS.$(BUILD_TYPE))\
|
---|
| 347 | $($(target)_ARFLAGS)\
|
---|
| 348 | $($(target)_ARFLAGS.$(BUILD_TYPE))\
|
---|
| 349 | )
|
---|
| 350 | $(eval libsuff := $(firstword\
|
---|
| 351 | $($(target)_LIBSUFF.$(BUILD_TARGET))\
|
---|
| 352 | $($(target)_LIBSUFF)\
|
---|
| 353 | $(TOOL_$(tool)_ARLIBSUFF.$(BUILD_TARGET))\
|
---|
| 354 | $(TOOL_$(tool)_ARLIBSUFF)\
|
---|
| 355 | $(SUFF_LIB)\
|
---|
| 356 | ))
|
---|
[73] | 357 | ## @todo prefix
|
---|
| 358 | $(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
|
---|
| 359 | $(eval lib := $(outbase)$(libsuff))
|
---|
| 360 | $(eval objs = $(_OBJS_$(target)))
|
---|
| 361 | $(eval dirdep := $(dir $(lib)).dir_created)
|
---|
| 362 | ## @todo fix dependencies
|
---|
| 363 | $(eval deps := )
|
---|
[72] | 364 |
|
---|
[73] | 365 | $(eval $(TOOL_$(tool)_LINK_LIBRARY))
|
---|
[72] | 366 |
|
---|
[73] | 367 | _OBJS += $(_OBJS_$(target))
|
---|
| 368 | _LIBS += $(lib)
|
---|
[75] | 369 | _OUT_FILES += $(lib)
|
---|
[72] | 370 | endef
|
---|
| 371 |
|
---|
| 372 | # Process libraries
|
---|
| 373 | $(foreach target, $(LIBRARIES), $(eval $(def_lib)))
|
---|
| 374 |
|
---|
| 375 |
|
---|
| 376 |
|
---|
| 377 | #
|
---|
| 378 | # PROGRAMS
|
---|
| 379 | #
|
---|
| 380 |
|
---|
[74] | 381 | ## Program (one).
|
---|
| 382 | # @param $(target) Normalized target (program) name.
|
---|
| 383 | define def_program
|
---|
| 384 | # source -> object
|
---|
| 385 | $(eval $(def_target_sources))
|
---|
[72] | 386 |
|
---|
[74] | 387 | # library
|
---|
| 388 | $(eval tool := $(firstword $($(target)_TOOL) $(TOOL)))
|
---|
| 389 | $(eval flags :=\
|
---|
| 390 | $(TOOL_$(tool)_LDFLAGS)\
|
---|
| 391 | $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
|
---|
| 392 | $(LDFLAGS)\
|
---|
| 393 | $(LDFLAGS.$(BUILD_TYPE))\
|
---|
| 394 | $($(target)_LDFLAGS)\
|
---|
| 395 | $($(target)_LDFLAGS.$(BUILD_TYPE))\
|
---|
| 396 | )
|
---|
| 397 | $(eval exesuff := $(firstword $($(target)_EXESUFF) $($(target)_EXESUFF) $(TOOL_$(tool)_LDEXESUFF) $(SUFF_EXE)))
|
---|
| 398 | $(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
|
---|
| 399 | $(eval exe := $(outbase)$(exesuff))
|
---|
| 400 | $(eval objs = $(_OBJS_$(target)))
|
---|
| 401 | $(eval libs :=\
|
---|
| 402 | $($(target)_LIBS.$(BUILD_TYPE))\
|
---|
| 403 | $($(target)_LIBS)\
|
---|
| 404 | $(LIBS.$(BUILD_TYPE))\
|
---|
| 405 | $(LIBS)\
|
---|
| 406 | $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
|
---|
| 407 | $(TOOL_$(tool)_LIBS)\
|
---|
| 408 | )
|
---|
| 409 | $(eval libpath :=\
|
---|
| 410 | $($(target)_LIBPATH.$(BUILD_TYPE))\
|
---|
| 411 | $($(target)_LIBPATH)\
|
---|
| 412 | $(LIBPATH.$(BUILD_TYPE))\
|
---|
| 413 | $(LIBPATH)\
|
---|
| 414 | $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
|
---|
| 415 | $(TOOL_$(tool)_LIBPATH)\
|
---|
| 416 | )
|
---|
| 417 | $(eval dirdep := $(dir $(exe)).dir_created)
|
---|
| 418 | ## @todo fix dependencies
|
---|
| 419 | $(eval deps := )
|
---|
| 420 | #
|
---|
| 421 | $(eval deffile := $(strip $(firstword
|
---|
| 422 | $($(target)_DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
|
---|
| 423 | $($(target)_DEFFILE.$(BUILD_TARGET))\
|
---|
| 424 | $($(target)_DEFFILE.$(BUILD_TYPE))\
|
---|
| 425 | $($(target)_DEFFILE)\
|
---|
| 426 | $(DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
|
---|
| 427 | $(DEFFILE.$(BUILD_TARGET))\
|
---|
| 428 | $(DEFFILE.$(BUILD_TYPE))\
|
---|
| 429 | $(DEFFILE)\
|
---|
| 430 | )))
|
---|
| 431 | $(eval custom_pre := $(strip $(firstword
|
---|
| 432 | $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
|
---|
| 433 | $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
|
---|
| 434 | $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
|
---|
| 435 | $($(target)_CUSTOM_PRE)\
|
---|
| 436 | $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
|
---|
| 437 | $(CUSTOM_PRE.$(BUILD_TARGET))\
|
---|
| 438 | $(CUSTOM_PRE.$(BUILD_TYPE))\
|
---|
| 439 | $(CUSTOM_PRE)\
|
---|
| 440 | )))
|
---|
| 441 | $(eval custom_post := $(strip $(firstword
|
---|
| 442 | $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
|
---|
| 443 | $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
|
---|
| 444 | $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
|
---|
| 445 | $($(target)_CUSTOM_POST)\
|
---|
| 446 | $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
|
---|
| 447 | $(CUSTOM_POST.$(BUILD_TARGET))\
|
---|
| 448 | $(CUSTOM_POST.$(BUILD_TYPE))\
|
---|
| 449 | $(CUSTOM_POST)\
|
---|
| 450 | )))
|
---|
[72] | 451 |
|
---|
[74] | 452 | $(eval $(TOOL_$(tool)_LINK_PROGRAM))
|
---|
| 453 |
|
---|
| 454 | _OBJS += $(_OBJS_$(target))
|
---|
| 455 | _EXES += $(exe)
|
---|
[75] | 456 | _OUT_FILES += $(exe)
|
---|
[74] | 457 | endef
|
---|
| 458 |
|
---|
| 459 | # Process libraries
|
---|
| 460 | $(foreach target, $(PROGRAMS), $(eval $(def_program)))
|
---|
| 461 |
|
---|
| 462 |
|
---|
| 463 |
|
---|
[72] | 464 | #
|
---|
| 465 | # DLLS
|
---|
| 466 | #
|
---|
| 467 |
|
---|
| 468 |
|
---|
| 469 |
|
---|
| 470 | #
|
---|
| 471 | # DRIVERS
|
---|
| 472 | #
|
---|
| 473 |
|
---|
| 474 |
|
---|
| 475 |
|
---|
| 476 | #
|
---|
| 477 | # OTHERS
|
---|
| 478 | #
|
---|
| 479 |
|
---|
| 480 |
|
---|
| 481 |
|
---|
| 482 | #
|
---|
| 483 | # DOCS
|
---|
| 484 | #
|
---|
| 485 |
|
---|
| 486 |
|
---|
| 487 | #
|
---|
| 488 | # Directories.
|
---|
| 489 | #
|
---|
[75] | 490 | _OUTPUT_FILES := $(_OBJS) $(_LIBS) $(_EXES) $(_DLLS)
|
---|
| 491 | _DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(dir $(_OUTPUT_FILES))))
|
---|
[72] | 492 |
|
---|
| 493 | define def_createdir
|
---|
| 494 | $(dirfile):
|
---|
[73] | 495 | $(call MSG_L1,Creating directory $$(@D))
|
---|
[72] | 496 | $(MKDIR) -p $$(@D)
|
---|
[73] | 497 | @echo dir_created > $$@
|
---|
[72] | 498 | endef
|
---|
| 499 |
|
---|
| 500 | $(foreach dirfile,$(_DIRFILES),$(eval $(def_createdir)))
|
---|
| 501 |
|
---|
[75] | 502 |
|
---|
[72] | 503 | #
|
---|
[75] | 504 | # Include dependency files.
|
---|
[72] | 505 | #
|
---|
[75] | 506 | $(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
|
---|
[72] | 507 |
|
---|
[75] | 508 |
|
---|
| 509 | #
|
---|
| 510 | # PASSES (including directory and makefile walking)
|
---|
| 511 | #
|
---|
| 512 | # Do all the default passes if it's unspecified.
|
---|
| 513 | PASSES ?= needed libraries binaries others publish
|
---|
[72] | 514 |
|
---|
[75] | 515 | ## Proritized list of the default makefile when walking subdirectories.
|
---|
| 516 | # The user can overload this list.
|
---|
| 517 | DEFAULT_MAKEFILE ?= Makefile.kmk makefile.kmk Makefile makefile
|
---|
[72] | 518 |
|
---|
[75] | 519 | ## Subdir
|
---|
| 520 | # @param $(pass) Lowercase pass name.
|
---|
| 521 | # @param $(PASS) Uppercase pass name.
|
---|
| 522 | # @param $(subdir) Subdirectory
|
---|
| 523 | # @param $(tag) tag to attach to the rule name.
|
---|
| 524 | define def_pass_subdir
|
---|
| 525 | pass_$(pass)$(tag)::
|
---|
| 526 | $(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
|
---|
| 527 | endef
|
---|
[72] | 528 |
|
---|
[75] | 529 | ## Submakefile
|
---|
| 530 | # @param $(pass) Lowercase pass name.
|
---|
| 531 | # @param $(PASS) Uppercase pass name.
|
---|
| 532 | # @param $(makefile) Makefile.
|
---|
| 533 | # @param $(tag) tag to attach to the rule name.
|
---|
| 534 | define def_pass_makefile
|
---|
| 535 | pass_$(pass)$(tag)::
|
---|
| 536 | $(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
|
---|
| 537 | endef
|
---|
[73] | 538 |
|
---|
[74] | 539 |
|
---|
[75] | 540 | ## Execute a pass.
|
---|
| 541 | # @param $(pass) Lowercase pass name.
|
---|
| 542 | # @param $(PASS) Uppercase pass name.
|
---|
| 543 | define def_pass
|
---|
| 544 | $(eval SUBDIRS_$(PASS) ?= $(SUBDIRS))
|
---|
| 545 | $(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER))
|
---|
| 546 | $(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE))
|
---|
| 547 | $(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER))
|
---|
| 548 |
|
---|
| 549 | $(eval tag:=_before)
|
---|
| 550 | $(foreach subdir,$(SUBDIRS_$(PASS)),$(eval $(def_pass_subdir)))
|
---|
| 551 | $(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)),$(eval $(def_pass_makefile)))
|
---|
| 552 |
|
---|
| 553 | $(eval tag:=_after)
|
---|
| 554 | $(foreach subdir,$(SUBDIRS_AFTER_$(PASS)),$(eval $(def_pass_subdir)))
|
---|
| 555 | $(foreach makefile,$(MAKEFILES_AFTER_$(PASS)),$(eval $(def_pass_makefile)))
|
---|
| 556 |
|
---|
| 557 | .NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
|
---|
| 558 | .PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
|
---|
| 559 | pass_$(pass): \
|
---|
| 560 | pass_$(pass)_before \
|
---|
| 561 | pass_$(pass)_doit \
|
---|
| 562 | pass_$(pass)_after
|
---|
| 563 |
|
---|
| 564 | endef
|
---|
| 565 |
|
---|
[76] | 566 |
|
---|
[75] | 567 | ## PASS: needed
|
---|
| 568 | # This pass builds targets which are required for building the rest.
|
---|
| 569 | pass_needed_doit: $(_NEEDEDS)
|
---|
| 570 | pass := needed
|
---|
| 571 | PASS := NEEDED
|
---|
| 572 | $(eval $(def_pass))
|
---|
| 573 |
|
---|
| 574 | ## PASS: libraries
|
---|
| 575 | # This pass builds library targets.
|
---|
| 576 | pass_libraries_doit: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
|
---|
| 577 | pass := libraries
|
---|
| 578 | PASS := LIBRARIES
|
---|
| 579 | $(eval $(def_pass))
|
---|
| 580 |
|
---|
| 581 | ## PASS: binaries
|
---|
| 582 | # This pass builds binary targets, i.e. programs, dlls, drivers and stuff.
|
---|
| 583 | pass_binaries_doit: $(_DLLS) $(_EXES) $(_KMODS) $(_OTHER_BINARIES)
|
---|
| 584 | pass := binaries
|
---|
| 585 | PASS := BINARIES
|
---|
| 586 | $(eval $(def_pass))
|
---|
| 587 |
|
---|
| 588 | ## PASS: others
|
---|
| 589 | # This pass builds binary targets, i.e. programs, dlls, drivers and stuff.
|
---|
| 590 | pass_others_doit: $(_OTHERS)
|
---|
| 591 | pass := others
|
---|
| 592 | PASS := OTHERS
|
---|
| 593 | $(eval $(def_pass))
|
---|
| 594 |
|
---|
| 595 | ## PASS: publish
|
---|
| 596 | # This pass installs the built entities to a sandbox area.
|
---|
| 597 | pass_publish_doit: publish
|
---|
| 598 | publish::
|
---|
| 599 | pass := publish
|
---|
| 600 | PASS := PUBLISH
|
---|
[76] | 601 | # $(sort).. not nice.
|
---|
[75] | 602 | SUBDIRS_PUBLISH ?= $(sort $(SUBDIRS) $(SUBDIRS_LIBRARIES) $(SUBDIRS_BINARIES) $(SUBDIRS_OTHERS))
|
---|
| 603 | SUBDIRS_AFTER_PUBLISH ?= $(sort $(SUBDIRS_AFTER) $(SUBDIRS_AFTER_LIBRARIES) $(SUBDIRS_AFTER_BINARIES) $(SUBDIRS_AFTER_OTHERS))
|
---|
| 604 | MAKEFILES_BEFORE_PUBLISH?= $(sort $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE_LIBRARIES) $(MAKEFILES_BEFORE_BINARIES) $(MAKEFILES_BEFORE_OTHERS))
|
---|
| 605 | MAKEFILES_AFTER_PUBLISH ?= $(sort $(MAKEFILES_AFTER) $(MAKEFILES_AFTER_LIBRARIES) $(MAKEFILES_AFTER_BINARIES) $(MAKEFILES_AFTER_OTHERS))
|
---|
| 606 | $(eval $(def_pass))
|
---|
| 607 |
|
---|
| 608 | ## PASS: packing
|
---|
| 609 | # This pass processes custom packing rules.
|
---|
| 610 | pass_packing_doit: packing
|
---|
| 611 | packing::
|
---|
| 612 | pass := packing
|
---|
| 613 | PASS := PACKING
|
---|
| 614 | $(eval $(def_pass))
|
---|
| 615 |
|
---|
| 616 | ## PASS: clean
|
---|
| 617 | # This pass removes all generated files.
|
---|
| 618 | pass_clean_doit:
|
---|
| 619 | $(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DIRFILES)
|
---|
| 620 | pass := clean
|
---|
| 621 | PASS := CLEAN
|
---|
| 622 | $(eval $(def_pass))
|
---|
| 623 | clean: pass_clean
|
---|
| 624 |
|
---|
| 625 | ## PASS: nothing
|
---|
| 626 | # This pass just walks the tree.
|
---|
| 627 | pass_nothing_doit:
|
---|
| 628 | $(call MSG_L1,Did nothing in $(CURDIR))
|
---|
| 629 | pass := nothing
|
---|
| 630 | PASS := NOTHING
|
---|
| 631 | $(eval $(def_pass))
|
---|
| 632 | nothing: pass_nothing
|
---|
| 633 |
|
---|
| 634 |
|
---|
| 635 |
|
---|
| 636 | #
|
---|
| 637 | # THE MAIN RULES
|
---|
| 638 | #
|
---|
| 639 | all_recursive: $(foreach pass,$(PASSES),pass_$(pass))
|
---|
| 640 |
|
---|
| 641 | # misc shortcuts.
|
---|
| 642 | target: needed libraries binaries others
|
---|
| 643 | objects: $(_OBJS)
|
---|
| 644 | programs: $(_EXES)
|
---|
| 645 | dlls: $(_DLLS)
|
---|
| 646 | kernelmodules: $(_KMODS)
|
---|
| 647 |
|
---|
| 648 |
|
---|
[72] | 649 | # end-of-file-content
|
---|
| 650 | __footer_kmk__ := 1
|
---|
| 651 | endif # __footer_kmk__
|
---|