]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/compiler/PrecompilingCommandLineCompiler.java
Changed spelling to manifest
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / compiler / PrecompilingCommandLineCompiler.java
CommitLineData
878ddf1f 1/*\r
2 * \r
3 * Copyright 2002-2004 The Ant-Contrib project\r
4 *\r
5 * Licensed under the Apache License, Version 2.0 (the "License");\r
6 * you may not use this file except in compliance with the License.\r
7 * You may obtain a copy of the License at\r
8 *\r
9 * http://www.apache.org/licenses/LICENSE-2.0\r
10 *\r
11 * Unless required by applicable law or agreed to in writing, software\r
12 * distributed under the License is distributed on an "AS IS" BASIS,\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 * See the License for the specific language governing permissions and\r
15 * limitations under the License.\r
16 */\r
17package net.sf.antcontrib.cpptasks.compiler;\r
18import java.io.BufferedReader;\r
19import java.io.File;\r
20import java.io.FileReader;\r
21import java.io.IOException;\r
22import java.io.Reader;\r
23\r
24import net.sf.antcontrib.cpptasks.parser.Parser;\r
25\r
26import org.apache.tools.ant.BuildException;\r
27import org.apache.tools.ant.types.Environment;\r
28/**\r
29 * A command line C compiler that can utilize precompilation of header files\r
30 * \r
31 * @author Curt Arnold\r
32 */\r
33public abstract class PrecompilingCommandLineCompiler\r
34 extends\r
35 CommandLineCompiler implements PrecompilingCompiler {\r
36 protected PrecompilingCommandLineCompiler(String command,\r
37 String identifierArg, String[] sourceExtensions,\r
38 String[] headerExtensions, String outputSuffix, boolean libtool,\r
39 PrecompilingCommandLineCompiler libtoolCompiler,\r
40 boolean newEnvironment, Environment env) {\r
41 super(command, identifierArg, sourceExtensions, headerExtensions,\r
42 outputSuffix, libtool, libtoolCompiler, newEnvironment, env);\r
43 }\r
44 /**\r
45 * \r
46 * This method may be used to get two distinct compiler configurations, one\r
47 * for compiling the specified file and producing a precompiled header\r
48 * file, and a second for compiling other files using the precompiled\r
49 * header file.\r
50 * \r
51 * The last (preferrably only) include directive in the prototype file will\r
52 * be used to mark the boundary between pre-compiled and normally compiled\r
53 * headers.\r
54 * \r
55 * @param config\r
56 * base configuration\r
57 * @param prototype\r
58 * A source file (for example, stdafx.cpp) that is used to build\r
59 * the precompiled header file. @returns null if precompiled\r
60 * headers are not supported or a two element array containing\r
61 * the precompiled header generation configuration and the\r
62 * consuming configuration\r
63 * \r
64 */\r
65 public CompilerConfiguration[] createPrecompileConfigurations(\r
66 CompilerConfiguration config, File prototype, String[] exceptFiles) {\r
67 //\r
68 // cast should success or someone is passing us a configuration\r
69 // that was prepared by another processor\r
70 //\r
71 CommandLineCompilerConfiguration cmdLineConfig = (CommandLineCompilerConfiguration) config;\r
72 //\r
73 // parse prototype file to determine last header\r
74 //\r
75 Parser parser = createParser(prototype);\r
76 String[] includes;\r
77 try {\r
78 Reader reader = new BufferedReader(new FileReader(prototype));\r
79 parser.parse(reader);\r
80 includes = parser.getIncludes();\r
81 } catch (IOException ex) {\r
82 throw new BuildException(\r
83 "Error parsing precompiled header protoype: "\r
84 + prototype.toString() + ":" + ex.toString());\r
85 }\r
86 if (includes.length == 0) {\r
87 throw new BuildException("Precompiled header prototype: "\r
88 + prototype.toString()\r
89 + " does not contain any include directives.");\r
90 }\r
91 CompilerConfiguration[] configs = new CompilerConfiguration[2];\r
92 configs[0] = createPrecompileGeneratingConfig(cmdLineConfig, prototype,\r
93 includes[0]);\r
94 configs[1] = createPrecompileUsingConfig(cmdLineConfig, prototype,\r
95 includes[0], exceptFiles);\r
96 return configs;\r
97 }\r
98 abstract protected CompilerConfiguration createPrecompileGeneratingConfig(\r
99 CommandLineCompilerConfiguration baseConfig, File prototype,\r
100 String lastInclude);\r
101 abstract protected CompilerConfiguration createPrecompileUsingConfig(\r
102 CommandLineCompilerConfiguration baseConfig, File prototype,\r
103 String lastInclude, String[] exceptFiles);\r
104}\r