fixed idiotic bug in SubDir
[k8jam.git] / defaults / Jambase
blob828d7b319a51d1c34087fe96f55f150b7bc1ecf5
2 # /+\
3 #  +\    Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
4 # \+/
6 # This file is part of Jam - see jam.c for Copyright information.
10 # JAMBASE - jam 2.5 ruleset providing make(1)-like functionality
12 # Supports UNIX, NT, and VMS.
14 # 12/27/93 (seiwald) - purturb library sources with SOURCE_GRIST
15 # 04/18/94 (seiwald) - use '?=' when setting OS specific vars
16 # 04/21/94 (seiwald) - do RmTemps together
17 # 05/05/94 (seiwald) - all supported C compilers support -o: relegate
18 #              RELOCATE as an option; set Ranlib to "" to disable it
19 # 06/01/94 (seiwald) - new 'actions existing' to do existing sources
20 # 08/25/94 (seiwald) - new ObjectCcFlags rule to append to per-target CCFLAGS
21 # 08/29/94 (seiwald) - new ObjectHdrs rule to append to per-target HDRS
22 # 09/19/94 (seiwald) - LinkLibraries and Undefs now append
23 #            - Rule names downshifted.
24 # 10/06/94 (seiwald) - Dumb yyacc stuff moved into Jamfile.
25 # 10/14/94 (seiwald) - (Crude) support for .s, .C, .cc, .cpp, and .f files.
26 # 01/08/95 (seiwald) - Shell now handled with awk, not sed
27 # 01/09/95 (seiwald) - Install* now take dest directory as target
28 # 01/10/95 (seiwald) - All entries sorted.
29 # 01/10/95 (seiwald) - NT support moved in, with LauraW's help.
30 # 01/10/95 (seiwald) - VMS support moved in.
31 # 02/06/95 (seiwald) - ObjectC++Flags and SubDirC++Flags added.
32 # 02/07/95 (seiwald) - Iron out when HDRSEARCH uses "" or SEARCH_SOURCE.
33 # 02/08/95 (seiwald) - SubDir works on VMS.
34 # 02/14/95 (seiwald) - MkDir and entourage.
35 # 04/30/95 (seiwald) - Use install -c flag so that it copies, not moves.
36 # 07/10/95 (taylor) - Support for Microsoft C++.
37 # 11/21/96 (peterk) - Support for BeOS
38 # 07/19/99 (sickel) - Support for Mac OS X Server (and maybe client)
39 # 02/18/00 (belmonte)- Support for Cygwin.
41 #Ketmar's changelog:
42 # [*] windoze support shortened (fuck it! %-)
43 # [-] OS/2 support removed (we'll cry for you...)
44 # [-] VMS support removed (nobody cares)
45 # [-] MAC support removed (should be rewritten!)
46 # [-] BEOS support removed (dead should be dead)
47 # [-] fortran support removed (who need that shit anyway?!)
48 # [+] C++ files will be compiled by g++, not gcc
49 # [+] MainC++ & MainC++FromObjects rules added (g++ linker instead of gcc)
50 # [+] LINKC++, LINKC++FLAGS, LINKC++LIBS, C++OPTIM variables added
51 # [+] LOCATE_BIN variable added (for Main rule)
52 # [+] PATH_SEPARATOR variable added
53 # [+] LOCATE_LIB and LOCATE_LIBSO variables added
54 # [+] xxxC++ renamed to C++xxx
55 # [+] SubIncludeOnce varname : TOP ... ;
56 # [-] xxxC++ rules removed (no need to keep obsolete crap)
57 # [-] aliases for compatibility with jam 2.2 removed
58 # [-] comented out all libtool crap
59 # [+] added rules: LinkFlagsOn, C++LinkFlagsOn, ObjCLinkFlagsOn
60 # [+] added rule: gcc-suggest-attrs
62 # Special targets defined in this file:
64 # all       - parent of first, shell, files, lib, exe
65 # first     - first dependent of 'all', for potential initialization
66 # shell     - parent of all Shell targets
67 # files     - parent of all File targets
68 # lib       - parent of all Library targets
69 # exe       - parent of all Main targets
70 # dirs      - parent of all MkDir targets
71 # clean     - removes all Shell, File, Library, and Main targets
72 # uninstall - removes all Install targets
75 # Rules defined by this file:
77 # as obj.o : source.s ;                  .s -> .o
78 # Bulk dir : files ;                     populate directory with many files
79 # Cc obj.o : source.c ;                  .c -> .o
80 # C++ obj.o : source.cc ;                .cc -> .o
81 # Clean clean : sources ;                remove sources with 'jam clean'
82 # File dest : source ;                   copy file
83 # GenFile source.c : program args ;      make custom file
84 # HardLink target : source ;             make link from source to target
85 # HdrRule source : headers ;             handle #includes
86 # InstallInto dir : sources ;            install any files
87 # InstallBin dir : sources ;             install binaries
88 # InstallLib dir : sources ;             install files
89 # InstallFile dir : sources ;            install files
90 # InstallMan dir : sources ;             install man pages
91 # InstallShell dir : sources ;           install shell scripts
92 # Lex source.c : source.l ;              .l -> .c
93 # Library lib : source ;                 archive library from compiled sources
94 # LibraryFromObjects lib : objects ;     archive library from objects
95 # LinkLibraries images : libraries ;     bag libraries onto Mains
96 # Main image : source ;                  link executable from compiled sources
97 # C++Main image : source ;               link c++ executable from compiled sources
98 # ObjC-Main image : source ;             link obj-c executable from compiled sources
99 # MainFromObjects image : objects ;      link executable from objects
100 # C++MainFromObjects image : objects ;   link c++ executable from objects
101 # ObjC-MainFromObjects image : objects ; link obj-c executable from objects
102 # MkDir dir ;                            make a directory, if not there
103 # Object object : source ;               compile object from source
104 # ObjectCcFlags source : flags ;         add compiler flags for object
105 # ObjectC++Flags source : flags ;        add compiler flags for object
106 # ObjectObjCFlags source : flags ;       add compiler flags for object
107 # ObjectHdrs source : dirs ;             add include directories for object
108 # Objects sources ;                      compile sources
109 # RmTemps target : sources ;             remove temp sources after target made
110 # Setuid images ;                        mark executables Setuid
111 # SoftLink target : source ;             make symlink from source to target
112 # SubDir TOP d1 d2 ... ;                 start a subdirectory Jamfile
113 # SubDirCcFlags flags ;                  add compiler flags until next SubDir
114 # SubDirC++Flags flags ;                 add compiler flags until next SubDir
115 # SubDirHdrs d1 d2 ... ;                 add include dir until next SubDir
116 # SubInclude TOP d1 d2 ... ;             include a subdirectory Jamfile
117 # Shell exe : source ;                   make a shell executable
118 # Undefines images : symbols ;           save undef's for linking
119 # UserObject object : source ;           handle unknown suffixes for Object
120 # Yacc source.c : source.y ;             .y -> .c
122 # Utility rules that have no side effects (not supported):
124 # FAppendSuffix f1 f2 ... : $(SUF) ;     return $(<) with suffixes
125 # FDirName d1 d2 ... ;                   return path from root to dir
126 # FGrist d1 d2 ... ;                     return d1!d2!...
127 # FGristFiles value ;                    return $(value:G=$(SOURCE_GRIST))
128 # FGristSourceFiles value ;              return $(value:G=$(SOURCE_GRIST))
129 # FStripCommon v1 : v2 ;                 strip common initial parts of v1 v2
130 # FReverse a1 a2 ... ;                   return ... a2 a1
131 # FRelPath d1 : d2 ;                     return rel path from d1 to d2
132 # FSubDir d1 d2 ... ;                    return path to root
136 # Brief review of the jam language:
138 # Statements:
139 #   rule RULE - statements to process a rule
140 #   actions RULE - system commands to carry out target update
142 # Modifiers on actions:
143 #   together - multiple instances of same rule on target get executed
144 #          once with their sources ($(>)) concatenated
145 #   updated - refers to updated sources ($(>)) only
146 #   ignore - ignore return status of command
147 #   quietly - don't trace its execution unless verbose
148 #   piecemeal - iterate command each time with a small subset of $(>)
149 #   existing - refers to currently existing sources ($(>)) only
150 #   bind vars - subject to binding before expanding in actions
152 # Special rules:
153 #   Always - always build a target
154 #   Depends - builds the dependency graph
155 #   Echo - blurt out targets on stdout
156 #   Exit - blurt out targets and exit
157 #   Includes - marks sources as headers for target (a codependency)
158 #   NoCare - don't panic if the target can't be built
159 #   NoUpdate - create the target if needed but never update it
160 #   NotFile - ignore the timestamp of the target (it's not a file)
161 #   Temporary - target need not be present if sources haven't changed
163 # Special variables set by jam:
164 #   $(<) - targets of a rule (to the left of the :)
165 #   $(>) - sources of a rule (to the right of the :)
166 #   $(xxx) - true on xxx (UNIX, VMS, NT, OS2, MAC)
167 #   $(OS) - name of OS - varies wildly
168 #   $(JAMVERSION) - version number (2.5)
170 # Special variables used by jam:
171 #   SEARCH - where to find something (used during binding and actions)
172 #   LOCATE - where to plop something not found with SEARCH
173 #   HDRRULE - rule to call to handle include files
174 #   HDRSCAN - egrep regex to extract include files
176 # Special targets:
177 #   all - default if none given on command line
180 # for perforce use -- jambase version
182 #JAMBASEDATE = 2004.10.07 ;
184 #THIS_IS_KJAM = "tan" ; # we are using kjam; removed as obsolete
185 THIS_IS_K8JAM = "tan" ; # we are using k8jam
187 # set to 'tan' for old 'libtool' behavior
188 #!LIBTOOL!#K8_USE_LIBTOOL = ;
191 # Initialize variables
194 ###############################################################################
195 # special values
196 ###############################################################################
198 OPTIM_SPEED = -O3 -march=native -mtune=native -mfpmath=sse ;
199 LINKFLAGS_SPEED = -s ;
201 OPTIM_SIZE = -Os -march=native -mtune=native ;
202 LINKFLAGS_SIZE = -s ;
204 OPTIM_DEBUG = -O0 -g ;
205 LINKFLAGS_DEBUG = -g ;
207 OPTIM_NOALIAS = -fno-strict-aliasing ;
211 # OS specific variable settings
214 ###############################################################################
215 # Windoze
216 ###############################################################################
217 if $(NT) {
218   PATH_SEPARATOR = "\\" ;
219   local SUPPORTED_TOOLSETS =
220     MINGW
221     LCC
222     PELLESC
223   ;
225   # if the JAM_TOOLSET environment variable is defined, check that it is
226   # one of our supported values
227   #
228   if $(JAM_TOOLSET) {
229     if ! $(JAM_TOOLSET) in $(SUPPORTED_TOOLSETS) {
230       Echo "The JAM_TOOLSET environment variable is defined but its value" ;
231       Echo "is invalid, please use one of the following:" ;
232       Echo ;
233       for t in $(SUPPORTED_TOOLSETS) { Echo "  " $(t) ; }
234       Exit ;
235     }
236   }
238   if ! $(JAM_TOOLSET) {
239     Echo "The JAM_TOOLSET environment variable is not defined, defaults to MINGW" ;
240     JAM_TOOLSET = MINGW ;
241     MINGW = "c:\\mingw\\" ;
242   }
244   MV        ?= move /y ;
245   CP        ?= copy ;
246   RM        ?= del /f/q ;
247   RMDIR     ?= rmdir /s/q ;
248   SLASH     ?= \\ ;
249   SUFLIB    ?= .lib ;
250   SUFOBJ    ?= .obj ;
251   SUFEXE    ?= .exe ;
252   SUFLIBSHR ?= .dll ;
254   if $(JAM_TOOLSET) = MINGW {
255     Echo "Compiler is GCC with MinGW" ;
256     AR           ?= ar -ru ;
257     RANLIB       ?= ranlib ;
258     CC           ?= mingw-gcc ;
259     CCFLAGS      ?= "" ;
260     C++          ?= mingw-g++ ;
261     C++FLAGS     ?= $(CCFLAGS) ;
262     LINK         ?= $(CC) ;
263     LINKFLAGS    ?= "" ;
264     LINKLIBS     ?= -lkernel32 ;
265     OPTIM        ?= ;
266     SUFOBJ        = .o ;
267     SUFLIB        = .a ;
268     SLASH         = / ;
269     # MinGW-specific thingy
270     MINGW_GUI     = "-Wl,-subsystem,windows" ;
271     MINGW_THREADS = "-mthreads" ;
272     # k8
273     C++OPTIM     ?= $(OPTIM) ;
274     C++LINK      ?= $(C++) ;
275     C++LINKFLAGS ?= $(LINKFLAGS) ;
276     C++LINKLIBS  ?= $(LINKLIBS) ;
277     #NOARSCAN     ?= true ;
278     # set path if any
279     if $(MINGW) {
280       CC = "$(MINGW)$(CC:J= )" ;
281       C++ = "$(MINGW)$(C++:J= )" ;
282       LINK = "$(MINGW)$(LINK:J= )" ;
283       C++LINK = "$(MINGW)$(C++LINK:J= )" ;
284       AR = "$(MINGW)$(AR:J= )" ;
285       RANLIB = "$(MINGW)$(RANLIB:J= )" ;
286     }
287   } else if $(JAM_TOOLSET) = LCC {
288     Echo "Compiler is Win32-LCC" ;
289     AR        ?= lcclib ;
290     CC        ?= lcc ;
291     CCFLAGS   ?= "" ;
292     C++       ?= "error" ;
293     LINK      ?= lcclnk ;
294     LINKFLAGS ?= "" ;
295     LINKLIBS  ?= "" ;
296     OPTIM     ?= ;
297     NOARSCAN   = true ;
298     # k8
299     C++LINK    = "error" ;
300   } else if $(JAM_TOOLSET) = PELLESC {
301     Echo "Compiler is PellesC" ;
302     AR        ?= polib ;
303     CC        ?= pocc ;
304     CCFLAGS   ?= "" ;
305     C++       ?= "error" ;
306     LINK      ?= polink ;
307     LINKFLAGS ?= ;
308     LINKLIBS  ?= ;
309     OPTIM     ?= ;
310     NOARSCAN   = true ;
311     LINKLIBS  ?= crt.lib oldnames.lib Win\\kernel32.lib ;
312     # k8
313     C++LINK    = "error" ;
314   } else {
315     # XXX: We need better comments here !!
316     Exit "On NT, set MINGW to the root of the MinGW dir (but it won't help you anyway)" ;
317   }
318   STDHRS ?= "" ;
319   PICFLAGS = ;
321 ###############################################################################
322 # UNIX
323 ###############################################################################
324 else if $(UNIX) {
325   PATH_SEPARATOR = "/" ;
326   switch $(OS) {
327     case CYGWIN :
328       CC       ?= gcc ;
329       CCFLAGS  += -D__cygwin__ ;
330       LEX      ?= flex ;
331       JAMSHELL ?= sh -c ;
332       RANLIB   ?= "" ;
333       SUFEXE   ?= .exe ;
334       YACC     ?= bison -y ;
335     }
337     # UNIX defaults
338     CC        ?= gcc ;
339     C++       ?= g++ ;
340     OBJCC     ?= gcc ;
341     CCFLAGS   ?= ;
342     OBJCFLAGS ?= $(CCFLAGS) ;
343     C++FLAGS  ?= $(CCFLAGS) ;
344     CHMOD     ?= chmod ;
345     CHGRP     ?= chgrp ;
346     CHOWN     ?= chown ;
347     LEX       ?= flex ;
348     LINKFLAGS ?= $(CCFLAGS) ;
349     LINKLIBS  ?= ;
350     OPTIM     ?= ;
351     RANLIB    ?= ranlib ;
352     YACC      ?= bison ;
353     YACCGEN   ?= .c ;
354     YACCFILES ?= y.tab ;
355     YACCFLAGS ?= -ld ;
356 #!LIBTOOL!#    if $(K8_USE_LIBTOOL) {
357 #!LIBTOOL!#      SUFOBJSHR ?= .lo ;
358 #!LIBTOOL!#      SUFLIBSHR ?= .la ;
359 #!LIBTOOL!#    } else {
360 #!LIBTOOL!#      SUFOBJSHR ?= .o ;
361 #!LIBTOOL!#      SUFLIBSHR ?= .so ;
362 #!LIBTOOL!#    }
363     SUFOBJSHR ?= .o ;
364     SUFLIBSHR ?= .so ;
365 #!LIBTOOL!#
366     PICFLAGS  ?= -fpic ;
367     STDHDRS   ?= /usr/include ;
370 # shared library object file suffix. We assume that it is identical
371 # than the normal one
372 SUFOBJSHR ?= $(SUFOBJ) ;
373 SUFLIBSHR ?= $(SUFLIB) ;
376 # the D compiler
377 DC ?= dmd ;
380 # General defaults; a lot like UNIX
382 PATH_SEPARATOR ?= "/" ;
383 AR          ?= ar ru ;
384 AS          ?= as ;
385 ASFLAGS     ?= ;
386 AWK         ?= awk ;
387 BINDIR      ?= /usr/local/bin ;
388 C++         ?= g++ ;  # k8: was cc
389 C++FLAGS    ?= ;
390 CC          ?= gcc ;  # k8: was cc
391 CCFLAGS     ?= ;
392 CP          ?= cp -f ;
393 CRELIB      ?= ;
394 DOT         ?= . ;
395 DOTDOT      ?= .. ;
396 EXEMODE     ?= 755 ;
397 FILEMODE    ?= 644 ;
398 HDRS        ?= ;
399 INSTALLGRIST    ?= installed ;
400 JAMFILE     ?= Jamfile ;
401 JAMRULES    ?= Jamrules ;
402 LEX         ?= ;
403 LIBDIR      ?= /usr/local/lib ;
404 LINK        ?= $(CC) ;
405 LINKFLAGS   ?= ;
406 LINKLIBS    ?= ;
407 LN          ?= ln ;
408 MANDIR      ?= /usr/local/man ;
409 MKDIR       ?= mkdir ;
410 MV          ?= mv -f ;
411 OPTIM       ?= ;
412 RCP         ?= rcp ;
413 RM          ?= rm -f ;
414 RMDIR       ?= $(RM) ;
415 RSH         ?= rsh ;
416 SED         ?= sed ;
417 SHELLHEADER ?= "#!/bin/sh" ;
418 SHELLMODE   ?= 755 ;
419 SLASH       ?= / ;
420 SUBDIRRULES ?= ;
421 SUBDIRRESET ?= ASFLAGS HDRS C++FLAGS CCFLAGS ;
422 SUFEXE      ?= "" ;
423 SUFLIB      ?= .a ;
424 SUFOBJ      ?= .o ;
425 UNDEFFLAG   ?= "-u _" ;
426 YACC        ?= ;
427 YACCGEN     ?= ;
428 YACCFILES   ?= ;
429 YACCFLAGS   ?= ;
431 HDRPATTERN = "^[[:space:]]*#[[:space:]]*include[[:space:]]*[<\"]([^\">]*)[\">].*$" ;
433 OSFULL = $(OS)$(OSVER)$(OSPLAT) $(OS)$(OSPLAT) $(OS)$(OSVER) $(OS) ;
435 # k8
436 C++OPTIM     ?= $(OPTIM) ;
437 C++LINK      ?= $(C++) ;
438 C++LINKFLAGS ?= $(LINKFLAGS) ;
439 C++LINKLIBS  ?= $(LINKLIBS) ;
441 OBJCOPTIM     ?= $(OPTIM) ;
442 OBJCLINK      ?= $(CC) ;
443 OBJCLINKFLAGS ?= $(LINKFLAGS) ;
444 OBJCLINKLIBS  ?= $(LINKLIBS) ;
445 OBJCLINKLIBS  += -lobjc ;
447 if $(OS) = "LINUX" {
448   if ( "gcc" in $(CC) ) && ! ( "-pipe" in $(CC) ) { CC += -pipe ; }
449   if ( "g++" in $(C++) ) && ! ( "-pipe" in $(C++) ) { C++ += -pipe ; }
452 #Echo "OS:" $(OS) ;
453 #Echo "OSFULL:" $(OSFULL) ;
454 #Echo "UNIX:" $(UNIX) ;
459 # Base dependencies - first for "bootstrap" kinds of rules
461 Depends all : shell files lib exe obj ;
462 Depends all shell files lib exe obj : first ;
463 NotFile all first shell files lib exe obj dirs clean uninstall ;
464 Always  clean uninstall ;
467 # Rules
470 # /As object : source ;
472 # Assemble the file _source_, called by the @Object rule.
474 # Do not call this rule directly, since _object_ and _source_ may have
475 # have platform-specific file extensions
477 rule As {
478   Depends $(<) : $(>) ;
479   ASFLAGS on $(<) += $(ASFLAGS) $(SUBDIRASFLAGS) ;
480   ASHDRS on $(<) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ;
483 # /Bulk  directory : sources ;
485 # Copies _sources_ into _directory_
487 rule Bulk {
488   local i ;
490   for i in $(>) {
491     File $(i:D=$(<)) : $(i) ;
492   }
496 # /Dc object : source ;
498 # Compile the file source into object, usin the D compiler $(DC), its
499 # flags $(DCFLAGS) and $(DOPTIM)
500 # Called by the @Object rule
502 # Do not call this rule directly, since _object_ and _source_ may have
503 # have platform-specific file extensions
505 rule Dc {
506   Depends $(<) : $(>) ;
507   # Just to clarify here: this sets the per-target DCFLAGS to
508   # be the current value of (global) DCFLAGS and SUBDIRDCFLAGS.
509   DCFLAGS on $(<) += $(DCFLAGS) $(SUBDIRDCFLAGS) ;
513 # /Cc object : source ;
515 # Compile the file source into object, using the C compiler $(CC), its
516 # flags $(CCFLAGS) and $(OPTIM), and the header file directories $(HDRS).
517 # Called by the @Object rule
519 # Do not call this rule directly, since _object_ and _source_ may have
520 # have platform-specific file extensions
522 rule Cc {
523   Depends $(<) : $(>) ;
525   # If the compiler's -o flag doesn't work, relocate the .o
526   if $(RELOCATE) { CcMv $(<) : $(>) ; }
528   # Just to clarify here: this sets the per-target CCFLAGS to
529   # be the current value of (global) CCFLAGS and SUBDIRCCFLAGS.
530   # CCHDRS and CCDEFS must be reformatted each time for some
531   # compiles (VMS, NT) that malign multiple -D or -I flags.
532   CCFLAGS on $(<) += $(CCFLAGS) $(SUBDIRCCFLAGS) ;
533   CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
534   CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
538 # /C++ object : source ;
540 # Compile the C++ source file _source_. Similar to @CC, called by @Object
542 # Do not call this rule directly, since _object_ and _source_ may have
543 # have platform-specific file extensions
545 rule C++ {
546   local ktmp ;
548   Depends $(<) : $(>) ;
550   if $(RELOCATE) { CcMv $(<) : $(>) ; }
552   # Just to clarify here: this sets the per-target CCFLAGS to
553   # be the current value of (global) CCFLAGS and SUBDIRCCFLAGS.
554   # CCHDRS and CCDEFS must be reformatted each time for some
555   # compiles (VMS, NT) that malign multiple -D or -I flags.
556   ktmp = $(C++FLAGS) ;
557   if ! $(ktmp) { ktmp = $(CCFLAGS) ; }
558   C++FLAGS on $(<) += $(ktmp) $(SUBDIRC++FLAGS) ;
560   ktmp = $(C++OPTIM) ;
561   if ! $(ktmp) { ktmp = $(OPTIM) ; }
562   C++OPTIM on $(<) += $(ktmp) ;
564   CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
565   CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
569 # /ObjC object : source ;
571 # Compile the ObjC source file _source_. Similar to @CC, called by @Object
573 # Do not call this rule directly, since _object_ and _source_ may have
574 # have platform-specific file extensions
576 rule ObjC {
577   local ktmp ;
579   Depends $(<) : $(>) ;
581   if $(RELOCATE) { CcMv $(<) : $(>) ; }
583   # Just to clarify here: this sets the per-target CCFLAGS to
584   # be the current value of (global) CCFLAGS and SUBDIRCCFLAGS.
585   # CCHDRS and CCDEFS must be reformatted each time for some
586   # compiles (VMS, NT) that malign multiple -D or -I flags.
587   ktmp = $(OBJCFLAGS) ;
588   if ! $(ktmp) { ktmp = $(CCFLAGS) ; }
589   OBJCFLAGS on $(<) += $(ktmp) $(SUBDIROBJCFLAGS) ;
591   ktmp = $(OBJCOPTIM) ;
592   if ! $(ktmp) { ktmp = $(OBJCOPTIM) ; }
593   OBJCOPTIM on $(<) += $(ktmp) ;
595   CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
596   CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
600 # /Chmod target ;
602 # (Unix and VMS only). Change file permissions on _target_ to target-specific
603 # $(MODE) value set by @Link, @File, @Install* and @Shell rules
605 rule Chmod {
606   if $(CHMOD) { Chmod1 $(<) ; }
609 # /Clean  clean : targets ;
611 # Removes existing _targets_ when _clean_ is built. clean is not a dependency
612 # of all, and must be built explicitely for targets to be removed
616 # /File target : source ;
618 # Copies _source_ into _target_
620 rule File {
621   Depends files : $(<) ;
622   Depends $(<) : $(>) ;
623   SEARCH on $(>) = $(SEARCH_SOURCE) ;
624   MODE on $(<) = $(FILEMODE) ;
625   Chmod $(<) ;
629 # /GenFile target : image sources ;
631 # Runs the command "_image_ _target_ _sources_" to create _target_ from
632 # _sources_ and _image_ (where _image_ is an executable built by the
633 # @Main rule)
635 rule GenFile {
636   local _t = [ FGristSourceFiles $(<) ] ;
637   local _s = [ FAppendSuffix $(>[1]) : $(SUFEXE) ] ;
638   Depends $(_t) : $(_s) $(>[2-]) ;
639   GenFile1 $(_t) : $(_s) $(>[2-]) ;
640   Clean clean : $(_t) ;
643 rule GenFile1 {
644   MakeLocate $(<) : $(LOCATE_SOURCE) ;
645   SEARCH on $(>) = $(SEARCH_SOURCE) ;
649 # /HardLink target : source ;
651 # Makes _target_ a hard link to _source_, if it isn't one already
652 # (Unix only)
654 rule HardLink {
655   Depends files : $(<) ;
656   Depends $(<) : $(>) ;
657   SEARCH on $(>) = $(SEARCH_SOURCE) ;
661 # /HdrMacroFile
663 # this rule is specific to FT-Jam. It is used to indicate that a given file
664 # contains definitions for filename macros (e.g. "#define MYFILE_H <myfile>.h")
665 # that can later be used in #include statements in the rest of the source
667 # these files must be parsed before any make is tried.
669 rule HdrMacroFile {
670   HDRMACRO $(<) ;
674 # /HdrRule source : headers ;
676 # Arranges the proper dependencies when the file _source_ includes the files
677 # _headers_ through the #include C preprocessor directive
679 # this rule is not intendend to be called explicitely. It is called
680 # automatically during header scanning on sources handled by the @Object
681 # rule (e.g. sources in @Main or @Library rules)
683 rule HdrRule {
684   # HdrRule source : headers ;
686   # N.B.  This rule is called during binding, potentially after
687   # the fate of many targets has been determined, and must be
688   # used with caution: don't add dependencies to unrelated
689   # targets, and don't set variables on $(<).
691   # Tell Jam that anything depending on $(<) also depends on $(>),
692   # set SEARCH so Jam can find the headers, but then say we don't
693   # care if we can't actually find the headers (they may have been
694   # within ifdefs),
696   local s = $(>:G=$(HDRGRIST:E)) ;
698   Includes $(<) : $(s) ;
699   SEARCH on $(s) = $(HDRSEARCH) ;
700   NoCare $(s) ;
702   # Propagate on $(<) to $(>)
704   HDRSEARCH on $(s) = $(HDRSEARCH) ;
705   HDRSCAN on $(s) = $(HDRSCAN) ;
706   HDRRULE on $(s) = $(HDRRULE) ;
707   HDRGRIST on $(s) = $(HDRGRIST) ;
711 # /Lex source.c : source.l ;
713 # Process the lex source file _source.l_ and rename the lex.yy.c
714 # to _source.c_ . Called by the @Object rule
716 rule Lex {
717   ##LexMv $(<) : $(>) ;
718   Depends $(<) : $(>) ;
719   MakeLocate $(<) : $(LOCATE_SOURCE) ;
720   Clean clean : $(<) ;
724 # /Library  library : sources ;
726 #  Compiles _sources_ and archives them into _library_. The intermediate
727 #  objects are deleted. Calles @Object and @LibraryFromObjects
729 #  If @Library is invoked with no suffix on _library_, the $(SUFLIB)
730 #  suffix is used
732 rule Library {
733   LibraryFromObjects $(<) : $(>:S=$(SUFOBJ)) ;
734   Objects $(>) ;
738 # /SharedLibrary  library : sources : def : import ;
740 # Compiles _sources_ and generates a shared _library_ (i.e. DLL on Windows,
741 # or shared object on Unix). Calls @SharedObjects and @SharedLibraryFromObjects
743 # If @SharedLibrary is invoked with no suffix on _library_, then
744 # $(SUFLIBSHR) suffix is used
746 # _def_ is the name of the corresponding definition file used to generate
747 # the library on Windows and OS/2 (ignored otherwise). If undefined, it
748 # will default to _library_ with the .def suffix
750 # _import_ is the name of the corresponding import library for Windows
751 # and OS/2 platforms (ignored otherwise). If undefined, it will default
752 # to _library_ with the .dll.lib suffix.
754 rule SharedLibrary {
755   #Echo "SharedLibrary: $(<)" ; #dbg
756   #Echo "SharedLibrary: $(>:S=$(SUFOBJSHR))" ; #dbg
757   #Echo "SharedLibrary: $(3)" ; #dbg
758   #Echo "SharedLibrary: $(4)" ; #dbg
759   SharedLibraryFromObjects $(<) : $(>:S=$(SUFOBJSHR)) : $(3) : $(4) ;
760   SharedObjects $(>) ;
763 ######################################################
764 # k8: REWORK!
765 ######################################################
766 #!LIBTOOL!#if $(UNIX) {
767 #!LIBTOOL!#  # this rule is used to find the 'libtool' script in the current
768 #!LIBTOOL!#  # path, this is required when compiling shared objects on Unix
769 #!LIBTOOL!#  rule LibToolFind {
770 #!LIBTOOL!#    if $(LIBTOOL) { return $(LIBTOOL) ; }
771 #!LIBTOOL!#    local matches = [ Glob $(PATH) : libtool ] ;
772 #!LIBTOOL!#    if ! $(matches) { Exit "could not find 'libtool' program in current path. Aborting !" ; }
773 #!LIBTOOL!#    LIBTOOL = $(matches[1]) ;
774 #!LIBTOOL!#    return $(LIBTOOL) ;
775 #!LIBTOOL!#  }
776 #!LIBTOOL!#}
779 # /LibraryFromObjects library : objects ;
781 # Archives _objects_ into _library_. The _objects_ are then deleted
783 # If _library_ has no suffix, the $(SUFLIB) suffix is used
785 # Called by @Library rule. Most people should never call this rule
786 # directly.
788 rule LibraryFromObjects {
789   local _i _l _s ;
791   # Add grist to file names
792   _s = [ FGristFiles $(>) ] ;
793   _l = $(<:S=$(SUFLIB)) ;
795   # library depends on its member objects
796   if $(KEEPOBJS) {
797     Depends obj : $(_s) ;
798   } else {
799     Depends lib : $(_l) ;
800   }
802   # Set LOCATE for the library and its contents.  The bound
803   # value shows up as $(NEEDLIBS) on the Link actions.
804   # For compatibility, we only do this if the library doesn't
805   # already have a path.
806   if ! $(_l:D) {
807     #!!MakeLocate $(_l) $(_l)($(_s:BS)) : $(LOCATE_TARGET) ;
808     MakeLocate $(_l) $(_l)($(_s:BS)) : $(LOCATE_LIB) ;
809   }
811   if $(NOARSCAN) {
812     # If we can't scan the library to timestamp its contents,
813     # we have to just make the library depend directly on the
814     # on-disk object files.
815     Depends $(_l) : $(_s) ;
816   } else {
817     # If we can scan the library, we make the library depend
818     # on its members and each member depend on the on-disk
819     # object file.
820     Depends $(_l) : $(_l)($(_s:BS)) ;
821     for _i in $(_s) {
822       Depends $(_l)($(_i:BS)) : $(_i) ;
823     }
824   }
826   Clean clean : $(_l) ;
828   if $(CRELIB) { CreLib $(_l) : $(_s[1]) ; }
830   Archive $(_l) : $(_s) ;
832   if $(RANLIB) { Ranlib $(_l) ; }
834   # If we can't scan the library, we have to leave the .o's around.
835   if ! ( $(NOARSCAN) || $(NOARUPDATE) ) { RmTemps $(_l) : $(_s) ; }
839 # /SharedLibraryFromObjects  library : objects : def : import ;
841 # Equivalent of @LibraryFromObjects for shared libraries.
843 # Called by @SharedLibrary. Most people shouldn't call this rule
844 # directly
846 rule SharedLibraryFromObjects {
847   local _i _l _s ;
849   # Add grist to file names
850   _s = [ FGristFiles $(>) ] ;
851   _l = $(<:S=$(SUFLIBSHR)) ;
853   #Echo "Library is $(_l)"    ;
854   # library depends on its member objects
855   if $(KEEPOBJS) {
856     Depends obj : $(_s) ;
857   } else {
858     Depends lib : $(_l) ;
859   }
861   # Set LOCATE for the library and its contents.  The bound
862   # value shows up as $(NEEDLIBS) on the Link actions.
863   # For compatibility, we only do this if the library doesn't
864   # already have a path.
865   if ! $(_l:D) {
866     #!!MakeLocate $(_l) : $(LOCATE_TARGET) ;
867     MakeLocate $(_l) : $(LOCATE_LIBSO) ;
868   }
870   #Echo "SharedLibraryFromObjects: _s = $(_s)" ; #dbg
871   #Echo "SharedLibraryFromObjects: _l = $(_l)" ; #dbg
873   # we never scan shared libraries for member objects
874   Depends $(_l) : $(_s) ;
876   Clean clean : $(_l) ;
878   # I don't know if VMS supports shared libraries, so I prefer
879   # to disable the following right now
880   #
881   #if $(CRELIB) { CreLib $(_l) : $(_s[1]) ; }
883   # creating the library is so much fun on Unix :-)
884   if $(UNIX) {
885 #!LIBTOOL!#    if $(K8_USE_LIBTOOL) {
886 #!LIBTOOL!#      local libtool = [ LibToolFind ] ;  # find the right libtool
887 #!LIBTOOL!#      AR on $(_l) = "$(libtool) --mode=link $(AR:J= )" ;
888 #!LIBTOOL!#    } else {
889       LINKFLAGS on $(_l) += "-shared" ;
890       C++LINKFLAGS on $(_l) += "-shared" ;
891       LinkUnixLibrary $(_l) : $(_s) ;
892 #!LIBTOOL!#    }
893   } else if $(NT) {
894     local _implib = $(4) ;
895     local _def    = $(3) ;
897     _implib ?= $(_l:S=$(SUFLIBSHR)$(SUFLIB)) ;
898     _def    ?= $(_l:S=.def) ;
900     Clean    clean : $(_implib) ;
901     Depends  lib   : $(_implib) $(_def) ;
903     Depends $(_implib) : $(_def) $(_l) ;
904     Depends $(_l)      : $(_def) ;
906     DEFFILENAME on $(_l) = $(_def) ;
907     IMPLIBNAME  on $(_l) = $(_implib) ;
909     #!!MakeLocate $(_implib)        : $(LOCATE_TARGET) ;
910     #!!MakeLocate $(_implib:S=.exp) : $(LOCATE_TARGET) ;
911     MakeLocate $(_implib)        : $(LOCATE_LIBSO) ;
912     MakeLocate $(_implib:S=.exp) : $(LOCATE_LIBSO) ;
914     if $(JAM_TOOLSET) in VISUALC BORLANDC LCC WATCOM DIGITALMARS {
915       SharedLink-$(JAM_TOOLSET) $(_l) : $(_s) : $(_implib) : $(_def) ;
916     }
917     DllLink $(_l) : $(_s) ;
918   } else {
919     Echo "Sorry, I don't know how to make a shared library on your system" ;
920     Exit "Please *DON'T* contact the K8Jam maintainer for help" ;
921   }
925 # Since building shared libraries is so different depending on the
926 # compiler being used, I've broken this task into compiler-specific
927 # ones
929 rule SharedLink-LCC {
930   Echo "Sorry, but generating DLLs with LCC is not supported. That's" ;
931   Echo "because the 'lcclnk' tool that comes with this compiler is" ;
932   Echo "unreliable and doesn't work as expected." ;
933   Exit ;
935   # the 'lcclnk' tool is absolutely broken:
936   #   - its -o flag doesn't work when there is a LIBRARY statement
937   #     in the .def file.
938   #
939   #   - it uses the LIBRARY name in the .def file to determine
940   #     the name of the dll and its import library, and always
941   #     places them in the current directory !!
942   #
943   #   - if there is no LIBRARY statement, the -o flag is only
944   #     used to determine where the DLL is placed, the import
945   #     library will always be placed in the current directory !!
946   #
948   # clean the .exp file too, don't know how to get rid of it
949   Clean clean : $(4:S=.exp) ;
953 # /Link  image : objects ;
955 # Links _image_ from _objects_ and sets permissions on _image_ to
956 # $(EXEMODE). _image_ must be an actual filename; suffix is not
957 # supplied.
959 # Called by @Main, shouldn't be called by most people
961 rule Link {
962   MODE on $(<) = $(EXEMODE) ;
963   Chmod $(<) ;
967 # /C++Link  image : objects ;
969 # Links _image_ from _objects_ and sets permissions on _image_ to
970 # $(EXEMODE). _image_ must be an actual filename; suffix is not
971 # supplied.
973 # Called by @Main, shouldn't be called by most people
975 rule C++Link {
976   MODE on $(<) = $(EXEMODE) ;
977   Chmod $(<) ;
980 rule ObjC-Link {
981   MODE on $(<) = $(EXEMODE) ;
982   Chmod $(<) ;
986 # /LinkLibraries image : libraries ;
988 # Makes _image_ depend on _libraries_ and includes them during linking
990 # _image_ may be referenced without a suffix in this rule invocation.
991 # @LinkLibraries supplies the suffix
993 # You should only use this rule with libraries created through the
994 # @Library rule. For external libraries, use something else (XXX)
996 rule LinkLibraries {
997   # make library dependencies of target
998   # set NEEDLIBS variable used by 'actions Main'
999   local _t = [ FAppendSuffix $(<) : $(SUFEXE) ] ;
1001   Depends $(_t) : $(>:S=$(SUFLIB)) ;
1002   NEEDLIBS on $(_t) += $(>:S=$(SUFLIB)) ;
1006 # /LinkSharedLibraries image : libraries :
1008 # Same as @LinkLibraries, but to link _image_ with shared libraries
1009 # generated through the @SharedLibrary rule
1011 rule LinkSharedLibraries {
1012   # make library dependencies of target
1013   # set NEEDLIBS variable used by 'actions Main'
1014   local _t   = [ FAppendSuffix $(<) : $(SUFEXE) ] ;
1015   local _ext = $(SUFLIBSHR) ;
1017   if $(NT) {
1018     # on NT, we need to link agains the import library, not the DLL itself !!
1019     _ext = $(SUFLIBSHR)$(SUFLIB) ;
1020   }
1021   Depends $(_t) : $(>:S=$(_ext))  ;
1022   NEEDLIBS on $(_t) += $(>:S=$(_ext)) ;
1026 # /Main image : sources ;
1028 # Compiles _sources_ and links them into _image_. Calls @Objects and
1029 # @MainFromObjects.
1031 # _image_ may be supplied without suffix.
1033 rule Main {
1034   MainFromObjects $(<) : $(>:S=$(SUFOBJ)) ;
1035   Objects $(>) ;
1039 # /C++Main image : sources ;
1041 # Compiles _sources_ and links them into _image_. Calls @Objects and
1042 # @C++MainFromObjects.
1044 # _image_ may be supplied without suffix.
1046 rule C++Main {
1047   C++MainFromObjects $(<) : $(>:S=$(SUFOBJ)) ;
1048   Objects $(>) ;
1051 rule ObjC-Main {
1052   ObjC-MainFromObjects $(<) : $(>:S=$(SUFOBJ)) ;
1053   Objects $(>) ;
1057 # /MainFromObjects image : objects ;
1059 # Links _objects_ into _image_. Dependency of exe.
1060 # @MainFromObjects provides a default suffix for _image_
1062 rule MainFromObjects {
1063   local _s _t ;
1065   # Add grist to file names
1066   # Add suffix to exe
1067   _s = [ FGristFiles $(>) ] ;
1068   _t = [ FAppendSuffix $(<) : $(SUFEXE) ] ;
1069   # so 'jam foo' works when it's really foo.exe
1071   if $(_t) != $(<) {
1072     Depends $(<) : $(_t) ;
1073     NotFile $(<) ;
1074   }
1076   # make compiled sources a dependency of target
1077   Depends exe : $(_t) ;
1078   Depends $(_t) : $(_s) ;
1079   #k8:MakeLocate $(_t) : $(LOCATE_TARGET) ;
1080   MakeLocate $(_t) : $(LOCATE_BIN) ;
1081   Clean clean : $(_t) ;
1083   # special case for stupid Borland C++, which always generates a
1084   # .tds file for executables, even when no debug information is needed
1085   #
1086   #if $(JAM_TOOLSET) = BORLANDC {
1087   #  MakeLocate $(_t:S=.tds) : $(LOCATE_TARGET) ;
1088   #  Clean  clean : $(_t:S=.tds) ;
1089   #}
1091   Link $(_t) : $(_s) ;
1095 # /C++MainFromObjects image : objects ;
1097 # Links _objects_ into _image_. Dependency of exe.
1098 # @MainFromObjects provides a default suffix for _image_
1100 rule C++MainFromObjects {
1101   local _s _t ;
1103   # Add grist to file names
1104   # Add suffix to exe
1105   _s = [ FGristFiles $(>) ] ;
1106   _t = [ FAppendSuffix $(<) : $(SUFEXE) ] ;
1107   # so 'jam foo' works when it's really foo.exe
1109   if $(_t) != $(<) {
1110     Depends $(<) : $(_t) ;
1111     NotFile $(<) ;
1112   }
1114   # make compiled sources a dependency of target
1115   Depends exe : $(_t) ;
1116   Depends $(_t) : $(_s) ;
1117   #k8:MakeLocate $(_t) : $(LOCATE_TARGET) ;
1118   MakeLocate $(_t) : $(LOCATE_BIN) ;
1119   Clean clean : $(_t) ;
1121   # special case for stupid Borland C++, which always generates a
1122   # .tds file for executables, even when no debug information is needed
1123   #
1124   #if $(JAM_TOOLSET) = BORLANDC {
1125   #  MakeLocate $(_t:S=.tds) : $(LOCATE_TARGET) ;
1126   #  Clean  clean : $(_t:S=.tds) ;
1127   #}
1129   C++Link $(_t) : $(_s) ;  ###k8:FIXME
1133 rule ObjC-MainFromObjects {
1134   local _s _t ;
1136   # Add grist to file names
1137   # Add suffix to exe
1138   _s = [ FGristFiles $(>) ] ;
1139   _t = [ FAppendSuffix $(<) : $(SUFEXE) ] ;
1140   # so 'jam foo' works when it's really foo.exe
1142   if $(_t) != $(<) {
1143     Depends $(<) : $(_t) ;
1144     NotFile $(<) ;
1145   }
1147   # make compiled sources a dependency of target
1148   Depends exe : $(_t) ;
1149   Depends $(_t) : $(_s) ;
1150   #k8:MakeLocate $(_t) : $(LOCATE_TARGET) ;
1151   MakeLocate $(_t) : $(LOCATE_BIN) ;
1152   Clean clean : $(_t) ;
1154   ObjC-Link $(_t) : $(_s) ;  ###k8:FIXME
1158 # /MakeLocate  targets : directory
1160 # Creates _dir_ and causes _target_ to be built into _dir_
1162 # This is done by setting the target-specific variable LOCATE
1163 # on _targets_, and arranges with @MkDir to create the target
1164 # directory
1166 rule MakeLocate {
1167   # Note we grist the directory name with 'dir',
1168   # so that directory path components and other
1169   # targets don't conflict.
1170   local srcname = $(<[1]:G=) ;
1171   local srcdir = $(srcname:D) ;
1172   local outdir = $(>[1]:G=dir) ;
1173   local odir ;
1174   if $(srcdir) {
1175     odir = $(outdir)$(PATH_SEPARATOR)$(srcdir) ;
1176   } else {
1177     odir = $(outdir) ;
1178   }
1179   #Echo "MakeLocate:" "$(<)" "|" "$(>)" ;
1180   #Echo "srcname:" "$(srcname)" ;
1181   #Echo "srcdir :" "$(srcdir)" ;
1182   #Echo "outdir :" "$(outdir)" ;
1183   #Echo "odir   :" "$(odir)" ;
1184   if $(>) {
1185     LOCATE on $(<) = $(>) ;
1186     Depends $(<) : $(odir) ;
1187     MkDir $(odir) ;
1188   }
1192 # /MkDir  dir ;
1194 # Creates _dir_ and its parent directories
1196 rule MkDir {
1197   # Ignore timestamps on directories: we only care if they exist.
1198   NoUpdate $(<) ;
1200   # Don't create . or any directory already created.
1201   if $(<:G=) != $(DOT) && ! $($(<)-mkdir) {
1202     # Cheesy gate to prevent multiple invocations on same dir
1203     # Arrange for jam dirs
1204     # MkDir1 has the actions
1205     $(<)-mkdir = true ;
1206     Depends dirs : $(<) ;
1207     MkDir1 $(<) ;
1209     # Recursively make parent directories.
1210     # $(<:P) = $(<)'s parent, & we recurse until root
1211     local s = $(<:P) ;
1213     # Don't try to create A: or A:\ on windows
1214     if $(NT) {
1215       switch $(s) {
1216         case "*:"   : s = ;
1217         case "*:\\" : s = ;
1218       }
1219     }
1220     # handle "C:", "C:/", "/cygdrive" and "/cygdrive/" in Cygwin
1221     if $(UNIX) && $(OS) = CYGWIN {
1222       switch $(s) {
1223         case "?:"   : s = ;
1224         case "?:/"  : s = ;
1225         case "<dir>/cygdrive"   : s = ;
1226         case "<dir>/cygdrive/"  : s = ;
1227       }
1228     }
1230     if $(s) = $(<) {
1231       # The parent is the same as the dir.
1232       # We're at the root, which some OS's can't stat, so we mark
1233       # it as NotFile.
1234       NotFile $(s) ;
1235     } else if $(s:G=) {
1236       # There's a parent; recurse.
1237       Depends $(<) : $(s) ;
1238       MkDir $(s) ;
1239     }
1240   }
1244 # /Object object : source ;
1246 # Compile s a single _source_ file into _object_. The @Main and @Library
1247 # rules use it to compile sources.
1249 # Causes _source_ to be scanned for #include directives and calls @HdrRule
1250 # to make all included files dependencies of _object_.
1252 # Calls one of the following rules depending on the suffix to do the
1253 # actual compilation:
1255 rule Object {
1256   # locate object and search for source, if wanted
1258   Clean clean : $(<) ;
1259   MakeLocate $(<) : $(LOCATE_TARGET) ;
1260   SEARCH on $(>) = $(SEARCH_SOURCE) ;
1262   # Save HDRS for -I$(HDRS) on compile.
1263   # We shouldn't need -I$(SEARCH_SOURCE) as cc can find headers
1264   # in the .c file's directory, but generated .c files (from
1265   # yacc, lex, etc) are located in $(LOCATE_TARGET), possibly
1266   # different from $(SEARCH_SOURCE).
1267   HDRS on $(<) = $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ;
1269   # handle #includes for source: Jam scans for headers with
1270   # the regexp pattern $(HDRSCAN) and then invokes $(HDRRULE)
1271   # with the scanned file as the target and the found headers
1272   # as the sources.  HDRSEARCH is the value of SEARCH used for
1273   # the found header files.  Finally, if jam must deal with
1274   # header files of the same name in different directories,
1275   # they can be distinguished with HDRGRIST.
1277   # $(SEARCH_SOURCE:E) is where cc first looks for #include
1278   # "foo.h" files.  If the source file is in a distant directory,
1279   # look there.  Else, look in "" (the current directory).
1281   HDRRULE on $(>) = HdrRule ;
1282   HDRSCAN on $(>) = $(HDRPATTERN) ;
1283   HDRSEARCH on $(>) = $(SEARCH_SOURCE:E) $(SUBDIRHDRS) $(HDRS) $(STDHDRS) ;
1284   HDRGRIST on $(>) = $(HDRGRIST) ;
1286   # propagate target specific-defines
1287   DEFINES on $(<) += $(DEFINES) ;
1289   if $(WINDOZE) && $(>:S) = ".rc" {
1290     WindozeResourceCompiler $(<) : $(>) ;
1291   } else if $(WINDOZE) && $(>:S) = ".o" {
1292     # do nothing
1293   } else {
1294     # if source is not .c, generate .c with specific rule
1295     switch $(>:S) {
1296       case .asm : As $(<) : $(>) ;
1297       case .c   : Cc $(<) : $(>) ;
1298       case .C   : C++ $(<) : $(>) ;
1299       case .cc  : C++ $(<) : $(>) ;
1300       case .cpp : C++ $(<) : $(>) ;
1301       case .cxx : C++ $(<) : $(>) ;
1302       case .c++ : C++ $(<) : $(>) ;
1303       case .C++ : C++ $(<) : $(>) ;
1304       case .m   : ObjC $(<) : $(>) ;
1305       case .d   : Dc $(<) : $(>) ;
1306       case .l   : Cc $(<) : $(<:S=.c) ;
1307                   Lex $(<:S=.c) : $(>) ;
1308       case .s   : As $(<) : $(>) ;
1309       case .y   : Cc $(<) : $(<:S=$(YACCGEN)) ;
1310                   Yacc $(<:S=$(YACCGEN)) : $(>) ;
1311       case *    : UserObject $(<) : $(>) ;
1312     }
1313   }
1317 # /ObjectCcFlags  sources : flags ;
1319 # this rule is used to add compiler flags to the compilation of
1320 # specific C sources files.
1322 rule ObjectCcFlags {
1323   CCFLAGS on [ FGristFiles $(<:S=$(SUFOBJ)) ] += $(>) ;
1327 # /ObjectC++Flags  sources : flags ;
1329 # this rule is used to add compiler flags to the compilation of
1330 # specific C++ source files
1332 rule ObjectC++Flags {
1333   C++FLAGS on [ FGristFiles $(<:S=$(SUFOBJ)) ] += $(>) ;
1337 rule ObjectObjCFlags {
1338   OBJCFLAGS on [ FGristFiles $(<:S=$(SUFOBJ)) ] += $(>) ;
1342 # /LinkFlagsOn  mains : flags ;
1344 # this rule is used to add compiler flags to the compilation of
1345 # specific C sources files.
1347 rule LinkFlagsOn {
1348   LINKFLAGS on [ FGristFiles $(<) ] += $(>) ;
1352 # /C++LinkFlagsOn  mains : flags ;
1354 # this rule is used to add compiler flags to the compilation of
1355 # specific C++ source files
1357 rule C++LinkFlagsOn {
1358   C++LINKFLAGS on [ FGristFiles $(<) ] += $(>) ;
1362 rule ObjCLinkFlagsOn {
1363   OBJCLINKFLAGS on [ FGristFiles $(<) ] += $(>) ;
1367 # /ObjectDefines  objects : macros ;
1369 # this rule is used to add macro defines to the compilation of
1370 # specific C and C++ source files
1372 rule ObjectDefines {
1373   # must reformat CCDEFS according to current defines
1374   local s = [ FGristFiles $(<:S=$(SUFOBJ)) ] ;
1376   DEFINES on $(s) += $(>) ;
1377   CCDEFS on $(s) = [ on $(s) FDefines $(DEFINES) ] ;
1381 # /ObjectHdrs  sources : paths ;
1383 # this rule is used to add include paths to the compilation of
1384 # specific C and C++ source files
1386 rule ObjectHdrs {
1387   # Add to HDRS for HdrScan's benefit.
1388   # must reformat CCHDRS according to headers
1389   local s = [ FGristFiles $(<:S=$(SUFOBJ)) ] ;
1391   HDRS on $(s) += $(>) ;
1392   CCHDRS on $(s) = [ on $(s) FIncludes $(HDRS) ] ;
1396 # /Objects sources ;
1398 # this rule is used to compile one or more sources into object files.
1399 # do not call it directly, it is used by the Main and Library rules
1400 # automatically
1402 rule Objects {
1403   local _i ;
1405   for _i in [ FGristFiles $(<) ] {
1406     Object $(_i:S=$(SUFOBJ)) : $(_i) ;
1407     Depends obj : $(_i:S=$(SUFOBJ)) ;
1408   }
1412 # /SharedObjects
1414 # this rule is used to compile one or more sources into 'shared object
1415 # files'. This means object files used to build either DLLs or Unix shared
1416 # libraries.
1418 # do not call this rule directly, it is called by SharedLibrary automatically
1420 rule SharedObjects {
1421   # temporarily override SUFOBJ with $(SUFOBJSHR) to
1422   local SUFOBJ = $(SUFOBJSHR) ;
1424   # call the normal Objects rule
1425   Objects $(<) ;
1427   # add the compiler-specific position-independent-code flag  where needed
1428   ObjectCcFlags $(<) : $(PICFLAGS) ;
1430   # change the compiler invokation for all these objects
1431   # to use Libtool on Unix systems. We explicitely disable the
1432   # generation of static objects here
1433 #!LIBTOOL!#  if $(UNIX) {
1434 #!LIBTOOL!#    #libtool on $(<:S=$(SUFOBJ)) = [ LibToolFind ] ;
1435 #!LIBTOOL!#    if $(K8_USE_LIBTOOL) {
1436 #!LIBTOOL!#      local libtool = [ LibToolFind ] ;
1437 #!LIBTOOL!#      CC on $(<:S=$(SUFOBJ)) = "$(libtool) --mode=compile $(CC:J= ) -dynamic" ;
1438 #!LIBTOOL!#      C++ on $(<:S=$(SUFOBJ)) = "$(libtool) --mode=compile $(C++:J= ) -dynamic" ; #k8:?
1439 #!LIBTOOL!#    }
1440 #!LIBTOOL!#  }
1444 rule RmTemps {
1445   Temporary $(>) ;
1449 rule Setuid {
1450   MODE on [ FAppendSuffix $(<) : $(SUFEXE) ] = 4711 ;
1454 rule Shell {
1455   Depends shell : $(<) ;
1456   Depends $(<) : $(>) ;
1457   SEARCH on $(>) = $(SEARCH_SOURCE) ;
1458   MODE on $(<) = $(SHELLMODE) ;
1459   Clean clean : $(<) ;
1460   Chmod $(<) ;
1464 rule SoftLink {
1465   Depends files : $(<) ;
1466   Depends $(<) : $(>) ;
1467   SEARCH on $(>) = $(SEARCH_SOURCE) ;
1468   Clean clean : $(<) ;
1472 rule SubDir {
1473   #
1474   # SubDir TOP d1 d2 ... ;
1475   #
1476   # Support for a project tree spanning multiple directories.
1477   #
1478   # SubDir declares a Jamfile's location in a project tree, setting
1479   # Jambase variables (SEARCH_SOURCE, LOCATE_TARGET) so that source
1480   # files can be found.
1481   #
1482   # TOP is a user-select variable name for root of the tree, and
1483   # d1 d2 ...  are the directory elements that lead from the root
1484   # of the tree to the directory of the Jamfile.
1485   #
1486   # TOP can be set externally, but normally the first SubDir call
1487   # computes TOP as the path up from the current directory; the
1488   # path contains one ../ for each of d1 d2 ...
1489   #
1490   # SubDir reads once the project-specific rules file Jamrules
1491   # in the TOP directory, if present.  This can be overridden
1492   # with the variable TOPRULES.
1493   #
1494   # SubDir supports multiple, overlaid project trees:  SubDir
1495   # invocations with different TOPs can appear in the same Jamfile.
1496   # The location established by the first SubDir call is used set
1497   # the TOPs for the subsequent SubDir calls.
1498   #
1499   # SubDir's public variables:
1500   #
1501   #   $(TOP) = path from CWD to root.
1502   #   $(SUBDIR) = path from CWD to the directory SubDir names.
1503   #   $(SUBDIR_TOKENS) = path from $(TOP) to $(SUBDIR) as dir names
1504   #   $(SEARCH_SOURCE) = $(SUBDIR)
1505   #   $(LOCATE_SOURCE) = $(ALL_LOCATE_TARGET) $(SUBDIR)
1506   #   $(LOCATE_TARGET) = $(ALL_LOCATE_TARGET) $(SUBDIR)
1507   #   $(LOCATE_BIN) = $(ALL_LOCATE_BIN) $(ALL_LOCATE_TARGET) $(SUBDIR)
1508   #   $(LOCATE_LIB) = $(ALL_LOCATE_LIB) $(ALL_LOCATE_TARGET) $(SUBDIR)
1509   #   $(LOCATE_LIBSO) = $(ALL_LOCATE_LIBSO) $(ALL_LOCATE_LIB) $(ALL_LOCATE_TARGET) $(SUBDIR)
1510   #   $(SOURCE_GRIST) = $(SUBDIR_TOKENS) with !'s
1511   #
1512   local _top = $(<[1]) ;
1513   local _tokens = $(<[2-]) ;
1514   local _xpath = $(_tokens:J=$(PATH_SEPARATOR)) ;
1516   #Echo "$(_tokens)" ;
1517   #Echo "$(_xpath) ";
1518   if $(_xpath) != "" { _xpath = "$(PATH_SEPARATOR)$(_xpath)" ; }
1520   #local sdr ;
1522   # First time through sets up relative root and includes Jamrules.
1523   if ! $(_top) { Exit "SubDir syntax error" ; }
1525   if ! $($(_top)-SET) {
1526     $(_top)-SET = true ;
1527     # First time we've seen this TOP.
1528     # We'll initialize a number of internal variables:
1529     #
1530     #   $(TOP-UP) = directories from ROOT to a common point
1531     #   $(TOP-DOWN) = directories from common point to TOP
1532     #   $(TOP-ROOT) = root directory for UP/DOWN -- normally CWD
1533     #   $(SUBDIR_UP) = current value of $(TOP-UP)
1534     #   $(SUBDIR_DOWN) = current value of $(TOP-DOWN)
1535     #   $(SUBDIR_ROOT) = current value of $(TOP-ROOT)
1536     #
1537     if $($(_top)) {
1538       # TOP externally set.
1539       # We'll ignore the relative (UP/DOWN) path that
1540       # got us here, and instead remember the hard ROOT.
1541       $(_top)-UP = ;
1542       $(_top)-DOWN = ;
1543       $(_top)-ROOT = $($(_top)) ;
1544     } else {
1545       # TOP not preset.
1547       # Establishing a new TOP.  In the simplest case,
1548       # (SUBDIR_UP/SUBDIR_DOWN/SUBDIR_ROOT unset), it's
1549       # merely a certain number of directories down from
1550       # the current directory, and FSubDirPath will set
1551       # TOP to a path consisting of ../ for each of the
1552       # elements of _tokens, because that represents how
1553       # far below TOP the current directory sits.
1554       #
1555       # In the more complicated case, the starting directory
1556       # isn't the directory of jam's invocation but an
1557       # location established by previous SubDir call.  The
1558       # starting directory is SUBDIR_UP directories up from
1559       # SUBDIR_ROOT, and then SUBDIR_DOWN directories down
1560       # from that.   If SUBDIR_ROOT is not set, that means
1561       # SUBDIR_DOWN and SUBDIR_UP represent the path from
1562       # the directory of jam's invocation.
1563       #
1564       # In the most complicated case, the _tokens also
1565       # represents directories down, because TOP is being
1566       # estalished in a directory other than TOP's root.
1567       # Hopefully, _tokens and SUBDIR_DOWN represent the
1568       # same final directory, relative to the new TOP and
1569       # the previous SubDIr's TOP.  To find the new TOP,
1570       # we have to chop off any common directories from
1571       # then ends of _tokens and SUBDIR_DOWN.  To do so,
1572       # we reverse each of them, call FStripCommon to
1573       # remove the initial common elements, and then
1574       # reverse them again.  After this process, if
1575       # both _tokens and SUBDIR_DOWN have elements, it
1576       # means the directory names estalished by the two
1577       # SubDir calls don't match, and a warning is issued.
1578       # All hell will likely break loose at this point,
1579       # since the whole SubDir scheme relies on the SubDir
1580       # calls accurately naming the current directory.
1582       # Strip common trailing elements of _tokens and SUBDIR_DOWN.
1583       _tokens = [ FReverse $(_tokens) ] ;
1584       SUBDIR_DOWN = [ FReverse $(SUBDIR_DOWN) ] ;
1585       FStripCommon _tokens : SUBDIR_DOWN ;
1586       SUBDIR_DOWN = [ FReverse $(SUBDIR_DOWN) ] ;
1587       _tokens = [ FReverse $(_tokens) ] ;
1589       if $(SUBDIR_DOWN) && $(_tokens) { Echo "Warning:" SubDir $(<) "misplaced!" ; }
1591       # We'll remember the relative (UP/DOWN) path that
1592       # got us here, plus any hard ROOT starting point
1593       # for the UP/DOWN.  If TOP is never set externally,
1594       # ROOT will always be "" (directory of jam's invocation).
1595       $(_top)-UP = $(SUBDIR_UP) $(_tokens) ;
1596       $(_top)-DOWN = $(SUBDIR_DOWN) ;
1597       $(_top)-ROOT = $(SUBDIR_ROOT:E="") ;
1598       $(_top) = [ FSubDirPath $(_top) ] ;
1599     }
1601     # Set subdir vars for the inclusion of the Jamrules,
1602     # just in case they have SubDir rules of their own.
1603     # Note that SUBDIR_DOWN is empty: it's all the way
1604     # up where the Jamrules live.  These gets overrided
1605     # just after the inclusion.
1606     SUBDIR_UP = $($(_top)-UP) ;
1607     SUBDIR_DOWN = ;
1608     SUBDIR_ROOT = $($(_top)-ROOT) ;
1610     # Include $(TOPRULES) or $(TOP)/Jamrules.
1611     # Include $(TOPRULES) if set.
1612     # Otherwise include $(TOP)/Jamrules if present.
1613     if $($(_top)RULES) {
1614       include $($(_top)RULES) ;
1615     } else {
1616       NoCare $(JAMRULES:R=$($(_top)):G=$(_top)) ;
1617       include $(JAMRULES:R=$($(_top)):G=$(_top)) ;
1618     }
1619   }
1621   # Get path from $(TOP) to named directory.
1622   # Save dir tokens for other potential uses.
1623   SUBDIR_UP = $($(_top)-UP) ;
1624   SUBDIR_DOWN = $($(_top)-DOWN) $(_tokens) ;
1625   SUBDIR_ROOT = $($(_top)-ROOT) ;
1626   SUBDIR_TOKENS = $(SUBDIR_DOWN) ;
1628   SUBDIR = [ FSubDirPath $(<) ] ;
1630   # Now set up SEARCH_SOURCE, LOCATE_TARGET, LOCATE_BIN, SOURCE_GRIST
1631   # These can be reset if needed.  For example, if the source
1632   # directory should not hold object files, LOCATE_TARGET can
1633   # subsequently be redefined.
1634   SEARCH_SOURCE = $(SUBDIR) ;
1636   #if $(SUBDIR) = "." { sdr = "" ; } else { sdr = "$(PATH_SEPARATOR)$(SUBDIR)" ; }
1638   if $(ALL_LOCATE_TARGET) {
1639     LOCATE_TARGET = "$(ALL_LOCATE_TARGET)$(_xpath)" ;
1640     LOCATE_SOURCE = "$(ALL_LOCATE_TARGET)$(_xpath)" ;
1641   } else {
1642     LOCATE_TARGET = $(SUBDIR) ;
1643     LOCATE_SOURCE = $(SUBDIR) ;
1644   }
1646   if $(ALL_LOCATE_BIN) {
1647     LOCATE_BIN = $(ALL_LOCATE_BIN) ;
1648   } else {
1649     LOCATE_BIN = $(LOCATE_TARGET) ;
1650   }
1652   if $(ALL_LOCATE_LIB) {
1653     LOCATE_LIB = $(ALL_LOCATE_LIB) ;
1654   } else {
1655     LOCATE_LIB = $(LOCATE_TARGET) ;
1656   }
1658   if $(ALL_LOCATE_LIBSO) {
1659     LOCATE_LIBSO = $(ALL_LOCATE_LIBSO) ;
1660   } else {
1661     LOCATE_LIBSO = $(LOCATE_LIB) ;
1662   }
1664   #Echo "ALL_LOCATE_LIB = $(ALL_LOCATE_LIB)" ;
1665   #Echo "LOCATE_LIB = $(LOCATE_LIB)" ;
1667   SOURCE_GRIST = [ FGrist $(SUBDIR_TOKENS) ] ;
1668   #if ! $(LOCATE_BIN) { LOCATE_BIN = $(LOCATE_TARGET) ; }
1670   ## OPT_HEADER_CACHE_EXT
1671   # With the header cache, we can grist all files found
1672   # during a header scan without incurring a performance
1673   # penalty.
1674   #
1675   HDRGRIST = $(SOURCE_GRIST) ;
1677   # Reset per-directory ccflags, hdrs, etc,
1678   # listed in SUBDIRRESET.
1679   # Note use of variable expanded assignment var
1680   SUBDIR$(SUBDIRRESET) = ;
1682   # Invoke user-specific SubDir extensions,
1683   # rule names listed in SUBDIRRULES.
1684   # Note use of variable expanded rule invocation
1685   $(SUBDIRRULES) $(<) ;
1689 rule FSubDirPath {
1690   # FSubDirPath TOP d1 ... ;
1692   # Returns path to named directory.
1694   # If jam is invoked in a subdirectory of the TOP, then we
1695   # need to prepend a ../ for every level we must climb up
1696   # (TOP-UP), and then append the directory names we must
1697   # climb down (TOP-DOWN), plus the named directories d1 ...
1698   # If TOP was set externally, or computed from another TOP
1699   # that was, we'll have to reroot the whole thing at TOP-ROOT.
1700   local _r = [ FRelPath $($(<[1])-UP) : $($(<[1])-DOWN) $(<[2-]) ] ;
1702   return $(_r:R=$($(<[1])-ROOT)) ;
1706 rule SubDirDcFlags {
1707   SUBDIRDCFLAGS += $(<) ;
1711 rule SubDirCcFlags {
1712   SUBDIRCCFLAGS += $(<) ;
1716 rule SubDirC++Flags {
1717   SUBDIRC++FLAGS += $(<) ;
1721 rule SubDirObjCFlags {
1722   SUBDIROBJCFLAGS += $(<) ;
1726 rule SubDirHdrs {
1727   SUBDIRHDRS += [ FDirName $(<) ] ;
1731 rule SubIncludeMany {
1732   # SubIncludeMany TOP d1 ... ;
1733   #
1734   # Include a subdirectory's Jamfile.
1736   # We use SubDir to get there, in case the included Jamfile
1737   # either doesn't have its own SubDir (naughty) or is a subtree
1738   # with its own TOP.
1739   #Echo "including " $(<) " : " $(>) ;
1741   if ! $($(<[1])) { Exit "SubIncludeMany" $(<[1]) "without prior SubDir" $(<[1]) ; }
1742   SubDir $(<) ;
1743   include $(JAMFILE:D=$(SUBDIR)) ;
1747 rule SubIncludeOnce {
1748   # SubIncludeOnce varname : TOP d1 ... ;
1749   #
1750   # Include a subdirectory's Jamfile.
1752   local _vn = $(<[1]) ;
1753   if ! $($(_vn)) {
1754     #Echo "processing $(_vn)" ;
1755     #Echo "$(>)" ;
1756     $(_vn) = tan ;
1757     SubIncludeMany $(>) ;
1758   #} else {
1759   #  Echo "skiped $(_vn) -- $($(_vn))" ;
1760   #  Echo "$(>)" ;
1761   }
1765 rule SubInclude {
1766   # SubInclude TOP d1 ... ;
1767   #
1768   # Include a subdirectory's Jamfile.
1769   if ! $($(<[1])) { Exit "SubInclude" $(<[1]) "without prior SubDir" $(<[1]) ; }
1770   local _sbiguard = _K8JAM_SUB_GUARD_$(<:J=_) ;
1771   SubIncludeOnce $(_sbiguard) : $(<) ;
1775 rule SubRules {
1776   # SubRules TOP d1 ... : Other-TOP ;
1777   #
1778   # Read another tree's Jamrules, by giving it's path according
1779   # to this tree and it's own name.
1780   if ! $($(<[1])) { Exit "SubRules" $(<[1]) "without prior SubDir" $(<[1]) ; }
1781   SubDir $(<) ;
1782   SubDir $(>) ;
1786 rule Undefines {
1787   UNDEFS on [ FAppendSuffix $(<) : $(SUFEXE) ] += $(UNDEFFLAG)$(>) ;
1791 rule UserObject {
1792   Exit "Unknown suffix on" $(>) "- see UserObject rule in Jamfile(5)." ;
1796 rule Yacc {
1797   local _h ;
1799   _h = $(<:BS=.h) ;
1801   # Some places don't have a yacc.
1802   MakeLocate $(<) $(_h) : $(LOCATE_SOURCE) ;
1803   #MakeLocate $(>) $(_h) : $(LOCATE_SOURCE) ;
1805   if $(YACC) {
1806     #local tmp ;
1807     #tmp = $(<:G=:D) ;
1808     #if $(tmp) { tmp = $(PATH_SEPARATOR)$(tmp) ; }
1809     #tmp = $(LOCATE_SOURCE[1])$(tmp) ;
1810     #CCFLAGS on $(<:S=$(SUFOBJ)) += -I$(tmp) ;
1811     #C++FLAGS on $(<:S=$(SUFOBJ)) += -I$(tmp) ;
1812     #OBJCFLAGS on $(<:S=$(SUFOBJ)) += -I$(tmp) ;
1813     #Echo "-------------------------" ;
1814     #Echo "LS:" "$(LOCATE_SOURCE)" ;
1815     #Echo "tmp:" "$(tmp)" ;
1816     #Echo "out:" "$(<)" ;
1817     #Echo "in :" "$(>)" ;
1818     #Echo "_h :" "$(_h)" ;
1819     #Echo "=========================" ;
1820     #
1821     Depends $(<) $(_h) : $(>) ;
1822     Yacc1 $(<) : $(>) ;
1823     #Yacc1 $(<) $(_h) : $(>) ;
1824     #YaccMv $(<) $(_h) : $(>) ;
1825     Clean clean : $(<) $(_h) ;
1826   }
1828   # make sure someone includes $(_h) else it will be
1829   # a deadly independent target
1830   Includes $(<) : $(_h) ;
1835 # Utility rules; no side effects on these
1839 # /FGrist path to file ;
1841 # Returns a single string that is used as grist
1843 rule FGrist {
1844   return $(<:J=!) ;
1848 rule FGristFiles {
1849   return $(<:G=$(SOURCE_GRIST:E)) ;
1853 rule FGristSourceFiles {
1854   ## LOCAL CHANGE: OPT_HEADER_CACHE_EXT
1855   # With header caching, there is no performance penalty to gristing
1856   # header files. It is also not correct to assume that header
1857   # files have global visibility.
1858   #
1859   # Here we comment out the old version and replace it with the new.
1860 #  # Produce source file name name with grist in it,
1861 #  # if SOURCE_GRIST is set.
1863 #  # Leave header files alone, because they have a global
1864 #  # visibility.
1865 #  if ! $(SOURCE_GRIST) {
1866 #    return $(<) ;
1867 #  } else {
1868 #    local _i _o ;
1870 #    for _i in $(<) {
1871 #      switch $(_i) {
1872 #        case *.h : _o += $(_i) ;
1873 #        case *   : _o += $(_i:G=$(SOURCE_GRIST)) ;
1874 #      }
1875 #    }
1876 #    return $(_o) ;
1877 #  }
1878   return [ FGristFiles $(<) ] ;
1882 rule FReverse {
1883   if $(1) { return [ FReverse $(1[2-]) ] $(1[1]) ; }
1887 rule FSubDir {
1888   # If $(>) is the path to the current directory, compute the
1889   # path (using ../../ etc) back to that root directory.
1890   # Sets result in $(<)
1891   if ! $(<[1]) {
1892     return $(DOT) ;
1893   } else {
1894     local _i _d ;
1896     _d = $(DOTDOT) ;
1897     for _i in $(<[2-]) { _d = $(_d:R=$(DOTDOT)) ; }
1898     return $(_d) ;
1899   }
1903 rule FStripCommon {
1904   # FStripCommon v1 : v2 ;
1906   # Strip common initial elements of variables v1 and v2.
1907   # Modifies the variable values themselves.
1908   if $($(<)[1]) && $($(<)[1]) = $($(>)[1]) {
1909     $(<) = $($(<)[2-]) ;
1910     $(>) = $($(>)[2-]) ;
1911     FStripCommon $(<) : $(>) ;
1912   }
1916 rule FRelPath {
1917   local _l _r ;
1919   # first strip off common parts
1920   _l = $(<) ;
1921   _r = $(>) ;
1922   FStripCommon _l : _r ;
1924   # now make path to root and path down
1925   _l = [ FSubDir $(_l) ] ;
1926   _r = [ FDirName $(_r) ] ;
1928   # Concatenate and save
1929   # XXX This should be better
1930   if $(_r) = $(DOT) { return $(_l) ; } else { return $(_r:R=$(_l)) ; }
1934 rule FAppendSuffix {
1935   # E.g., "FAppendSuffix yacc lex foo.bat : $(SUFEXE) ;"
1936   # returns (yacc,lex,foo.bat) on Unix and
1937   # (yacc.exe,lex.exe,foo.bat) on NT.
1938   if $(>) {
1939     local _i _o ;
1941     for _i in $(<) {
1942       if $(_i:S) { _o += $(_i) ; } else { _o += $(_i:S=$(>)) ; }
1943     }
1944     return $(_o) ;
1945   } else {
1946     return $(<) ;
1947   }
1952 # Operating system specific utility rules
1953 # First, the (generic) UNIX versions
1956 rule FQuote { return "\\\"$(<)\\\"" ; }
1957 rule FDefines { return -D$(<) ; }
1958 rule FIncludes { return -I$(<) ; }
1960 rule FDirName {
1961   # Turn individual elements in $(<) into a usable path.
1962   local _i ;
1963   local _s = $(DOT) ;
1965   for _i in $(<) { _s = $(_i:R=$(_s)) ; }
1966   return $(_s) ;
1970 if $(NT) && $(JAM_TOOLSET) != MINGW && $(JAM_TOOLSET) != LCC {
1971   rule FDefines { return /D$(<) ; }
1972   rule FIncludes { return /I$(<) ; }
1977 # various install rules
1980 rule InstallInto {
1981   # InstallInto dir : sources ;
1983   local i t ;
1985   t = $(>:G=$(INSTALLGRIST)) ;
1987   # Arrange for jam install
1988   # Arrange for jam uninstall
1989   # sources are in SEARCH_SOURCE
1990   # targets are in dir
1992   Depends install : $(t) ;
1993   Clean uninstall : $(t) ;
1994   SEARCH on $(>) = $(SEARCH_SOURCE) ;
1995   MakeLocate $(t) : $(<) ;
1997   # For each source, make gristed target name
1998   # and Install, Chmod, Chown, and Chgrp
1999   for i in $(>) {
2000     local tt = $(i:G=$(INSTALLGRIST)) ;
2002     Depends $(tt) : $(i) ;
2003     Install $(tt) : $(i) ;
2004     Chmod $(tt) ;
2006     if $(OWNER) && $(CHOWN) {
2007       Chown $(tt) ;
2008       OWNER on $(tt) = $(OWNER) ;
2009     }
2010     if $(GROUP) && $(CHGRP) {
2011       Chgrp $(tt) ;
2012       GROUP on $(tt) = $(GROUP) ;
2013     }
2014   }
2018 # /InstallBin dir : sources ;
2020 # Copy _sources_ into _dir_ with mode $(EXEMODE)
2022 rule InstallBin {
2023   local _t = [ FAppendSuffix $(>) : $(SUFEXE) ] ;
2025   InstallInto $(<) : $(_t) ;
2026   MODE on $(_t:G=$(INSTALLGRIST)) = $(EXEMODE) ;
2030 # /InstallFile dir : sources ;
2032 # Copy _sources_ into _dir_ with mode $(FILEMODE)
2034 rule InstallFile {
2035   InstallInto $(<) : $(>) ;
2036   MODE on $(>:G=$(INSTALLGRIST)) = $(FILEMODE) ;
2040 # /InstallLib dir : sources ;
2042 # Copy _sources_ into _dir_ with mode $(FILEMODE)
2044 rule InstallLib {
2045   InstallInto $(<) : $(>) ;
2046   MODE on $(>:G=$(INSTALLGRIST)) = $(FILEMODE) ;
2050 # /InstallMan dir : sources ;
2052 #  Copy _sources_ into the appropriate subdirectory of _dir_ with mode
2053 #  $(FILEMODE). The subdirectory is manS, where S is the suffix of each of
2054 #  sources.
2056 rule InstallMan {
2057   # Really this just strips the . from the suffix
2058   local i s d ;
2060   for i in $(>) {
2061     switch $(i:S) {
2062       case .1 : s = 1 ; case .2 : s = 2 ; case .3 : s = 3 ;
2063       case .4 : s = 4 ; case .5 : s = 5 ; case .6 : s = 6 ;
2064       case .7 : s = 7 ; case .8 : s = 8 ; case .l : s = l ;
2065       case .n : s = n ; case .man : s = 1 ;
2066     }
2067     d = man$(s) ;
2068     InstallInto $(d:R=$(<)) : $(i) ;
2069   }
2070   MODE on $(>:G=$(INSTALLGRIST)) = $(FILEMODE) ;
2074 # /InstallShell dir : sources ;
2076 # Copy _sources_ into _dir_ with mode $(SHELLMODE)
2078 rule InstallShell {
2079   InstallInto $(<) : $(>) ;
2080   MODE on $(>:G=$(INSTALLGRIST)) = $(SHELLMODE) ;
2084 rule WindozeResourceCompiler {
2085   DEPENDS $(<) : $(>) ;
2086   Clean clean : $(<) ;
2089 rule windoze-fix {
2090   if $(WINDOZE) {
2091     if $(WINDOZE_THREADS) {
2092       CC += -mthreads ;
2093       CC++ += -mthreads ;
2094     }
2095     local ss = $(WINSUBSYS) ;
2096     if ! $(ss) { ss = "console" ; }
2097     LINK += "-Wl,-subsystem,$(ss)" ;
2098     C++LINK += "-Wl,-subsystem,$(ss)" ;
2099     if $(WINLIBS) { LINKLIBS += $(WINLIBS) ; } else { LINKLIBS += -lkernel32 ; }
2100   }
2105 # Actions
2107 actions WindozeResourceCompiler {
2108   "$(WINE)" $(MGPATH)windres.exe -i $(>) -o $(<)
2112 # First the defaults
2114 actions updated together piecemeal Archive {
2115   $(AR) $(<) $(>)
2119 actions As {
2120   $(AS) $(ASFLAGS) $(ASHDRS) -o $(<) $(>)
2124 actions Cc {
2125   $(CC) -c -o $(<) $(CFLAGS.all) $(CCFLAGS) $(OPTIM.all) $(OPTIM) $(CCDEFS) $(CCHDRS) $(>)
2129 actions C++ {
2130   $(C++) -c -o $(<) $(CFLAGS.all) $(C++FLAGS) $(OPTIM.all) $(C++OPTIM) $(CCDEFS) $(CCHDRS) $(>)
2134 actions ObjC {
2135   $(OBJCC) -c -o $(<) $(CFLAGS.all) $(OBJCFLAGS) $(OPTIM.all) $(OBJCOPTIM) $(CCDEFS) $(CCHDRS) $(>)
2139 actions Dc {
2140   $(DC) -c -of$(<) $(DCFLAGS) $(DOPTIM) $(>)
2144 actions Chgrp {
2145   $(CHGRP) $(GROUP) $(<)
2149 actions Chmod1 {
2150   $(CHMOD) $(MODE) $(<)
2154 actions Chown {
2155   $(CHOWN) $(OWNER) $(<)
2159 actions piecemeal together existing Clean {
2160   $(RM) $(>)
2164 actions File {
2165   $(CP) $(>) $(<)
2169 actions GenFile1 {
2170   $(>[1]) $(<) $(>[2-])
2174 actions HardLink {
2175   $(RM) $(<) && $(LN) $(>) $(<)
2179 actions Install {
2180   $(CP) $(>) $(<)
2184 actions Lex {
2185   $(LEX) -o $(<) $(>)
2189 ##actions LexMv {
2190 ##  $(MV) lex.yy.c $(<)
2194 actions Link bind NEEDLIBS {
2195   $(LINK) $(LINKFLAGS.all) $(LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS.all) $(LINKLIBS)
2198 actions C++Link bind NEEDLIBS {
2199   $(C++LINK) $(LINKFLAGS.all) $(C++LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS.all) $(C++LINKLIBS)
2202 actions ObjC-Link bind NEEDLIBS {
2203   $(OBJCLINK) $(LINKFLAGS.all) $(OBJCLINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS.all) $(OBJCLINKLIBS)
2207 actions updated together piecemeal LinkUnixLibrary bind NEEDLIBS {
2208   $(LINK) $(LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS)
2211 actions updated together piecemeal C++LinkUnixLibrary bind NEEDLIBS {
2212   $(C++LINK) $(C++LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(C++LINKLIBS)
2216 actions MkDir1 {
2217   $(MKDIR) $(<)
2221 actions together Ranlib {
2222   $(RANLIB) $(<)
2226 actions quietly updated piecemeal together RmTemps {
2227   $(RM) $(>)
2231 actions Shell {
2232 #DONT_TOUCH
2233   $(AWK) '
2234     NR == 1 { print "$(SHELLHEADER)" }
2235     NR == 1 && /^[#:]/ { next }
2236     /^##/ { next }
2237     { print }
2238   ' < $(>) > $(<)
2239 #DONT_TOUCH
2243 actions SoftLink {
2244   $(RM) $(<) && $(LN) -s $(>) $(<)
2248 actions Yacc1 {
2249   $(YACC) $(YACCFLAGS) $(>) -o $(<)
2253 actions YaccMv {
2254   #$(MV) $(YACCFILES).c $(<[1])
2255   #$(MV) $(YACCFILES).h $(<[2])
2260 # RELOCATE - for compilers with broken -o flags
2262 if $(RELOCATE) {
2263   actions C++ {
2264     $(C++) -c $(C++FLAGS) $(OPTIM) $(CCDEFS) $(CCHDRS) $(>)
2265   }
2266   actions Cc {
2267     $(CC) -c $(CCFLAGS) $(OPTIM) $(CCDEFS) $(CCHDRS) $(>)
2268   }
2269   actions ignore CcMv {
2270     [ $(<) != $(>:BS=$(SUFOBJ)) ] && $(MV) $(>:BS=$(SUFOBJ)) $(<)
2271   }
2276 # NOARUPDATE - can't update an archive
2278 if $(NOARUPDATE) {
2279   actions Archive {
2280     $(AR) $(<) $(>)
2281   }
2286 # UNIX specific actions
2288 if $(UNIX) {
2289   actions GenFile1 {
2290     PATH="$PATH:."
2291     $(>[1]) $(<) $(>[2-])
2292   }
2297 # NT specific actions
2299 if $(NT) {
2300   if $(JAM_TOOLSET) = MINGW {
2301     actions together piecemeal Archive {
2302       $(AR) $(<) $(>:T)
2303     }
2304     actions Cc {
2305       $(CC) -c -o $(<) $(CCFLAGS) $(OPTIM) $(CCDEFS) $(CCHDRS) -I$(STDHDRS) $(>)
2306     }
2307     actions C++ {
2308       $(C++) -c -o $(<) $(C++FLAGS) $(OPTIM) $(CCDEFS) $(CCHDRS) -I$(STDHDRS) $(>)
2309     }
2310     actions DllLink bind DEFFILENAME IMPLIBNAME {
2311       $(LINK) $(LINKFLAGS) -shared -o $(<) $(>) $(DEFFILENAME) -Wl,--out-implib,$(IMPLIBNAME)
2312     }
2313   } else if $(JAM_TOOLSET) = LCC {
2314     actions together piecemeal Archive {
2315       $(AR) /out:$(<) $(>)
2316     }
2317     actions Cc {
2318       $(CC) $(CCFLAGS) $(OPTIM) $(CCDEFS) $(CCHDRS) -Fo$(<) -I$(STDHDRS) $(>)
2319     }
2320     actions Link bind NEEDLIBS {
2321       $(LINK) $(LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS)
2322     }
2323     actions DllLink bind NEEDLIBS DEFFILENAME {
2324       $(LINK) $(LINKFLAGS) -DLL -o $(<) $(UNDEFS) $(>) $(DEFFILENAME) $(NEEDLIBS) $(LINKLIBS)
2325     }
2326     actions ignore DllLinkMv {
2327       $(MV) $(2) $(1)
2328     }
2329     actions Shell {
2330       $(CP) $(>) $(<)
2331     }
2332   } else if $(JAM_TOOLSET) = PELLESC {
2333     actions together piecemeal Archive {
2334       $(AR) /OUT:$(<) $(>)
2335     }
2336     actions Cc {
2337       $(CC) $(CCFLAGS) $(OPTIM) $(CCDEFS) $(CCHDRS)   /Fo $(<) -I$(STDHDRS)  $(>)
2338     }
2339     actions Link bind NEEDLIBS {
2340       $(LINK) $(LINKFLAGS) /OUT:$(<) $(>) $(NEEDLIBS) $(LINKLIBS)
2341     }
2342     actions DllLink bind NEEDLIBS DEFFILENAME IMPLIBNAME {
2343       $(LINK) $(LINKFLAGS) /DLL /DEF:$(DEFFILENAME) /IMPLIB:$(IMPLIBNAME) /OUT:$(<) $(>) $(NEEDLIBS) $(LINKLIBS)
2344     }
2345     actions Shell {
2346       $(CP) $(>) $(<)
2347     }
2348   }
2353 # Ketmar's additions
2355 rule SetCPUFlags {
2356   if $(OS) != "LINUX" {
2357     DETECTED_CPU = "i486" ;
2358     OPTIM_SPEED = -O3 -march=i486 -mtune=i486 ;
2359   } else {
2360     DETECTED_CPU = native ;
2361     OPTIM_SPEED = -O3 -march=native -mtune=native ;
2362   }
2366 # VAR = [ RemoveOptWild regexp-options-to-remove : options-list ] ;
2367 # remove options from list with egrep-like regexps
2368 rule RemoveOptWild {
2369   local oname = $(1) ;
2370   local str = $(2) ;
2371   local res = ;
2372   local f ;
2373   local t ;
2374   #Echo "removing " $(oname) " from " $(str) ;
2375   for f in $(str) {
2376     t = [ Match $(oname) : $(f) ] ;
2377     #Echo $(f) ": " $(t) ;
2378     if $(t[1]) = "" {
2379       #Echo "include: " $(f) ;
2380       res += $(f) ;
2381     }
2382   }
2383   return $(res) ;
2387 # profile rules
2388 K8JAM-KNOWN-PROFILES =
2389   none default  # don't change
2390   empty         # remove optimisation flags
2391   speed         # optimise for speed
2392   size          # optimise for size
2393   debug         # don't optimize, add debug info
2394   standard      # -O2
2398 rule --k8jam-profile-none {
2399   Echo "MSG: default profile" ;
2400   OPT_PROFILE = ;
2403 rule --k8jam-profile-empty {
2404   Echo "MSG: default profile" ;
2407 rule --k8jam-profile-empty-- {
2408   Echo "MSG: empty profile" ;
2409   SLACK_PKG_ARCH = "i486" ;
2410   LINKFLAGS.all += -s ;
2413 rule --k8jam-profile-speed-- {
2414   Echo "MSG: 'speed' profile" ;
2415   SLACK_PKG_ARCH = "i686" ;
2416   CFLAGS.all += $(OPTIM_SPEED) ;
2417   LINKFLAGS.all += $(LINKFLAGS_SPEED) ;
2420 rule --k8jam-profile-size-- {
2421   Echo "MSG: 'size' profile" ;
2422   SLACK_PKG_ARCH = "i686" ;
2423   CFLAGS.all += $(OPTIM_SIZE) ;
2424   LINKFLAGS.all += $(LINKFLAGS_SIZE) ;
2427 rule --k8jam-profile-debug-- {
2428   Echo "MSG: 'debug' profile" ;
2429   SLACK_PKG_ARCH = "i486" ;
2430   LINKFLAGS.all -= -s ;
2431   CFLAGS.all += $(OPTIM_DEBUG) ;
2432   LINKFLAGS.all += $(LINKFLAGS_DEBUG) ;
2435 rule --k8jam-profile-standard-- {
2436   Echo "MSG: 'standard' profile" ;
2437   SLACK_PKG_ARCH = "i486" ;
2438   CFLAGS.all += -O2 ;
2439   LINKFLAGS.all += -s ;
2443 # profile "name" ;
2444 # set compile flags for profile; works only for gcc/g++
2445 # available profiles:
2446 #  none, default: don't change
2447 #  empty: remove optimisation flags
2448 #  speed: optimise for speed and pIII
2449 #  size: optimise for size
2450 #  debug: don't optimize, add debug info
2451 #  standard: -O2
2452 rule profile {
2453   if ! $(1) in $(K8JAM-KNOWN-PROFILES) {
2454     Echo "known profiles: $(K8JAM-KNOWN-PROFILES)" ;
2455     Exit "unknown profile: $(1)" ;
2456   }
2458   local orm = "(^\\-march\\=)" "(^\\-mtune\\=)" "(^\\-mfpmath\\=)" "(^\\-O.$)" ;
2459   local ormff = "(^\\-f[^n][^o])" ;
2461   OPTIM = [ RemoveOptWild $(orm) $(ormff) : $(OPTIM) ] ;
2462   C++OPTIM = [ RemoveOptWild $(orm) $(ormff) : $(C++OPTIM) ] ;
2463   OBJCOPTIM = [ RemoveOptWild $(orm) $(ormff) : $(OBJCOPTIM) ] ;
2464   OPTIM.all = [ RemoveOptWild $(orm) $(ormff) : $(OPTIM.all) ] ;
2465   LINKFLAGS -= "-g" "-s" ;
2466   C++LINKFLAGS -= "-g" "-s" ;
2467   OBJCLINKFLAGS -= "-g" "-s" ;
2468   LINKFLAGS.all -= "-g" "-s" ;
2470   OPT_PROFILE = $(1) ;
2471   --k8jam-profile-$(OPT_PROFILE)-- ;
2473 #SLACK_PKG_ARCH ?= "i486" ;
2476 # selects 'debug', 'standard', 'speed' or 'size' profile according to vars:
2477 #  DEBUG = 1 : debug
2478 #  OPT_SIZE = 1 : size
2479 #  OPT_SPEED = 1 : speed
2480 #  OPT=SIZE or OPT=SPEED
2481 #  default: standard
2482 rule set-profile {
2483   local otp ;
2485   if $(OPT) = "size" { otp = "size" ; }
2486   else if $(OPT) = "SIZE" { otp = "size" ; }
2487   if $(OPT) = "speed" { otp = "speed" ; }
2488   else if $(OPT) = "SPEED" { otp = "speed" ; }
2489   else if $(OPT_SIZE) { otp = "size" ; }
2490   else if $(OPT_SPEED) { otp = "speed" ; }
2492   if $(DEBUG) {
2493     profile "debug" ;
2494   } else if $(otp) = "size" {
2495     profile "size" ;
2496   } else if $(otp) = "speed" {
2497     profile "speed" ;
2498   } else {
2499     profile "standard" ;
2500   }
2501   if $(VALGRIND) {
2502     CFLAGS.all -= "-g" "-s" ;
2503     LINKFLAGS.all -= "-g" "-s" ;
2504     CFLAGS.all += -g ;
2505     LINKFLAGS.all += -g ;
2506   }
2507   if ! $(NO_WARNINGS) {
2508     CFLAGS.all += -Wall ;
2509   }
2513 # set default 'locate' vars -- _build/, etc
2514 rule set-default-subdir-locates {
2515   local bdir ;
2516   local d = $(TOP) ;
2518   if ! $(d) { d = "." ; }
2519   if $(WINDOZE) { bdir = _wbuild ; } else { bdir = _build ; }
2521   ALL_LOCATE_BIN = $(d) ;
2522   ALL_LOCATE_LIBSO = $(d) ;
2523   ALL_LOCATE_TARGET = "$(d)$(PATH_SEPARATOR)$(bdir)" ;
2524   ALL_LOCATE_LIB = "$(d)$(PATH_SEPARATOR)$(bdir)$(PATH_SEPARATOR)_libs" ;
2525   HCACHEFILE = "$(d)$(PATH_SEPARATOR)$(bdir)$(PATH_SEPARATOR).jamhdr.cache" ;
2527   Clean clean : $(HCACHEFILE) ;
2531 rule set-default-target-locations {
2532   set-default-subdir-locates ;
2535 rule set-default-locations {
2536   set-default-subdir-locates ;
2539 rule set-target-locations {
2540   set-default-subdir-locates ;
2545 # windoze setup
2548 rule setup-windoze {
2549   if ! $(WINDOZE) { WINDOZE = 1 ; }
2550   PICFLAGS = ;
2551   SUFLIBSHR = .dll ;
2552   #WINDOZE_THREADS = -mthreads ;
2553   #WINDOZE_THREADS = ;
2554   WINE ?= "wine" ;
2555   MGPATH ?= "c:\\\\mingw\\\\bin\\\\" ;
2556   MGCC ?= "mingw32-gcc.exe -static-libgcc" ;
2557   MG++ ?= "mingw32-g++.exe -static-libgcc -static-libstdc++" ;
2558   CC = "$(WINE)" $(MGPATH)$(MGCC) ;
2559   LINK = "$(WINE)" $(MGPATH)$(MGCC) -Wl,--enable-auto-import ;
2560   AR = "$(WINE)" $(MGPATH)ar.exe -ru ;
2561   RANLIB = "$(WINE)" $(MGPATH)ranlib.exe ;
2562   C++ = "$(WINE)" $(MGPATH)$(MG++) ;
2563   C++LINK = "$(WINE)" $(MGPATH)$(MG++) -Wl,--enable-auto-import ;
2564   #LINKLIBS += -lkernel32 ;
2565   #LINKLIBS += -luser32 ;
2566   #LINKLIBS += -ladvapi32 ;
2567   #LINKLIBS += -lws2_32 ;
2568   #WINSUBSYS = "windows" ;
2569   #WINSUBSYS = "console" ;
2570   SUFEXE = .exe ;
2571   #LINKFLAGS += "-Wl,-subsystem,$(WINSUBSYS)" ;
2575 rule check-setup-windoze {
2576   if $(WINDOZE) { setup-windoze ; }
2580 rule use-mingw32 {
2581   CC = i686-pc-mingw32-gcc -pipe -static-libgcc ;
2582   C++ = i686-pc-mingw32-g++ -pipe -static-libgcc -static-libstdc++ ;
2583   LINK = i686-pc-mingw32-gcc -pipe -Wl,--enable-auto-import ;
2584   C++LINK = i686-pc-mingw32-g++ -pipe -Wl,--enable-auto-import ;
2585   AR = i686-pc-mingw32-ar -ru ;
2586   RANLIB = i686-pc-mingw32-ranlib ;
2588   actions WindozeResourceCompiler {
2589     i686-pc-mingw32-windres -i $(>) -o $(<)
2590   }
2594 # ObjectNoAliasing filelist ;
2595 # turn off aliasing optimization for specified files
2596 # works only for gcc/g++
2597 rule ObjectNoAliasing {
2598   local isGCC = "ona" ;
2599   local isG++ = "ona" ;
2600   if ( "gcc" in $(CC) ) || ( $(JAM_TOOLSET) = MINGW ) { isGCC = "tan" ; }
2601   if ( "g++" in $(C++) ) || ( $(JAM_TOOLSET) = MINGW ) { isG++ = "tan" ; }
2602   if $(JAM_FORCE_GCC_OPTIONS) { isGCC = "tan" ; isG++ = "tan" ; }
2604   if $(isGCC) = "tan" { CCFLAGS on [ FGristFiles $(<:S=$(SUFOBJ)) ] += $(OPTIM_NOALIAS) ; }
2605   if $(isG++) = "tan" { C++FLAGS on [ FGristFiles $(<:S=$(SUFOBJ)) ] += $(OPTIM_NOALIAS) ; }
2606   OBJCFLAGS on [ FGristFiles $(<:S=$(SUFOBJ)) ] += $(OPTIM_NOALIAS) ;
2610 rule gcc-suggest-attrs {
2611   if $(SUGGEST) {
2612     CFLAGS.all += -Wsuggest-attribute=const ;
2613     CFLAGS.all += -Wsuggest-attribute=pure ;
2614     CFLAGS.all += -Wsuggest-attribute=noreturn ;
2615   }
2619 # call $(1)
2620 # add output to var $(2)
2621 # return resulting (non-empty) string if library is present
2622 # if $(2) = "" -- don't add flags, just return
2623 # [ lib-config-ex "pkg-config sdl --cflags" : "CFLAGS" ]
2624 rule lib-config-ex {
2625   local cf lf res ;
2626   cf = [ Command "$(1) 2>/dev/null" : parse-output exit-code code-first ] ;
2627   if $(cf[1]) = "0" && $(cf[2]) {
2628     res = $(cf[2-]) ;
2629     if $(2) {
2630       $(2) += $(cf[2-]) ;
2631     }
2632   } else {
2633     res = ;
2634   }
2635   return $(res) ;
2639 # call $(1) --cflags and $(1) --libs (many libs provides such configurators)
2640 # add necessary flags to compiler and linker vars
2641 # return "tan" (non-empty string) if library is present
2642 # if $(2) != "" -- don't add flags, just check
2643 # [ lib-config "pkg-config sdl" ]
2644 rule lib-config {
2645   local cf lf hasit ;
2647   cf = [ Command "$(1) --cflags 2>/dev/null" : parse-output exit-code code-first ] ;
2648   #Echo "cf:" $(cf) ;
2649   if $(cf[1]) = "0" && $(cf[2]) {
2650     hasit = "tan" ;
2651     #Echo "flags:" $(cf[2-]) ;
2652     if ! $(2) {
2653       CCFLAGS += $(cf[2-]) ;
2654       C++FLAGS += $(cf[2-]) ;
2655       OBJCFLAGS += $(cf[2-]) ;
2656     }
2657   }
2659   lf = [ Command "$(1) --libs 2>/dev/null" : parse-output exit-code code-first ] ;
2660   #Echo "lf:" $(lf) ;
2661   if $(lf[1]) = "0" && $(lf[2]) {
2662     hasit = "tan" ;
2663     #Echo "flags:" $(lf[2-]) ;
2664     if ! $(2) {
2665       LINKFLAGS += $(lf[2-]) ;
2666       C++LINKFLAGS += $(lf[2-]) ;
2667       OBJCLINKFLAGS += $(lf[2-]) ;
2668     }
2669   }
2671   return $(hasit) ;
2674 rule pkg-config {
2675   local res ;
2676   res = [ lib-config "pkg-config $(1)" ] ;
2677   return $(res) ;
2681 rule pkg-config-has {
2682   local res ;
2683   res = [ lib-config-ex "pkg-config $(1) --cflags --libs" ] ;
2684   return $(res) ;
2688 rule sys-has-command {
2689   local cf ;
2691   cf = [ Command "which \"$(1)\" 2>/dev/null 1>&2" : exit-code code-first ] ;
2692   #Echo "cf:" $(cf) ;
2693   if $(cf[1]) = "0" {
2694     return "tan" ;
2695   }
2697   return "" ;
2702 # Objective C vars
2705 OBJC_GNUSTEP_BASE_LIB = gnustep-base ;
2706 OBJC_GNUSTEP_GUI_LIB = gnustep-gui ;
2709 # Objective C rules
2711 rule ObjCUseGNUstepBase {
2712   if ! $(K8_INTERNAL_GNUSTEP_BASE) {
2713     #Echo "-l$(OBJC_GNUSTEP_BASE_LIB)" ;
2714     OBJCLINKLIBS += "-l$(OBJC_GNUSTEP_BASE_LIB)" ;
2715     K8_INTERNAL_GNUSTEP_BASE = tan ;
2716   }
2719 rule ObjCUseGNUstepGui {
2720   ObjCUseGNUstepBase ;
2721   if ! $(K8_INTERNAL_GNUSTEP_GUI) {
2722     K8_INTERNAL_GNUSTEP_GUI = tan ;
2723     #Echo "-l$(OBJC_GNUSTEP_GUI_LIB)" ;
2724     OBJCLINKLIBS += "-l$(OBJC_GNUSTEP_GUI_LIB)" ;
2725   }
2728 rule ObjCUseGNUstep {
2729   ObjCUseGNUstepBase ;
2730   ObjCUseGNUstepGui ;
2735 # 'help' and 'push' targets
2737 rule ShowHelpProfile {
2738   NotFile help-profile ;
2739   Always help-profile ;
2740   AShowHelpProfile help-profile ;
2742 actions AShowHelpProfile {
2743   echo "profile flags:"
2744   echo "  DEBUG=1           -- debug build"
2745   echo "  OPT_SPEED=1       -- optimize for speed"
2746   echo "  OPT_SIZE=1        -- optimize for size"
2747   echo "  VALGRIND=1        -- do not strip debug info"
2748   echo "  NO_WARNINGS=1     -- do not all '-Wall' flag"
2749   echo "WARNING: DON'T FORGET TO DO 'jam clean' before building with new flags!"
2751 ShowHelpProfile ;
2753 rule ShowHelp {
2754   NotFile help ;
2755   Always help ;
2756   AShowHelp help ;
2757   #AShowHelpProfile help ;
2759 actions AShowHelp {
2760   echo "WARNING: default help; override 'actions AShowHelp' definition to use 'help' target!"
2762 ShowHelp ;
2764 rule GitPush {
2765   NotFile push ;
2766   Always push ;
2767   AGitPush push ;
2769 actions AGitPush {
2770   echo "WARNING: add 'actions AGitPush' definition to use 'push' target!"
2772 GitPush ;
2775 check-setup-windoze ;
2778 # Now include the user's Jamfile.
2780 include $(JAMFILE) ;