View Javadoc
1   package org.codehaus.mojo.natives.msvc;
2   
3   /*
4    * The MIT License
5    *
6    * Copyright (c) 2004, The Codehaus
7    *
8    * Permission is hereby granted, free of charge, to any person obtaining a copy of
9    * this software and associated documentation files (the "Software"), to deal in
10   * the Software without restriction, including without limitation the rights to
11   * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12   * of the Software, and to permit persons to whom the Software is furnished to do
13   * so, subject to the following conditions:
14   * 
15   * The above copyright notice and this permission notice shall be included in all
16   * copies or substantial portions of the Software.
17   * 
18   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24   * SOFTWARE.
25   */
26  
27  import java.io.File;
28  import java.util.HashMap;
29  import java.util.Map;
30  
31  import org.codehaus.mojo.natives.NativeBuildException;
32  import org.codehaus.mojo.natives.util.EnvUtil;
33  
34  /**
35   * Equivalent of MSVC2005's vcvars32.bat
36   */
37  
38  public class MSVC2005x86EnvFactory
39      extends AbstractMSVC2005EnvFactory
40  {
41  
42      protected Map createEnvs()
43          throws NativeBuildException
44      {
45          File vsInstallDir =
46              new File( EnvUtil.getEnv( MSVS2005_INSTALL_ENV_KEY, MSVS2005_INSTALL_ENV_KEY, DEFAULT_MSVS2005_INSTALL_DIR ) );
47  
48          if ( !vsInstallDir.isDirectory() )
49          {
50              throw new NativeBuildException( vsInstallDir.getPath() + " is not a directory." );
51          }
52  
53          Map envs = new HashMap();
54  
55          envs.put( "VSINSTALLDIR", vsInstallDir.getPath() );
56  
57          File vcInstallDir = new File( vsInstallDir.getPath() + "/VC" );
58          envs.put( "VCINSTALLDIR", vcInstallDir.getPath() );
59  
60          File frameworkDir = new File( getSystemRoot() + "/Microsoft.NET/Framework" );
61          envs.put( "FrameworkDir", frameworkDir.getPath() );
62  
63          String frameworkVersion = "v2.0.50727";
64          envs.put( "FrameworkVersion", frameworkVersion );
65  
66          File frameworkSDKDir = new File( vsInstallDir.getPath() + "/SDK/v2.0" );
67          envs.put( "FrameworkSDKDir", frameworkSDKDir.getPath() );
68  
69          File devEnvDir = new File( vsInstallDir.getPath() + "/Common7/IDE" );
70          envs.put( "DevEnvDir", devEnvDir.getPath() );
71  
72          File platformSDKDir = new File( vcInstallDir.getPath() + "/PlatformSDK" );
73  
74          // setup new PATH
75          String currentPath = System.getProperty( "java.library.path" );
76  
77          String newPath =
78              devEnvDir.getPath() + ";" + vcInstallDir.getPath() + "\\BIN;" + vcInstallDir.getPath()
79                  + "\\Common7\\Tools;" + vcInstallDir.getPath() + "\\Common7\\Tools\\bin;" + platformSDKDir.getPath()
80                  + "\\BIN;" + frameworkSDKDir.getPath() + "\\BIN;" + frameworkDir.getPath() + "\\" + frameworkVersion
81                  + ";" + vcInstallDir.getPath() + "\\VCPackages;" + currentPath;
82  
83          envs.put( "PATH", newPath );
84  
85          // setup new INCLUDE PATH
86          String currentIncludePath = EnvUtil.getEnv( "INCLUDE" );
87  
88          String newIncludePath =
89              vcInstallDir.getPath() + "\\ATLMFC\\INCLUDE;" + vcInstallDir.getPath() + "\\INCLUDE;"
90                  + platformSDKDir.getPath() + "\\INCLUDE;" + frameworkSDKDir.getPath() + "\\INCLUDE;"
91                  + currentIncludePath;
92  
93          envs.put( "INCLUDE", newIncludePath );
94  
95          //
96          // setup new LIB PATH
97          //
98          String currentLibPath = EnvUtil.getEnv( "LIB" );
99  
100         String newLibPath =
101             vcInstallDir.getPath() + "\\ATLMFC\\LIB;" + vcInstallDir.getPath() + "\\LIB;" + platformSDKDir.getPath()
102                 + "\\LIB;" + frameworkSDKDir.getPath() + "\\LIB;" + currentLibPath;
103 
104         envs.put( "LIB", newLibPath );
105 
106         //
107         // setup new LIBPATH
108         //
109 
110         String currentLibPathPath =
111             frameworkDir.getPath() + "\\" + frameworkVersion + ";" + vcInstallDir.getPath() + "\\ATLMFC\\LIB";
112 
113         envs.put( "LIBPATH", currentLibPathPath );
114 
115         // http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=473294&SiteID=1
116         envs.put( "SystemRoot", getSystemRoot() );
117 
118         return envs;
119 
120     }
121 
122 }