source: trunk/kBuild/header.kmk@ 519

Last change on this file since 519 was 513, checked in by bird, 19 years ago

Build new code. Windows can use the same DIRDEP macro as the other platforms now.

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