[69] | 1 | # $Id: header.kmk 292 2005-06-01 15:06:11Z 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 __header_kmk__
|
---|
| 28 | # start-of-file-content
|
---|
| 29 |
|
---|
| 30 | #
|
---|
| 31 | # default rule
|
---|
| 32 | #
|
---|
| 33 | all: all_recursive
|
---|
| 34 |
|
---|
| 35 | #
|
---|
| 36 | # Try avoid inference rules.
|
---|
| 37 | #
|
---|
| 38 | .SUFFIXES:
|
---|
| 39 | SUFFIXES :=
|
---|
| 40 |
|
---|
[72] | 41 |
|
---|
[69] | 42 | #
|
---|
[95] | 43 | # General purpose macros.
|
---|
| 44 | #
|
---|
[204] | 45 |
|
---|
[95] | 46 | ## get last word in a list.
|
---|
| 47 | # @returns last word in $1.
|
---|
| 48 | # @param $1 Word list.
|
---|
| 49 | lastword = $(word $(words $(1)), $(1))
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | #
|
---|
[72] | 53 | # Assert build type.
|
---|
[69] | 54 | #
|
---|
| 55 | ifndef BUILD_TYPE
|
---|
| 56 | ifndef BUILD_MODE
|
---|
[72] | 57 | $(error kBuild: You must define BUILD_TYPE!)
|
---|
[69] | 58 | endif
|
---|
| 59 | BUILD_TYPE := $(BUILD_MODE)
|
---|
| 60 | endif
|
---|
[72] | 61 | ifeq ($(BUILD_TYPE),DEBUG)
|
---|
| 62 | BUILD_TYPE := debug
|
---|
| 63 | endif
|
---|
| 64 | ifeq ($(BUILD_TYPE),RELEASE)
|
---|
| 65 | BUILD_TYPE := release
|
---|
| 66 | endif
|
---|
| 67 | ifeq ($(BUILD_TYPE),PROFILE)
|
---|
| 68 | BUILD_TYPE := profile
|
---|
| 69 | endif
|
---|
[69] | 70 |
|
---|
| 71 |
|
---|
| 72 | #
|
---|
[72] | 73 | # Assert build platform.
|
---|
[70] | 74 | #
|
---|
[72] | 75 | _BUILD_PLATFORM_OK := 0
|
---|
[271] | 76 | # OS/2 (have uppercase legacy)
|
---|
[72] | 77 | ifeq ($(BUILD_PLATFORM),OS2)
|
---|
[271] | 78 | override BUILD_PLATFORM := os2
|
---|
[72] | 79 | endif
|
---|
| 80 | ifeq ($(BUILD_PLATFORM),os2)
|
---|
| 81 | _BUILD_PLATFORM_OK := 1
|
---|
| 82 | endif
|
---|
[70] | 83 |
|
---|
[72] | 84 | # Linux
|
---|
| 85 | ifeq ($(BUILD_PLATFORM),LINUX)
|
---|
[88] | 86 | $(error kBuild: BUILD_PLATFORM must be all lowercase!)
|
---|
[72] | 87 | endif
|
---|
| 88 | ifeq ($(BUILD_PLATFORM),linux)
|
---|
| 89 | _BUILD_PLATFORM_OK := 1
|
---|
| 90 | endif
|
---|
| 91 |
|
---|
| 92 | # Win32
|
---|
| 93 | ifeq ($(BUILD_PLATFORM),WIN32)
|
---|
[88] | 94 | $(error kBuild: BUILD_PLATFORM must be all lowercase!)
|
---|
[72] | 95 | endif
|
---|
[83] | 96 | ifeq ($(BUILD_PLATFORM),win32)
|
---|
[72] | 97 | _BUILD_PLATFORM_OK := 1
|
---|
| 98 | endif
|
---|
| 99 |
|
---|
[292] | 100 | # L4
|
---|
| 101 | ifeq ($(BUILD_PLATFORM),L4)
|
---|
| 102 | $(error kBuild: BUILD_PLATFORM must be all lowercase!)
|
---|
| 103 | endif
|
---|
| 104 | ifeq ($(BUILD_PLATFORM),l4)
|
---|
| 105 | _BUILD_PLATFORM_OK := 1
|
---|
| 106 | endif
|
---|
| 107 |
|
---|
[72] | 108 | ifeq ($(_BUILD_PLATFORM_OK),0)
|
---|
| 109 | $(error kBuild: BUILD_PLATFORM value '$(BUILD_PLATFORM)' was not recongized!)
|
---|
| 110 | endif
|
---|
[95] | 111 | BUILD_PLATFORM_ARCH := x86
|
---|
| 112 | BUILD_PLATFORM_CPU := i586
|
---|
[72] | 113 |
|
---|
| 114 |
|
---|
[70] | 115 | #
|
---|
[72] | 116 | # Assert target platform.
|
---|
| 117 | #
|
---|
| 118 | ifndef BUILD_TARGET
|
---|
| 119 | # not defined, set to the same as build platform
|
---|
| 120 | BUILD_TARGET := $(BUILD_PLATFORM)
|
---|
| 121 | else
|
---|
| 122 | _BUILD_TARGET_OK := 0
|
---|
| 123 | # OS/2
|
---|
| 124 | ifeq ($(BUILD_TARGET),OS2)
|
---|
[88] | 125 | $(error kBuild: BUILD_TARGET must be all lowercase!)
|
---|
[72] | 126 | endif
|
---|
| 127 | ifeq ($(BUILD_TARGET),os2)
|
---|
| 128 | _BUILD_TARGET_OK := 1
|
---|
| 129 | endif
|
---|
| 130 |
|
---|
| 131 | # Linux
|
---|
| 132 | ifeq ($(BUILD_TARGET),LINUX)
|
---|
[88] | 133 | $(error kBuild: BUILD_TARGET must be all lowercase!)
|
---|
[72] | 134 | endif
|
---|
| 135 | ifeq ($(BUILD_TARGET),linux)
|
---|
| 136 | _BUILD_TARGET_OK := 1
|
---|
| 137 | endif
|
---|
| 138 |
|
---|
| 139 | # Win32
|
---|
| 140 | ifeq ($(BUILD_TARGET),WIN32)
|
---|
[88] | 141 | $(error kBuild: BUILD_TARGET must be all lowercase!)
|
---|
[72] | 142 | endif
|
---|
[77] | 143 | ifeq ($(BUILD_TARGET),win32)
|
---|
[72] | 144 | _BUILD_TARGET_OK := 1
|
---|
| 145 | endif
|
---|
| 146 |
|
---|
[292] | 147 | # L4
|
---|
| 148 | ifeq ($(BUILD_TARGET),L4)
|
---|
| 149 | $(error kBuild: BUILD_TARGET must be all lowercase!)
|
---|
| 150 | endif
|
---|
| 151 | ifeq ($(BUILD_TARGET),l4)
|
---|
| 152 | _BUILD_TARGET_OK := 1
|
---|
| 153 | endif
|
---|
| 154 |
|
---|
[72] | 155 | ifeq ($(_BUILD_TARGET_OK),0)
|
---|
| 156 | $(error kBuild: BUILD_TARGET value '$(BUILD_TARGET)' was not recongized!)
|
---|
| 157 | endif
|
---|
| 158 | endif
|
---|
[78] | 159 | BUILD_TARGET_ARCH := x86
|
---|
| 160 | BUILD_TARGET_CPU := i586
|
---|
[72] | 161 |
|
---|
[266] | 162 | # Adjust the DEPTH definition first
|
---|
| 163 | ifeq ($(strip $(DEPTH)),)
|
---|
| 164 | DEPTH := .
|
---|
| 165 | endif
|
---|
[72] | 166 |
|
---|
| 167 | #
|
---|
[69] | 168 | # Common definitions.
|
---|
| 169 | #
|
---|
| 170 | PATH_CURRENT := $(CURDIR)
|
---|
[70] | 171 | # Get the real root path.
|
---|
[85] | 172 | PATH_ROOT := $(PATH_CURRENT)
|
---|
[70] | 173 | ifneq ($(DEPTH),.)
|
---|
| 174 | $(foreach d,$(subst /, ,$(DEPTH)), $(eval PATH_ROOT := $(patsubst %/,%,$(dir $(PATH_ROOT)))) )
|
---|
[69] | 175 | endif
|
---|
[70] | 176 | # Subdirectory relative to the root.
|
---|
[266] | 177 | ifneq ($(DEPTH),.)
|
---|
[72] | 178 | CURSUBDIR := $(patsubst $(PATH_ROOT)/%,%,$(CURDIR))
|
---|
[266] | 179 | else
|
---|
| 180 | CURSUBDIR := .
|
---|
| 181 | endif
|
---|
[70] | 182 | # Output directories.
|
---|
[242] | 183 | ifndef PATH_OUT_BASE
|
---|
| 184 | PATH_OUT_BASE := $(PATH_ROOT)/out
|
---|
| 185 | endif
|
---|
[240] | 186 | ifndef PATH_OUT
|
---|
[245] | 187 | ifdef BUILD_TARGET_SUB # (BUILD_TARGET_SUB is not currently recognized by kBuild in any other places.)
|
---|
| 188 | PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET)/$(BUILD_TARGET_SUB)/$(BUILD_TYPE)
|
---|
| 189 | else
|
---|
[242] | 190 | PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET)/$(BUILD_TYPE)
|
---|
[240] | 191 | endif
|
---|
[245] | 192 | endif
|
---|
[69] | 193 | PATH_OBJ := $(PATH_OUT)/obj
|
---|
[271] | 194 | PATH_TARGET := $(PATH_OBJ)/$(CURSUBDIR)
|
---|
| 195 | ifndef KBUILD_NEW_STUFF
|
---|
[69] | 196 | PATH_BIN := $(PATH_OUT)/bin
|
---|
| 197 | PATH_LIB := $(PATH_OUT)/lib
|
---|
| 198 | PATH_DOC := $(PATH_ROOT)/out/doc
|
---|
[271] | 199 | else
|
---|
| 200 | PATH_INS := $(PATH_OUT)
|
---|
| 201 | PATH_BIN := $(PATH_INS)/bin
|
---|
| 202 | PATH_DLL := $(PATH_INS)/bin
|
---|
| 203 | PATH_LIB := $(PATH_INS)/lib
|
---|
| 204 | PATH_DOC := $(PATH_INS)/doc
|
---|
| 205 | endif
|
---|
[70] | 206 |
|
---|
| 207 | # Usually kBuild is external to the source tree.
|
---|
| 208 | ifndef PATH_KBUILD
|
---|
| 209 | PATH_KBUILD := $(PATH_ROOT)/kBuild
|
---|
| 210 | endif
|
---|
| 211 | # kBuild tools
|
---|
[69] | 212 | PATH_TOOLS_W32 := $(PATH_KBUILD)/bin/x86.win32
|
---|
| 213 | PATH_TOOLS_LNX := $(PATH_KBUILD)/bin/x86.linux
|
---|
| 214 | PATH_TOOLS_OS2 := $(PATH_KBUILD)/bin/x86.os2
|
---|
| 215 | # kBuild files which might be of interest.
|
---|
| 216 | FILE_KBUILD_HEADER := $(PATH_KBUILD)/header.kmk
|
---|
| 217 | FILE_KBUILD_CONFIG := $(PATH_KBUILD)/config.kmk
|
---|
| 218 | FILE_KBUILD_FOOTER := $(PATH_KBUILD)/footer.kmk
|
---|
| 219 |
|
---|
[72] | 220 | SUFF_DEP := .dep
|
---|
[204] | 221 | MAKEFILE := $(firstword $(MAKEFILE_LIST))
|
---|
[69] | 222 |
|
---|
[72] | 223 |
|
---|
[69] | 224 | #
|
---|
| 225 | # Get rid of the GNU Make default stuff
|
---|
| 226 | #
|
---|
[230] | 227 | ifndef KMK_VERSION
|
---|
[69] | 228 | include $(PATH_KBUILD)/StampOutPredefines.kmk
|
---|
[216] | 229 | endif
|
---|
[69] | 230 |
|
---|
| 231 | #
|
---|
[72] | 232 | # Build platform setup.
|
---|
[69] | 233 | #
|
---|
| 234 | # OS/2
|
---|
[72] | 235 | ifeq ($(BUILD_PLATFORM),os2)
|
---|
[69] | 236 | PATH_TOOLS := $(PATH_TOOLS_OS2)
|
---|
[83] | 237 | EXEC_X86_WIN32 := innopec.exe
|
---|
[69] | 238 | HOSTSUFF_EXE := .exe
|
---|
| 239 | endif
|
---|
| 240 |
|
---|
| 241 | # Linux
|
---|
[72] | 242 | ifeq ($(BUILD_PLATFORM),linux)
|
---|
[69] | 243 | PATH_TOOLS := $(PATH_TOOLS_LNX)
|
---|
[135] | 244 | EXEC_X86_WIN32 := wine
|
---|
[69] | 245 | HOSTSUFF_EXE :=
|
---|
| 246 | endif
|
---|
[70] | 247 |
|
---|
[69] | 248 | # Win32
|
---|
[72] | 249 | ifeq ($(BUILD_PLATFORM),win32)
|
---|
[69] | 250 | PATH_TOOLS := $(PATH_TOOLS_W32)
|
---|
| 251 | EXEC_X86_WIN32 :=
|
---|
| 252 | HOSTSUFF_EXE := .exe
|
---|
| 253 | endif
|
---|
| 254 |
|
---|
[125] | 255 |
|
---|
[73] | 256 | #
|
---|
| 257 | # Build target setup.
|
---|
| 258 | #
|
---|
| 259 | ifeq ($(BUILD_TARGET),os2)
|
---|
| 260 | SUFF_OBJ := .obj
|
---|
| 261 | SUFF_LIB := .lib
|
---|
| 262 | SUFF_DLL := .dll
|
---|
| 263 | SUFF_EXE := .exe
|
---|
[86] | 264 | SUFF_SYS := .sys
|
---|
[73] | 265 | SUFF_RES := .res
|
---|
| 266 | endif
|
---|
| 267 | ifeq ($(BUILD_TARGET),win32)
|
---|
| 268 | SUFF_OBJ := .obj
|
---|
| 269 | SUFF_LIB := .lib
|
---|
| 270 | SUFF_DLL := .dll
|
---|
| 271 | SUFF_EXE := .exe
|
---|
[86] | 272 | SUFF_SYS := .sys
|
---|
[73] | 273 | SUFF_RES := .res
|
---|
| 274 | endif
|
---|
| 275 | ifeq ($(BUILD_TARGET),linux)
|
---|
| 276 | SUFF_OBJ := .o
|
---|
| 277 | SUFF_LIB := .a
|
---|
| 278 | SUFF_DLL := .so
|
---|
| 279 | SUFF_EXE :=
|
---|
[86] | 280 | SUFF_SYS := .a
|
---|
[73] | 281 | SUFF_RES :=
|
---|
| 282 | endif
|
---|
[69] | 283 |
|
---|
[73] | 284 |
|
---|
[69] | 285 | #
|
---|
| 286 | # Standard kBuild tools.
|
---|
| 287 | #
|
---|
| 288 | DEP := $(PATH_TOOLS)/kDep$(HOSTSUFF_EXE)
|
---|
[262] | 289 | DEP_PRE := $(PATH_TOOLS)/kDepPre$(HOSTSUFF_EXE)
|
---|
[233] | 290 | ifeq ($(MAKE),kmk)
|
---|
| 291 | MAKE := $(PATH_TOOLS)/kmk$(HOSTSUFF_EXE)
|
---|
| 292 | endif
|
---|
| 293 |
|
---|
[69] | 294 | # Standard Unix shell utils.
|
---|
[230] | 295 | ifdef KMK_BUILTIN
|
---|
| 296 | ECHO := kmk_builtin_echo
|
---|
| 297 | MKDIR := kmk_builtin_mkdir
|
---|
| 298 | RM := kmk_builtin_rm
|
---|
| 299 | CP := kmk_builtin_cp
|
---|
| 300 | else
|
---|
| 301 | ECHO := echo
|
---|
[69] | 302 | MKDIR := $(PATH_TOOLS)/mkdir$(HOSTSUFF_EXE)
|
---|
| 303 | RM := $(PATH_TOOLS)/rm$(HOSTSUFF_EXE)
|
---|
[87] | 304 | CP := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
|
---|
[230] | 305 | endif
|
---|
[237] | 306 | CP_EXT := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
|
---|
[87] | 307 | MV := $(PATH_TOOLS)/mv$(HOSTSUFF_EXE)
|
---|
[69] | 308 | SED := $(PATH_TOOLS)/sed$(HOSTSUFF_EXE)
|
---|
| 309 | CAT := $(PATH_TOOLS)/cat$(HOSTSUFF_EXE)
|
---|
| 310 | # Bourn shell clone.
|
---|
| 311 | MAKESHELL := $(PATH_TOOLS)/ash$(HOSTSUFF_EXE)
|
---|
| 312 | SHELL := $(MAKESHELL)
|
---|
| 313 | export SHELL MAKESHELL
|
---|
| 314 |
|
---|
| 315 |
|
---|
| 316 | #
|
---|
[73] | 317 | # Message macros.
|
---|
[204] | 318 | #
|
---|
| 319 |
|
---|
[73] | 320 | ifndef BUILD_QUIET
|
---|
[75] | 321 | ifdef BUILD_DEBUG
|
---|
| 322 | BUILD_VERBOSE := 9
|
---|
| 323 | endif
|
---|
[230] | 324 | MSG_L1 = @$(ECHO) "kBuild: $1"
|
---|
[73] | 325 | ifdef BUILD_VERBOSE
|
---|
[230] | 326 | MSG_L2 = @$(ECHO) "kBuild: $1"
|
---|
[75] | 327 | QUIET :=
|
---|
[73] | 328 | else
|
---|
[75] | 329 | QUIET := @
|
---|
[73] | 330 | MSG_L2 =
|
---|
| 331 | endif
|
---|
| 332 | ifdef BUILD_DEBUG
|
---|
[230] | 333 | MSG_L3 = @$(ECHO) "kBuild: $1"
|
---|
[73] | 334 | else
|
---|
| 335 | MSG_L3 =
|
---|
| 336 | endif
|
---|
| 337 | else
|
---|
[75] | 338 | QUIET :=
|
---|
[73] | 339 | MSG_L1 =
|
---|
| 340 | MSG_L2 =
|
---|
| 341 | MSG_L3 =
|
---|
| 342 | endif
|
---|
| 343 |
|
---|
[130] | 344 | ## ABSPATH - make paths absolute.
|
---|
[129] | 345 | # This implementation is clumsy and doesn't resolve '..' and '.' components.
|
---|
[73] | 346 | #
|
---|
[129] | 347 | # @param $1 The paths to make absolute.
|
---|
| 348 | ABSPATH = $(foreach path,$(1)\
|
---|
| 349 | ,$(strip $(if $(subst <,,$(firstword $(subst /, ,<$(path)))),\
|
---|
| 350 | $(if $(patsubst %:,,$(firstword $(subst :,: ,$(path)))),$(PATH_CURRENT)/$(path),$(path)),\
|
---|
| 351 | $(path))))
|
---|
[130] | 352 | ## DIRDEP - make create directory dependencies.
|
---|
| 353 | #
|
---|
| 354 | # @param $1 The paths to the directories which must be created.
|
---|
| 355 | DIRDEP = $(foreach path,$(1),$(path)/.dir_created)
|
---|
[129] | 356 |
|
---|
[204] | 357 |
|
---|
[129] | 358 | ## Cygwin kludge.
|
---|
| 359 | # This converts /cygdrive/x/% to x:%.
|
---|
| 360 | #
|
---|
| 361 | # @param $1 The paths to make native.
|
---|
| 362 | # @remark This macro is pretty much obsolete since we don't use cygwin base make.
|
---|
| 363 | ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR))
|
---|
| 364 | CYGPATHMIXED = $(foreach path,$(1)\
|
---|
| 365 | ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
|
---|
| 366 | else
|
---|
| 367 | CYGPATHMIXED = $(1)
|
---|
| 368 | endif
|
---|
| 369 |
|
---|
| 370 | #
|
---|
[69] | 371 | # This is how we find the closest config.kmk.
|
---|
| 372 | # It's a little hacky but I think it works fine.
|
---|
[70] | 373 | #
|
---|
| 374 | _CFGDIR := .
|
---|
[78] | 375 | _CFGFILES := ./Config.kmk ./config.kmk
|
---|
[69] | 376 | define def_include_config
|
---|
[78] | 377 | $(eval _CFGDIR := $(_CFGDIR)/$(dir))
|
---|
| 378 | _CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
|
---|
[69] | 379 | endef
|
---|
| 380 | # walk down the _RELATIVE_ path specified by DEPTH.
|
---|
[78] | 381 | $(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
|
---|
[69] | 382 | # add the default config file.
|
---|
[78] | 383 | _CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
|
---|
[69] | 384 | _CFGFILES :=
|
---|
| 385 | _CFGDIR :=
|
---|
| 386 |
|
---|
| 387 | # Include the config.kmk we found file (or the default one).
|
---|
| 388 | include $(_CFGFILE)
|
---|
| 389 |
|
---|
| 390 |
|
---|
| 391 | # end-of-file-content
|
---|
[72] | 392 | __header_kmk__ := 1
|
---|
[69] | 393 | endif # __header_kmk__
|
---|