| 1 | # $Id: header.kmk 135 2004-07-11 03:34:20Z 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 | 
 | 
|---|
| 41 | 
 | 
|---|
| 42 | #
 | 
|---|
| 43 | # General purpose macros.
 | 
|---|
| 44 | #
 | 
|---|
| 45 |                 
 | 
|---|
| 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 | #
 | 
|---|
| 53 | # Assert build type.
 | 
|---|
| 54 | #
 | 
|---|
| 55 | ifndef BUILD_TYPE
 | 
|---|
| 56 | ifndef BUILD_MODE
 | 
|---|
| 57 | $(error kBuild: You must define BUILD_TYPE!)
 | 
|---|
| 58 | endif
 | 
|---|
| 59 | BUILD_TYPE          := $(BUILD_MODE)
 | 
|---|
| 60 | endif
 | 
|---|
| 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
 | 
|---|
| 70 | 
 | 
|---|
| 71 | 
 | 
|---|
| 72 | #
 | 
|---|
| 73 | # Assert build platform.
 | 
|---|
| 74 | #
 | 
|---|
| 75 | _BUILD_PLATFORM_OK  := 0
 | 
|---|
| 76 | # OS/2
 | 
|---|
| 77 | ifeq ($(BUILD_PLATFORM),OS2)
 | 
|---|
| 78 | $(error kBuild: BUILD_PLATFORM must be all lowercase!)
 | 
|---|
| 79 | endif
 | 
|---|
| 80 | ifeq ($(BUILD_PLATFORM),os2)
 | 
|---|
| 81 | _BUILD_PLATFORM_OK  := 1
 | 
|---|
| 82 | endif
 | 
|---|
| 83 | 
 | 
|---|
| 84 | # Linux
 | 
|---|
| 85 | ifeq ($(BUILD_PLATFORM),LINUX)
 | 
|---|
| 86 | $(error kBuild: BUILD_PLATFORM must be all lowercase!)
 | 
|---|
| 87 | endif
 | 
|---|
| 88 | ifeq ($(BUILD_PLATFORM),linux)
 | 
|---|
| 89 | _BUILD_PLATFORM_OK  := 1
 | 
|---|
| 90 | endif
 | 
|---|
| 91 | 
 | 
|---|
| 92 | # Win32
 | 
|---|
| 93 | ifeq ($(BUILD_PLATFORM),WIN32)
 | 
|---|
| 94 | $(error kBuild: BUILD_PLATFORM must be all lowercase!)
 | 
|---|
| 95 | endif
 | 
|---|
| 96 | ifeq ($(BUILD_PLATFORM),win32)
 | 
|---|
| 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
 | 
|---|
| 103 | BUILD_PLATFORM_ARCH   := x86
 | 
|---|
| 104 | BUILD_PLATFORM_CPU    := i586
 | 
|---|
| 105 | 
 | 
|---|
| 106 | 
 | 
|---|
| 107 | #
 | 
|---|
| 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)
 | 
|---|
| 117 | $(error kBuild: BUILD_TARGET must be all lowercase!)
 | 
|---|
| 118 | endif
 | 
|---|
| 119 | ifeq ($(BUILD_TARGET),os2)
 | 
|---|
| 120 | _BUILD_TARGET_OK    := 1
 | 
|---|
| 121 | endif
 | 
|---|
| 122 | 
 | 
|---|
| 123 | # Linux
 | 
|---|
| 124 | ifeq ($(BUILD_TARGET),LINUX)
 | 
|---|
| 125 | $(error kBuild: BUILD_TARGET must be all lowercase!)
 | 
|---|
| 126 | endif
 | 
|---|
| 127 | ifeq ($(BUILD_TARGET),linux)
 | 
|---|
| 128 | _BUILD_TARGET_OK    := 1
 | 
|---|
| 129 | endif
 | 
|---|
| 130 | 
 | 
|---|
| 131 | # Win32
 | 
|---|
| 132 | ifeq ($(BUILD_TARGET),WIN32)
 | 
|---|
| 133 | $(error kBuild: BUILD_TARGET must be all lowercase!)
 | 
|---|
| 134 | endif
 | 
|---|
| 135 | ifeq ($(BUILD_TARGET),win32)
 | 
|---|
| 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
 | 
|---|
| 143 | BUILD_TARGET_ARCH   := x86
 | 
|---|
| 144 | BUILD_TARGET_CPU    := i586
 | 
|---|
| 145 | 
 | 
|---|
| 146 | 
 | 
|---|
| 147 | #
 | 
|---|
| 148 | # Common definitions.
 | 
|---|
| 149 | #
 | 
|---|
| 150 | PATH_CURRENT        := $(CURDIR)
 | 
|---|
| 151 | # Get the real root path.
 | 
|---|
| 152 | PATH_ROOT           := $(PATH_CURRENT)
 | 
|---|
| 153 | ifneq ($(DEPTH),.)
 | 
|---|
| 154 | $(foreach d,$(subst /, ,$(DEPTH)), $(eval PATH_ROOT := $(patsubst %/,%,$(dir $(PATH_ROOT)))) )
 | 
|---|
| 155 | endif
 | 
|---|
| 156 | # Subdirectory relative to the root.
 | 
|---|
| 157 | CURSUBDIR           := $(patsubst $(PATH_ROOT)/%,%,$(CURDIR))
 | 
|---|
| 158 | # Output directories.
 | 
|---|
| 159 | PATH_OUT            := $(PATH_ROOT)/out/$(BUILD_TARGET)/$(BUILD_TYPE)
 | 
|---|
| 160 | PATH_OBJ            := $(PATH_OUT)/obj
 | 
|---|
| 161 | PATH_BIN            := $(PATH_OUT)/bin
 | 
|---|
| 162 | PATH_LIB            := $(PATH_OUT)/lib
 | 
|---|
| 163 | PATH_DOC            := $(PATH_ROOT)/out/doc
 | 
|---|
| 164 | PATH_TARGET         := $(PATH_OBJ)/$(CURSUBDIR)
 | 
|---|
| 165 | 
 | 
|---|
| 166 | # Usually kBuild is external to the source tree.
 | 
|---|
| 167 | ifndef PATH_KBUILD
 | 
|---|
| 168 | PATH_KBUILD         := $(PATH_ROOT)/kBuild
 | 
|---|
| 169 | endif
 | 
|---|
| 170 | # kBuild tools
 | 
|---|
| 171 | PATH_TOOLS_W32      := $(PATH_KBUILD)/bin/x86.win32
 | 
|---|
| 172 | PATH_TOOLS_LNX      := $(PATH_KBUILD)/bin/x86.linux
 | 
|---|
| 173 | PATH_TOOLS_OS2      := $(PATH_KBUILD)/bin/x86.os2
 | 
|---|
| 174 | # kBuild files which might be of interest.
 | 
|---|
| 175 | FILE_KBUILD_HEADER  := $(PATH_KBUILD)/header.kmk
 | 
|---|
| 176 | FILE_KBUILD_CONFIG  := $(PATH_KBUILD)/config.kmk
 | 
|---|
| 177 | FILE_KBUILD_FOOTER  := $(PATH_KBUILD)/footer.kmk
 | 
|---|
| 178 | 
 | 
|---|
| 179 | SUFF_DEP            := .dep
 | 
|---|
| 180 | 
 | 
|---|
| 181 | 
 | 
|---|
| 182 | #
 | 
|---|
| 183 | # Get rid of the GNU Make default stuff
 | 
|---|
| 184 | #
 | 
|---|
| 185 | include $(PATH_KBUILD)/StampOutPredefines.kmk
 | 
|---|
| 186 | 
 | 
|---|
| 187 | 
 | 
|---|
| 188 | #
 | 
|---|
| 189 | # Build platform setup.
 | 
|---|
| 190 | #
 | 
|---|
| 191 | # OS/2
 | 
|---|
| 192 | ifeq ($(BUILD_PLATFORM),os2)
 | 
|---|
| 193 | PATH_TOOLS          := $(PATH_TOOLS_OS2)
 | 
|---|
| 194 | EXEC_X86_WIN32      := innopec.exe
 | 
|---|
| 195 | HOSTSUFF_EXE        := .exe
 | 
|---|
| 196 | endif
 | 
|---|
| 197 | 
 | 
|---|
| 198 | # Linux
 | 
|---|
| 199 | ifeq ($(BUILD_PLATFORM),linux)
 | 
|---|
| 200 | PATH_TOOLS          := $(PATH_TOOLS_LNX)
 | 
|---|
| 201 | EXEC_X86_WIN32      := wine
 | 
|---|
| 202 | HOSTSUFF_EXE        :=
 | 
|---|
| 203 | endif
 | 
|---|
| 204 | 
 | 
|---|
| 205 | # Win32
 | 
|---|
| 206 | ifeq ($(BUILD_PLATFORM),win32)
 | 
|---|
| 207 | PATH_TOOLS          := $(PATH_TOOLS_W32)
 | 
|---|
| 208 | EXEC_X86_WIN32      :=
 | 
|---|
| 209 | HOSTSUFF_EXE        := .exe
 | 
|---|
| 210 | endif
 | 
|---|
| 211 | 
 | 
|---|
| 212 | 
 | 
|---|
| 213 | #
 | 
|---|
| 214 | # Build target setup.
 | 
|---|
| 215 | #
 | 
|---|
| 216 | ifeq ($(BUILD_TARGET),os2)
 | 
|---|
| 217 | SUFF_OBJ            := .obj
 | 
|---|
| 218 | SUFF_LIB            := .lib
 | 
|---|
| 219 | SUFF_DLL            := .dll
 | 
|---|
| 220 | SUFF_EXE            := .exe
 | 
|---|
| 221 | SUFF_SYS            := .sys
 | 
|---|
| 222 | SUFF_RES            := .res
 | 
|---|
| 223 | endif
 | 
|---|
| 224 | ifeq ($(BUILD_TARGET),win32)
 | 
|---|
| 225 | SUFF_OBJ            := .obj
 | 
|---|
| 226 | SUFF_LIB            := .lib
 | 
|---|
| 227 | SUFF_DLL            := .dll
 | 
|---|
| 228 | SUFF_EXE            := .exe
 | 
|---|
| 229 | SUFF_SYS            := .sys
 | 
|---|
| 230 | SUFF_RES            := .res
 | 
|---|
| 231 | endif
 | 
|---|
| 232 | ifeq ($(BUILD_TARGET),linux)
 | 
|---|
| 233 | SUFF_OBJ            := .o
 | 
|---|
| 234 | SUFF_LIB            := .a
 | 
|---|
| 235 | SUFF_DLL            := .so
 | 
|---|
| 236 | SUFF_EXE            :=
 | 
|---|
| 237 | SUFF_SYS            := .a
 | 
|---|
| 238 | SUFF_RES            :=
 | 
|---|
| 239 | endif
 | 
|---|
| 240 | 
 | 
|---|
| 241 | 
 | 
|---|
| 242 | #
 | 
|---|
| 243 | # Standard kBuild tools.
 | 
|---|
| 244 | #
 | 
|---|
| 245 | DEP                 := $(PATH_TOOLS)/kDep$(HOSTSUFF_EXE)
 | 
|---|
| 246 | # Standard Unix shell utils.
 | 
|---|
| 247 | MKDIR               := $(PATH_TOOLS)/mkdir$(HOSTSUFF_EXE)
 | 
|---|
| 248 | RM                  := $(PATH_TOOLS)/rm$(HOSTSUFF_EXE)
 | 
|---|
| 249 | CP                  := $(PATH_TOOLS)/cp$(HOSTSUFF_EXE)
 | 
|---|
| 250 | MV                  := $(PATH_TOOLS)/mv$(HOSTSUFF_EXE)
 | 
|---|
| 251 | SED                 := $(PATH_TOOLS)/sed$(HOSTSUFF_EXE)
 | 
|---|
| 252 | CAT                 := $(PATH_TOOLS)/cat$(HOSTSUFF_EXE)
 | 
|---|
| 253 | # Bourn shell clone.
 | 
|---|
| 254 | MAKESHELL           := $(PATH_TOOLS)/ash$(HOSTSUFF_EXE)
 | 
|---|
| 255 | SHELL               := $(MAKESHELL)
 | 
|---|
| 256 | export SHELL MAKESHELL
 | 
|---|
| 257 | 
 | 
|---|
| 258 | 
 | 
|---|
| 259 | #
 | 
|---|
| 260 | # Message macros.
 | 
|---|
| 261 | #                       
 | 
|---|
| 262 |         
 | 
|---|
| 263 | ifndef BUILD_QUIET
 | 
|---|
| 264 | ifdef BUILD_DEBUG
 | 
|---|
| 265 | BUILD_VERBOSE := 9
 | 
|---|
| 266 | endif
 | 
|---|
| 267 | MSG_L1          = @echo "kBuild: $1"
 | 
|---|
| 268 | ifdef BUILD_VERBOSE
 | 
|---|
| 269 | MSG_L2          = @echo "kBuild: $1"
 | 
|---|
| 270 | QUIET           :=
 | 
|---|
| 271 | else
 | 
|---|
| 272 | QUIET           := @
 | 
|---|
| 273 | MSG_L2          =
 | 
|---|
| 274 | endif
 | 
|---|
| 275 | ifdef BUILD_DEBUG
 | 
|---|
| 276 | MSG_L3      = @echo "kBuild: $1"
 | 
|---|
| 277 | else
 | 
|---|
| 278 | MSG_L3      =
 | 
|---|
| 279 | endif
 | 
|---|
| 280 | else
 | 
|---|
| 281 | QUIET           :=
 | 
|---|
| 282 | MSG_L1          =
 | 
|---|
| 283 | MSG_L2      =
 | 
|---|
| 284 | MSG_L3      =
 | 
|---|
| 285 | endif
 | 
|---|
| 286 | 
 | 
|---|
| 287 | ## ABSPATH - make paths absolute.
 | 
|---|
| 288 | # This implementation is clumsy and doesn't resolve '..' and '.' components.
 | 
|---|
| 289 | #
 | 
|---|
| 290 | # @param        $1      The paths to make absolute.
 | 
|---|
| 291 | ABSPATH = $(foreach path,$(1)\
 | 
|---|
| 292 |             ,$(strip $(if $(subst <,,$(firstword $(subst /, ,<$(path)))),\
 | 
|---|
| 293 |                       $(if $(patsubst %:,,$(firstword $(subst :,: ,$(path)))),$(PATH_CURRENT)/$(path),$(path)),\
 | 
|---|
| 294 |                       $(path))))
 | 
|---|
| 295 | ## DIRDEP - make create directory dependencies.
 | 
|---|
| 296 | #
 | 
|---|
| 297 | # @param        $1      The paths to the directories which must be created.
 | 
|---|
| 298 | DIRDEP = $(foreach path,$(1),$(path)/.dir_created)
 | 
|---|
| 299 |                 
 | 
|---|
| 300 | 
 | 
|---|
| 301 | ## Cygwin kludge.
 | 
|---|
| 302 | # This converts /cygdrive/x/% to x:%.
 | 
|---|
| 303 | #
 | 
|---|
| 304 | # @param        $1      The paths to make native.
 | 
|---|
| 305 | # @remark       This macro is pretty much obsolete since we don't use cygwin base make.
 | 
|---|
| 306 | ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR))
 | 
|---|
| 307 | CYGPATHMIXED = $(foreach path,$(1)\
 | 
|---|
| 308 |    ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
 | 
|---|
| 309 | else
 | 
|---|
| 310 | CYGPATHMIXED = $(1)
 | 
|---|
| 311 | endif
 | 
|---|
| 312 | 
 | 
|---|
| 313 | #
 | 
|---|
| 314 | # This is how we find the closest config.kmk.
 | 
|---|
| 315 | # It's a little hacky but I think it works fine.
 | 
|---|
| 316 | #
 | 
|---|
| 317 | _CFGDIR     := .
 | 
|---|
| 318 | _CFGFILES   := ./Config.kmk ./config.kmk
 | 
|---|
| 319 | define def_include_config
 | 
|---|
| 320 | $(eval _CFGDIR := $(_CFGDIR)/$(dir))
 | 
|---|
| 321 | _CFGFILES   += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
 | 
|---|
| 322 | endef
 | 
|---|
| 323 | # walk down the _RELATIVE_ path specified by DEPTH.
 | 
|---|
| 324 | $(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
 | 
|---|
| 325 | # add the default config file.
 | 
|---|
| 326 | _CFGFILE    := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
 | 
|---|
| 327 | _CFGFILES   :=
 | 
|---|
| 328 | _CFGDIR     :=
 | 
|---|
| 329 | 
 | 
|---|
| 330 | # Include the config.kmk we found file (or the default one).
 | 
|---|
| 331 | include $(_CFGFILE)
 | 
|---|
| 332 | 
 | 
|---|
| 333 | 
 | 
|---|
| 334 | # end-of-file-content
 | 
|---|
| 335 | __header_kmk__ := 1
 | 
|---|
| 336 | endif # __header_kmk__
 | 
|---|