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 MSVC6's vcvars32.bat
36   */
37  
38  public class MSVC6EnvFactory
39      extends AbstractMSVCEnvFactory
40  {
41      private static final String MSVS6_INSTALL_ENV_KEY = "MSVS6_INSTALL_DIR";
42  
43      private static final String DEFAULT_MSVS6_INSTALL_DIR = getProgramFilesX86() + "/Microsoft Visual Studio";
44  
45      protected Map createEnvs()
46          throws NativeBuildException
47      {
48          File vsDir =
49              new File( EnvUtil.getEnv( MSVS6_INSTALL_ENV_KEY, MSVS6_INSTALL_ENV_KEY, DEFAULT_MSVS6_INSTALL_DIR ) );
50  
51          if ( !vsDir.isDirectory() )
52          {
53              throw new NativeBuildException( vsDir.getPath() + " is not a directory." );
54          }
55  
56          Map envs = new HashMap();
57  
58          String vcOsDir = "WINNT";
59  
60          String winDir = EnvUtil.getEnv( "windir" );
61  
62          File vsCommonDir = new File( vsDir + "/Common" );
63  
64          File vsCommonToolDir = new File( vsCommonDir + "/TOOLS" );
65  
66          File msDevDir = new File( vsCommonDir + "/msdev98" );
67  
68          File msvcDir = new File( vsDir + "/VC98" );
69  
70          envs.put( "MSVCDir", msvcDir.getPath() );
71  
72          // setup new PATH
73          String currentPath = System.getProperty( "java.library.path" );
74  
75          String newPath =
76              msDevDir.getPath() + "\\BIN;" + msvcDir.getPath() + "\\BIN;" + vsCommonToolDir.getPath() + "\\" + vcOsDir
77                  + ";" + vsCommonToolDir.getPath() + ";" + winDir + ";" + currentPath;
78  
79          envs.put( "PATH", newPath );
80  
81          // setup new INCLUDE PATH
82          String currentIncludePath = EnvUtil.getEnv( "INCLUDE" );
83  
84          String newIncludePath =
85              msvcDir.getPath() + "\\ATL\\INCLUDE;" + msvcDir.getPath() + "\\INCLUDE;" + msvcDir.getPath()
86                  + "\\MFC\\INCLUDE;" + vsCommonToolDir.getPath() + vcOsDir + ";" + vsCommonToolDir.getPath() + ";"
87                  + currentIncludePath;
88  
89          envs.put( "INCLUDE", newIncludePath );
90  
91          //
92          // setup new LIB PATH
93          //
94          String currentLibPath = EnvUtil.getEnv( "LIB" );
95  
96          String newLibPath = msvcDir.getPath() + "\\LIB;" + msvcDir.getPath() + "\\MFC\\LIB;" + currentLibPath;
97  
98          envs.put( "LIB", newLibPath );
99  
100         return envs;
101 
102     }
103 
104 }