source: trunk/kBuild/header.kmk@ 556

Last change on this file since 556 was 552, checked in by bird, 19 years ago
  • kBuild/footer.kmk:

o Recursive template inheritance.

  • kBuild/header.kmk, kBuild/footer.kmk:

o Removed some checks for features which are present in both gmake 3.81 and kmk.

Anyone trying to bootstrap kBuild will have to build gmake 3.81 first.

  • Config.kmk, src/gmake:

o Allow all kinds of ways of saying Windows in BUILD_TARGET.

  • kBuild/bin/x86.win32/:

o Rebuilt kmk.exe.

  • kBuild/bin/x86.os2/:

o Added kDepPre.exe and kDepIDB.exe.
o Rebuilt kmk.exe and kmk_gmake.exe.

  • src/gmake:

o Update KMK_FEATURES to include the optimizations from earlier this week.

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