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