1    /* 
     2     *  Copyright (c) 2009 Texas Instruments and others.
     3     *  All rights reserved. This program and the accompanying materials
     4     *  are made available under the terms of the Eclipse Public License v1.0
     5     *  which accompanies this distribution, and is available at
     6     *  http://www.eclipse.org/legal/epl-v10.html
     7     * 
     8     *  Contributors:
     9     *      Texas Instruments - initial implementation
    10     * 
    11     * */
    12    /*
    13     *  ======== Win32.xdc ========
    14     */
    15    
    16    /*!
    17     *  ======== Win32 ========
    18     *  Microsoft Windows 32-bit target using the Visual C/C++ compiler
    19     *
    20     *  This target can be configured to be used with different versions of
    21     *  Microsoft Visual C/C++ and different installations of Platform SDK (or a
    22     *  newer equivalent Windows SDK). The optional Platform SDK is needed only
    23     *  for building applications that use Windows API.
    24     *  The target `Win32` contains default configurations for Visual C/C++
    25     *  versions 6.0, 7.0 and 8.0, but in order to support future versions of
    26     *  Visual C/C++ and different Platform SDK installations, there
    27     *  is a parameter {@link #vcPath}, which users can set in their `config.bld`
    28     *  files to enable usage of this target with their installations. 
    29     *
    30     *  Unlike the Visual C/C++ 6.x tool chain, this compiler complies very
    31     *  closely with the C/C++ language specification.  This target may be
    32     *  necessary in situations that take full advantage of the C++ language.
    33     */
    34    metaonly module Win32 inherits microsoft.targets.ITarget {
    35    
    36        override readonly config string name                = "Win32";      
    37        override readonly config string os                  = "Windows";    
    38        override readonly config string suffix              = "86W";
    39        override readonly config string isa                 = "x86";        
    40        override readonly config xdc.bld.ITarget.Model model = {
    41            endian: "little"
    42        };
    43    
    44        override readonly config string rts = "microsoft.targets.rts";
    45    
    46        override config string platform     = "host.platforms.PC";
    47        override config string execExt      = ".exe";
    48        
    49        /*!
    50         *  ======== VCPath ========
    51         *
    52         *  Object that defines various paths in a particular Visual Studio
    53         *  installation.
    54         *
    55         *  Different Visual Studio installations keep the actual compiler and
    56         *  additional required DLLs in separate directories. Also, a Platform SDK
    57         *  installation is needed for building programs that use Windows API.
    58         *
    59         *  @field(compilerDir) Relative path from this target's rootDir to the
    60         *          directory that contains the compiler.
    61         *
    62         *  @field(dllPath) Relative path from this target's rootDir to the 
    63         *          directory that contains mspdb.dll, mspdbcore.dll, etc.
    64         *
    65         *  @field(sdkPath) Relative path from this target's rootDir to a
    66         *          Platform SDK installation or an absolute path to a Platform SDK
    67         *          installation. Platform SDK is required if the target is used to
    68         *          build executables that use Windows API.
    69         *
    70         *  @field(libs) List of libraries to be added to the linker command line.
    71         *          If Platform SDK is used, the list should contain required 
    72         *          libraries from sdkPath/lib. Otherwise, only the libraries from
    73         *          compilerDir/lib can be added to 'libs'.
    74         */
    75        struct VCPath {
    76            string compilerDir;
    77            string dllPath;
    78            string sdkPath;
    79            string libs;
    80        };
    81    
    82        /*!
    83         *  ======== vcPath ========
    84         *  Location of the compiler, additional DLLs, and Platform SDK
    85         *  installation
    86         *
    87         *  This parameter is a map that contains information about paths to DLLs
    88         *  needed for building applications, and paths to the optional Platform
    89         *  SDK. Keys in the map are user-selected aliases for different Visual
    90         *  C/C++ releases. The values are {@link #VCPath} objects. 
    91         *  This parameter can be set only in `config.bld`, together with
    92         *  `rootDir`. If `vcPath` is not set in `rootDir`, the default values
    93         *  specified below are used. After a user sets this target's `rootDir`,
    94         *  XDCtools search through the 
    95         *  values in `vcPath`, looking for a field `compilerDir` whose content
    96         *  matches a name of a subdirectory in `rootDir`. Once a match is found,
    97         *  the content of that element of the map is used to find a path to
    98         *  required DLLs, a path to Platform SDK and a list of libraries.
    99         *
   100         *  @a(Examples)
   101         *  If the content of `vcPath`, set in `config.bld` is
   102         *  @p(code)
   103         *      Win32.vcPath = [
   104         *          ["Visual Studio 7",
   105         *              {
   106         *                  compilerDir: "Vc7",
   107         *                  dllPath: "Common7/IDE;VisualStudio.NETProfessional-English",
   108         *                  sdkPath: "C:/PlatformSDK",
   109         *                  libs: " msvcrt.lib setargv.obj oldnames.lib ole32.lib oleaut32.lib olepro32.lib uuid.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib comctl32.lib mfc70.lib msvcirt.lib"
   110         *              }
   111         *          ],
   112         *          ["Visual Studio C++ 2005",
   113         *              {
   114         *                  compilerDir: "VC",
   115         *                  dllPath: "Common7/IDE",
   116         *                  sdkPath: "VC/PlatformSDK",
   117         *                  libs: " msvcrt.lib setargv.obj oldnames.lib ole32.lib oleaut32.lib olepro32.lib uuid.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib comctl32.lib"
   118         *              }
   119         *          ]
   120         *      ];
   121         *  @p
   122         *  and the `rootDir` for the target `Win32` is set to 
   123         *  `"C:/Program Files/Microsoft Visual Studio 8"`, XDCtools will first 
   124         *  check if there is a directory `"Vc7"` under `rootDir`. If the directory
   125         *  is not found, the next element in the map and its `compilerDir` field
   126         *  are queried. In this case, the next element's `compilerDir` is `"VC"`.
   127         *  If that directory is found under `rootDir`, the other fields in that
   128         *  element are used as follows: `compilerDir` and `dllPath` are added to
   129         *  the environment variable `PATH`. The contents of `sdkPath` and `libs`
   130         *  are added to appropriate command lines.
   131         *
   132         *  If none of the elements in the map has `compilerDir` that corresponds
   133         *  to a subdirectory in `rootDir`, the configuration fails.
   134         *
   135         *  Once a user sets up `vcPath` with all available installations of
   136         *  Visual Studio, simply by switching `rootDir` for this target, the
   137         *  right component of `vcPath` will be selected.
   138         *     
   139         *  The default version of this parameter contains settings for several
   140         *  Visual Studio releases. Therefore, a user does not have to completely
   141         *  redefine `vcPath`. Only the fields that corresponds to settings that
   142         *  differ between user's configuration and the default configuration
   143         *  need to be changes. For example, if the only difference between the
   144         *  default configuration and a user's environment is that the user
   145         *  installed Platform SDK to be used with Visual C/C++ 8 in a different
   146         *  directory, only that field needs to be changed.
   147         *  @p(code)
   148         *      var Win32 = xdc.module('microsoft.targets.Win32');
   149         *      Win32.vcPath["VC8"].sdkPath = "C:/WindowsSDK";
   150         *  @p
   151         *
   152         *  If Platform SDK is not installed, sdkPath should be empty and the 
   153         *  libraries from Platform SDK should be removed from 'libs':
   154         *  @p(code)
   155         *      var Win32 = xdc.module('microsoft.targets.Win32');
   156         *      Win32.vcPath = [
   157         *          ["VC8",
   158         *              {
   159         *                  compilerDir: "VC",
   160         *                  dllPath: "Common7/IDE",
   161         *                  sdkPath: "",
   162         *                  libs: " msvcrt.lib setargv.obj oldnames.lib"
   163         *              }
   164         *          ],
   165         *      ];
   166         *  @p
   167         *
   168         */
   169        config VCPath vcPath[string] = [
   170            ["VC6", {compilerDir: "vc98", dllPath: "common/msdev98/bin",
   171                     sdkPath: "",
   172                     libs: " msvcrt.lib setargv.obj oldnames.lib ole32.lib oleaut32.lib olepro32.lib uuid.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib comctl32.lib mfc42.lib msvcirt.lib"}],
   173            ["VC7", {compilerDir: "Vc7",
   174                     dllPath: "Common7/IDE;VisualStudio.NETProfessional-English",
   175                     sdkPath: "Vc7/PlatformSDK",
   176                     libs: " msvcrt.lib setargv.obj oldnames.lib ole32.lib oleaut32.lib olepro32.lib uuid.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib comctl32.lib mfc70.lib msvcirt.lib"}],
   177            /* Free version of VC8.0 doesn't include mfc libraries. */
   178            ["VC8", {compilerDir: "VC",   dllPath: "Common7/IDE",
   179                     sdkPath: "VC/PlatformSDK",
   180                     libs: " msvcrt.lib setargv.obj oldnames.lib ole32.lib oleaut32.lib olepro32.lib uuid.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib comctl32.lib"}],
   181        ];
   182    
   183        /*!
   184         *  ======== profiles ========
   185         *  Standard options profiles are overwritten because we can't use 'MTs'
   186         *  and -D_DEBUG=1. Both of them added the debug version of the C runtime
   187         *  library to the manifest.
   188         */
   189        override config xdc.bld.ITarget.OptionSet profiles[string] = [
   190            ["debug", {
   191                compileOpts: {
   192                    copts: "-Z7 -Odi -MT",
   193                    defs:  "",
   194                },
   195                linkOpts: "-debug ",
   196            }],
   197    
   198            ["release", {
   199                compileOpts: {
   200                    copts: "-O2 -MT",
   201                    defs:  "",
   202                },
   203                linkOpts: "",
   204            }],
   205        ];
   206    
   207        /*!
   208         *  ======== ar ========
   209         *  The archiver command and all required options
   210         *  @p(dlist)
   211         *      -`-nologo`
   212         *          don't display archiver copyright
   213         */
   214        override readonly config xdc.bld.ITarget2.Command ar = {
   215            cmd: "$(rootDir)/$(compilerDir)/bin/lib.exe -nologo",
   216            opts: ""
   217        };
   218    
   219        /*!
   220         *  ======== cc ========
   221         *  The compile command and all required options
   222         *  @p(dlist)
   223         *      -`-W3`
   224         *          enable all warnings recommended for production purposes.
   225         *      -`-c`
   226         *          don't link
   227         *      -`-nologo`
   228         *          don't display compiler copyright
   229         *      -`-Zp1`
   230         *          Packs structure members on 1-byte boundry
   231         */
   232        override readonly config xdc.bld.ITarget2.Command cc = {
   233            cmd: "$(rootDir)/$(compilerDir)/bin/cl.exe -nologo -c",
   234            opts: '-Zp1 -W3 -DWIN32 -D_DLL -D_AFXDLL -DEXPORT=""'
   235        };
   236    
   237        /*!
   238         *  ======== asm ========
   239         *  The assemble command and all required options
   240         *  @p(dlist)
   241         *      -`-c`
   242         *          don't link
   243         *      -`-nologo`
   244         *          don't display macro assembler copyright
   245         */
   246        override readonly config xdc.bld.ITarget2.Command asm = {
   247            cmd: "$(rootDir)/$(compilerDir)/bin/ml -c",
   248            opts: "-nologo"
   249        };
   250    
   251        /*!
   252         *  ======== lnk ========
   253         *  The linker command and all required options
   254         *  @p(dlist)
   255         *      -`-nologo`
   256         *          Don't display linker copyright
   257         */
   258        override readonly config xdc.bld.ITarget2.Command lnk = {
   259            cmd: "$(rootDir)/$(compilerDir)/bin/link",
   260            opts: "-nologo"
   261        };
   262        
   263        /*!
   264         *  ======== ccOpts ========
   265         *  User modifiable default options.
   266         *  @p(dlist)
   267         *      -`-G5` (removed because it is incompatible with VC8.0)
   268         *          Optimizes code to favor the Pentium processor
   269         *      -`-Ob1`
   270         *          Expand only functions marked as inline or, in a C++
   271         *          member function, defined within a class declaration
   272         *      -`-Gs`
   273         *          Probe stack to automatically grow stack as necessary
   274         *      -`-GX` (removed because it is incompatible with VC8.0)
   275         *          Enables synchronous exception handling
   276         *      -`-WL`
   277         *          Write errors/warnings on a single output line
   278         */
   279        override config xdc.bld.ITarget2.Options ccOpts = {
   280            prefix: "-Ob1 -Gs",
   281            suffix: "-Dfar= "
   282        };
   283    
   284        /*!
   285         *  ======== lnkOpts ========
   286         *  User modifiable linker options
   287         *  @p(dlist)
   288         *      -`-libpath`...
   289         *              directories to search for toolchain specific libraries
   290         *      -`-nodefaultlib`
   291         *              don't search for default libraries when linking; all
   292         *              libraries used must be explicitly named
   293         *      -`-incremental:no`
   294         *              link for execution (no subsequent link will occur)
   295         *      -`-machine:ix86`
   296         *              link for the Intel x86 architecture
   297         *      -`-map:$(XDCCFGDIR)/$@.map`
   298         *              output any link map information to the specified file
   299         *              ($(XDCCFGDIR) is usually package/cfg)
   300         *      -`-pdb:$(XDCCFGDIR)/$@.pdb`
   301         *              output any program debug information to the specified file
   302         *              ($(XDCCFGDIR) is usually package/cfg)
   303         */
   304        override config xdc.bld.ITarget2.Options lnkOpts = {
   305            prefix: "-libpath:$(rootDir)/$(compilerDir)/lib -libpath:$(rootDir)/$(compilerDir)/atlmfc/lib -libpath:$(rootDir)/$(compilerDir)/mfc/lib -libpath:$(sdkPath)/lib",
   306            suffix: "-map:$(XDCCFGDIR)/$@.map -pdb:$(XDCCFGDIR)/$@.pdb -machine:ix86 -nodefaultlib -incremental:no"
   307        };
   308            
   309        /*!
   310         *  ======== includeOpts ========
   311         *  User modifiable include paths
   312         *  @p(dlist)
   313         *      -`-I$(rootDir)/$(compilerDir)/include`
   314         *          include compiler specific headers
   315         */
   316        override config string includeOpts = "-I$(rootDir)/$(compilerDir)/include -I$(rootDir)/$(compilerDir)/atlmfc/include -I$(rootDir)/$(compilerDir)/mfc/include -I$(rootDir)/$(compilerDir)/atl/include -I$(sdkPath)/include";
   317    }
   318    /*
   319     *  @(#) microsoft.targets; 1, 0, 2, 0,442; 1-31-2011 12:17:26; /db/ztree/library/trees/xdctargets/xdctargets-c42x/src/ xlibrary
   320    
   321     */
   322