source: trunk/kBuild/header.kmk@ 568

Last change on this file since 568 was 557, checked in by bird, 19 years ago

Initial Mac OS X / Darwin bootstrapping.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.5 KB
Line 
1# $Id: header.kmk 557 2006-09-28 15:56:25Z bird $
2## @file
3#
4# kBuild - File included at top of makefile.
5#
6# Copyright (c) 2004-2005 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
27ifndef __header_kmk__
28# start-of-file-content
29
30#
31# default rule
32#
33all: all_recursive
34
35#
36# The FORCE rule.
37#
38FORCE:
39
40#
41# Try avoid inference rules.
42#
43.SUFFIXES:
44SUFFIXES :=
45
46
47#
48# General purpose macros.
49#
50
51## get last word in a list.
52# @returns last word in $1.
53# @param $1 Word list.
54lastword = $(word $(words $(1)), $(1))
55
56##
57# Newline character(s).
58define NL
59
60
61endef
62
63##
64# Tab character.
65TAB := $(subst ., ,.)
66
67##
68# Space character.
69SP := $(subst ., ,.)
70
71##
72# Checks if two strings are equal.
73# @returns blank if equal
74# @returns non-blank if not equal.
75# @param $1 String 1.
76# @param $2 String 2
77STRCMP = $( todo )
78
79#
80# Assert build type.
81#
82ifndef BUILD_TYPE
83ifndef BUILD_MODE
84$(error kBuild: You must define BUILD_TYPE!)
85endif
86BUILD_TYPE := $(BUILD_MODE)
87endif
88ifeq ($(BUILD_TYPE),DEBUG)
89BUILD_TYPE := debug
90endif
91ifeq ($(BUILD_TYPE),RELEASE)
92BUILD_TYPE := release
93endif
94ifeq ($(BUILD_TYPE),PROFILE)
95BUILD_TYPE := profile
96endif
97
98
99#
100# Assert build platform.
101#
102ifndef BUILD_PLATFORM
103 $(error kBuild: BUILD_PLATFORM is undefined!)
104else
105 BUILD_PLATFORM := $(strip $(BUILD_PLATFORM))
106 ifneq ($(words $(BUILD_PLATFORM))$(filter-out darwin freebsd l4 linux nt os2 win win32 win64,$(BUILD_PLATFORM)),1)
107 # OS/2 (have uppercase legacy)
108 ifeq ($(BUILD_PLATFORM),OS2)
109 $(error kBuild: BUILD_PLATFORM must be all lowercase!)
110 endif
111 $(error kBuild: BUILD_PLATFORM value '$(BUILD_PLATFORM)' was not recognized!)
112 endif
113endif
114
115# Fill in defaults if needed.
116ifndef BUILD_PLATFORM_ARCH
117 ifeq ($(filter-out win64,$(BUILD_PLATFORM)),)
118 BUILD_PLATFORM_ARCH := amd64
119 else
120 BUILD_PLATFORM_ARCH := x86
121 endif
122endif
123ifndef BUILD_PLATFORM_CPU
124 ifeq ($(filter-out amd64,$(BUILD_PLATFORM_ARCH)),)
125 BUILD_PLATFORM_CPU:= k8
126 else
127 BUILD_PLATFORM_CPU:= i586
128 endif
129endif
130
131
132#
133# Assert target platform.
134#
135ifndef BUILD_TARGET
136# not defined, set to the same as build platform
137BUILD_TARGET := $(BUILD_PLATFORM)
138else
139 BUILD_TARGET := $(strip $(BUILD_TARGET))
140 ifneq ($(words $(BUILD_TARGET))$(filter-out darwin freebsd l4 linux nt os2 win win32 win64,$(BUILD_TARGET)),1)
141 # OS/2 (have uppercase legacy)
142 ifeq ($(BUILD_TARGET),OS2)
143 $(error kBuild: BUILD_TARGET must be all lowercase!)
144 endif
145 $(error kBuild: BUILD_TARGET value '$(BUILD_TARGET)' was not recognized!)
146 endif
147endif
148
149# Fill in defaults if needed.
150ifndef BUILD_TARGET_ARCH
151 BUILD_TARGET_ARCH := x86
152endif
153ifndef BUILD_TARGET_CPU
154 BUILD_TARGET_CPU := i586
155endif
156
157# Adjust the DEPTH definition first
158ifeq ($(strip $(DEPTH)),)
159DEPTH := .
160endif
161
162#
163# Common definitions.
164#
165PATH_CURRENT := $(abspath $(CURDIR))
166ifneq ($(strip $(SUB_DEPTH)),)
167PATH_SUB_CURRENT := $(abspath $(PATH_CURRENT)/$(SUB_DEPTH))
168else
169PATH_SUB_CURRENT := $(PATH_CURRENT)
170endif
171PATH_ROOT := $(abspath $(PATH_CURRENT)/$(DEPTH))
172
173# Subdirectory relative to the root.
174ifneq ($(PATH_ROOT),$(PATH_CURRENT))
175CURSUBDIR := $(patsubst $(PATH_ROOT)/%,%,$(PATH_SUB_CURRENT))
176else
177CURSUBDIR := .
178endif
179
180# Output directories.
181ifndef PATH_OUT_BASE
182PATH_OUT_BASE := $(PATH_ROOT)/out
183endif
184ifndef PATH_OUT
185ifdef BUILD_TARGET_SUB # (BUILD_TARGET_SUB is not currently recognized by kBuild in any other places.)
186PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET).$(BUILD_TARGET_ARCH).$(BUILD_TARGET_SUB)/$(BUILD_TYPE)
187else
188PATH_OUT := $(PATH_OUT_BASE)/$(BUILD_TARGET).$(BUILD_TARGET_ARCH)/$(BUILD_TYPE)
189endif
190endif # !define PATH_OUT
191PATH_OBJ = $(PATH_OUT)/obj
192PATH_TARGET = $(PATH_OBJ)/$(CURSUBDIR)
193PATH_INS = $(PATH_OUT)
194PATH_BIN = $(PATH_INS)/bin
195PATH_DLL = $(PATH_INS)/bin
196PATH_SYS = $(PATH_INS)/bin
197PATH_LIB = $(PATH_INS)/lib
198PATH_DOC = $(PATH_INS)/doc
199
200# Usually kBuild is external to the source tree.
201ifndef PATH_KBUILD
202PATH_KBUILD := $(PATH_ROOT)/kBuild
203endif
204PATH_KBUILD := $(abspath $(PATH_KBUILD))
205# kBuild files which might be of interest.
206FILE_KBUILD_HEADER := $(PATH_KBUILD)/header.kmk
207FILE_KBUILD_CONFIG := $(PATH_KBUILD)/config.kmk
208FILE_KBUILD_FOOTER := $(PATH_KBUILD)/footer.kmk
209
210SUFF_DEP := .dep
211MAKEFILE := $(firstword $(MAKEFILE_LIST))
212
213
214#
215# Disable some features and stamp out predefines if we're running
216# vanilla GNU Make.
217#
218ifndef KMK_VERSION
219NO_COMPILE_CMDS_DEPS:= 1
220NO_LINK_CMDS_DEPS := 1
221include $(PATH_KBUILD)/StampOutPredefines.kmk
222endif
223
224#
225# Build platform setup.
226#
227# OS/2
228ifeq ($(BUILD_PLATFORM),os2)
229EXEC_X86_WIN32 := innopec.exe
230HOSTSUFF_EXE := .exe
231endif
232
233# Linux
234ifeq ($(BUILD_PLATFORM),linux)
235EXEC_X86_WIN32 := wine
236HOSTSUFF_EXE :=
237endif
238
239# Win, Win32, Win64, NT.
240ifeq ($(filter-out win32 win64 win nt,$(BUILD_PLATFORM)),)
241EXEC_X86_WIN32 :=
242HOSTSUFF_EXE := .exe
243endif
244
245# FreeBSD
246ifeq ($(BUILD_PLATFORM),freebsd)
247EXEC_X86_WIN32 := wine
248HOSTSUFF_EXE :=
249endif
250
251# Darwin / Mac OS X
252ifeq ($(BUILD_PLATFORM),darwin)
253EXEC_X86_WIN32 := false
254HOSTSUFF_EXE :=
255endif
256
257
258PATH_TOOLS := $(PATH_KBUILD)/bin/$(BUILD_PLATFORM_ARCH).$(BUILD_PLATFORM)
259ifeq ($(wildcard $(PATH_TOOLS)/kmk_ash$(HOSTSUFF_EXE)),)
260 ifeq ($(BUILD_TARGET_ARCH),amd64)
261 PATH_TOOLS := $(PATH_KBUILD)/bin/x86.$(BUILD_PLATFORM)
262 endif
263 ifeq ($(wildcard $(PATH_TOOLS)/kmk_ash$(HOSTSUFF_EXE)),)
264 ifeq ($(filter-out win64 win nt ,$(BUILD_PLATFORM)),)
265 PATH_TOOLS := $(PATH_KBUILD)/bin/x86.win32
266 endif
267 endif
268 ifeq ($(wildcard $(PATH_TOOLS)/kmk_ash$(HOSTSUFF_EXE)),)
269 # give up
270 PATH_TOOLS := $(PATH_KBUILD)/bin/$(BUILD_PLATFORM_ARCH).$(BUILD_PLATFORM)
271 endif
272endif
273
274
275#
276# Build target setup.
277#
278ifeq ($(filter-out win32 win64 win nt os2,$(BUILD_TARGET)),)
279SUFF_OBJ := .obj
280SUFF_LIB := .lib
281SUFF_DLL := .dll
282SUFF_EXE := .exe
283SUFF_SYS := .sys
284SUFF_RES := .res
285endif
286ifeq ($(BUILD_TARGET),l4)
287SUFF_OBJ := .o
288SUFF_LIB := .a
289SUFF_DLL := .s.so
290SUFF_EXE :=
291SUFF_SYS := .a
292SUFF_RES :=
293endif
294ifeq ($(BUILD_TARGET),darwin)
295SUFF_OBJ := .o
296SUFF_LIB := .a
297SUFF_DLL := .dylib
298SUFF_EXE :=
299SUFF_SYS := .a
300SUFF_RES :=
301endif
302ifndef SUFF_OBJ
303SUFF_OBJ := .o
304SUFF_LIB := .a
305SUFF_DLL := .so
306SUFF_EXE :=
307SUFF_SYS := .a
308SUFF_RES :=
309endif
310
311#
312# Standard kBuild tools.
313#
314ifeq ($(MAKE),kmk)
315MAKE := $(PATH_TOOLS)/kmk$(HOSTSUFF_EXE)
316endif
317
318DEP_EXT := $(PATH_TOOLS)/kDep$(HOSTSUFF_EXE)
319ifeq ($(filter kDep,$(KMK_BUILTIN)),kDep)
320DEP := kmk_builtin_kDep
321else
322DEP := $(DEP_EXT)
323endif
324
325DEP_IDB_EXT := $(PATH_TOOLS)/kDepIDB$(HOSTSUFF_EXE)
326ifeq ($(filter kDepPre,$(KMK_BUILTIN)),kDepIDB)
327DEP_IDB := $(if kmk_builtin_kDepIDB
328else
329DEP_IDB := $(DEP_IDB_EXT)
330endif
331
332DEP_PRE_EXT := $(PATH_TOOLS)/kDepPre$(HOSTSUFF_EXE)
333ifeq ($(filter kDepPre,$(KMK_BUILTIN)),kDepPre)
334DEP_PRE := $(if kmk_builtin_kDepPre
335else
336DEP_PRE := $(DEP_PRE_EXT)
337endif
338
339APPEND_EXT := $(PATH_TOOLS)/kmk_append$(HOSTSUFF_EXE)
340ifeq ($(filter append,$(KMK_BUILTIN)),append)
341APPEND := kmk_builtin_append
342else
343APPEND := $(APPEND_EXT)
344endif
345
346CAT_EXT := $(PATH_TOOLS)/kmk_cat$(HOSTSUFF_EXE)
347ifeq ($(filter cat,$(KMK_BUILTIN)),cat)
348CAT := kmk_builtin_cat
349else
350CAT := $(CAT_EXT)
351endif
352
353CP_EXT := $(PATH_TOOLS)/kmk_cp$(HOSTSUFF_EXE)
354ifeq ($(filter cp,$(KMK_BUILTIN)),cp)
355CP := kmk_builtin_cp
356else
357CP := $(CP_EXT)
358endif
359
360ECHO_EXT := $(PATH_TOOLS)/kmk_echo$(HOSTSUFF_EXE)
361ifeq ($(filter echo,$(KMK_BUILTIN)),echo)
362ECHO := kmk_builtin_echo
363else
364ECHO := $(ECHO_EXT)
365endif
366
367INSTALL_EXT := $(PATH_TOOLS)/kmk_install$(HOSTSUFF_EXE)
368ifeq ($(filter install,$(KMK_BUILTIN)),install)
369INSTALL := kmk_builtin_install
370else
371INSTALL := $(INSTALL_EXT)
372endif
373
374LN_EXT := $(PATH_TOOLS)/kmk_ln$(HOSTSUFF_EXE)
375ifeq ($(filter ln,$(KMK_BUILTIN)),ln)
376LN := kmk_builtin_ln
377else
378LN := $(LN_EXT)
379endif
380
381MKDIR_EXT := $(PATH_TOOLS)/kmk_mkdir$(HOSTSUFF_EXE)
382ifeq ($(filter mkdir,$(KMK_BUILTIN)),mkdir)
383MKDIR := kmk_builtin_mkdir
384else
385MKDIR := $(MKDIR_EXT)
386endif
387
388MV_EXT := $(PATH_TOOLS)/kmk_mv$(HOSTSUFF_EXE)
389ifeq ($(filter mv,$(KMK_BUILTIN)),mv)
390MV := kmk_builtin_mv
391else
392MV := $(MV_EXT)
393endif
394
395RM_EXT := $(PATH_TOOLS)/kmk_rm$(HOSTSUFF_EXE)
396ifeq ($(filter rm,$(KMK_BUILTIN)),rm)
397RM := kmk_builtin_rm
398else
399RM := $(RM_EXT)
400endif
401
402SED_EXT := $(PATH_TOOLS)/kmk_sed$(HOSTSUFF_EXE)
403ifeq ($(filter sed,$(KMK_BUILTIN)),sed)
404SED := kmk_builtin_sed
405else
406SED := $(SED_EXT)
407endif
408
409# Our default shell is the Almquist shell from *BSD.
410ASH := $(PATH_TOOLS)/kmk_ash$(HOSTSUFF_EXE)
411MAKESHELL := $(ASH)
412SHELL := $(ASH)
413export SHELL MAKESHELL
414
415# Symlinking is problematic on some platforms...
416LN_SYMLINK := $(LN) -s
417
418
419
420#
421# Message macros.
422#
423
424ifndef BUILD_QUIET
425ifdef BUILD_DEBUG
426BUILD_VERBOSE := 9
427endif
428MSG_L1 = @$(ECHO) "kBuild: $1"
429ifdef BUILD_VERBOSE
430MSG_L2 = @$(ECHO) "kBuild: $1"
431QUIET :=
432else
433QUIET := @
434MSG_L2 =
435endif
436ifdef BUILD_DEBUG
437MSG_L3 = @$(ECHO) "kBuild: $1"
438else
439MSG_L3 =
440endif
441else
442QUIET :=
443MSG_L1 =
444MSG_L2 =
445MSG_L3 =
446endif
447
448## ABSPATH - make paths absolute.
449# This implementation is clumsy and doesn't resolve '..' and '.' components.
450#
451# @param $1 The paths to make absolute.
452ABSPATH = $(abspath $(1))
453
454## DIRDEP - make create directory dependencies.
455#
456# @param $1 The paths to the directories which must be created.
457DIRDEP = $(foreach path,$(patsubst %/,%,$(1)),$(path)/)
458
459
460## Cygwin kludge.
461# This converts /cygdrive/x/% to x:%.
462#
463# @param $1 The paths to make native.
464# @remark This macro is pretty much obsolete since we don't use cygwin base make.
465ifneq ($(patsubst /cygdrive/%,%,$(CURDIR)),$(CURDIR))
466CYGPATHMIXED = $(foreach path,$(1)\
467 ,$(if $(patsubst /cygdrive/%,,$(path)),$(path),$(patsubst $(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path)))))/%,$(strip $(firstword $(subst /, ,$(patsubst /cygdrive/%,%,$(path))))):/%,$(patsubst /cygdrive/%,%,$(path)))))
468else
469CYGPATHMIXED = $(1)
470endif
471
472#
473# Initialize some of the globals which the Config.kmk and
474# others can add stuff to if they like for processing in the footer.
475#
476
477## ALL_TARGET
478# This is the list of all targets.
479ALL_TARGETS :=
480
481## TEMPLATE_PATHS
482# List a paths (separated by space) where templates can be found.
483TEMPLATE_PATHS :=
484
485## TOOL_PATHS
486# List of paths (separated by space) where tools can be found.
487TOOL_PATHS :=
488
489## SDK_PATHS
490# List of paths (separated by space) where SDKs can be found.
491SDK_PATHS :=
492
493## Proritized list of the default makefile when walking subdirectories.
494# The user can overload this list.
495DEFAULT_MAKEFILE := Makefile.kmk makefile.kmk Makefile makefile
496
497## PROPS_SINGLE
498# The list of non-accumulative target properties.
499# A Config.kmk file can add it's own properties to this list and kBuild
500# will do the necessary inheritance from templates to targets.
501PROPS_SINGLE := TOOL ARTOOL CTOOL CXXTOOL ASTOOL LDTOOL INST NOINST
502
503## PROPS_DEFERRED
504# This list of non-accumulative target properties which are functions,
505# and thus should not be expanded until the very last moment.
506PROPS_DEFERRED := INSTFUN INSTALLER
507
508## PROPS_ACCUMULATE
509# The list of accumulative target properties.
510# A Config.kmk file can add it's own properties to this list and kBuild
511# will do the necessary inheritance from templates to targets.
512PROPS_ACCUMULATE := \
513 SDKS DEFS DEPS INCS SOURCES \
514 COPTS CFLAGS CDEFS CINCS CXXOPTS CXXFLAGS CXXDEFS CXXINCS \
515 ASOPTS ASFLAGS ASDEFS ASINCS \
516 LDFLAGS LIBS LIBPATH \
517 BLD_TYPE BLD_TRG BLD_TRG_ARCH BLD_TRG_CPU \
518 SYSSUFF EXESUFF DLLSUFF LIBSUFF ARLIBSUFF \
519
520
521## PROPS_TOOLS
522# This is a subset of the other PROPS
523PROPS_TOOLS := TOOL CTOOL CXXTOOL ASTOOL ARTOOL LDTOOL
524
525
526#
527# Pass configuration.
528#
529# The PASS_<passname>_trgs variable is listing the targets.
530# The PASS_<passname>_vars variable is listing the target variables.
531# The PASS_<passname>_pass variable is the lowercased passname.
532#
533
534## PASS: bldprogs
535# This pass builds targets which are required for building the rest.
536PASS_BLDPROGS := Build Programs
537PASS_BLDPROGS_trgs :=
538PASS_BLDPROGS_vars := _BLDPROGS
539PASS_BLDPROGS_pass := bldprogs
540
541## PASS: libraries
542# This pass builds library targets.
543PASS_LIBRARIES := Libraries
544PASS_LIBRARIES_trgs :=
545PASS_LIBRARIES_vars := _LIBS _IMPORT_LIBS _OTHER_LIBRARIES
546PASS_LIBRARIES_pass := libraries
547
548## PASS: binaries
549# This pass builds dll targets.
550PASS_DLLS := DLLs
551PASS_DLLS_trgs :=
552PASS_DLLS_vars := _DLLS _OTHER_DLLS
553PASS_DLLS_pass := dlls
554
555## PASS: binaries
556# This pass builds binary targets, i.e. programs, system modules and stuff.
557PASS_BINARIES := Programs
558PASS_BINARIES_trgs :=
559PASS_BINARIES_vars := _PROGRAMS _SYSMODS _OTHER_BINARIES
560PASS_BINARIES_pass := binaries
561
562## PASS: others
563# This pass builds other targets.
564PASS_OTHERS := Other Stuff
565PASS_OTHERS_trgs :=
566PASS_OTHERS_vars := _OTHERS
567PASS_OTHERS_pass := others
568
569## PASS: install
570# This pass installs the built entities to a sandbox area.
571PASS_INSTALLS := Install
572PASS_INSTALLS_trgs :=
573PASS_INSTALLS_vars := _INSTALLS_DIRS _INSTALLS
574PASS_INSTALLS_pass := installs
575
576## PASS: packing
577# This pass processes custom packing rules.
578PASS_PACKING := Packing
579PASS_PACKING_trgs :=
580PASS_PACKING_vars := _PACKING
581PASS_PACKING_pass := packing
582#alias
583packing: pass_packing
584
585## PASS: clean
586# This pass removes all generated files.
587PASS_CLEAN := Clean
588PASS_CLEAN_trgs := do-clean
589PASS_CLEAN_vars :=
590PASS_CLEAN_pass := clean
591# alias
592clean: pass_clean
593
594## PASS: nothing
595# This pass just walks the tree.
596PASS_NOTHING := Nothing
597PASS_NOTHING_trgs := do-nothing
598PASS_NOTHING_vars :=
599PASS_NOTHING_pass := nothing
600# alias
601nothing: pass_nothing
602
603## DEFAULT_PASSES
604# The default passes and their order.
605DEFAULT_PASSES := BLDPROGS LIBRARIES DLLS BINARIES OTHERS INSTALLS
606
607## PASSES
608# The passes that should be defined. This must include
609# all passes mentioned by DEFAULT_PASSES.
610PASSES := $(DEFAULT_PASSES) NOTHING CLEAN
611
612
613#
614# This is how we find the closest config.kmk.
615# It's a little hacky but I think it works fine.
616#
617_CFGDIR := .
618_CFGFILES := ./Config.kmk ./config.kmk
619define def_include_config
620$(eval _CFGDIR := $(_CFGDIR)/$(dir))
621_CFGFILES += $(_CFGDIR)/Config.kmk $(_CFGDIR)/config.kmk
622endef
623# walk down the _RELATIVE_ path specified by DEPTH.
624$(foreach dir,$(subst /, ,$(DEPTH)), $(eval $(def_include_config)) )
625# add the default config file.
626_CFGFILE := $(firstword $(wildcard $(_CFGFILES) $(FILE_KBUILD_CONFIG)))
627_CFGFILES :=
628_CFGDIR :=
629ifeq ($(_CFGFILE),)
630$(error kBuild: no Config.kmk file found! Check the DEPTH: DEPTH='$(DEPTH)' PATH_CURRENT='$(PATH_CURRENT)')
631endif
632
633# Include the config.kmk we found file (or the default one).
634include $(_CFGFILE)
635
636
637# end-of-file-content
638__header_kmk__ := 1
639endif # __header_kmk__
640
Note: See TracBrowser for help on using the repository browser.