File: msvc.jam

package info (click to toggle)
boost-build 2.0-m11-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,624 kB
  • ctags: 2,387
  • sloc: ansic: 12,978; python: 5,209; xml: 4,782; cpp: 555; yacc: 456; sh: 237; makefile: 71
file content (850 lines) | stat: -rw-r--r-- 29,209 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
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
# Copyright (c) 2003 David Abrahams.
# Copyright (c) 2005 Vladimir Prus.
# Copyright (c) 2005 Alexey Pakhunov.
# Copyright (c) 2006 Bojan Resnik.
#
# Use, modification and distribution is subject to the Boost Software
# License Version 1.0. (See accompanying file LICENSE_1_0.txt or
# http://www.boost.org/LICENSE_1_0.txt)

import property ;
import generators ;
import os ;
import type ;
import toolset : flags ;
import errors : error ;
import feature : feature get-values ;
import path ;
import sequence : unique ;
import common ;
import "class" : new ;
import rc ;
import midl ;
import mc ;
import pch ;

if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ]
{
    .debug-configuration = true ;
}

feature.extend toolset : msvc ;

feature.subfeature toolset msvc : vendor
  : intel
  : propagated optional
  # intel and msvc supposedly have link-compatible objects... remains
  # to be seen, though ;-)
  ;

# List of all registered configurations
.versions = [ new configurations ] ;

# Inherit MIDL flags
toolset.inherit-flags msvc : midl ;

# Inherit MC flags
toolset.inherit-flags msvc : mc ;

RM =  [ common.rm-command ] ;
nl = "
" ;


# Initialize the toolset for a specific version. As the result, path to
# compiler and, possible, program names are set up, and will be used when
# that version of compiler is requested. For example, you might have:
#
#    using msvc : 6.5 : cl.exe ;
#    using msvc : 7.0 : Y:/foo/bar/cl.exe ;
#
# The version paramater can be ommited:
#
#    using msvc : : Z:/foo/bar/cl.exe ;
#
# Two special version keywords may be supplied:
#   - all - all detected versions will be registered;
#   - default - this is an equivalent to an empty version.
#
# Depending on a supplied version, detected configurations and presence 
# 'cl.exe' in the path different results may be achieved. The following 
# table describes all possible cases:
#
#                                      Nothing            "x.y"
# Passed   Nothing       "x.y"         detected,          detected,
# version  detected      detected      cl.exe in path     cl.exe in path
# 
# default  Error         Use "x.y"     Create "default"   Use "x.y"
# all      None          Use all       None               Use all
# x.y      -             Use "x.y"     -                  Use "x.y"
# a.b      Error         Error         Create "a.b"       Create "a.b"
# 
# "x.y" - refers to a detected version;
# "a.b" - refers to an undetected version.
#
# Note: for free VC7.1 tools, we don't correctly find vcvars32.bar when user
# explicitly provides a path.
rule init ( 
    version ? # the msvc version which is being configured. When omitted
            # the tools invoked when no explicit version is given will be configured.
    : command * 
    # the command to invoke the compiler. If not specified:
    #       - if version is given, default location for that version will be searched
    # 
    #       - if version is not given, default locations for 7.1, 7.0 and 6.* will 
    #              be searched    
    # 
    #       - if compiler is not found in default locations, PATH will be searched.    
    : options * 
    # options can include <setup>, <compiler>, <assembler>, <linker> and <resource-compiler>
)
{
    if $(command)
    {
        options += <command>$(command) ;
    }

    configure $(version) : $(options) ;
}


# 'configure' is a newer version of 'init'. The parameter 'command' is passed as 
# a part of the 'options' list.
rule configure (
    version ? :
    options * 
    )
{
    switch $(version)
    {
        case all :
            if $(options)
            {
                error "msvc: options should be empty when 'all' is specified" ;
            }

            # use all detected versions
            for local v in [ $(.versions).all ]
            {
                configure-really $(v) ;
            }

        case "default" :
            configure-really : $(options) ;

        case * :
            configure-really $(version) : $(options) ;
    }
}


# Supported CPU architectures
cpu-arch-i386 = 
    <architecture>/<address-model>
    <architecture>/<address-model>32
    <architecture>x86/<address-model>   
    <architecture>x86/<address-model>32 ;

cpu-arch-amd64 = 
    <architecture>/<address-model>64    
    <architecture>x86/<address-model>64 ;

cpu-arch-ia64 =
    <architecture>ia64/<address-model>  
    <architecture>ia64/<address-model>64 ;


local rule configure-really (
    version ? :
    options *
    )
{
    # If no version supplied use the default configuration. Note that condition 
    # remains versionless.
    local v = $(version) ;
    if ! $(v)
    {
        # take the first detected version
        version = [ $(.versions).all ] ;
        version = $(version[1]) ;

        # Note: 'version' can still be empty at this point if no versions were 
        # detected.
        version ?= "default" ;
    }

    # Version alias -> real version number
    if $(.version-alias-$(version))
    {
        version = $(.version-alias-$(version)) ;
    }

    # Check whether selected configuration is used already
    if $(version) in [ $(.versions).used ]
    {
        # Allow multiple 'toolset.usage' calls for the same configuration
        # if the identical sets of options are used 
        if $(options) && ( $(options) != [ $(.versions).get $(version) : options ] )
        {
            error "msvc: the toolset version '$(version)' is configured already" ;
        }
    }
    else
    {
        # Register a new configuration 
        $(.versions).register $(version) ;

        # Add user-supplied to auto-detected options
        options = [ $(.versions).get $(version) : options ] $(options) ;

        # Mark the configuration as 'used'.
        $(.versions).use $(version) ;

        # Generate condition and save it
        local condition = [ common.check-init-parameters msvc : 
            version $(v) ] ;

        $(.versions).set $(version) : condition : $(condition) ;


        local command = [ get-values <command> : $(options) ] ;

        # If version is specified, we try to search first in default paths,
        # and only then in PATH.
        command = [ common.get-invocation-command msvc : cl.exe : $(command)
          : [ default-paths $(version) ] : $(version) ] ;

        common.handle-options msvc : $(condition) : $(command) : $(options) ;
            

        if ! $(version) 
        {
            # Even if version is not explicitly specified, try to detect the version
            # from the path.
            if [ MATCH "(Microsoft Visual Studio 8)" : $(command) ]
            {
                version = 8.0 ;
            }                 
            else if [ MATCH "(NET 2003[\/\\]VC7)" : $(command) ]
            {
                version = 7.1 ;
            }
            else if [ MATCH "(Microsoft Visual C\\+\\+ Toolkit 2003)" : $(command) ]
            {
                version = 7.1toolkit ;
            }
            else if [ MATCH "(.NET[\/\\]VC7)" : $(command) ]
            {
                version = 7.0 ;
            }
            else
            {
                version = 6.0 ;
            }                
        }

        
        # Generate and register setup command

        local below-8.0 = [ MATCH ^([67]\\.) : $(version) ] ;

        local cpu = i386 ;

        local setup ;
        local setup-option ;

        if $(command)
        {
            command = [ common.get-absolute-tool-path $(command[-1]) ] ;

            local parent = [ path.make $(command) ] ;
            parent = [ path.parent $(parent) ] ;
            parent = [ path.native $(parent) ] ;

            # setup will be used if the script name has been specified. 
            # If setup is not specified, a default script will be used instead.
            setup = [ get-values <setup> : $(options) ] ;

            if ! $(setup)
            {
                if $(below-8.0)
                {
                    setup ?= vcvars32.bat ;
                }
                else
                {
                    setup ?= vcvarsall.bat ;
                }

                # The vccars32.bat is actually in "bin" directory.
                # (except for free VC7.1 tools)
                setup = [ GLOB $(command) $(parent) : $(setup) ] ;
            }

            if $(setup)
            {
                # Note Cygwin to Windows translation 
                setup = "\""$(setup[1]:W)"\"" ;

                if ! $(below-8.0)
                {
                    cpu = i386 amd64 ia64 ;
                    setup-option = x86 x86_amd64 x86_ia64 ;
                }
            }
        }

        local prefix = "call " ;
        local suffix = " >nul
" ;
        if ! [ os.name ] in NT
        {
            prefix = "cmd.exe /S /C call " ;
            suffix = " >nul \"&&\" " ;
        }

        command = $(prefix)$(setup)" "$(setup-option:E="")$(suffix) ;

        # Setup script is not required in some configurations
        command ?= "" ;

        # Get tool names (if any) and finish setup

        compiler = [ get-values <compiler> : $(options) ] ;
        compiler ?= cl ;

        linker = [ get-values <linker> : $(options) ] ;
        linker ?= link ;

        resource-compiler = [ get-values <resource-compiler> : $(options) ] ;
        resource-compiler ?= rc ;

        assembler = [ get-values <assembler> : $(options) ] ;
        assembler ?= ml ;

        idl-compiler = [ get-values <idl-compiler> : $(options) ] ;
        idl-compiler ?= midl ;

        mc-compiler = [ get-values <mc-compiler> : $(options) ] ;
        mc-compiler ?= mc ;

        manifest-tool = mt ;

        for local i in 1 2 3
        {
            local c = $(cpu[$(i)]) ;

            if $(c)
            {
                local cond = $(condition)/$(cpu-arch-$(c)) ;

                if $(.debug-configuration)
                {
                    ECHO "msvc: condition: '$(cond)', "
                        "command: '$(command[$(i)])'" ;
                }
        
                flags msvc.compile .CC  $(cond) : $(command[$(i)])$(compiler) /Zm800 -nologo ;
                flags msvc.compile .RC  $(cond) : $(command[$(i)])$(resource-compiler) ;
                flags msvc.compile .ASM $(cond) : $(command[$(i)])$(assembler) ;
                flags msvc.link    .LD  $(cond) : $(command[$(i)])$(linker) /NOLOGO /INCREMENTAL:NO ;
                flags msvc.archive .LD  $(cond) : $(command[$(i)])$(linker) /lib /NOLOGO  ;
                flags msvc.compile .IDL $(cond) : $(command[$(i)])$(idl-compiler) ;
                flags msvc.compile .MC  $(cond) : $(command[$(i)])$(mc-compiler) ;

                if ! [ os.name ] in NT
                {
                    flags msvc.link .MT $(cond) : $(command[$(i)])$(manifest-tool) -nologo ;
                }
                else
                {
                    flags msvc.link .MT $(cond) : $(manifest-tool) -nologo ;
                }
            }
        }

        # Set version-specific flags
        configure-version-specific $(version) : $(condition) ;
    }
}


# Supported CPU types
cpu-type-g5 = i586 pentium pentium-mmx ;
cpu-type-g6 = 
    i686 pentiumpro pentium2 pentium3 pentium3m pentium-m k6 k6-2 k6-3 
    winchip-c6 winchip2 c3 c3-2 ;

cpu-type-em64t = prescott nocona ;
cpu-type-amd64 = k8 opteron athlon64 athlon-fx ;

cpu-type-g7 = 
    pentium4 pentium4m athlon athlon-tbird athlon-4 athlon-xp athlon-mp 
    $(cpu-type-em64t) $(cpu-type-amd64) ;

cpu-type-itanium = itanium itanium1 merced ;
cpu-type-itanium2 = itanium2 mckinley ;


local rule configure-version-specific ( version : condition )
{
    # Starting with versions 7.0, the msvc compiler have the /Zc:forScope
    # and /Zc:wchar_t options that improve C++ standard conformance, but
    # those options are off by default.
    # If we're sure that msvc version is at 7.*, add those options explicitly.
    # We can be sure either if user specified version 7.* explicitly,
    # or if the installation path contain 7.* (this is checked above).
    if ! [ MATCH ^(6\\.) : $(version) ]
    {
        flags msvc.compile CFLAGS $(condition) : /Zc:forScope /Zc:wchar_t ;
        flags msvc.compile.c++ C++FLAGS $(condition) : /wd4675 ;
        # disable the function is deprecated warning
        # Some version of msvc have a bug, that cause deprecation
        # warning to be emitted even with /W0
        flags msvc.compile CFLAGS $(condition)/<warnings>off : /wd4996 ; 
        # 64-bit compatibility warning
        flags msvc.compile CFLAGS $(condition)/<warnings>all : /Wp64 ; 
    }
    
    #
    # Processor-specific optimization
    #

    if [ MATCH ^([67]\\.) : $(version) ]
    {
        # 8.0 deprecates some of the options
        flags msvc.compile CFLAGS $(condition)/<optimization>speed $(condition)/<optimization>space : /Ogiy /Gs ;
        flags msvc.compile CFLAGS $(condition)/<optimization>speed : /Ot ;
        flags msvc.compile CFLAGS $(condition)/<optimization>space : /Os ;

        flags msvc.compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set> : /GB ;
        flags msvc.compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set>i386 : /G3 ;
        flags msvc.compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set>i486 : /G4 ;
        flags msvc.compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set>$(cpu-type-g5) : /G5 ;
        flags msvc.compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set>$(cpu-type-g6) : /G6 ;
        flags msvc.compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set>$(cpu-type-g7) : /G7 ;
        
        # Improve floating-point accuracy. Otherwise, some of C++ Boost's
        # "math" tests will fail.
        flags msvc.compile CFLAGS $(condition) : /Op ;

        # 7.1 and below have single-threaded static RTL
        flags msvc.compile CFLAGS $(condition)/<runtime-debugging>off/<runtime-link>static/<threading>single : /ML ;
        flags msvc.compile CFLAGS $(condition)/<runtime-debugging>on/<runtime-link>static/<threading>single : /MLd ;
    }
    else
    {
        # 8.0 adds some more options
        flags msvc.compile CFLAGS $(condition)/$(cpu-arch-amd64)/<instruction-set> : /favor:blend ;
        flags msvc.compile CFLAGS $(condition)/$(cpu-arch-amd64)/<instruction-set>$(cpu-type-em64t) : /favor:EM64T ;
        flags msvc.compile CFLAGS $(condition)/$(cpu-arch-amd64)/<instruction-set>$(cpu-type-amd64) : /favor:AMD64 ;

        # 8.0 only has multi-threaded static RTL
        flags msvc.compile CFLAGS $(condition)/<runtime-debugging>off/<runtime-link>static/<threading>single : /MT ;
        flags msvc.compile CFLAGS $(condition)/<runtime-debugging>on/<runtime-link>static/<threading>single : /MTd ;
    }
}


# Returns the default installation path for the given version. 
local rule default-path ( version )
{
    # Use auto-detected path if possible 
    local path = [ get-values <command> : 
        [ $(.versions).get $(version) : options ] ] ;

    if $(path)
    {
        path = $(path:D) ;
    }
    else
    {
        # Check environment
        if $(.version-$(version)-env)
        {
            local vc-path = [ os.environ $(.version-$(version)-env) ] ;
            if $(vc-path)
            {
                vc-path = [ path.make $(vc-path) ] ;
                vc-path = [ path.join $(vc-path) $(.version-$(version)-envpath) ] ;
                vc-path = [ path.native $(vc-path) ] ;

                path = $(vc-path) ;
            }
        }

        # Check default path
        if ! $(path) && $(.version-$(version)-path)
        {
            path = [ path.native [ path.join $(.ProgramFiles) $(.version-$(version)-path) ] ] ;
        }
    }

    return $(path) ;
}

# Returns either the default installation path (if 'version' is not empty) or list of all 
# known default paths (if no version is given)
rule default-paths ( version ? )
{
    local possible-paths ;
    
    if $(version)
    {
        possible-paths += [ default-path $(version) ] ;
    }
    else
    {
        for local i in $(.known-versions)
        {
            possible-paths += [ default-path $(i) ] ;
        }
    }

    return $(possible-paths) ;
}


# Declare generators

# is it possible to combine these?
# make the generators non-composing, so that they don't convert each source
# into separate rsp file.
generators.register-linker msvc.link : OBJ SEARCHED_LIB STATIC_LIB IMPORT_LIB : EXE : <toolset>msvc ;
generators.register-linker msvc.link.dll : OBJ SEARCHED_LIB STATIC_LIB IMPORT_LIB : SHARED_LIB IMPORT_LIB : <toolset>msvc ;
  
generators.register-archiver msvc.archive : OBJ : STATIC_LIB : <toolset>msvc ;
generators.register-c-compiler msvc.compile.c++ : CPP : OBJ : <toolset>msvc ;
generators.register-c-compiler msvc.compile.c : C : OBJ : <toolset>msvc ;

# Using 'register-c-compiler' adds the build directory to INCLUDES
generators.register-c-compiler msvc.compile.rc : RC : OBJ(%_res) : <toolset>msvc ;
generators.override msvc.compile.rc : rc.compile.resource ;
generators.register-standard msvc.compile.asm : ASM : OBJ : <toolset>msvc ;

generators.register-c-compiler msvc.compile.idl : IDL : MSTYPELIB H C(%_i) C(%_proxy) C(%_dlldata) : <toolset>msvc ;
generators.override msvc.compile.idl : midl.compile.idl ;

generators.register-standard msvc.compile.mc : MC : H RC : <toolset>msvc ;
generators.override msvc.compile.mc : mc.compile ;

generators.register [ new pch-generator msvc.compile.pch : PCHEADER : OBJ PCH : <toolset>msvc ] ;

#
# Declare flags and action for compilation
#
feature.feature debug-store : object database : propagated ;

flags msvc.compile CFLAGS <optimization>speed : /O2 ;
flags msvc.compile CFLAGS <optimization>space : /O1 ;

flags msvc.compile CFLAGS $(cpu-arch-ia64)/<instruction-set>$(cpu-type-itanium) : /G1 ;
flags msvc.compile CFLAGS $(cpu-arch-ia64)/<instruction-set>$(cpu-type-itanium2) : /G2 ;

flags msvc.compile CFLAGS <debug-symbols>on/<debug-store>object : /Z7 ;
flags msvc.compile CFLAGS <debug-symbols>on/<debug-store>database : /Zi ;
flags msvc.compile CFLAGS <optimization>off : /Od ;
flags msvc.compile CFLAGS <inlining>off : /Ob0 ;
flags msvc.compile CFLAGS <inlining>on : /Ob1 ;
flags msvc.compile CFLAGS <inlining>full : /Ob2 ;

flags msvc.compile CFLAGS <warnings>on : /W3 ;
flags msvc.compile CFLAGS <warnings>off : /W0 ;
flags msvc.compile CFLAGS <warnings>all : /W4 ;
flags msvc.compile CFLAGS <warnings-as-errors>on : /WX ;

flags msvc.compile C++FLAGS  <exception-handling>on/<asynch-exceptions>off/<extern-c-nothrow>off : /EHs ;
flags msvc.compile C++FLAGS  <exception-handling>on/<asynch-exceptions>off/<extern-c-nothrow>on : /EHsc ;
flags msvc.compile C++FLAGS  <exception-handling>on/<asynch-exceptions>on/<extern-c-nothrow>off : /EHa ;
flags msvc.compile C++FLAGS  <exception-handling>on/<asynch-exceptions>on/<extern-c-nothrow>on : /EHac ;

flags msvc.compile CFLAGS <rtti>on : /GR ;
flags msvc.compile CFLAGS <runtime-debugging>off/<runtime-link>shared : /MD ;
flags msvc.compile CFLAGS <runtime-debugging>on/<runtime-link>shared : /MDd ;

flags msvc.compile CFLAGS <runtime-debugging>off/<runtime-link>static/<threading>multi : /MT ;
flags msvc.compile CFLAGS <runtime-debugging>on/<runtime-link>static/<threading>multi : /MTd ;

flags msvc.compile.c OPTIONS <cflags> : ;
flags msvc.compile.c++ OPTIONS <cxxflags> : ;

flags msvc.compile PDB_CFLAG <debug-symbols>on/<debug-store>database : /Fd ;  # not used yet

flags msvc.compile DEFINES <define> ;
flags msvc.compile UNDEFS <undef> ;
flags msvc.compile INCLUDES <include> ;

flags msvc.compile PCH_SOURCE <pch-source> ;
flags msvc.compile PCH_HEADER <pch>on : <pch-header> ;
flags msvc.compile PCH_FILE <pch>on : <pch-file> ;

rule get-rspline ( target : lang-opt )
{
    CC_RSPLINE on $(target) = [ on $(target) return $(lang-opt) -U$(UNDEFS) $(CFLAGS) $(C++FLAGS) $(OPTIONS) -c $(nl)-D$(DEFINES) $(nl)\"-I$(INCLUDES)\" ] ;
}

rule compile-c-c++ ( targets + : sources * )
{
    DEPENDS $(<[1]) : [ on $(<[1]) return $(PCH_HEADER) ] ;
    DEPENDS $(<[1]) : [ on $(<[1]) return $(PCH_FILE) ] ;
}

actions compile-c-c++
{
    $(.CC) @"@($(<[1]:W).rsp:E="$(>[1]:W)" -Fo"$(<[1]:W)" -Yu"$(>[3]:D=)" -Fp"$(>[2]:W)" $(CC_RSPLINE))"
}

rule compile.c ( targets + : sources * : properties * )
{
    C++FLAGS on $(targets[1]) = ;
    get-rspline $(targets) : -TC ;
    compile-c-c++ $(<) : $(>) [ on $(<) return $(PCH_FILE) ] [ on $(<) return $(PCH_HEADER) ] ;
}

rule compile.c++ ( targets + : sources * : properties * )
{
    get-rspline $(targets[1]) : -TP ;
    compile-c-c++ $(<) : $(>) [ on $(<) return $(PCH_FILE) ] [ on $(<) return $(PCH_HEADER) ] ;
}

actions compile-pch
{
    $(.CC) @"@($(<[1]:W).rsp:E="$(>[2]:W)" -Fo"$(<[1]:W)" -Yc"$(>[1]:D=)" -Yl"__bjam_pch_symbol_$(>[1]:D=)" -Fp"$(<[2]:W)" $(CC_RSPLINE))"
}

rule compile.pch ( targets + : sources * : properties * )
{
    DEPENDS $(<) : [ on $(<) return $(PCH_SOURCE) ] ;
    get-rspline $(targets[1]) : -TP ;
    compile-pch $(targets) : $(sources) [ on $(<) return $(PCH_SOURCE) ] ;
}

actions compile.rc
{
    $(.RC) -l 0x409 -U$(UNDEFS) -D$(DEFINES) -I"$(INCLUDES)" -fo "$(<:W)" "$(>:W)"
}

# See midl.jam for details
TOUCH_FILE = [ common.file-touch-command ] ;

actions compile.idl
{
    $(.IDL) /nologo @"@($(<[1]:W).rsp:E=$(nl)"$(>:W)" $(nl)-D$(DEFINES) $(nl)"-I$(INCLUDES)" $(nl)-U$(UNDEFS) $(nl)$(MIDLFLAGS) $(nl)/tlb "$(<[1]:W)" $(nl)/h "$(<[2]:W)" $(nl)/iid "$(<[3]:W)" $(nl)/proxy "$(<[4]:W)" $(nl)/dlldata "$(<[5]:W)")"
    $(TOUCH_FILE) "$(<[4]:W)"  
    $(TOUCH_FILE) "$(<[5]:W)"  
}

# Declare flags and action for the assembler

flags msvc.compile.asm USER_ASMFLAGS <asmflags> : ;

#
# for the assembler the following options are turned on by default:
#
# -coff  generate COFF format object file (compatible with cl.exe output)
# -Zp4   align structures to 4 bytes
# -Cp    preserve case of user identifiers
# -Cx    preserve case in publics, externs

actions compile.asm
{
    $(.ASM) -nologo -c -coff -Zp4 -Cp -Cx $(USER_ASMFLAGS) -Fo "$(<:W)" "$(>:W)"
}

# Declare flags and action for linking
flags msvc.link PDB_LINKFLAG <debug-symbols>on/<debug-store>database : /PDB: ; # not used yet
flags msvc.link LINKFLAGS <debug-symbols>on : /DEBUG ;
flags msvc.link DEF_FILE <def-file> ;
# The linker disables the default optimizations when using /DEBUG. Whe have
# to enable them manually for release builds with debug symbols.
flags msvc LINKFLAGS <debug-symbols>on/<runtime-debugging>off : /OPT:REF,ICF ;

flags msvc LINKFLAGS <user-interface>console : /subsystem:console ;
flags msvc LINKFLAGS <user-interface>gui : /subsystem:windows ;
flags msvc LINKFLAGS <user-interface>wince : /subsystem:windowsce ;
flags msvc LINKFLAGS <user-interface>native : /subsystem:native ;
flags msvc LINKFLAGS <user-interface>auto : /subsystem:posix ;

flags msvc.link OPTIONS <linkflags> ;
flags msvc.link LINKPATH <library-path> ;


flags msvc.link FINDLIBS_ST <find-static-library> ;
flags msvc.link FINDLIBS_SA <find-shared-library> ;
flags msvc.link LIBRARY_OPTION <toolset>msvc : "" : unchecked ;
flags msvc.link LIBRARIES_MENTIONED_BY_FILE : <library-file> ;

flags msvc.archive AROPTIONS <archiveflags> ;


rule link.dll ( targets + : sources * : properties * )
{
    DEPENDS $(<) : [ on $(<) return $(DEF_FILE) ] ;
}

# Declare action for creating static libraries
# If library exists, remove it before adding files. See
# http://article.gmane.org/gmane.comp.lib.boost.build/4241    
# for rationale.
if [ os.name ] in NT
{    
    # The 'DEL' command would issue a message to stdout
    # if the file does not exist, so need a check.
    actions archive
    {  
        if exist "$(<[1])" DEL "$(<[1])"  
        $(.LD) $(AROPTIONS) /out:"$(<[1])" @"@($(<[1]:W).rsp:E=$(nl)"$(>)" $(nl)$(LIBRARIES_MENTIONED_BY_FILE) $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_ST:S=.lib)" $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_SA:S=.lib)")"
    }
}
else
{
    actions archive
    {  
        $(RM) "$(<[1])"
        $(.LD) $(AROPTIONS) /out:"$(<[1])" @"@($(<[1]:W).rsp:E=$(nl)"$(>)" $(nl)$(LIBRARIES_MENTIONED_BY_FILE) $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_ST:S=.lib)" $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_SA:S=.lib)")"
    }
}
        
# incremental linking a DLL causes no end of problems: if the
# actual exports don't change, the import .lib file is never
# updated. Therefore, the .lib is always out-of-date and gets
# rebuilt every time. I'm not sure that incremental linking is
# such a great idea in general, but in this case I'm sure we
# don't want it.

# Windows Manifests is a new way to specify dependencies 
# on managed DotNet assemblies and Windows native DLLs. The 
# manifests are embedded as resourses and are useful in 
# any PE targets (both DLL and EXE)

if [ os.name ] in NT
{
    actions link bind DEF_FILE
    {
        $(.LD) $(LINKFLAGS) /out:"$(<[1]:W)" /LIBPATH:"$(LINKPATH:W)" $(OPTIONS) @"@($(<[1]:W).rsp:E=$(nl)"$(>)" $(nl)$(LIBRARIES_MENTIONED_BY_FILE) $(nl)$(LIBRARIES) $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_ST:S=.lib)" $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_SA:S=.lib)")"
        if exist "$(<[1]).manifest" (
            $(.MT) -manifest "$(<[1]).manifest" "-outputresource:$(<[1]);1"
        )
    }

    actions link.dll bind DEF_FILE
    {
        $(.LD) /DLL $(LINKFLAGS) /out:"$(<[1]:W)" /IMPLIB:"$(<[2]:W)" /LIBPATH:"$(LINKPATH:W)" /def:$(DEF_FILE) $(OPTIONS) @"@($(<[1]:W).rsp:E=$(nl)"$(>)" $(nl)$(LIBRARIES_MENTIONED_BY_FILE) $(nl)$(LIBRARIES) $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_ST:S=.lib)" $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_SA:S=.lib)")"
        if exist "$(<[1]).manifest" (
            $(.MT) -manifest "$(<[1]).manifest" "-outputresource:$(<[1]);2"
        )
    }
}
else
{
    actions link bind DEF_FILE
    {
        $(.LD) $(LINKFLAGS) /out:"$(<[1]:W)" /LIBPATH:"$(LINKPATH:W)" $(OPTIONS) @"@($(<[1]:W).rsp:E=$(nl)"$(>)" $(nl)$(LIBRARIES_MENTIONED_BY_FILE) $(nl)$(LIBRARIES) $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_ST:S=.lib)" $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_SA:S=.lib)")"
        if test -e "$(<[1]).manifest"; then
            $(.MT) -manifest "$(<[1]:W).manifest" "-outputresource:$(<[1]:W);1"
        fi
    }

    actions link.dll bind DEF_FILE
    {
        $(.LD) /DLL $(LINKFLAGS) /out:"$(<[1]:W)" /IMPLIB:"$(<[2]:W)" /LIBPATH:"$(LINKPATH:W)" /def:$(DEF_FILE) $(OPTIONS) @"@($(<[1]:W).rsp:E=$(nl)"$(>)" $(nl)$(LIBRARIES_MENTIONED_BY_FILE) $(nl)$(LIBRARIES) $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_ST:S=.lib)" $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_SA:S=.lib)")"
        if test -e "$(<[1]).manifest"; then
            $(.MT) -manifest "$(<[1]:W).manifest" "-outputresource:$(<[1]:W);2"
        fi
    }
}


actions compile.mc
{
    $(.MC) $(MCFLAGS) -h "$(<[1]:DW)" -r "$(<[2]:DW)" "$(>:W)"
}


#
# Autodetection code
#     detects versions listed as '.known-versions' using registry, environment 
#     and checking default paths. Supports both native Windows and Cygwin.
#

.ProgramFiles = [ path.make [ common.get-program-files-dir ] ] ;

.known-versions = 8.0 8.0express 7.1 7.1toolkit 7.0 6.0 ;

# Version aliases
.version-alias-6 = 6.0 ;
.version-alias-7 = 7.0 ;
.version-alias-8 = 8.0 ;
 
# Name of the registry key that contains Visual C++ installation path
#   (relative to "HKEY_LOCAL_MACHINE\SOFTWARE\\Microsoft"
.version-6.0-reg = "VisualStudio\\6.0\\Setup\\Microsoft Visual C++" ;
.version-7.0-reg = "VisualStudio\\7.0\\Setup\\VC" ;
.version-7.1-reg = "VisualStudio\\7.1\\Setup\\VC" ;
.version-8.0-reg = "VisualStudio\\8.0\\Setup\\VC" ;
.version-8.0express-reg = "VCExpress\\8.0\\Setup\\VC" ;

# Visual C++ Toolkit 2003 do not store its installation path in the registry.
# The environment variable 'VCToolkitInstallDir' and the default installation 
# path will be checked instead.
.version-7.1toolkit-path    = "Microsoft Visual C++ Toolkit 2003" "bin" ;
.version-7.1toolkit-env     = VCToolkitInstallDir ;

# Path to the folder containing "cl.exe" relative to the value of the corresponding 
# environment variable
.version-7.1toolkit-envpath = "bin" ;


# Validates given path, registers found configuration and prints debug information 
# about it.
local rule register-configuration ( version : path ? )
{
    if $(path)
    {
        local command = [ GLOB $(path) : cl.exe ] ;

        if $(command)
        {
            if $(.debug-configuration)
            {
                ECHO "notice: msvc-$(version) detected, command: '$(command)'" ;
            }

            $(.versions).register $(version) ;
            $(.versions).set $(version) : options : <command>$(command) ;
        }
    }
}

if [ os.name ] in NT CYGWIN
{
    # Get installation paths from the registry

    for local i in $(.known-versions)
    {
        if $(.version-$(i)-reg)
        {
            local vc-path = [ W32_GETREG
                "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"$(.version-$(i)-reg)
                : "ProductDir" ] ;
            
            if $(vc-path)
            {
                vc-path = [ path.native [ path.join [ path.make-NT $(vc-path) ] "bin" ] ] ;
                register-configuration $(i) : $(vc-path) ;
            }
        }
    }
}


# Check environment and default installation paths

for local i in $(.known-versions)
{
    if ! $(i) in [ $(.versions).all ]
    {
        register-configuration $(i) : [ default-path $(i) ] ;
    }
}