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