default profiles now using '-std=gnu99'
[k8jam.git] / defaults / Jambase
blob917c4314b48d63100a31c720a6181850cc283a99
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_STANDARD = -O2 -march=native -mtune=native ;
205 LINKFLAGS_STANDARD = -s ;
207 OPTIM_DEBUG = -O0 -g ;
208 LINKFLAGS_DEBUG = -g ;
210 OPTIM_NOALIAS = -fno-strict-aliasing ;
214 # OS specific variable settings
217 ###############################################################################
218 # Windoze
219 ###############################################################################
220 if $(NT) {
221   PATH_SEPARATOR = "\\" ;
222   local SUPPORTED_TOOLSETS =
223     MINGW
224     LCC
225     PELLESC
226   ;
228   # if the JAM_TOOLSET environment variable is defined, check that it is
229   # one of our supported values
230   #
231   if $(JAM_TOOLSET) {
232     if ! $(JAM_TOOLSET) in $(SUPPORTED_TOOLSETS) {
233       Echo "The JAM_TOOLSET environment variable is defined but its value" ;
234       Echo "is invalid, please use one of the following:" ;
235       Echo ;
236       for t in $(SUPPORTED_TOOLSETS) { Echo "  " $(t) ; }
237       Exit ;
238     }
239   }
241   if ! $(JAM_TOOLSET) {
242     Echo "The JAM_TOOLSET environment variable is not defined, defaults to MINGW" ;
243     JAM_TOOLSET = MINGW ;
244     MINGW = "c:\\mingw\\" ;
245   }
247   MV        ?= move /y ;
248   CP        ?= copy ;
249   RM        ?= del /f/q ;
250   RMDIR     ?= rmdir /s/q ;
251   SLASH     ?= \\ ;
252   SUFLIB    ?= .lib ;
253   SUFOBJ    ?= .obj ;
254   SUFEXE    ?= .exe ;
255   SUFLIBSHR ?= .dll ;
257   if $(JAM_TOOLSET) = MINGW {
258     Echo "Compiler is GCC with MinGW" ;
259     AR           ?= ar -ru ;
260     RANLIB       ?= ranlib ;
261     CC           ?= mingw-gcc ;
262     CCFLAGS      ?= "" ;
263     C++          ?= mingw-g++ ;
264     C++FLAGS     ?= $(CCFLAGS) ;
265     LINK         ?= $(CC) ;
266     LINKFLAGS    ?= "" ;
267     LINKLIBS     ?= -lkernel32 ;
268     OPTIM        ?= ;
269     SUFOBJ        = .o ;
270     SUFLIB        = .a ;
271     SLASH         = / ;
272     # MinGW-specific thingy
273     MINGW_GUI     = "-Wl,-subsystem,windows" ;
274     MINGW_THREADS = "-mthreads" ;
275     # k8
276     C++OPTIM     ?= $(OPTIM) ;
277     C++LINK      ?= $(C++) ;
278     C++LINKFLAGS ?= $(LINKFLAGS) ;
279     C++LINKLIBS  ?= $(LINKLIBS) ;
280     #NOARSCAN     ?= true ;
281     # set path if any
282     if $(MINGW) {
283       CC = "$(MINGW)$(CC:J= )" ;
284       C++ = "$(MINGW)$(C++:J= )" ;
285       LINK = "$(MINGW)$(LINK:J= )" ;
286       C++LINK = "$(MINGW)$(C++LINK:J= )" ;
287       AR = "$(MINGW)$(AR:J= )" ;
288       RANLIB = "$(MINGW)$(RANLIB:J= )" ;
289     }
290   } else if $(JAM_TOOLSET) = LCC {
291     Echo "Compiler is Win32-LCC" ;
292     AR        ?= lcclib ;
293     CC        ?= lcc ;
294     CCFLAGS   ?= "" ;
295     C++       ?= "error" ;
296     LINK      ?= lcclnk ;
297     LINKFLAGS ?= "" ;
298     LINKLIBS  ?= "" ;
299     OPTIM     ?= ;
300     NOARSCAN   = true ;
301     # k8
302     C++LINK    = "error" ;
303   } else if $(JAM_TOOLSET) = PELLESC {
304     Echo "Compiler is PellesC" ;
305     AR        ?= polib ;
306     CC        ?= pocc ;
307     CCFLAGS   ?= "" ;
308     C++       ?= "error" ;
309     LINK      ?= polink ;
310     LINKFLAGS ?= ;
311     LINKLIBS  ?= ;
312     OPTIM     ?= ;
313     NOARSCAN   = true ;
314     LINKLIBS  ?= crt.lib oldnames.lib Win\\kernel32.lib ;
315     # k8
316     C++LINK    = "error" ;
317   } else {
318     # XXX: We need better comments here !!
319     Exit "On NT, set MINGW to the root of the MinGW dir (but it won't help you anyway)" ;
320   }
321   STDHRS ?= "" ;
322   PICFLAGS = ;
324 ###############################################################################
325 # UNIX
326 ###############################################################################
327 else if $(UNIX) {
328   PATH_SEPARATOR = "/" ;
329   switch $(OS) {
330     case CYGWIN :
331       CC       ?= gcc ;
332       CCFLAGS  += -D__cygwin__ ;
333       LEX      ?= flex ;
334       JAMSHELL ?= sh -c ;
335       RANLIB   ?= "" ;
336       SUFEXE   ?= .exe ;
337       YACC     ?= bison -y ;
338     }
340     # UNIX defaults
341     CC        ?= gcc ;
342     C++       ?= g++ ;
343     OBJCC     ?= gcc ;
344     CCFLAGS   ?= ;
345     OBJCFLAGS ?= $(CCFLAGS) ;
346     C++FLAGS  ?= $(CCFLAGS) ;
347     CHMOD     ?= chmod ;
348     CHGRP     ?= chgrp ;
349     CHOWN     ?= chown ;
350     LEX       ?= flex ;
351     LINKFLAGS ?= $(CCFLAGS) ;
352     LINKLIBS  ?= ;
353     OPTIM     ?= ;
354     RANLIB    ?= ranlib ;
355     YACC      ?= bison ;
356     YACCGEN   ?= .c ;
357     YACCFILES ?= y.tab ;
358     YACCFLAGS ?= -ld ;
359 #!LIBTOOL!#    if $(K8_USE_LIBTOOL) {
360 #!LIBTOOL!#      SUFOBJSHR ?= .lo ;
361 #!LIBTOOL!#      SUFLIBSHR ?= .la ;
362 #!LIBTOOL!#    } else {
363 #!LIBTOOL!#      SUFOBJSHR ?= .o ;
364 #!LIBTOOL!#      SUFLIBSHR ?= .so ;
365 #!LIBTOOL!#    }
366     SUFOBJSHR ?= .o ;
367     SUFLIBSHR ?= .so ;
368 #!LIBTOOL!#
369     PICFLAGS  ?= -fpic ;
370     STDHDRS   ?= /usr/include ;
373 # shared library object file suffix. We assume that it is identical
374 # than the normal one
375 SUFOBJSHR ?= $(SUFOBJ) ;
376 SUFLIBSHR ?= $(SUFLIB) ;
379 # the D compiler
380 DC ?= dmd ;
383 # General defaults; a lot like UNIX
385 PATH_SEPARATOR ?= "/" ;
386 AR          ?= ar ru ;
387 AS          ?= as ;
388 ASFLAGS     ?= ;
389 AWK         ?= awk ;
390 BINDIR      ?= /usr/local/bin ;
391 C++         ?= g++ ;  # k8: was cc
392 C++FLAGS    ?= ;
393 CC          ?= gcc ;  # k8: was cc
394 CCFLAGS     ?= ;
395 CP          ?= cp -f ;
396 CRELIB      ?= ;
397 DOT         ?= . ;
398 DOTDOT      ?= .. ;
399 EXEMODE     ?= 755 ;
400 FILEMODE    ?= 644 ;
401 HDRS        ?= ;
402 INSTALLGRIST    ?= installed ;
403 JAMFILE     ?= Jamfile ;
404 JAMRULES    ?= Jamrules ;
405 LEX         ?= ;
406 LIBDIR      ?= /usr/local/lib ;
407 LINK        ?= $(CC) ;
408 LINKFLAGS   ?= ;
409 LINKLIBS    ?= ;
410 LN          ?= ln ;
411 MANDIR      ?= /usr/local/man ;
412 MKDIR       ?= mkdir ;
413 MV          ?= mv -f ;
414 OPTIM       ?= ;
415 RCP         ?= rcp ;
416 RM          ?= rm -f ;
417 RMDIR       ?= $(RM) ;
418 RSH         ?= rsh ;
419 SED         ?= sed ;
420 SHELLHEADER ?= "#!/bin/sh" ;
421 SHELLMODE   ?= 755 ;
422 SLASH       ?= / ;
423 SUBDIRRULES ?= ;
424 SUBDIRRESET ?= ASFLAGS HDRS C++FLAGS CCFLAGS ;
425 SUFEXE      ?= "" ;
426 SUFLIB      ?= .a ;
427 SUFOBJ      ?= .o ;
428 UNDEFFLAG   ?= "-u _" ;
429 YACC        ?= ;
430 YACCGEN     ?= ;
431 YACCFILES   ?= ;
432 YACCFLAGS   ?= ;
434 HDRPATTERN = "^[[:space:]]*#[[:space:]]*include[[:space:]]*[<\"]([^\">]*)[\">].*$" ;
436 OSFULL = $(OS)$(OSVER)$(OSPLAT) $(OS)$(OSPLAT) $(OS)$(OSVER) $(OS) ;
438 # k8
439 C++OPTIM     ?= $(OPTIM) ;
440 C++LINK      ?= $(C++) ;
441 C++LINKFLAGS ?= $(LINKFLAGS) ;
442 C++LINKLIBS  ?= $(LINKLIBS) ;
444 OBJCOPTIM     ?= $(OPTIM) ;
445 OBJCLINK      ?= $(CC) ;
446 OBJCLINKFLAGS ?= $(LINKFLAGS) ;
447 OBJCLINKLIBS  ?= $(LINKLIBS) ;
448 OBJCLINKLIBS  += -lobjc ;
450 if $(OS) = "LINUX" {
451   if ( "gcc" in $(CC) ) && ! ( "-pipe" in $(CC) ) { CC += -pipe ; }
452   if ( "g++" in $(C++) ) && ! ( "-pipe" in $(C++) ) { C++ += -pipe ; }
455 #Echo "OS:" $(OS) ;
456 #Echo "OSFULL:" $(OSFULL) ;
457 #Echo "UNIX:" $(UNIX) ;
462 # Base dependencies - first for "bootstrap" kinds of rules
464 Depends all : shell files lib exe obj ;
465 Depends all shell files lib exe obj : first ;
466 NotFile all first shell files lib exe obj dirs clean uninstall ;
467 Always  clean uninstall ;
470 # Rules
473 # /As object : source ;
475 # Assemble the file _source_, called by the @Object rule.
477 # Do not call this rule directly, since _object_ and _source_ may have
478 # have platform-specific file extensions
480 rule As {
481   Depends $(<) : $(>) ;
482   ASFLAGS on $(<) += $(ASFLAGS) $(SUBDIRASFLAGS) ;
483   ASHDRS on $(<) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ;
486 # /Bulk  directory : sources ;
488 # Copies _sources_ into _directory_
490 rule Bulk {
491   local i ;
493   for i in $(>) {
494     File $(i:D=$(<)) : $(i) ;
495   }
499 # /Dc object : source ;
501 # Compile the file source into object, usin the D compiler $(DC), its
502 # flags $(DCFLAGS) and $(DOPTIM)
503 # Called by the @Object rule
505 # Do not call this rule directly, since _object_ and _source_ may have
506 # have platform-specific file extensions
508 rule Dc {
509   Depends $(<) : $(>) ;
510   # Just to clarify here: this sets the per-target DCFLAGS to
511   # be the current value of (global) DCFLAGS and SUBDIRDCFLAGS.
512   DCFLAGS on $(<) += $(DCFLAGS) $(SUBDIRDCFLAGS) ;
516 # /Cc object : source ;
518 # Compile the file source into object, using the C compiler $(CC), its
519 # flags $(CCFLAGS) and $(OPTIM), and the header file directories $(HDRS).
520 # Called by the @Object rule
522 # Do not call this rule directly, since _object_ and _source_ may have
523 # have platform-specific file extensions
525 rule Cc {
526   Depends $(<) : $(>) ;
528   # If the compiler's -o flag doesn't work, relocate the .o
529   if $(RELOCATE) { CcMv $(<) : $(>) ; }
531   # Just to clarify here: this sets the per-target CCFLAGS to
532   # be the current value of (global) CCFLAGS and SUBDIRCCFLAGS.
533   # CCHDRS and CCDEFS must be reformatted each time for some
534   # compiles (VMS, NT) that malign multiple -D or -I flags.
535   CCFLAGS on $(<) += $(CCFLAGS) $(SUBDIRCCFLAGS) ;
536   CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
537   CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
541 # /C++ object : source ;
543 # Compile the C++ source file _source_. Similar to @CC, called by @Object
545 # Do not call this rule directly, since _object_ and _source_ may have
546 # have platform-specific file extensions
548 rule C++ {
549   local ktmp ;
551   Depends $(<) : $(>) ;
553   if $(RELOCATE) { CcMv $(<) : $(>) ; }
555   # Just to clarify here: this sets the per-target CCFLAGS to
556   # be the current value of (global) CCFLAGS and SUBDIRCCFLAGS.
557   # CCHDRS and CCDEFS must be reformatted each time for some
558   # compiles (VMS, NT) that malign multiple -D or -I flags.
559   ktmp = $(C++FLAGS) ;
560   if ! $(ktmp) { ktmp = $(CCFLAGS) ; }
561   C++FLAGS on $(<) += $(ktmp) $(SUBDIRC++FLAGS) ;
563   ktmp = $(C++OPTIM) ;
564   if ! $(ktmp) { ktmp = $(OPTIM) ; }
565   C++OPTIM on $(<) += $(ktmp) ;
567   CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
568   CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
572 # /ObjC object : source ;
574 # Compile the ObjC source file _source_. Similar to @CC, called by @Object
576 # Do not call this rule directly, since _object_ and _source_ may have
577 # have platform-specific file extensions
579 rule ObjC {
580   local ktmp ;
582   Depends $(<) : $(>) ;
584   if $(RELOCATE) { CcMv $(<) : $(>) ; }
586   # Just to clarify here: this sets the per-target CCFLAGS to
587   # be the current value of (global) CCFLAGS and SUBDIRCCFLAGS.
588   # CCHDRS and CCDEFS must be reformatted each time for some
589   # compiles (VMS, NT) that malign multiple -D or -I flags.
590   ktmp = $(OBJCFLAGS) ;
591   if ! $(ktmp) { ktmp = $(CCFLAGS) ; }
592   OBJCFLAGS on $(<) += $(ktmp) $(SUBDIROBJCFLAGS) ;
594   ktmp = $(OBJCOPTIM) ;
595   if ! $(ktmp) { ktmp = $(OBJCOPTIM) ; }
596   OBJCOPTIM on $(<) += $(ktmp) ;
598   CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
599   CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
603 # /Chmod target ;
605 # (Unix and VMS only). Change file permissions on _target_ to target-specific
606 # $(MODE) value set by @Link, @File, @Install* and @Shell rules
608 rule Chmod {
609   if $(CHMOD) { Chmod1 $(<) ; }
612 # /Clean  clean : targets ;
614 # Removes existing _targets_ when _clean_ is built. clean is not a dependency
615 # of all, and must be built explicitely for targets to be removed
619 # /File target : source ;
621 # Copies _source_ into _target_
623 rule File {
624   Depends files : $(<) ;
625   Depends $(<) : $(>) ;
626   SEARCH on $(>) = $(SEARCH_SOURCE) ;
627   MODE on $(<) = $(FILEMODE) ;
628   Chmod $(<) ;
632 # /GenFile target : image sources ;
634 # Runs the command "_image_ _target_ _sources_" to create _target_ from
635 # _sources_ and _image_ (where _image_ is an executable built by the
636 # @Main rule)
638 rule GenFile {
639   local _t = [ FGristSourceFiles $(<) ] ;
640   local _s = [ FAppendSuffix $(>[1]) : $(SUFEXE) ] ;
641   Depends $(_t) : $(_s) $(>[2-]) ;
642   GenFile1 $(_t) : $(_s) $(>[2-]) ;
643   Clean clean : $(_t) ;
646 rule GenFile1 {
647   MakeLocate $(<) : $(LOCATE_SOURCE) ;
648   SEARCH on $(>) = $(SEARCH_SOURCE) ;
652 # /HardLink target : source ;
654 # Makes _target_ a hard link to _source_, if it isn't one already
655 # (Unix only)
657 rule HardLink {
658   Depends files : $(<) ;
659   Depends $(<) : $(>) ;
660   SEARCH on $(>) = $(SEARCH_SOURCE) ;
664 # /HdrMacroFile
666 # this rule is specific to FT-Jam. It is used to indicate that a given file
667 # contains definitions for filename macros (e.g. "#define MYFILE_H <myfile>.h")
668 # that can later be used in #include statements in the rest of the source
670 # these files must be parsed before any make is tried.
672 rule HdrMacroFile {
673   HDRMACRO $(<) ;
677 # /HdrRule source : headers ;
679 # Arranges the proper dependencies when the file _source_ includes the files
680 # _headers_ through the #include C preprocessor directive
682 # this rule is not intendend to be called explicitely. It is called
683 # automatically during header scanning on sources handled by the @Object
684 # rule (e.g. sources in @Main or @Library rules)
686 rule HdrRule {
687   # HdrRule source : headers ;
689   # N.B.  This rule is called during binding, potentially after
690   # the fate of many targets has been determined, and must be
691   # used with caution: don't add dependencies to unrelated
692   # targets, and don't set variables on $(<).
694   # Tell Jam that anything depending on $(<) also depends on $(>),
695   # set SEARCH so Jam can find the headers, but then say we don't
696   # care if we can't actually find the headers (they may have been
697   # within ifdefs),
699   local s = $(>:G=$(HDRGRIST:E)) ;
701   Includes $(<) : $(s) ;
702   SEARCH on $(s) = $(HDRSEARCH) ;
703   NoCare $(s) ;
705   # Propagate on $(<) to $(>)
707   HDRSEARCH on $(s) = $(HDRSEARCH) ;
708   HDRSCAN on $(s) = $(HDRSCAN) ;
709   HDRRULE on $(s) = $(HDRRULE) ;
710   HDRGRIST on $(s) = $(HDRGRIST) ;
714 # /Lex source.c : source.l ;
716 # Process the lex source file _source.l_ and rename the lex.yy.c
717 # to _source.c_ . Called by the @Object rule
719 rule Lex {
720   ##LexMv $(<) : $(>) ;
721   Depends $(<) : $(>) ;
722   MakeLocate $(<) : $(LOCATE_SOURCE) ;
723   Clean clean : $(<) ;
727 # /Library  library : sources ;
729 #  Compiles _sources_ and archives them into _library_. The intermediate
730 #  objects are deleted. Calles @Object and @LibraryFromObjects
732 #  If @Library is invoked with no suffix on _library_, the $(SUFLIB)
733 #  suffix is used
735 rule Library {
736   LibraryFromObjects $(<) : $(>:S=$(SUFOBJ)) ;
737   Objects $(>) ;
741 # /SharedLibrary  library : sources : def : import ;
743 # Compiles _sources_ and generates a shared _library_ (i.e. DLL on Windows,
744 # or shared object on Unix). Calls @SharedObjects and @SharedLibraryFromObjects
746 # If @SharedLibrary is invoked with no suffix on _library_, then
747 # $(SUFLIBSHR) suffix is used
749 # _def_ is the name of the corresponding definition file used to generate
750 # the library on Windows and OS/2 (ignored otherwise). If undefined, it
751 # will default to _library_ with the .def suffix
753 # _import_ is the name of the corresponding import library for Windows
754 # and OS/2 platforms (ignored otherwise). If undefined, it will default
755 # to _library_ with the .dll.lib suffix.
757 rule SharedLibrary {
758   #Echo "SharedLibrary: $(<)" ; #dbg
759   #Echo "SharedLibrary: $(>:S=$(SUFOBJSHR))" ; #dbg
760   #Echo "SharedLibrary: $(3)" ; #dbg
761   #Echo "SharedLibrary: $(4)" ; #dbg
762   SharedLibraryFromObjects $(<) : $(>:S=$(SUFOBJSHR)) : $(3) : $(4) ;
763   SharedObjects $(>) ;
766 ######################################################
767 # k8: REWORK!
768 ######################################################
769 #!LIBTOOL!#if $(UNIX) {
770 #!LIBTOOL!#  # this rule is used to find the 'libtool' script in the current
771 #!LIBTOOL!#  # path, this is required when compiling shared objects on Unix
772 #!LIBTOOL!#  rule LibToolFind {
773 #!LIBTOOL!#    if $(LIBTOOL) { return $(LIBTOOL) ; }
774 #!LIBTOOL!#    local matches = [ Glob $(PATH) : libtool ] ;
775 #!LIBTOOL!#    if ! $(matches) { Exit "could not find 'libtool' program in current path. Aborting !" ; }
776 #!LIBTOOL!#    LIBTOOL = $(matches[1]) ;
777 #!LIBTOOL!#    return $(LIBTOOL) ;
778 #!LIBTOOL!#  }
779 #!LIBTOOL!#}
782 # /LibraryFromObjects library : objects ;
784 # Archives _objects_ into _library_. The _objects_ are then deleted
786 # If _library_ has no suffix, the $(SUFLIB) suffix is used
788 # Called by @Library rule. Most people should never call this rule
789 # directly.
791 rule LibraryFromObjects {
792   local _i _l _s ;
794   # Add grist to file names
795   _s = [ FGristFiles $(>) ] ;
796   _l = $(<:S=$(SUFLIB)) ;
798   # library depends on its member objects
799   if $(KEEPOBJS) {
800     Depends obj : $(_s) ;
801   } else {
802     Depends lib : $(_l) ;
803   }
805   # Set LOCATE for the library and its contents.  The bound
806   # value shows up as $(NEEDLIBS) on the Link actions.
807   # For compatibility, we only do this if the library doesn't
808   # already have a path.
809   if ! $(_l:D) {
810     #!!MakeLocate $(_l) $(_l)($(_s:BS)) : $(LOCATE_TARGET) ;
811     MakeLocate $(_l) $(_l)($(_s:BS)) : $(LOCATE_LIB) ;
812   }
814   if $(NOARSCAN) {
815     # If we can't scan the library to timestamp its contents,
816     # we have to just make the library depend directly on the
817     # on-disk object files.
818     Depends $(_l) : $(_s) ;
819   } else {
820     # If we can scan the library, we make the library depend
821     # on its members and each member depend on the on-disk
822     # object file.
823     Depends $(_l) : $(_l)($(_s:BS)) ;
824     for _i in $(_s) {
825       Depends $(_l)($(_i:BS)) : $(_i) ;
826     }
827   }
829   Clean clean : $(_l) ;
831   if $(CRELIB) { CreLib $(_l) : $(_s[1]) ; }
833   Archive $(_l) : $(_s) ;
835   if $(RANLIB) { Ranlib $(_l) ; }
837   # If we can't scan the library, we have to leave the .o's around.
838   if ! ( $(NOARSCAN) || $(NOARUPDATE) ) { RmTemps $(_l) : $(_s) ; }
842 # /SharedLibraryFromObjects  library : objects : def : import ;
844 # Equivalent of @LibraryFromObjects for shared libraries.
846 # Called by @SharedLibrary. Most people shouldn't call this rule
847 # directly
849 rule SharedLibraryFromObjects {
850   local _i _l _s ;
852   # Add grist to file names
853   _s = [ FGristFiles $(>) ] ;
854   _l = $(<:S=$(SUFLIBSHR)) ;
856   #Echo "Library is $(_l)"    ;
857   # library depends on its member objects
858   if $(KEEPOBJS) {
859     Depends obj : $(_s) ;
860   } else {
861     Depends lib : $(_l) ;
862   }
864   # Set LOCATE for the library and its contents.  The bound
865   # value shows up as $(NEEDLIBS) on the Link actions.
866   # For compatibility, we only do this if the library doesn't
867   # already have a path.
868   if ! $(_l:D) {
869     #!!MakeLocate $(_l) : $(LOCATE_TARGET) ;
870     MakeLocate $(_l) : $(LOCATE_LIBSO) ;
871   }
873   #Echo "SharedLibraryFromObjects: _s = $(_s)" ; #dbg
874   #Echo "SharedLibraryFromObjects: _l = $(_l)" ; #dbg
876   # we never scan shared libraries for member objects
877   Depends $(_l) : $(_s) ;
879   Clean clean : $(_l) ;
881   # I don't know if VMS supports shared libraries, so I prefer
882   # to disable the following right now
883   #
884   #if $(CRELIB) { CreLib $(_l) : $(_s[1]) ; }
886   # creating the library is so much fun on Unix :-)
887   if $(UNIX) {
888 #!LIBTOOL!#    if $(K8_USE_LIBTOOL) {
889 #!LIBTOOL!#      local libtool = [ LibToolFind ] ;  # find the right libtool
890 #!LIBTOOL!#      AR on $(_l) = "$(libtool) --mode=link $(AR:J= )" ;
891 #!LIBTOOL!#    } else {
892       LINKFLAGS on $(_l) += "-shared" ;
893       C++LINKFLAGS on $(_l) += "-shared" ;
894       LinkUnixLibrary $(_l) : $(_s) ;
895 #!LIBTOOL!#    }
896   } else if $(NT) {
897     local _implib = $(4) ;
898     local _def    = $(3) ;
900     _implib ?= $(_l:S=$(SUFLIBSHR)$(SUFLIB)) ;
901     _def    ?= $(_l:S=.def) ;
903     Clean    clean : $(_implib) ;
904     Depends  lib   : $(_implib) $(_def) ;
906     Depends $(_implib) : $(_def) $(_l) ;
907     Depends $(_l)      : $(_def) ;
909     DEFFILENAME on $(_l) = $(_def) ;
910     IMPLIBNAME  on $(_l) = $(_implib) ;
912     #!!MakeLocate $(_implib)        : $(LOCATE_TARGET) ;
913     #!!MakeLocate $(_implib:S=.exp) : $(LOCATE_TARGET) ;
914     MakeLocate $(_implib)        : $(LOCATE_LIBSO) ;
915     MakeLocate $(_implib:S=.exp) : $(LOCATE_LIBSO) ;
917     if $(JAM_TOOLSET) in VISUALC BORLANDC LCC WATCOM DIGITALMARS {
918       SharedLink-$(JAM_TOOLSET) $(_l) : $(_s) : $(_implib) : $(_def) ;
919     }
920     DllLink $(_l) : $(_s) ;
921   } else {
922     Echo "Sorry, I don't know how to make a shared library on your system" ;
923     Exit "Please *DON'T* contact the K8Jam maintainer for help" ;
924   }
928 # Since building shared libraries is so different depending on the
929 # compiler being used, I've broken this task into compiler-specific
930 # ones
932 rule SharedLink-LCC {
933   Echo "Sorry, but generating DLLs with LCC is not supported. That's" ;
934   Echo "because the 'lcclnk' tool that comes with this compiler is" ;
935   Echo "unreliable and doesn't work as expected." ;
936   Exit ;
938   # the 'lcclnk' tool is absolutely broken:
939   #   - its -o flag doesn't work when there is a LIBRARY statement
940   #     in the .def file.
941   #
942   #   - it uses the LIBRARY name in the .def file to determine
943   #     the name of the dll and its import library, and always
944   #     places them in the current directory !!
945   #
946   #   - if there is no LIBRARY statement, the -o flag is only
947   #     used to determine where the DLL is placed, the import
948   #     library will always be placed in the current directory !!
949   #
951   # clean the .exp file too, don't know how to get rid of it
952   Clean clean : $(4:S=.exp) ;
956 # /Link  image : objects ;
958 # Links _image_ from _objects_ and sets permissions on _image_ to
959 # $(EXEMODE). _image_ must be an actual filename; suffix is not
960 # supplied.
962 # Called by @Main, shouldn't be called by most people
964 rule Link {
965   MODE on $(<) = $(EXEMODE) ;
966   Chmod $(<) ;
970 # /C++Link  image : objects ;
972 # Links _image_ from _objects_ and sets permissions on _image_ to
973 # $(EXEMODE). _image_ must be an actual filename; suffix is not
974 # supplied.
976 # Called by @Main, shouldn't be called by most people
978 rule C++Link {
979   MODE on $(<) = $(EXEMODE) ;
980   Chmod $(<) ;
983 rule ObjC-Link {
984   MODE on $(<) = $(EXEMODE) ;
985   Chmod $(<) ;
989 # /LinkLibraries image : libraries ;
991 # Makes _image_ depend on _libraries_ and includes them during linking
993 # _image_ may be referenced without a suffix in this rule invocation.
994 # @LinkLibraries supplies the suffix
996 # You should only use this rule with libraries created through the
997 # @Library rule. For external libraries, use something else (XXX)
999 rule LinkLibraries {
1000   # make library dependencies of target
1001   # set NEEDLIBS variable used by 'actions Main'
1002   local _t = [ FAppendSuffix $(<) : $(SUFEXE) ] ;
1004   Depends $(_t) : $(>:S=$(SUFLIB)) ;
1005   NEEDLIBS on $(_t) += $(>:S=$(SUFLIB)) ;
1009 # /LinkSharedLibraries image : libraries :
1011 # Same as @LinkLibraries, but to link _image_ with shared libraries
1012 # generated through the @SharedLibrary rule
1014 rule LinkSharedLibraries {
1015   # make library dependencies of target
1016   # set NEEDLIBS variable used by 'actions Main'
1017   local _t   = [ FAppendSuffix $(<) : $(SUFEXE) ] ;
1018   local _ext = $(SUFLIBSHR) ;
1020   if $(NT) {
1021     # on NT, we need to link agains the import library, not the DLL itself !!
1022     _ext = $(SUFLIBSHR)$(SUFLIB) ;
1023   }
1024   Depends $(_t) : $(>:S=$(_ext))  ;
1025   NEEDLIBS on $(_t) += $(>:S=$(_ext)) ;
1029 # /Main image : sources ;
1031 # Compiles _sources_ and links them into _image_. Calls @Objects and
1032 # @MainFromObjects.
1034 # _image_ may be supplied without suffix.
1036 rule Main {
1037   MainFromObjects $(<) : $(>:S=$(SUFOBJ)) ;
1038   Objects $(>) ;
1042 # /C++Main image : sources ;
1044 # Compiles _sources_ and links them into _image_. Calls @Objects and
1045 # @C++MainFromObjects.
1047 # _image_ may be supplied without suffix.
1049 rule C++Main {
1050   C++MainFromObjects $(<) : $(>:S=$(SUFOBJ)) ;
1051   Objects $(>) ;
1054 rule ObjC-Main {
1055   ObjC-MainFromObjects $(<) : $(>:S=$(SUFOBJ)) ;
1056   Objects $(>) ;
1060 # /MainFromObjects image : objects ;
1062 # Links _objects_ into _image_. Dependency of exe.
1063 # @MainFromObjects provides a default suffix for _image_
1065 rule MainFromObjects {
1066   local _s _t ;
1068   # Add grist to file names
1069   # Add suffix to exe
1070   _s = [ FGristFiles $(>) ] ;
1071   _t = [ FAppendSuffix $(<) : $(SUFEXE) ] ;
1072   # so 'jam foo' works when it's really foo.exe
1074   if $(_t) != $(<) {
1075     Depends $(<) : $(_t) ;
1076     NotFile $(<) ;
1077   }
1079   # make compiled sources a dependency of target
1080   Depends exe : $(_t) ;
1081   Depends $(_t) : $(_s) ;
1082   #k8:MakeLocate $(_t) : $(LOCATE_TARGET) ;
1083   MakeLocate $(_t) : $(LOCATE_BIN) ;
1084   Clean clean : $(_t) ;
1086   # special case for stupid Borland C++, which always generates a
1087   # .tds file for executables, even when no debug information is needed
1088   #
1089   #if $(JAM_TOOLSET) = BORLANDC {
1090   #  MakeLocate $(_t:S=.tds) : $(LOCATE_TARGET) ;
1091   #  Clean  clean : $(_t:S=.tds) ;
1092   #}
1094   Link $(_t) : $(_s) ;
1098 # /C++MainFromObjects image : objects ;
1100 # Links _objects_ into _image_. Dependency of exe.
1101 # @MainFromObjects provides a default suffix for _image_
1103 rule C++MainFromObjects {
1104   local _s _t ;
1106   # Add grist to file names
1107   # Add suffix to exe
1108   _s = [ FGristFiles $(>) ] ;
1109   _t = [ FAppendSuffix $(<) : $(SUFEXE) ] ;
1110   # so 'jam foo' works when it's really foo.exe
1112   if $(_t) != $(<) {
1113     Depends $(<) : $(_t) ;
1114     NotFile $(<) ;
1115   }
1117   # make compiled sources a dependency of target
1118   Depends exe : $(_t) ;
1119   Depends $(_t) : $(_s) ;
1120   #k8:MakeLocate $(_t) : $(LOCATE_TARGET) ;
1121   MakeLocate $(_t) : $(LOCATE_BIN) ;
1122   Clean clean : $(_t) ;
1124   # special case for stupid Borland C++, which always generates a
1125   # .tds file for executables, even when no debug information is needed
1126   #
1127   #if $(JAM_TOOLSET) = BORLANDC {
1128   #  MakeLocate $(_t:S=.tds) : $(LOCATE_TARGET) ;
1129   #  Clean  clean : $(_t:S=.tds) ;
1130   #}
1132   C++Link $(_t) : $(_s) ;  ###k8:FIXME
1136 rule ObjC-MainFromObjects {
1137   local _s _t ;
1139   # Add grist to file names
1140   # Add suffix to exe
1141   _s = [ FGristFiles $(>) ] ;
1142   _t = [ FAppendSuffix $(<) : $(SUFEXE) ] ;
1143   # so 'jam foo' works when it's really foo.exe
1145   if $(_t) != $(<) {
1146     Depends $(<) : $(_t) ;
1147     NotFile $(<) ;
1148   }
1150   # make compiled sources a dependency of target
1151   Depends exe : $(_t) ;
1152   Depends $(_t) : $(_s) ;
1153   #k8:MakeLocate $(_t) : $(LOCATE_TARGET) ;
1154   MakeLocate $(_t) : $(LOCATE_BIN) ;
1155   Clean clean : $(_t) ;
1157   ObjC-Link $(_t) : $(_s) ;  ###k8:FIXME
1161 # /MakeLocate  targets : directory
1163 # Creates _dir_ and causes _target_ to be built into _dir_
1165 # This is done by setting the target-specific variable LOCATE
1166 # on _targets_, and arranges with @MkDir to create the target
1167 # directory
1169 rule MakeLocate {
1170   # Note we grist the directory name with 'dir',
1171   # so that directory path components and other
1172   # targets don't conflict.
1173   local srcname = $(<[1]:G=) ;
1174   local srcdir = $(srcname:D) ;
1175   local outdir = $(>[1]:G=dir) ;
1176   local odir ;
1177   if $(srcdir) {
1178     odir = $(outdir)$(PATH_SEPARATOR)$(srcdir) ;
1179   } else {
1180     odir = $(outdir) ;
1181   }
1182   #Echo "MakeLocate:" "$(<)" "|" "$(>)" ;
1183   #Echo "srcname:" "$(srcname)" ;
1184   #Echo "srcdir :" "$(srcdir)" ;
1185   #Echo "outdir :" "$(outdir)" ;
1186   #Echo "odir   :" "$(odir)" ;
1187   if $(>) {
1188     LOCATE on $(<) = $(>) ;
1189     Depends $(<) : $(odir) ;
1190     MkDir $(odir) ;
1191   }
1195 # /MkDir  dir ;
1197 # Creates _dir_ and its parent directories
1199 rule MkDir {
1200   # Ignore timestamps on directories: we only care if they exist.
1201   NoUpdate $(<) ;
1203   # Don't create . or any directory already created.
1204   if $(<:G=) != $(DOT) && ! $($(<)-mkdir) {
1205     # Cheesy gate to prevent multiple invocations on same dir
1206     # Arrange for jam dirs
1207     # MkDir1 has the actions
1208     $(<)-mkdir = true ;
1209     Depends dirs : $(<) ;
1210     MkDir1 $(<) ;
1212     # Recursively make parent directories.
1213     # $(<:P) = $(<)'s parent, & we recurse until root
1214     local s = $(<:P) ;
1216     # Don't try to create A: or A:\ on windows
1217     if $(NT) {
1218       switch $(s) {
1219         case "*:"   : s = ;
1220         case "*:\\" : s = ;
1221       }
1222     }
1223     # handle "C:", "C:/", "/cygdrive" and "/cygdrive/" in Cygwin
1224     if $(UNIX) && $(OS) = CYGWIN {
1225       switch $(s) {
1226         case "?:"   : s = ;
1227         case "?:/"  : s = ;
1228         case "<dir>/cygdrive"   : s = ;
1229         case "<dir>/cygdrive/"  : s = ;
1230       }
1231     }
1233     if $(s) = $(<) {
1234       # The parent is the same as the dir.
1235       # We're at the root, which some OS's can't stat, so we mark
1236       # it as NotFile.
1237       NotFile $(s) ;
1238     } else if $(s:G=) {
1239       # There's a parent; recurse.
1240       Depends $(<) : $(s) ;
1241       MkDir $(s) ;
1242     }
1243   }
1247 # /Object object : source ;
1249 # Compile s a single _source_ file into _object_. The @Main and @Library
1250 # rules use it to compile sources.
1252 # Causes _source_ to be scanned for #include directives and calls @HdrRule
1253 # to make all included files dependencies of _object_.
1255 # Calls one of the following rules depending on the suffix to do the
1256 # actual compilation:
1258 rule Object {
1259   # locate object and search for source, if wanted
1261   Clean clean : $(<) ;
1262   MakeLocate $(<) : $(LOCATE_TARGET) ;
1263   SEARCH on $(>) = $(SEARCH_SOURCE) ;
1265   # Save HDRS for -I$(HDRS) on compile.
1266   # We shouldn't need -I$(SEARCH_SOURCE) as cc can find headers
1267   # in the .c file's directory, but generated .c files (from
1268   # yacc, lex, etc) are located in $(LOCATE_TARGET), possibly
1269   # different from $(SEARCH_SOURCE).
1270   HDRS on $(<) = $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ;
1272   # handle #includes for source: Jam scans for headers with
1273   # the regexp pattern $(HDRSCAN) and then invokes $(HDRRULE)
1274   # with the scanned file as the target and the found headers
1275   # as the sources.  HDRSEARCH is the value of SEARCH used for
1276   # the found header files.  Finally, if jam must deal with
1277   # header files of the same name in different directories,
1278   # they can be distinguished with HDRGRIST.
1280   # $(SEARCH_SOURCE:E) is where cc first looks for #include
1281   # "foo.h" files.  If the source file is in a distant directory,
1282   # look there.  Else, look in "" (the current directory).
1284   HDRRULE on $(>) = HdrRule ;
1285   HDRSCAN on $(>) = $(HDRPATTERN) ;
1286   HDRSEARCH on $(>) = $(SEARCH_SOURCE:E) $(SUBDIRHDRS) $(HDRS) $(STDHDRS) ;
1287   HDRGRIST on $(>) = $(HDRGRIST) ;
1289   # propagate target specific-defines
1290   DEFINES on $(<) += $(DEFINES) ;
1292   if $(WINDOZE) && $(>:S) = ".rc" {
1293     WindozeResourceCompiler $(<) : $(>) ;
1294   } else if $(WINDOZE) && $(>:S) = ".o" {
1295     # do nothing
1296   } else {
1297     # if source is not .c, generate .c with specific rule
1298     switch $(>:S) {
1299       case .asm : As $(<) : $(>) ;
1300       case .c   : Cc $(<) : $(>) ;
1301       case .C   : C++ $(<) : $(>) ;
1302       case .cc  : C++ $(<) : $(>) ;
1303       case .cpp : C++ $(<) : $(>) ;
1304       case .cxx : C++ $(<) : $(>) ;
1305       case .c++ : C++ $(<) : $(>) ;
1306       case .C++ : C++ $(<) : $(>) ;
1307       case .m   : ObjC $(<) : $(>) ;
1308       case .d   : Dc $(<) : $(>) ;
1309       case .l   : Cc $(<) : $(<:S=.c) ;
1310                   Lex $(<:S=.c) : $(>) ;
1311       case .s   : As $(<) : $(>) ;
1312       case .y   : Cc $(<) : $(<:S=$(YACCGEN)) ;
1313                   Yacc $(<:S=$(YACCGEN)) : $(>) ;
1314       case *    : UserObject $(<) : $(>) ;
1315     }
1316   }
1320 # /ObjectCcFlags  sources : flags ;
1322 # this rule is used to add compiler flags to the compilation of
1323 # specific C sources files.
1325 rule ObjectCcFlags {
1326   CCFLAGS on [ FGristFiles $(<:S=$(SUFOBJ)) ] += $(>) ;
1330 # /ObjectC++Flags  sources : flags ;
1332 # this rule is used to add compiler flags to the compilation of
1333 # specific C++ source files
1335 rule ObjectC++Flags {
1336   C++FLAGS on [ FGristFiles $(<:S=$(SUFOBJ)) ] += $(>) ;
1340 rule ObjectObjCFlags {
1341   OBJCFLAGS on [ FGristFiles $(<:S=$(SUFOBJ)) ] += $(>) ;
1345 # /LinkFlagsOn  mains : flags ;
1347 # this rule is used to add compiler flags to the compilation of
1348 # specific C sources files.
1350 rule LinkFlagsOn {
1351   LINKFLAGS on [ FGristFiles $(<) ] += $(>) ;
1355 # /C++LinkFlagsOn  mains : flags ;
1357 # this rule is used to add compiler flags to the compilation of
1358 # specific C++ source files
1360 rule C++LinkFlagsOn {
1361   C++LINKFLAGS on [ FGristFiles $(<) ] += $(>) ;
1365 rule ObjCLinkFlagsOn {
1366   OBJCLINKFLAGS on [ FGristFiles $(<) ] += $(>) ;
1370 # /ObjectDefines  objects : macros ;
1372 # this rule is used to add macro defines to the compilation of
1373 # specific C and C++ source files
1375 rule ObjectDefines {
1376   # must reformat CCDEFS according to current defines
1377   local s = [ FGristFiles $(<:S=$(SUFOBJ)) ] ;
1379   DEFINES on $(s) += $(>) ;
1380   CCDEFS on $(s) = [ on $(s) FDefines $(DEFINES) ] ;
1384 # /ObjectHdrs  sources : paths ;
1386 # this rule is used to add include paths to the compilation of
1387 # specific C and C++ source files
1389 rule ObjectHdrs {
1390   # Add to HDRS for HdrScan's benefit.
1391   # must reformat CCHDRS according to headers
1392   local s = [ FGristFiles $(<:S=$(SUFOBJ)) ] ;
1394   HDRS on $(s) += $(>) ;
1395   CCHDRS on $(s) = [ on $(s) FIncludes $(HDRS) ] ;
1399 # /Objects sources ;
1401 # this rule is used to compile one or more sources into object files.
1402 # do not call it directly, it is used by the Main and Library rules
1403 # automatically
1405 rule Objects {
1406   local _i ;
1408   for _i in [ FGristFiles $(<) ] {
1409     Object $(_i:S=$(SUFOBJ)) : $(_i) ;
1410     Depends obj : $(_i:S=$(SUFOBJ)) ;
1411   }
1415 # /SharedObjects
1417 # this rule is used to compile one or more sources into 'shared object
1418 # files'. This means object files used to build either DLLs or Unix shared
1419 # libraries.
1421 # do not call this rule directly, it is called by SharedLibrary automatically
1423 rule SharedObjects {
1424   # temporarily override SUFOBJ with $(SUFOBJSHR) to
1425   local SUFOBJ = $(SUFOBJSHR) ;
1427   # call the normal Objects rule
1428   Objects $(<) ;
1430   # add the compiler-specific position-independent-code flag  where needed
1431   ObjectCcFlags $(<) : $(PICFLAGS) ;
1433   # change the compiler invokation for all these objects
1434   # to use Libtool on Unix systems. We explicitely disable the
1435   # generation of static objects here
1436 #!LIBTOOL!#  if $(UNIX) {
1437 #!LIBTOOL!#    #libtool on $(<:S=$(SUFOBJ)) = [ LibToolFind ] ;
1438 #!LIBTOOL!#    if $(K8_USE_LIBTOOL) {
1439 #!LIBTOOL!#      local libtool = [ LibToolFind ] ;
1440 #!LIBTOOL!#      CC on $(<:S=$(SUFOBJ)) = "$(libtool) --mode=compile $(CC:J= ) -dynamic" ;
1441 #!LIBTOOL!#      C++ on $(<:S=$(SUFOBJ)) = "$(libtool) --mode=compile $(C++:J= ) -dynamic" ; #k8:?
1442 #!LIBTOOL!#    }
1443 #!LIBTOOL!#  }
1447 rule RmTemps {
1448   Temporary $(>) ;
1452 rule Setuid {
1453   MODE on [ FAppendSuffix $(<) : $(SUFEXE) ] = 4711 ;
1457 rule Shell {
1458   Depends shell : $(<) ;
1459   Depends $(<) : $(>) ;
1460   SEARCH on $(>) = $(SEARCH_SOURCE) ;
1461   MODE on $(<) = $(SHELLMODE) ;
1462   Clean clean : $(<) ;
1463   Chmod $(<) ;
1467 rule SoftLink {
1468   Depends files : $(<) ;
1469   Depends $(<) : $(>) ;
1470   SEARCH on $(>) = $(SEARCH_SOURCE) ;
1471   Clean clean : $(<) ;
1475 rule SubDir {
1476   #
1477   # SubDir TOP d1 d2 ... ;
1478   #
1479   # Support for a project tree spanning multiple directories.
1480   #
1481   # SubDir declares a Jamfile's location in a project tree, setting
1482   # Jambase variables (SEARCH_SOURCE, LOCATE_TARGET) so that source
1483   # files can be found.
1484   #
1485   # TOP is a user-select variable name for root of the tree, and
1486   # d1 d2 ...  are the directory elements that lead from the root
1487   # of the tree to the directory of the Jamfile.
1488   #
1489   # TOP can be set externally, but normally the first SubDir call
1490   # computes TOP as the path up from the current directory; the
1491   # path contains one ../ for each of d1 d2 ...
1492   #
1493   # SubDir reads once the project-specific rules file Jamrules
1494   # in the TOP directory, if present.  This can be overridden
1495   # with the variable TOPRULES.
1496   #
1497   # SubDir supports multiple, overlaid project trees:  SubDir
1498   # invocations with different TOPs can appear in the same Jamfile.
1499   # The location established by the first SubDir call is used set
1500   # the TOPs for the subsequent SubDir calls.
1501   #
1502   # SubDir's public variables:
1503   #
1504   #   $(TOP) = path from CWD to root.
1505   #   $(SUBDIR) = path from CWD to the directory SubDir names.
1506   #   $(SUBDIR_TOKENS) = path from $(TOP) to $(SUBDIR) as dir names
1507   #   $(SEARCH_SOURCE) = $(SUBDIR)
1508   #   $(LOCATE_SOURCE) = $(ALL_LOCATE_TARGET) $(SUBDIR)
1509   #   $(LOCATE_TARGET) = $(ALL_LOCATE_TARGET) $(SUBDIR)
1510   #   $(LOCATE_BIN) = $(ALL_LOCATE_BIN) $(ALL_LOCATE_TARGET) $(SUBDIR)
1511   #   $(LOCATE_LIB) = $(ALL_LOCATE_LIB) $(ALL_LOCATE_TARGET) $(SUBDIR)
1512   #   $(LOCATE_LIBSO) = $(ALL_LOCATE_LIBSO) $(ALL_LOCATE_LIB) $(ALL_LOCATE_TARGET) $(SUBDIR)
1513   #   $(SOURCE_GRIST) = $(SUBDIR_TOKENS) with !'s
1514   #
1515   local _top = $(<[1]) ;
1516   local _tokens = $(<[2-]) ;
1517   local _xpath = $(_tokens:J=$(PATH_SEPARATOR)) ;
1519   #Echo "$(_tokens)" ;
1520   #Echo "$(_xpath) ";
1521   if $(_xpath) != "" { _xpath = "$(PATH_SEPARATOR)$(_xpath)" ; }
1523   #local sdr ;
1525   # First time through sets up relative root and includes Jamrules.
1526   if ! $(_top) { Exit "SubDir syntax error" ; }
1528   if ! $($(_top)-SET) {
1529     $(_top)-SET = true ;
1530     # First time we've seen this TOP.
1531     # We'll initialize a number of internal variables:
1532     #
1533     #   $(TOP-UP) = directories from ROOT to a common point
1534     #   $(TOP-DOWN) = directories from common point to TOP
1535     #   $(TOP-ROOT) = root directory for UP/DOWN -- normally CWD
1536     #   $(SUBDIR_UP) = current value of $(TOP-UP)
1537     #   $(SUBDIR_DOWN) = current value of $(TOP-DOWN)
1538     #   $(SUBDIR_ROOT) = current value of $(TOP-ROOT)
1539     #
1540     if $($(_top)) {
1541       # TOP externally set.
1542       # We'll ignore the relative (UP/DOWN) path that
1543       # got us here, and instead remember the hard ROOT.
1544       $(_top)-UP = ;
1545       $(_top)-DOWN = ;
1546       $(_top)-ROOT = $($(_top)) ;
1547     } else {
1548       # TOP not preset.
1550       # Establishing a new TOP.  In the simplest case,
1551       # (SUBDIR_UP/SUBDIR_DOWN/SUBDIR_ROOT unset), it's
1552       # merely a certain number of directories down from
1553       # the current directory, and FSubDirPath will set
1554       # TOP to a path consisting of ../ for each of the
1555       # elements of _tokens, because that represents how
1556       # far below TOP the current directory sits.
1557       #
1558       # In the more complicated case, the starting directory
1559       # isn't the directory of jam's invocation but an
1560       # location established by previous SubDir call.  The
1561       # starting directory is SUBDIR_UP directories up from
1562       # SUBDIR_ROOT, and then SUBDIR_DOWN directories down
1563       # from that.   If SUBDIR_ROOT is not set, that means
1564       # SUBDIR_DOWN and SUBDIR_UP represent the path from
1565       # the directory of jam's invocation.
1566       #
1567       # In the most complicated case, the _tokens also
1568       # represents directories down, because TOP is being
1569       # estalished in a directory other than TOP's root.
1570       # Hopefully, _tokens and SUBDIR_DOWN represent the
1571       # same final directory, relative to the new TOP and
1572       # the previous SubDIr's TOP.  To find the new TOP,
1573       # we have to chop off any common directories from
1574       # then ends of _tokens and SUBDIR_DOWN.  To do so,
1575       # we reverse each of them, call FStripCommon to
1576       # remove the initial common elements, and then
1577       # reverse them again.  After this process, if
1578       # both _tokens and SUBDIR_DOWN have elements, it
1579       # means the directory names estalished by the two
1580       # SubDir calls don't match, and a warning is issued.
1581       # All hell will likely break loose at this point,
1582       # since the whole SubDir scheme relies on the SubDir
1583       # calls accurately naming the current directory.
1585       # Strip common trailing elements of _tokens and SUBDIR_DOWN.
1586       _tokens = [ FReverse $(_tokens) ] ;
1587       SUBDIR_DOWN = [ FReverse $(SUBDIR_DOWN) ] ;
1588       FStripCommon _tokens : SUBDIR_DOWN ;
1589       SUBDIR_DOWN = [ FReverse $(SUBDIR_DOWN) ] ;
1590       _tokens = [ FReverse $(_tokens) ] ;
1592       if $(SUBDIR_DOWN) && $(_tokens) { Echo "Warning:" SubDir $(<) "misplaced!" ; }
1594       # We'll remember the relative (UP/DOWN) path that
1595       # got us here, plus any hard ROOT starting point
1596       # for the UP/DOWN.  If TOP is never set externally,
1597       # ROOT will always be "" (directory of jam's invocation).
1598       $(_top)-UP = $(SUBDIR_UP) $(_tokens) ;
1599       $(_top)-DOWN = $(SUBDIR_DOWN) ;
1600       $(_top)-ROOT = $(SUBDIR_ROOT:E="") ;
1601       $(_top) = [ FSubDirPath $(_top) ] ;
1602     }
1604     # Set subdir vars for the inclusion of the Jamrules,
1605     # just in case they have SubDir rules of their own.
1606     # Note that SUBDIR_DOWN is empty: it's all the way
1607     # up where the Jamrules live.  These gets overrided
1608     # just after the inclusion.
1609     SUBDIR_UP = $($(_top)-UP) ;
1610     SUBDIR_DOWN = ;
1611     SUBDIR_ROOT = $($(_top)-ROOT) ;
1613     # Include $(TOPRULES) or $(TOP)/Jamrules.
1614     # Include $(TOPRULES) if set.
1615     # Otherwise include $(TOP)/Jamrules if present.
1616     if $($(_top)RULES) {
1617       include $($(_top)RULES) ;
1618     } else {
1619       NoCare $(JAMRULES:R=$($(_top)):G=$(_top)) ;
1620       include $(JAMRULES:R=$($(_top)):G=$(_top)) ;
1621     }
1622   }
1624   # Get path from $(TOP) to named directory.
1625   # Save dir tokens for other potential uses.
1626   SUBDIR_UP = $($(_top)-UP) ;
1627   SUBDIR_DOWN = $($(_top)-DOWN) $(_tokens) ;
1628   SUBDIR_ROOT = $($(_top)-ROOT) ;
1629   SUBDIR_TOKENS = $(SUBDIR_DOWN) ;
1631   SUBDIR = [ FSubDirPath $(<) ] ;
1633   # Now set up SEARCH_SOURCE, LOCATE_TARGET, LOCATE_BIN, SOURCE_GRIST
1634   # These can be reset if needed.  For example, if the source
1635   # directory should not hold object files, LOCATE_TARGET can
1636   # subsequently be redefined.
1637   SEARCH_SOURCE = $(SUBDIR) ;
1639   #if $(SUBDIR) = "." { sdr = "" ; } else { sdr = "$(PATH_SEPARATOR)$(SUBDIR)" ; }
1641   if $(ALL_LOCATE_TARGET) {
1642     LOCATE_TARGET = "$(ALL_LOCATE_TARGET)$(_xpath)" ;
1643     LOCATE_SOURCE = "$(ALL_LOCATE_TARGET)$(_xpath)" ;
1644   } else {
1645     LOCATE_TARGET = $(SUBDIR) ;
1646     LOCATE_SOURCE = $(SUBDIR) ;
1647   }
1649   if $(ALL_LOCATE_BIN) {
1650     LOCATE_BIN = $(ALL_LOCATE_BIN) ;
1651   } else {
1652     LOCATE_BIN = $(LOCATE_TARGET) ;
1653   }
1655   if $(ALL_LOCATE_LIB) {
1656     LOCATE_LIB = $(ALL_LOCATE_LIB) ;
1657   } else {
1658     LOCATE_LIB = $(LOCATE_TARGET) ;
1659   }
1661   if $(ALL_LOCATE_LIBSO) {
1662     LOCATE_LIBSO = $(ALL_LOCATE_LIBSO) ;
1663   } else {
1664     LOCATE_LIBSO = $(LOCATE_LIB) ;
1665   }
1667   #Echo "ALL_LOCATE_LIB = $(ALL_LOCATE_LIB)" ;
1668   #Echo "LOCATE_LIB = $(LOCATE_LIB)" ;
1670   SOURCE_GRIST = [ FGrist $(SUBDIR_TOKENS) ] ;
1671   #if ! $(LOCATE_BIN) { LOCATE_BIN = $(LOCATE_TARGET) ; }
1673   ## OPT_HEADER_CACHE_EXT
1674   # With the header cache, we can grist all files found
1675   # during a header scan without incurring a performance
1676   # penalty.
1677   #
1678   HDRGRIST = $(SOURCE_GRIST) ;
1680   # Reset per-directory ccflags, hdrs, etc,
1681   # listed in SUBDIRRESET.
1682   # Note use of variable expanded assignment var
1683   SUBDIR$(SUBDIRRESET) = ;
1685   # Invoke user-specific SubDir extensions,
1686   # rule names listed in SUBDIRRULES.
1687   # Note use of variable expanded rule invocation
1688   $(SUBDIRRULES) $(<) ;
1692 rule FSubDirPath {
1693   # FSubDirPath TOP d1 ... ;
1695   # Returns path to named directory.
1697   # If jam is invoked in a subdirectory of the TOP, then we
1698   # need to prepend a ../ for every level we must climb up
1699   # (TOP-UP), and then append the directory names we must
1700   # climb down (TOP-DOWN), plus the named directories d1 ...
1701   # If TOP was set externally, or computed from another TOP
1702   # that was, we'll have to reroot the whole thing at TOP-ROOT.
1703   local _r = [ FRelPath $($(<[1])-UP) : $($(<[1])-DOWN) $(<[2-]) ] ;
1705   return $(_r:R=$($(<[1])-ROOT)) ;
1709 rule SubDirDcFlags {
1710   SUBDIRDCFLAGS += $(<) ;
1714 rule SubDirCcFlags {
1715   SUBDIRCCFLAGS += $(<) ;
1719 rule SubDirC++Flags {
1720   SUBDIRC++FLAGS += $(<) ;
1724 rule SubDirObjCFlags {
1725   SUBDIROBJCFLAGS += $(<) ;
1729 rule SubDirHdrs {
1730   SUBDIRHDRS += [ FDirName $(<) ] ;
1734 rule SubIncludeMany {
1735   # SubIncludeMany TOP d1 ... ;
1736   #
1737   # Include a subdirectory's Jamfile.
1739   # We use SubDir to get there, in case the included Jamfile
1740   # either doesn't have its own SubDir (naughty) or is a subtree
1741   # with its own TOP.
1742   #Echo "including " $(<) " : " $(>) ;
1744   if ! $($(<[1])) { Exit "SubIncludeMany" $(<[1]) "without prior SubDir" $(<[1]) ; }
1745   SubDir $(<) ;
1746   include $(JAMFILE:D=$(SUBDIR)) ;
1750 rule SubIncludeOnce {
1751   # SubIncludeOnce varname : TOP d1 ... ;
1752   #
1753   # Include a subdirectory's Jamfile.
1755   local _vn = $(<[1]) ;
1756   if ! $($(_vn)) {
1757     #Echo "processing $(_vn)" ;
1758     #Echo "$(>)" ;
1759     $(_vn) = tan ;
1760     SubIncludeMany $(>) ;
1761   #} else {
1762   #  Echo "skiped $(_vn) -- $($(_vn))" ;
1763   #  Echo "$(>)" ;
1764   }
1768 rule SubInclude {
1769   # SubInclude TOP d1 ... ;
1770   #
1771   # Include a subdirectory's Jamfile.
1772   if ! $($(<[1])) { Exit "SubInclude" $(<[1]) "without prior SubDir" $(<[1]) ; }
1773   local _sbiguard = _K8JAM_SUB_GUARD_$(<:J=_) ;
1774   SubIncludeOnce $(_sbiguard) : $(<) ;
1778 rule SubRules {
1779   # SubRules TOP d1 ... : Other-TOP ;
1780   #
1781   # Read another tree's Jamrules, by giving it's path according
1782   # to this tree and it's own name.
1783   if ! $($(<[1])) { Exit "SubRules" $(<[1]) "without prior SubDir" $(<[1]) ; }
1784   SubDir $(<) ;
1785   SubDir $(>) ;
1789 rule Undefines {
1790   UNDEFS on [ FAppendSuffix $(<) : $(SUFEXE) ] += $(UNDEFFLAG)$(>) ;
1794 rule UserObject {
1795   Exit "Unknown suffix on" $(>) "- see UserObject rule in Jamfile(5)." ;
1799 rule Yacc {
1800   local _h ;
1802   _h = $(<:BS=.h) ;
1804   # Some places don't have a yacc.
1805   MakeLocate $(<) $(_h) : $(LOCATE_SOURCE) ;
1806   #MakeLocate $(>) $(_h) : $(LOCATE_SOURCE) ;
1808   if $(YACC) {
1809     #local tmp ;
1810     #tmp = $(<:G=:D) ;
1811     #if $(tmp) { tmp = $(PATH_SEPARATOR)$(tmp) ; }
1812     #tmp = $(LOCATE_SOURCE[1])$(tmp) ;
1813     #CCFLAGS on $(<:S=$(SUFOBJ)) += -I$(tmp) ;
1814     #C++FLAGS on $(<:S=$(SUFOBJ)) += -I$(tmp) ;
1815     #OBJCFLAGS on $(<:S=$(SUFOBJ)) += -I$(tmp) ;
1816     #Echo "-------------------------" ;
1817     #Echo "LS:" "$(LOCATE_SOURCE)" ;
1818     #Echo "tmp:" "$(tmp)" ;
1819     #Echo "out:" "$(<)" ;
1820     #Echo "in :" "$(>)" ;
1821     #Echo "_h :" "$(_h)" ;
1822     #Echo "=========================" ;
1823     #
1824     Depends $(<) $(_h) : $(>) ;
1825     Yacc1 $(<) : $(>) ;
1826     #Yacc1 $(<) $(_h) : $(>) ;
1827     #YaccMv $(<) $(_h) : $(>) ;
1828     Clean clean : $(<) $(_h) ;
1829   }
1831   # make sure someone includes $(_h) else it will be
1832   # a deadly independent target
1833   Includes $(<) : $(_h) ;
1838 # Utility rules; no side effects on these
1842 # /FGrist path to file ;
1844 # Returns a single string that is used as grist
1846 rule FGrist {
1847   return $(<:J=!) ;
1851 rule FGristFiles {
1852   return $(<:G=$(SOURCE_GRIST:E)) ;
1856 rule FGristSourceFiles {
1857   ## LOCAL CHANGE: OPT_HEADER_CACHE_EXT
1858   # With header caching, there is no performance penalty to gristing
1859   # header files. It is also not correct to assume that header
1860   # files have global visibility.
1861   #
1862   # Here we comment out the old version and replace it with the new.
1863 #  # Produce source file name name with grist in it,
1864 #  # if SOURCE_GRIST is set.
1866 #  # Leave header files alone, because they have a global
1867 #  # visibility.
1868 #  if ! $(SOURCE_GRIST) {
1869 #    return $(<) ;
1870 #  } else {
1871 #    local _i _o ;
1873 #    for _i in $(<) {
1874 #      switch $(_i) {
1875 #        case *.h : _o += $(_i) ;
1876 #        case *   : _o += $(_i:G=$(SOURCE_GRIST)) ;
1877 #      }
1878 #    }
1879 #    return $(_o) ;
1880 #  }
1881   return [ FGristFiles $(<) ] ;
1885 rule FReverse {
1886   if $(1) { return [ FReverse $(1[2-]) ] $(1[1]) ; }
1890 rule FSubDir {
1891   # If $(>) is the path to the current directory, compute the
1892   # path (using ../../ etc) back to that root directory.
1893   # Sets result in $(<)
1894   if ! $(<[1]) {
1895     return $(DOT) ;
1896   } else {
1897     local _i _d ;
1899     _d = $(DOTDOT) ;
1900     for _i in $(<[2-]) { _d = $(_d:R=$(DOTDOT)) ; }
1901     return $(_d) ;
1902   }
1906 rule FStripCommon {
1907   # FStripCommon v1 : v2 ;
1909   # Strip common initial elements of variables v1 and v2.
1910   # Modifies the variable values themselves.
1911   if $($(<)[1]) && $($(<)[1]) = $($(>)[1]) {
1912     $(<) = $($(<)[2-]) ;
1913     $(>) = $($(>)[2-]) ;
1914     FStripCommon $(<) : $(>) ;
1915   }
1919 rule FRelPath {
1920   local _l _r ;
1922   # first strip off common parts
1923   _l = $(<) ;
1924   _r = $(>) ;
1925   FStripCommon _l : _r ;
1927   # now make path to root and path down
1928   _l = [ FSubDir $(_l) ] ;
1929   _r = [ FDirName $(_r) ] ;
1931   # Concatenate and save
1932   # XXX This should be better
1933   if $(_r) = $(DOT) { return $(_l) ; } else { return $(_r:R=$(_l)) ; }
1937 rule FAppendSuffix {
1938   # E.g., "FAppendSuffix yacc lex foo.bat : $(SUFEXE) ;"
1939   # returns (yacc,lex,foo.bat) on Unix and
1940   # (yacc.exe,lex.exe,foo.bat) on NT.
1941   if $(>) {
1942     local _i _o ;
1944     for _i in $(<) {
1945       if $(_i:S) { _o += $(_i) ; } else { _o += $(_i:S=$(>)) ; }
1946     }
1947     return $(_o) ;
1948   } else {
1949     return $(<) ;
1950   }
1955 # Operating system specific utility rules
1956 # First, the (generic) UNIX versions
1959 rule FQuote { return "\\\"$(<)\\\"" ; }
1960 rule FDefines { return -D$(<) ; }
1961 rule FIncludes { return -I$(<) ; }
1963 rule FDirName {
1964   # Turn individual elements in $(<) into a usable path.
1965   local _i ;
1966   local _s = $(DOT) ;
1968   for _i in $(<) { _s = $(_i:R=$(_s)) ; }
1969   return $(_s) ;
1973 if $(NT) && $(JAM_TOOLSET) != MINGW && $(JAM_TOOLSET) != LCC {
1974   rule FDefines { return /D$(<) ; }
1975   rule FIncludes { return /I$(<) ; }
1980 # various install rules
1982 rule AddSlash {
1983   local _ttt = [ Split "$(<[1])" ] ;
1984   local _len = [ ListLength $(_ttt) ];
1985   if $(_len) != "0" && $(_ttt[$(_len)]) != "/" { _ttt = "$(<[1])/" ; } else { _ttt = $(<[1]) ; }
1986   return $(_ttt) ;
1990 rule InstallDestDir {
1991   local ddd = [ AddSlash $(DESTDIR) ] ;
1992   local spl = [ Split $(<) ] ;
1994   if $(spl[1]) != "/" {
1995     local ppp = [ AddSlash $(PREFIX) ] ;
1996     if ! $(ppp) { ppp = "/usr/local/" ; }
1997     if $(ddd) { ppp = $(ddd)$(ppp) ; }
1998     return $(ppp)$(<);
1999   } else {
2000     return $(ddd)$(<) ;
2001   }
2005 # InstallInto dir : sources ;
2006 rule InstallInto {
2007   local i t ddir ;
2009   t = $(>:G=$(INSTALLGRIST)) ;
2010   ddir = [ InstallDestDir $(<) ] ;
2012   # Arrange for jam install
2013   # Arrange for jam uninstall
2014   # sources are in SEARCH_SOURCE
2015   # targets are in dir
2017   Depends install : $(t) ;
2018   Clean uninstall : $(t) ;
2019   SEARCH on $(ddir) = $(SEARCH_SOURCE) ;
2020   MakeLocate $(t) : $(ddir) ;
2022   # For each source, make gristed target name
2023   # and Install, Chmod, Chown, and Chgrp
2024   for i in $(>) {
2025     local tt = $(i:G=$(INSTALLGRIST)) ;
2027     Depends $(tt) : $(i) ;
2028     Install $(tt) : $(i) ;
2029     Chmod $(tt) ;
2031     if $(OWNER) && $(CHOWN) {
2032       Chown $(tt) ;
2033       OWNER on $(tt) = $(OWNER) ;
2034     }
2035     if $(GROUP) && $(CHGRP) {
2036       Chgrp $(tt) ;
2037       GROUP on $(tt) = $(GROUP) ;
2038     }
2039   }
2043 # /InstallBin dir : sources ;
2045 # Copy _sources_ into _dir_ with mode $(EXEMODE)
2047 rule InstallBin {
2048   local _t = [ FAppendSuffix $(>) : $(SUFEXE) ] ;
2050   InstallInto $(<) : $(_t) ;
2051   MODE on $(_t:G=$(INSTALLGRIST)) = $(EXEMODE) ;
2055 # /InstallFile dir : sources ;
2057 # Copy _sources_ into _dir_ with mode $(FILEMODE)
2059 rule InstallFile {
2060   InstallInto $(<) : $(>) ;
2061   MODE on $(>:G=$(INSTALLGRIST)) = $(FILEMODE) ;
2065 # /InstallLib dir : sources ;
2067 # Copy _sources_ into _dir_ with mode $(FILEMODE)
2069 rule InstallLib {
2070   InstallInto $(<) : $(>) ;
2071   MODE on $(>:G=$(INSTALLGRIST)) = $(FILEMODE) ;
2075 # /InstallMan dir : sources ;
2077 #  Copy _sources_ into the appropriate subdirectory of _dir_ with mode
2078 #  $(FILEMODE). The subdirectory is manS, where S is the suffix of each of
2079 #  sources.
2081 rule InstallMan {
2082   # Really this just strips the . from the suffix
2083   local i s d ;
2085   for i in $(>) {
2086     switch $(i:S) {
2087       case .1 : s = 1 ; case .2 : s = 2 ; case .3 : s = 3 ;
2088       case .4 : s = 4 ; case .5 : s = 5 ; case .6 : s = 6 ;
2089       case .7 : s = 7 ; case .8 : s = 8 ; case .l : s = l ;
2090       case .n : s = n ; case .man : s = 1 ;
2091     }
2092     d = man$(s) ;
2093     InstallInto $(d:R=$(<)) : $(i) ;
2094   }
2095   MODE on $(>:G=$(INSTALLGRIST)) = $(FILEMODE) ;
2099 # /InstallShell dir : sources ;
2101 # Copy _sources_ into _dir_ with mode $(SHELLMODE)
2103 rule InstallShell {
2104   InstallInto $(<) : $(>) ;
2105   MODE on $(>:G=$(INSTALLGRIST)) = $(SHELLMODE) ;
2109 rule WindozeResourceCompiler {
2110   DEPENDS $(<) : $(>) ;
2111   Clean clean : $(<) ;
2114 rule windoze-fix {
2115   if $(WINDOZE) {
2116     if $(WINDOZE_THREADS) {
2117       CC += -mthreads ;
2118       CC++ += -mthreads ;
2119     }
2120     local ss = $(WINSUBSYS) ;
2121     if ! $(ss) { ss = "console" ; }
2122     LINK += "-Wl,-subsystem,$(ss)" ;
2123     C++LINK += "-Wl,-subsystem,$(ss)" ;
2124     if $(WINLIBS) { LINKLIBS += $(WINLIBS) ; } else { LINKLIBS += -lkernel32 ; }
2125   }
2130 # Actions
2132 actions WindozeResourceCompiler {
2133   "$(WINE)" $(MGPATH)windres.exe -i $(>) -o $(<)
2137 # First the defaults
2139 actions updated together piecemeal Archive {
2140   $(AR) $(<) $(>)
2144 actions As {
2145   $(AS) $(ASFLAGS) $(ASHDRS) -o $(<) $(>)
2149 actions Cc {
2150   $(CC) -c -o $(<) $(CFLAGS.all) $(CCFLAGS) $(OPTIM.all) $(OPTIM) $(CCDEFS) $(CCHDRS) $(>)
2154 actions C++ {
2155   $(C++) -c -o $(<) $(CFLAGS.all) $(C++FLAGS) $(OPTIM.all) $(C++OPTIM) $(CCDEFS) $(CCHDRS) $(>)
2159 actions ObjC {
2160   $(OBJCC) -c -o $(<) $(CFLAGS.all) $(OBJCFLAGS) $(OPTIM.all) $(OBJCOPTIM) $(CCDEFS) $(CCHDRS) $(>)
2164 actions Dc {
2165   $(DC) -c -of$(<) $(DCFLAGS) $(DOPTIM) $(>)
2169 actions Chgrp {
2170   $(CHGRP) $(GROUP) $(<)
2174 actions Chmod1 {
2175   $(CHMOD) $(MODE) $(<)
2179 actions Chown {
2180   $(CHOWN) $(OWNER) $(<)
2184 actions piecemeal together existing Clean {
2185   $(RM) $(>)
2189 actions File {
2190   $(CP) $(>) $(<)
2194 actions GenFile1 {
2195   $(>[1]) $(<) $(>[2-])
2199 actions HardLink {
2200   $(RM) $(<) && $(LN) $(>) $(<)
2204 actions Install {
2205   $(CP) $(>) $(<)
2209 actions Lex {
2210   $(LEX) -o $(<) $(>)
2214 ##actions LexMv {
2215 ##  $(MV) lex.yy.c $(<)
2219 actions Link bind NEEDLIBS {
2220   $(LINK) $(LINKFLAGS.all) $(LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS.all) $(LINKLIBS)
2223 actions C++Link bind NEEDLIBS {
2224   $(C++LINK) $(LINKFLAGS.all) $(C++LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS.all) $(C++LINKLIBS)
2227 actions ObjC-Link bind NEEDLIBS {
2228   $(OBJCLINK) $(LINKFLAGS.all) $(OBJCLINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS.all) $(OBJCLINKLIBS)
2232 actions updated together piecemeal LinkUnixLibrary bind NEEDLIBS {
2233   $(LINK) $(LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS)
2236 actions updated together piecemeal C++LinkUnixLibrary bind NEEDLIBS {
2237   $(C++LINK) $(C++LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(C++LINKLIBS)
2241 actions MkDir1 {
2242   $(MKDIR) $(<)
2246 actions together Ranlib {
2247   $(RANLIB) $(<)
2251 actions quietly updated piecemeal together RmTemps {
2252   $(RM) $(>)
2256 actions Shell {
2257 #DONT_TOUCH
2258   $(AWK) '
2259     NR == 1 { print "$(SHELLHEADER)" }
2260     NR == 1 && /^[#:]/ { next }
2261     /^##/ { next }
2262     { print }
2263   ' < $(>) > $(<)
2264 #DONT_TOUCH
2268 actions SoftLink {
2269   $(RM) $(<) && $(LN) -s $(>) $(<)
2273 actions Yacc1 {
2274   $(YACC) $(YACCFLAGS) $(>) -o $(<)
2278 actions YaccMv {
2279   #$(MV) $(YACCFILES).c $(<[1])
2280   #$(MV) $(YACCFILES).h $(<[2])
2285 # RELOCATE - for compilers with broken -o flags
2287 if $(RELOCATE) {
2288   actions C++ {
2289     $(C++) -c $(C++FLAGS) $(OPTIM) $(CCDEFS) $(CCHDRS) $(>)
2290   }
2291   actions Cc {
2292     $(CC) -c $(CCFLAGS) $(OPTIM) $(CCDEFS) $(CCHDRS) $(>)
2293   }
2294   actions ignore CcMv {
2295     [ $(<) != $(>:BS=$(SUFOBJ)) ] && $(MV) $(>:BS=$(SUFOBJ)) $(<)
2296   }
2301 # NOARUPDATE - can't update an archive
2303 if $(NOARUPDATE) {
2304   actions Archive {
2305     $(AR) $(<) $(>)
2306   }
2311 # UNIX specific actions
2313 if $(UNIX) {
2314   actions GenFile1 {
2315     PATH="$PATH:."
2316     $(>[1]) $(<) $(>[2-])
2317   }
2322 # NT specific actions
2324 if $(NT) {
2325   if $(JAM_TOOLSET) = MINGW {
2326     actions together piecemeal Archive {
2327       $(AR) $(<) $(>:T)
2328     }
2329     actions Cc {
2330       $(CC) -c -o $(<) $(CCFLAGS) $(OPTIM) $(CCDEFS) $(CCHDRS) -I$(STDHDRS) $(>)
2331     }
2332     actions C++ {
2333       $(C++) -c -o $(<) $(C++FLAGS) $(OPTIM) $(CCDEFS) $(CCHDRS) -I$(STDHDRS) $(>)
2334     }
2335     actions DllLink bind DEFFILENAME IMPLIBNAME {
2336       $(LINK) $(LINKFLAGS) -shared -o $(<) $(>) $(DEFFILENAME) -Wl,--out-implib,$(IMPLIBNAME)
2337     }
2338   } else if $(JAM_TOOLSET) = LCC {
2339     actions together piecemeal Archive {
2340       $(AR) /out:$(<) $(>)
2341     }
2342     actions Cc {
2343       $(CC) $(CCFLAGS) $(OPTIM) $(CCDEFS) $(CCHDRS) -Fo$(<) -I$(STDHDRS) $(>)
2344     }
2345     actions Link bind NEEDLIBS {
2346       $(LINK) $(LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS)
2347     }
2348     actions DllLink bind NEEDLIBS DEFFILENAME {
2349       $(LINK) $(LINKFLAGS) -DLL -o $(<) $(UNDEFS) $(>) $(DEFFILENAME) $(NEEDLIBS) $(LINKLIBS)
2350     }
2351     actions ignore DllLinkMv {
2352       $(MV) $(2) $(1)
2353     }
2354     actions Shell {
2355       $(CP) $(>) $(<)
2356     }
2357   } else if $(JAM_TOOLSET) = PELLESC {
2358     actions together piecemeal Archive {
2359       $(AR) /OUT:$(<) $(>)
2360     }
2361     actions Cc {
2362       $(CC) $(CCFLAGS) $(OPTIM) $(CCDEFS) $(CCHDRS)   /Fo $(<) -I$(STDHDRS)  $(>)
2363     }
2364     actions Link bind NEEDLIBS {
2365       $(LINK) $(LINKFLAGS) /OUT:$(<) $(>) $(NEEDLIBS) $(LINKLIBS)
2366     }
2367     actions DllLink bind NEEDLIBS DEFFILENAME IMPLIBNAME {
2368       $(LINK) $(LINKFLAGS) /DLL /DEF:$(DEFFILENAME) /IMPLIB:$(IMPLIBNAME) /OUT:$(<) $(>) $(NEEDLIBS) $(LINKLIBS)
2369     }
2370     actions Shell {
2371       $(CP) $(>) $(<)
2372     }
2373   }
2378 # Ketmar's additions
2380 rule SetCPUFlags {
2381   if $(OS) != "LINUX" {
2382     DETECTED_CPU = "i486" ;
2383     OPTIM_SPEED = -O3 -march=i486 -mtune=i486 ;
2384   } else {
2385     DETECTED_CPU = native ;
2386     OPTIM_SPEED = -O3 -march=native -mtune=native ;
2387   }
2391 # VAR = [ RemoveOptWild regexp-options-to-remove : options-list ] ;
2392 # remove options from list with egrep-like regexps
2393 rule RemoveOptWild {
2394   local oname = $(1) ;
2395   local str = $(2) ;
2396   local res = ;
2397   local f ;
2398   local t ;
2399   #Echo "removing " $(oname) " from " $(str) ;
2400   for f in $(str) {
2401     t = [ Match $(oname) : $(f) ] ;
2402     #Echo $(f) ": " $(t) ;
2403     if $(t[1]) = "" {
2404       #Echo "include: " $(f) ;
2405       res += $(f) ;
2406     }
2407   }
2408   return $(res) ;
2412 # profile rules
2413 K8JAM-KNOWN-PROFILES =
2414   none default  # don't change
2415   empty         # remove optimisation flags
2416   speed         # optimise for speed
2417   size          # optimise for size
2418   debug         # don't optimize, add debug info
2419   standard      # -O2
2423 rule --k8jam-profile-none-- {
2424   Echo "MSG: default profile" ;
2425   OPT_PROFILE = ;
2428 rule --k8jam-profile-empty-- {
2429   Echo "MSG: empty profile" ;
2430   SLACK_PKG_ARCH = "i486" ;
2431   LINKFLAGS.all += -s ;
2434 rule --k8jam-profile-speed-- {
2435   Echo "MSG: 'speed' profile" ;
2436   SLACK_PKG_ARCH = "i686" ;
2437   CFLAGS.all += $(OPTIM_SPEED) ;
2438   LINKFLAGS.all += $(LINKFLAGS_SPEED) ;
2439   OPTIM += -std=gnu99 ;
2442 rule --k8jam-profile-size-- {
2443   Echo "MSG: 'size' profile" ;
2444   SLACK_PKG_ARCH = "i686" ;
2445   CFLAGS.all += $(OPTIM_SIZE) ;
2446   LINKFLAGS.all += $(LINKFLAGS_SIZE) ;
2447   OPTIM += -std=gnu99 ;
2450 rule --k8jam-profile-debug-- {
2451   Echo "MSG: 'debug' profile" ;
2452   SLACK_PKG_ARCH = "i486" ;
2453   LINKFLAGS.all -= -s ;
2454   CFLAGS.all += $(OPTIM_DEBUG) ;
2455   LINKFLAGS.all += $(LINKFLAGS_DEBUG) ;
2456   OPTIM += -std=gnu99 ;
2459 rule --k8jam-profile-standard-- {
2460   Echo "MSG: 'standard' profile" ;
2461   SLACK_PKG_ARCH = "i486" ;
2462   CFLAGS.all += $(OPTIM_STANDARD) ;
2463   LINKFLAGS.all += $(LINKFLAGS_STANDARD) ;
2464   OPTIM += -std=gnu99 ;
2468 # remove-opt-flags $(var)
2469 # remove optimization flags from compiler options
2470 rule remove-opt-flags {
2471   local orm = "(^\\-march\\=)" "(^\\-mtune\\=)" "(^\\-mfpmath\\=)" "(^\\-O.$)" ;
2472   local ormff = "(^\\-f[^n][^o])" ;
2473   local res = [ RemoveOptWild $(orm) $(ormff) : $(<) ] ;
2474   return $(res) ;
2478 rule remove-opt-flags-for-all-compilers {
2479   OPTIM = [ remove-opt-flags $(OPTIM) ] ;
2480   C++OPTIM = [ remove-opt-flags $(C++OPTIM) ] ;
2481   OBJCOPTIM = [ remove-opt-flags $(OBJCOPTIM) ] ;
2482   OPTIM.all = [ remove-opt-flags $(OPTIM.all) ] ;
2484   OPTIM = [ RemoveOptWild $(orm) $(ormff) : $(OPTIM) ] ;
2485   C++OPTIM = [ RemoveOptWild $(orm) $(ormff) : $(C++OPTIM) ] ;
2486   OBJCOPTIM = [ RemoveOptWild $(orm) $(ormff) : $(OBJCOPTIM) ] ;
2487   OPTIM.all = [ RemoveOptWild $(orm) $(ormff) : $(OPTIM.all) ] ;
2491 # profile "name" ;
2492 # set compile flags for profile; works only for gcc/g++
2493 # available profiles:
2494 #  none, default: don't change
2495 #  empty: remove optimisation flags
2496 #  speed: optimise for speed and pIII
2497 #  size: optimise for size
2498 #  debug: don't optimize, add debug info
2499 #  standard: -O2
2500 rule profile {
2501   if ! $(1) in $(K8JAM-KNOWN-PROFILES) {
2502     Echo "known profiles: $(K8JAM-KNOWN-PROFILES)" ;
2503     Exit "unknown profile: $(1)" ;
2504   }
2506   remove-opt-flags-for-all-compilers ;
2507   LINKFLAGS -= "-g" "-s" ;
2508   C++LINKFLAGS -= "-g" "-s" ;
2509   OBJCLINKFLAGS -= "-g" "-s" ;
2510   LINKFLAGS.all -= "-g" "-s" ;
2512   OPT_PROFILE = $(1) ;
2513   --k8jam-profile-$(OPT_PROFILE)-- ;
2515 #SLACK_PKG_ARCH ?= "i486" ;
2518 # selects 'debug', 'standard', 'speed' or 'size' profile according to vars:
2519 #  DEBUG = 1 : debug
2520 #  OPT_SIZE = 1 : size
2521 #  OPT_SPEED = 1 : speed
2522 #  OPT=SIZE or OPT=SPEED
2523 #  default: standard
2524 rule set-profile {
2525   local otp ;
2527   if $(OPT) = "size" { otp = "size" ; }
2528   else if $(OPT) = "SIZE" { otp = "size" ; }
2529   if $(OPT) = "speed" { otp = "speed" ; }
2530   else if $(OPT) = "SPEED" { otp = "speed" ; }
2531   else if $(OPT_SIZE) { otp = "size" ; }
2532   else if $(OPT_SPEED) { otp = "speed" ; }
2534   if $(DEBUG) {
2535     profile "debug" ;
2536   } else if $(otp) = "size" {
2537     profile "size" ;
2538   } else if $(otp) = "speed" {
2539     profile "speed" ;
2540   } else {
2541     profile "standard" ;
2542   }
2543   if $(VALGRIND) {
2544     CFLAGS.all -= "-g" "-s" ;
2545     LINKFLAGS.all -= "-g" "-s" ;
2546     CFLAGS.all += -g ;
2547     LINKFLAGS.all += -g ;
2548   }
2549   if ! $(NO_WARNINGS) {
2550     CFLAGS.all += -Wall ;
2551   }
2555 # set default 'locate' vars -- _build/, etc
2556 rule set-default-subdir-locates {
2557   local bdir ;
2558   local d = $(TOP) ;
2560   if ! $(d) { d = "." ; }
2561   if $(WINDOZE) { bdir = _wbuild ; } else { bdir = _build ; }
2563   ALL_LOCATE_BIN = $(d) ;
2564   ALL_LOCATE_LIBSO = $(d) ;
2565   ALL_LOCATE_TARGET = "$(d)$(PATH_SEPARATOR)$(bdir)" ;
2566   ALL_LOCATE_LIB = "$(d)$(PATH_SEPARATOR)$(bdir)$(PATH_SEPARATOR)_libs" ;
2567   HCACHEFILE = "$(d)$(PATH_SEPARATOR)$(bdir)$(PATH_SEPARATOR).jamhdr.cache" ;
2569   Clean clean : $(HCACHEFILE) ;
2573 rule set-default-target-locations {
2574   set-default-subdir-locates ;
2577 rule set-default-locations {
2578   set-default-subdir-locates ;
2581 rule set-target-locations {
2582   set-default-subdir-locates ;
2587 # windoze setup
2590 rule setup-windoze {
2591   if ! $(WINDOZE) { WINDOZE = 1 ; }
2592   PICFLAGS = ;
2593   SUFLIBSHR = .dll ;
2594   #WINDOZE_THREADS = -mthreads ;
2595   #WINDOZE_THREADS = ;
2596   WINE ?= "wine" ;
2597   MGPATH ?= "c:\\\\mingw\\\\bin\\\\" ;
2598   MGCC ?= "mingw32-gcc.exe -static-libgcc" ;
2599   MG++ ?= "mingw32-g++.exe -static-libgcc -static-libstdc++" ;
2600   CC = "$(WINE)" $(MGPATH)$(MGCC) ;
2601   LINK = "$(WINE)" $(MGPATH)$(MGCC) -Wl,--enable-auto-import ;
2602   AR = "$(WINE)" $(MGPATH)ar.exe -ru ;
2603   RANLIB = "$(WINE)" $(MGPATH)ranlib.exe ;
2604   C++ = "$(WINE)" $(MGPATH)$(MG++) ;
2605   C++LINK = "$(WINE)" $(MGPATH)$(MG++) -Wl,--enable-auto-import ;
2606   #LINKLIBS += -lkernel32 ;
2607   #LINKLIBS += -luser32 ;
2608   #LINKLIBS += -ladvapi32 ;
2609   #LINKLIBS += -lws2_32 ;
2610   #WINSUBSYS = "windows" ;
2611   #WINSUBSYS = "console" ;
2612   SUFEXE = .exe ;
2613   #LINKFLAGS += "-Wl,-subsystem,$(WINSUBSYS)" ;
2617 rule check-setup-windoze {
2618   if $(WINDOZE) { setup-windoze ; }
2622 rule use-mingw32 {
2623   CC = i686-pc-mingw32-gcc -pipe -static-libgcc ;
2624   C++ = i686-pc-mingw32-g++ -pipe -static-libgcc -static-libstdc++ ;
2625   LINK = i686-pc-mingw32-gcc -pipe -Wl,--enable-auto-import ;
2626   C++LINK = i686-pc-mingw32-g++ -pipe -Wl,--enable-auto-import ;
2627   AR = i686-pc-mingw32-ar -ru ;
2628   RANLIB = i686-pc-mingw32-ranlib ;
2630   actions WindozeResourceCompiler {
2631     i686-pc-mingw32-windres -i $(>) -o $(<)
2632   }
2636 # ObjectNoAliasing filelist ;
2637 # turn off aliasing optimization for specified files
2638 # works only for gcc/g++
2639 rule ObjectNoAliasing {
2640   local isGCC = "ona" ;
2641   local isG++ = "ona" ;
2642   if ( "gcc" in $(CC) ) || ( $(JAM_TOOLSET) = MINGW ) { isGCC = "tan" ; }
2643   if ( "g++" in $(C++) ) || ( $(JAM_TOOLSET) = MINGW ) { isG++ = "tan" ; }
2644   if $(JAM_FORCE_GCC_OPTIONS) { isGCC = "tan" ; isG++ = "tan" ; }
2646   if $(isGCC) = "tan" { CCFLAGS on [ FGristFiles $(<:S=$(SUFOBJ)) ] += $(OPTIM_NOALIAS) ; }
2647   if $(isG++) = "tan" { C++FLAGS on [ FGristFiles $(<:S=$(SUFOBJ)) ] += $(OPTIM_NOALIAS) ; }
2648   OBJCFLAGS on [ FGristFiles $(<:S=$(SUFOBJ)) ] += $(OPTIM_NOALIAS) ;
2652 rule gcc-suggest-attrs {
2653   if $(SUGGEST) {
2654     CFLAGS.all += -Wsuggest-attribute=const ;
2655     CFLAGS.all += -Wsuggest-attribute=pure ;
2656     CFLAGS.all += -Wsuggest-attribute=noreturn ;
2657   }
2661 # call $(1)
2662 # add output to var $(2)
2663 # return resulting (non-empty) string if library is present
2664 # if $(2) = "" -- don't add flags, just return
2665 # [ lib-config-ex "pkg-config sdl --cflags" : "CFLAGS" ]
2666 rule lib-config-ex {
2667   local cf lf res ;
2668   cf = [ Command "$(1) 2>/dev/null" : parse-output exit-code code-first ] ;
2669   if $(cf[1]) = "0" && $(cf[2]) {
2670     res = $(cf[2-]) ;
2671     if $(2) {
2672       $(2) += $(cf[2-]) ;
2673     }
2674   } else {
2675     res = ;
2676   }
2677   return $(res) ;
2681 # call $(1) --cflags and $(1) --libs (many libs provides such configurators)
2682 # add necessary flags to compiler and linker vars
2683 # return "tan" (non-empty string) if library is present
2684 # if $(2) != "" -- don't add flags, just check
2685 # [ lib-config "pkg-config sdl" ]
2686 rule lib-config {
2687   local cf lf hasit ;
2689   cf = [ Command "$(1) --cflags 2>/dev/null" : parse-output exit-code code-first ] ;
2690   #Echo "cf:" $(cf) ;
2691   if $(cf[1]) = "0" && $(cf[2]) {
2692     hasit = "tan" ;
2693     #Echo "flags:" $(cf[2-]) ;
2694     if ! $(2) {
2695       CCFLAGS += $(cf[2-]) ;
2696       C++FLAGS += $(cf[2-]) ;
2697       OBJCFLAGS += $(cf[2-]) ;
2698     }
2699   }
2701   lf = [ Command "$(1) --libs 2>/dev/null" : parse-output exit-code code-first ] ;
2702   #Echo "lf:" $(lf) ;
2703   if $(lf[1]) = "0" && $(lf[2]) {
2704     hasit = "tan" ;
2705     #Echo "flags:" $(lf[2-]) ;
2706     if ! $(2) {
2707       LINKFLAGS += $(lf[2-]) ;
2708       C++LINKFLAGS += $(lf[2-]) ;
2709       OBJCLINKFLAGS += $(lf[2-]) ;
2710     }
2711   }
2713   return $(hasit) ;
2716 rule pkg-config {
2717   local res ;
2718   res = [ lib-config "pkg-config $(1)" ] ;
2719   return $(res) ;
2723 rule pkg-config-has {
2724   local res ;
2725   res = [ lib-config-ex "pkg-config $(1) --cflags --libs" ] ;
2726   return $(res) ;
2730 rule sys-has-command {
2731   local cf ;
2733   cf = [ Command "which \"$(1)\" 2>/dev/null 1>&2" : exit-code code-first ] ;
2734   #Echo "cf:" $(cf) ;
2735   if $(cf[1]) = "0" {
2736     return "tan" ;
2737   }
2739   return "" ;
2744 # Objective C vars
2747 OBJC_GNUSTEP_BASE_LIB = gnustep-base ;
2748 OBJC_GNUSTEP_GUI_LIB = gnustep-gui ;
2751 # Objective C rules
2753 rule ObjCUseGNUstepBase {
2754   if ! $(K8_INTERNAL_GNUSTEP_BASE) {
2755     #Echo "-l$(OBJC_GNUSTEP_BASE_LIB)" ;
2756     OBJCLINKLIBS += "-l$(OBJC_GNUSTEP_BASE_LIB)" ;
2757     K8_INTERNAL_GNUSTEP_BASE = tan ;
2758   }
2761 rule ObjCUseGNUstepGui {
2762   ObjCUseGNUstepBase ;
2763   if ! $(K8_INTERNAL_GNUSTEP_GUI) {
2764     K8_INTERNAL_GNUSTEP_GUI = tan ;
2765     #Echo "-l$(OBJC_GNUSTEP_GUI_LIB)" ;
2766     OBJCLINKLIBS += "-l$(OBJC_GNUSTEP_GUI_LIB)" ;
2767   }
2770 rule ObjCUseGNUstep {
2771   ObjCUseGNUstepBase ;
2772   ObjCUseGNUstepGui ;
2777 # 'help' and 'push' targets
2779 rule ShowHelpProfile {
2780   NotFile help-profile ;
2781   Always help-profile ;
2782   AShowHelpProfile help-profile ;
2784 actions AShowHelpProfile {
2785   echo "profile flags:"
2786   echo "  DEBUG=1           -- debug build"
2787   echo "  OPT_SPEED=1       -- optimize for speed"
2788   echo "  OPT_SIZE=1        -- optimize for size"
2789   echo "  VALGRIND=1        -- do not strip debug info"
2790   echo "  NO_WARNINGS=1     -- do not all '-Wall' flag"
2791   echo "WARNING: DON'T FORGET TO DO 'jam clean' before building with new flags!"
2793 ShowHelpProfile ;
2795 rule ShowHelp {
2796   NotFile help ;
2797   Always help ;
2798   AShowHelp help ;
2799   #AShowHelpProfile help ;
2801 actions AShowHelp {
2802   echo "WARNING: default help; override 'actions AShowHelp' definition to use 'help' target!"
2804 ShowHelp ;
2806 rule GitPush {
2807   NotFile push ;
2808   Always push ;
2809   AGitPush push ;
2811 actions AGitPush {
2812   echo "WARNING: add 'actions AGitPush' definition to use 'push' target!"
2814 GitPush ;
2817 check-setup-windoze ;
2820 # Now include the user's Jamfile.
2822 include $(JAMFILE) ;