source: trunk/kBuild/header.kmk@ 530

Last change on this file since 530 was 525, checked in by bird, 19 years ago

Turn off command dependencies when using vanilla GNU Make.

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