File: build.jam

package info (click to toggle)
boost-jam 3.1.10-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,004 kB
  • ctags: 1,703
  • sloc: ansic: 11,378; yacc: 456; sh: 192; makefile: 43
file content (758 lines) | stat: -rw-r--r-- 19,542 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
#~ Copyright 2002-2004 Rene Rivera.
#~ Distributed under the Boost Software License, Version 1.0.
#~ (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)

# Platform related specifics.
if $(NT) { rule .path { return "$(<:J=\\)" ; } }
else if $(OS2) { rule .path { return "$(<:J=\\)" ; } }
else if $(VMS) { rule .path { return "[.$(<:J=/)]" ; } }
else if $(MAC) { rule .path { return ":$(<:J=\:)" ; } }
else { rule .path { return "$(<:J=/)" ; } }
if $(VMS) { . = "_" ; }
else { . = "." ; }

# Info about what we are building.
NAME = boost-jam ;
VERSION = 3$(.)1$(.)10 ;
RELEASE = 1 ;
LICENSE = 1_0 ;

# Generate development debug binaries?
if --debug in $(ARGV)
{
    debug = true ;
}

# Attempt to generate and/or build the grammar?
if --grammar in $(ARGV)
{
    grammar = true ;
}

# Do we need to add a default build type argument?
if ! ( --release in $(ARGV) ) &&
   ! ( --debug in $(ARGV) )
{
    ARGV += --release ;
}

# An explicit root for the toolset? (trim spaces)
toolset-root = [ MATCH --toolset-root=(.*) : $(ARGV) ] ;
{
    local t = [ MATCH "[ ]*(.*)" : $(toolset-root:J=" ") ] ;
    toolset-root = ;
    while $(t)
    {
        t = [ MATCH "([^ ]+)([ ]*)(.*)" : $(t) ] ;
        toolset-root += $(t[1]) ;
        if $(t[3]) { toolset-root += $(t[2]) ; }
        t = $(t[3]) ;
    }
    toolset-root = $(toolset-root:J="") ;
}

# Configure the implemented toolsets. These are minimal
# commands and options to compile the full Jam. When
# adding new toolsets make sure to add them to the
# "known" list also.
rule toolset ( name command .type ? : opt.out + : opt.define * : flags * : linklibs * )
{
    .type ?= "" ;
    tool.$(name)$(.type).cc ?= $(command) ;
    tool.$(name)$(.type).opt.out ?= $(opt.out) ;
    tool.$(name)$(.type).opt.define ?= $(opt.define) ;
    tool.$(name)$(.type).flags ?= $(flags) ;
    tool.$(name)$(.type).linklibs ?= $(linklibs) ;
    if ! $(name) in $(toolsets) { toolsets += $(name) ; }
}
rule opt ( type : yes-opt * : no-opt * ) { if $(type) in $(ARGV) { return $(yes-opt) ; } else { return $(no-opt) ; } }
## HP-UX aCC compiler
toolset acc cc : "-o " : -D
    : -Ae
    [ opt --release : -s -O3 ]
    [ opt --debug : -g -pg ] ;
## Borland C++ 5.5.x
toolset borland bcc32 : -e -n : /D
    : -WC -w- -q "-I$(toolset-root)Include" "-L$(toolset-root)Lib"
    [ opt --release : -O2 -vi -w-inl ]
    [ opt --debug : -v -Od -vi- ] ;
## Generic Unix cc
if ! $(CC) { CC = cc ; }
toolset cc $(CC) : "-o " : -D
    : $(CFLAGS)
    [ opt --release : -s -O ]
    [ opt --debug : -g ]
    : $(LIBS) ;
## Comeau C/C++ 4.x
toolset como como : "-o " : -D
    :
    [ opt --release : --inlining ]
    [ opt --debug : --no_inlining ] ;
## MacOSX Darwin, using GCC 2.9.x, 3.x
toolset darwin cc :  "-o " : -D
    :
    [ opt --release : -Wl,-x -O3 -finline-functions ]
    [ opt --debug : -g -O0 -fno-inline -pg ] ;
## GCC 2.x, 3.x
toolset gcc gcc : "-o " : -D
    : -pedantic
    [ opt --release : [ opt --symbols : -g : -s ] -O3 -finline-functions ]
    [ opt --debug : -g -O0 -fno-inline ] ;
## GCC 2.x, 3.x on CYGWIN but without cygwin1.dll
toolset gcc-nocygwin gcc : "-o " : -D
    : -s -O3 -mno-cygwin
    [ opt --release : -finline-functions ]
    [ opt --debug : -s -O3 -fno-inline -pg ] ;
## Intel C/C++ for Linux
toolset intel-linux icc : "-o " : -D
    :
    [ opt --release : -Xlinker -s -O3 ]
    [ opt --debug : -g -O0 -p ] ;
## Intel C/C++ for Win32
toolset intel-win32 icl : /Fe : -D
    : /nologo
    [ opt --release : /ML /O2 /Ob2 /Gy /GF /GA /GB ]
    [ opt --debug : /MLd /DEBUG /Z7 /Od /Ob0 ] ;
## KCC ?
toolset kcc KCC : "-o " : -D
    :
    [ opt --release : -s +K2 ]
    [ opt --debug : -g +K0 ] ;
## Borland Kylix
toolset kylix bc++ : -o : -D
    : -tC -q
    [ opt --release : -O2 -vi -w-inl ]
    [ opt --debug : -v -Od -vi- ] ;
## Metrowerks CodeWarrior 8.x
{
    local mwcc = ; if $(NT) { mwcc = mwcc ; } else { mwcc = mwc$(OSPLAT:L) ; }
    mwcc ?= mwcc ;
    toolset metrowerks $(mwcc) : "-o " : -D
        : -subsystem console -cwd include -ladvapi32.lib
        [ opt --release : -runtime ss -opt full -inline auto -inline level=8 ]
        [ opt --debug : -runtime ssd -O0 -inline off ] ;
}
## MINGW GCC
toolset mingw gcc : "-o " : -D
    :
    [ opt --release : -s -O3 -finline-functions ]
    [ opt --debug : -g -O0 -fno-inline -pg ] ;
## MIPS Pro
toolset mipspro cc : "-o " : -D
    :
    [ opt --release : -s -O3 -g0 -INLINE:none ]
    [ opt --debug : -g -O0 -INLINE ] ;
## Microsoft Visual Studio C++ 6.x
toolset msvc cl : /Fe : -D
    : /nologo
    [ opt --release : /ML /O2 /Ob2 /Gy /GF /GA /GB ]
    [ opt --debug : /MLd /DEBUG /Z7 /Od /Ob0 ]
    : kernel32.lib advapi32.lib ;
## Sun Workshop 6 C++
toolset sunpro cc : "-o " : -D
    :
    [ opt --release : -s -fast -xO4 ]
    [ opt --debug : -g ] ;
## Compaq Alpha CXX
toolset tru64cxx cc : "-o " : -D
    :
    [ opt --release : -s -O5 -inline speed ]
    [ opt --debug : -g -O0 -pg ] ;
## IBM VisualAge C++
toolset vacpp xlc : "-o " : -D
    :
    [ opt --release : -s -O3 -qstrict -qinline ]
    [ opt --debug : -g -qNOOPTimize -qnoinline -pg ] ;
## Microsoft Visual C++ .NET 7.x
toolset vc7 cl : /Fe : -D
    : /nologo
    [ opt --release : /ML /O2 /Ob2 /Gy /GF /GA /GB ]
    [ opt --debug : /MLd /DEBUG /Z7 /Od /Ob0 ]
    : kernel32.lib advapi32.lib ;
## VMS/OpenVMS DEC C
toolset vmsdecc cc : /OBJECT= : "/DEFINES=(" "," ")"
    : /STANDARD=VAXC /PREFIX_LIBRARY_ENTRIES=ALL_ENTRIES
    [ opt --release : /OPTIMIZE /NODEBUG ]
    [ opt --debug : /NOOPTIMIZE /DEBUG ]
    ;
toolset vmsdecc link .link : /EXECUTABLE= :
    : /NOMAP
    [ opt --release : /NODEBUG ]
    [ opt --debug : /DEBUG ]
    ;

# First set the build commands and options according to the
# preset toolset.
toolset = [ MATCH --toolset=(.*) : $(ARGV) ] ;
if ! $(toolset)
{
    # For some reason, the following test does not catch 
    # empty toolset.
    ECHO "###" ;
    ECHO "###" No toolset specified. Please use --toolset option. ;
    ECHO "###" ;
    ECHO "###" Known toolsets are: $(toolsets:J=", ") ;
    EXIT "###" ;    
}
if ! $(toolset) in $(toolsets)
{
    ECHO "###" ;
    ECHO "###" Unknown toolset: $(toolset) ;
    ECHO "###" ;
    ECHO "###" Known toolsets are: $(toolsets:J=", ") ;
    EXIT "###" ;
}
--cc = $(tool.$(toolset).cc) ;
if $(tool.$(toolset).opt.out[2])
{
    --bin = $(tool.$(toolset).opt.out[1]) ;
    --dir = $(tool.$(toolset).opt.out[2]) ;
}
else
{
    --out = $(tool.$(toolset).opt.out) ;
}
--def = $(tool.$(toolset).opt.define) ;
--flags = $(tool.$(toolset).flags) ;
--defs = $(tool.$(toolset).defines) ;
--libs = $(tool.$(toolset).linklibs) ;
if $(tool.$(toolset).link.cc)
{
    --link = $(tool.$(toolset).link.cc) ;
    if $(tool.$(toolset).link.opt.out[2])
    {
        --link-bin = $(tool.$(toolset).link.opt.out[1]) ;
        --link-dir = $(tool.$(toolset).link.opt.out[2]) ;
    }
    else
    {
        --link-out = $(tool.$(toolset).link.opt.out) ;
    }
    --link-def = $(tool.$(toolset).link.opt.define) ;
    --link-flags = $(tool.$(toolset).link.flags) ;
    --link-defs = $(tool.$(toolset).link.defines) ;
    --link-libs = $(tool.$(toolset).link.linklibs) ;
}

# Put executables in platform-specific subdirectory.
locate-target = $(LOCATE_TARGET) ;
if $(VMS)
{
    locate-target ?= bin$(.)vms ;
    platform = vms ;
}
else if $(MAC)
{
    locate-target ?= bin$(.)$(OS:L)$(OSPLAT:L) ;
    platform = $(OS:L)$(OSPLAT:L) ;
}
else if $(OSPLAT)
{
    locate-target ?= bin$(.)$(OS:L)$(OSPLAT:L) ;
    platform = $(OS:L)$(OSPLAT:L) ;
}
else
{
    locate-target ?= bin$(.)$(OS:L) ;
    platform = $(OS:L) ;
}
if $(debug)
{
    locate-target = [ .path $(locate-target)$(.)debug ] ;
}
else
{
    locate-target = [ .path $(locate-target) ] ;
}

# We have some different files for UNIX, VMS, and NT.
jam.source =
    command.c compile.c expand.c glob.c
    hash.c hcache.c headers.c hdrmacro.c
    jam.c jambase.c jamgram.c
    lists.c make.c make1.c newstr.c
    option.c parse.c regexp.c rules.c
    scan.c search.c subst.c
    timestamp.c variable.c modules.c strings.c filesys.c 
    builtins.c pwd.c class.c native.c modules/set.c 
    modules/path.c modules/regex.c modules/property-set.c
    modules/sequence.c modules/order.c
    ;
if $(NT)
{
    jam.source += execnt.c filent.c pathunix.c w32_getreg.c ;
}
else if $(OS2)
{
    jam.source += execunix.c fileos2.c pathunix.c ;
} 
else if $(VMS)
{
    jam.source += execvms.c filevms.c pathvms.c ;
}
else if $(MAC)
{
    jam.source += execmac.c filemac.c pathmac.c ;
}
else
{
    jam.source += execunix.c fileunix.c pathunix.c ;
}

# Debug assertions, or not.
if ! $(debug) || --noassert in $(ARGV)
{
    --defs += NDEBUG ;
}

# Enable some optional features.
--defs += OPT_HEADER_CACHE_EXT ;
--defs += OPT_GRAPH_DEBUG_EXT ;
--defs += OPT_SEMAPHORE ;

# Bug fixes
--defs += OPT_FIX_TARGET_VARIABLES_EXT ;

# Improvements
--defs += OPT_IMPROVED_PATIENCE_EXT ;

if ( $(OS) = NT || $(NT) ) && ! NT in $(--defs)
{
    --defs += NT ;
}
if $(VMS)
{
    --defs += VMS ;
}
--defs += YYSTACKSIZE=5000 ;

# The basic symbolic targets...
NOTFILE all clean dist ;
ALWAYS clean ;

# Utility rules and actions...
rule .clean
{
    .rm. clean : $(<) ;
}
if $(NT) { actions piecemeal together existing .rm. {
    del /F /Q $(>)
} }
if $(UNIX) { actions piecemeal together existing .rm. {
    rm -f $(>)
} }
if $(VMS) { actions piecemeal together existing .rm. {
    DELETE $(>[--2]:J=";*, ") $(>[-1]);*
} }
if $(NT) {
    --chmod+w = "attrib -r " ;
}
if $(UNIX) {
    --chmod+w = "chmod +w " ;
}
if $(VMS) {
    --chmod+w = "SET FILE/PROT=(S:RWED) " ;
}

rule .mkdir
{
    NOUPDATE $(<) ;
    if $(<:P) { DEPENDS $(<) : $(<:P) ; .mkdir $(<:P) ; }
    if ! $(md<$(<)>) { .mkdir. $(<) ; md<$(<)> = - ; }
}
if $(NT) { actions .mkdir. {
    md $(<)
} }
if $(UNIX) { actions .mkdir. {
    mkdir $(<)
} }
if $(VMS) { actions .mkdir. {
    CREATE/DIR $(<J=", ")
} }

rule .exe
{
    local exe = $(<) ;
    if $(NT) || ( $(UNIX) && $(OS) = CYGWIN ) || $(VMS) { exe = $(exe:S=.exe) ; }
    LOCATE on $(exe) = $(locate-target) ;
    DEPENDS all : $(exe) ;
    .mkdir $(locate-target) ;
    if $(--link)
    {
        for local s in $(>)
        {
            local o = $(s:S=.o) ;
            LOCATE on $(o) = $(locate-target) ;
            DEPENDS $(exe) : $(o) ;
            DEPENDS $(o) : $(s) ;
            DEPENDS $(o) : $(locate-target) ;
            .cc. $(o) : $(s) ;
            .clean $(o) ;
        }
        DEPENDS $(exe) : $(>:S=.o) ;
        DEPENDS $(exe) : $(locate-target) ;
        .ld. $(exe) : $(>:S=.o) ;
        .clean $(exe) ;
    }
    else
    {
        DEPENDS $(exe) : $(>) ;
        DEPENDS $(exe) : $(locate-target) ;
        .cc. $(exe) : $(>) ;
        .clean $(exe) ;
    }
    return $(exe) ;
}
if ! $(--def[2]) { actions .cc. {
    "$(--cc)" $(--bin)$(<:D=) $(--dir)$(<:D) $(--out)$(<) $(--def)$(--defs) $(--flags) "$(--libs)" $(>)
} }
else { actions .cc. {
    "$(--cc)" $(--bin)$(<:D=) $(--dir)$(<:D) $(--out)$(<) $(--def[1])$(--defs:J=$(--def[2]))$(--def[3]) $(--flags) "$(--libs)" $(>)
} }
if $(VMS) { actions .ld. {
    "$(--link)" $(--link-bin)$(<:D=) $(--link-dir)$(<:D) $(--link-out)$(<) $(--link-def)$(--link-defs) $(--link-flags) "$(--link-libs)" $(>J=", ")
} }
else { actions .ld. {
    "$(--link)" $(--link-bin)$(<:D=) $(--link-dir)$(<:D) $(--link-out)$(<) $(--link-def)$(--link-defs) $(--link-flags) "$(--link-libs)" $(>)
} }

rule .link
{
    DEPENDS all : $(<) ;
    DEPENDS $(<) : $(>) ;
    .link. $(<) : $(>) ;
    .clean $(<) ;
}
if $(NT) { actions .link. {
    copy $(>) $(<)
} }
if $(UNIX) { actions .link. {
    ln -f $(>) $(<)
} }
if $(VMS) { actions .link. {
    COPY/REPLACE $(>) $(<)
} }

rule .move
{
    DEPENDS $(<) : $(>) ;
    .move. $(<) : $(>) ;
}
if $(NT) { actions .move. {
    del /f $(<)
    rename $(>) $(<)
} }
if $(UNIX) { actions .move. {
    mv -f $(>) $(<)
} }
if $(VMS) { actions .move. {
    RENAME $(>) $(<)
} }

# Generate the grammar tokens table, and the real yacc grammar.
rule .yyacc
{
    local exe = [ .exe yyacc : yyacc.c ] ;
    NOUPDATE $(exe) ;
    DEPENDS $(<) : $(exe) $(>) ;
    LEAVES $(<) ;
    yyacc.exe on $(<) = $(exe:R=$(locate-target)) ;
    .yyacc. $(<) : $(>) ;
}
actions .yyacc. {
    $(--chmod+w)$(<[1])
    $(--chmod+w)$(<[2])
    "$(yyacc.exe)" $(<) $(>)
}
if $(grammar)
{
    .yyacc jamgram.y jamgramtab.h : jamgram.yy ;
}
else
{
    .exe yyacc : yyacc.c ;
}

# How to build the grammar.
if $(NT)
{
    SUFEXE = .exe ;
    # try some other likely spellings...
    PATH ?= $(Path) ;
    PATH ?= $(path) ;
}
SUFEXE ?= "" ;

yacc ?= [ GLOB $(PATH) : yacc$(SUFEXE) ] ;
yacc ?= [ GLOB $(PATH) : bison$(SUFEXE) ] ;
yacc ?= [ GLOB "$(ProgramFiles:J= )\\GnuWin32\\bin" "C:\\Program Files\\GnuWin32\\bin" : bison$(SUFEXE) ] ;
yacc = $(yacc[1]) ;
switch $(yacc:D=:S=)
{
    case bison : yacc += -d --yacc ;
    case yacc  : yacc += -d ;
}
if $(debug) && $(yacc)
{
    yacc += -t -v ;
}
yacc += $(YACCFLAGS) ;

rule .yacc
{
    DEPENDS $(<) : $(>) ;
    LEAVES $(<) ;
    .yacc. $(<) : $(>) ;
}
if $(NT) { actions .yacc. {
    "$(yacc)" $(>)
    if not errorlevel 1 (
        del /f $(<[1])
        rename y.tab$(<[1]:S) $(<[1])
        del /f $(<[2])
        rename y.tab$(<[2]:S) $(<[2])
    ) else set _error_ =
} }
if $(UNIX) { actions .yacc. {
    if ` "$(yacc)" $(>) ` ; then
        mv -f y.tab$(<[1]:S) $(<[1])
        mv -f y.tab$(<[2]:S) $(<[2])
    else
        exit 1
    fi
} }
if $(VMS) { actions .yacc. {
    IF "$(yacc)" $(>)
    THEN
        RENAME y_tab$(<[1]:S) $(<[1])
        RENAME y_tab$(<[2]:S) $(<[2])
    ENDIF
} }
if $(grammar) && ! $(yacc)
{
    EXIT "Could not find the 'yacc' tool, and therefore can not build the grammar." ;
}
if $(grammar) && $(yacc)
{
    .yacc jamgram.c jamgram.h : jamgram.y ;
}

# How to build the compiled in jambase.
rule .mkjambase
{
    local exe = [ .exe mkjambase : mkjambase.c ] ;
    DEPENDS $(<) : $(exe) $(>) ;
    LEAVES $(<) ;
    mkjambase.exe on $(<) = $(exe:R=$(locate-target)) ;
    .mkjambase. $(<) : $(>) ;
}
actions .mkjambase. {
    $(--chmod+w)$(<)
    $(mkjambase.exe) $(<) $(>)
}
.mkjambase jambase.c : Jambase ;

# How to build Jam.
rule .jam
{
    $(>).exe = [ .exe $(>) : $(jam.source) ] ;
    $(<).exe = $(<:S=$($(>).exe:S)) ;
    LOCATE on $($(<).exe) = $(locate-target) ;
    .link $($(<).exe) : $($(>).exe) ;
    
    DEPENDS all : $($(>).exe) $($(<).exe) ;
}
.jam bjam : jam ;

# Scan sources for header dependencies.
rule .scan
{
    HDRRULE on $(<:D=) = .hdr.scan ;
    HDRSCAN on $(<:D=) = "^[     ]*#[    ]*include[  ]*[<\"]([^\">]*)[\">].*$" ;
}
rule .hdr.scan
{
    local hdrs = [ GLOB . : $(>:D=) ] ;
    INCLUDES $(<:D=) : $(hdrs:D=) ;
    HDRRULE on $(>:D=) = .hdr.scan ;
    HDRSCAN on $(>:D=) = "^[     ]*#[    ]*include[  ]*[<\"]([^\">]*)[\">].*$" ;
}
.scan [ GLOB . : *.c ] ;

# Distribution making from here on out.
dist.license =
    #~ [ GLOB . : LICENSE_$(LICENSE).txt ] [ GLOB [ .path .. .. .. ] : LICENSE_$(LICENSE).txt ] ;
    [ GLOB . : LICENSE_$(LICENSE).txt ]
    [ GLOB [ .path .. .. .. ] : LICENSE_$(LICENSE).txt ]
    [ GLOB [ .path .. boost ] : LICENSE_$(LICENSE).txt ] ;
dist.docs =
    $(dist.license[1])
    index.html
    Porting
    Jam.html
    ;
dist.source =
    [ GLOB . : *.c *.h ]
    ;
dist.source = $(dist.source:D=)
    $(dist.docs)
    build.jam build.bat build.sh build_vms.com
    Jambase
    jamgram.y jamgram.yy
    [ .path debian changelog ]
    [ .path debian control ]
    [ .path debian copyright ]
    [ .path debian jam.man.sgml ]
    [ .path debian rules ]
    [ .path modules set.c ]
    [ .path modules path.c ]
    [ .path modules regex.c ]
    [ .path modules property-set.c ]
    [ .path modules sequence.c ]
    [ .path modules order.c ]
    boost-jam.spec
    ;
dist.bin =
    bjam
    ;
dist.bin =
    $(dist.license[1])
    $(dist.bin:S=$(bjam.exe:S))
    ;

if $(NT)
{
    zip ?= [ GLOB "$(ProgramFiles:J= )\\7-ZIP" "C:\\Program Files\\7-ZIP" : "7zn.exe" ] ;
    zip ?= [ GLOB $(PATH) : zip.exe ] ;
    zip ?= zip ;
    zip = $(zip[1]) ;
    switch $(zip:D=:S=)
    {
        case 7zn : zip += a -r -tzip ;
        case zip  : zip += -9r ;
    }
    actions piecemeal .pack. {
    "$(zip)" "$(<)" "$(>)"
    }
    actions piecemeal .zip. {
    "$(zip)" "$(<)" "$(>)"
    }
    actions piecemeal .cp. {
    copy /Y "$(>)" "$(<)"
    }
}
if $(UNIX)
{
    actions .pack. {
    tar zcf "$(<)" "$(>)"
    }
    actions .zip. {
    gzip -c9 "$(>)" > "$(<)"
    }
    actions .cp. {
    cp -Rpf "$(>)" "$(<)"
    }
}

# The single binary, compressed.
rule .binary
{
    local zip = ;
    if $(NT) { zip = $($(<).exe:S=.zip) ; }
    if $(UNIX) { zip = $($(<).exe:S=.tgz) ; }
    zip = $(zip:S=)-$(VERSION)-$(RELEASE)-$(platform)$(zip:S) ;
    DEPENDS $(zip) : $($(<).exe) ;
    DEPENDS dist : $(zip) ;
    #~ LOCATE on $(zip) = $(locate-target) ;
    if $(NT) { .zip. $(zip) : $($(<).exe) ; }
    if $(UNIX) { .pack. $(zip) : $($(<).exe) ; }
    .clean $(zip) ;
}

# Package some file.
rule .package ( dst-dir : src-files + )
{
    local dst-files ;
    for local src-path in $(src-files)
    {
        local src-subdir = $(src-path:D) ;
        local src-file = $(src-path) ;
        while $(src-subdir:D) { src-subdir = $(src-subdir:D) ; }
        if $(src-subdir) = ".."
        {
            src-file = $(src-file:D=) ;
        }
        dst-files += $(src-file:R=$(dst-dir)) ;
    }
    
    local pack = ;
    if $(NT) { pack = $(dst-dir).zip ; }
    if $(UNIX) { pack = $(dst-dir).tgz ; }
    
    DEPENDS dist : $(pack) ;
    DEPENDS $(pack) : $(dst-files) ;
    
    local dst-files-queue = $(dst-files) ;
    for local src-path in $(src-files)
    {
        local dst-file = $(dst-files-queue[1]) ;
        dst-files-queue = $(dst-files-queue[2-]) ;
        DEPENDS $(dst-file) : $(src-path) $(dst-file:D) ;
        .mkdir $(dst-file:D) ;
        
        .cp. $(dst-file) : $(src-path) ;
        .clean $(dst-file) ;
    }
    
    .pack. $(pack) : $(dst-files) ;
    .clean $(pack) ;
}

# RPM distro file.
rpm-tool = [ GLOB $(PATH) : "rpmbuild" "rpm" ] ;
rule .rpm ( name : source )
{
    local rpm-arch = ;
    switch $(OSPLAT)
    {
        case X86       : rpm-arch ?= i386 ;
        case PPC       : rpm-arch ?= ppc ;
        case AXP       : rpm-arch ?= alpha ;
        # no guaranty for these:
        case IA64      : rpm-arch ?= ia64 ;
        case ARM       : rpm-arch ?= arm ;
        case SPARC     : rpm-arch ?= sparc ;
        case *         : rpm-arch ?= other ;
    }
    local target = $(name)-rpm ;
    NOTFILE $(target) ;
    DEPENDS dist : $(target) ;
    DEPENDS $(target) : $(name).$(rpm-arch).rpm $(name).src.rpm ;
    DEPENDS $(name).$(rpm-arch).rpm : $(source) ;
    DEPENDS $(name).src.rpm : $(name).$(rpm-arch).rpm ;
    docs on $(target) = $(dist.docs:J=" ") ;
    arch on $(target) = $(rpm-arch) ;
    if $(rpm-arch) = ppc { target-opt on $(target) = --target= ; }
    else { target-opt on $(target) = "--target " ; }
    .rpm. $(target) : $(source) ;
    .clean $(name).$(rpm-arch).rpm $(name).src.rpm ;
}
actions .rpm. {
    export BOOST_JAM_TOOLSET="$(toolset)"
    $(rpm-tool[1]) -ta $(target-opt)$(arch) $(>) | tee rpm.out
    cp `grep -e '^Wrote:' rpm.out | sed 's/^Wrote: //'` .
    rm -f rpm.out
}

# The distribution targets. Don't bother with the targets if
# distribution build not requested.
if dist in $(ARGV)
{
    #~ .binary bjam ;
    .package $(NAME)-$(VERSION) : $(dist.source) ;
    .package $(NAME)-$(VERSION)-$(RELEASE)-$(platform) : $(dist.bin) ;
    if $(rpm-tool)
    {
        .rpm $(NAME)-$(VERSION)-$(RELEASE) : $(NAME)-$(VERSION).tgz ;
    }
}