source: trunk/kBuild/header.kmk@ 378

Last change on this file since 378 was 353, checked in by bird, 20 years ago

Use fixed lot's of those $$$$(PATH_<target>) thingies. Better target install, install pass and install target type. Generic passes. And more.

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