]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/compiler/PrecompilingCommandLineCompiler.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / Cpptasks / net / sf / antcontrib / cpptasks / compiler / PrecompilingCommandLineCompiler.java
diff --git a/Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/compiler/PrecompilingCommandLineCompiler.java b/Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/compiler/PrecompilingCommandLineCompiler.java
new file mode 100644 (file)
index 0000000..6e3c145
--- /dev/null
@@ -0,0 +1,104 @@
+/*\r
+ * \r
+ * Copyright 2002-2004 The Ant-Contrib project\r
+ *\r
+ *  Licensed under the Apache License, Version 2.0 (the "License");\r
+ *  you may not use this file except in compliance with the License.\r
+ *  You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ */\r
+package net.sf.antcontrib.cpptasks.compiler;\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileReader;\r
+import java.io.IOException;\r
+import java.io.Reader;\r
+\r
+import net.sf.antcontrib.cpptasks.parser.Parser;\r
+\r
+import org.apache.tools.ant.BuildException;\r
+import org.apache.tools.ant.types.Environment;\r
+/**\r
+ * A command line C compiler that can utilize precompilation of header files\r
+ * \r
+ * @author Curt Arnold\r
+ */\r
+public abstract class PrecompilingCommandLineCompiler\r
+        extends\r
+            CommandLineCompiler implements PrecompilingCompiler {\r
+    protected PrecompilingCommandLineCompiler(String command,\r
+            String identifierArg, String[] sourceExtensions,\r
+            String[] headerExtensions, String outputSuffix, boolean libtool,\r
+            PrecompilingCommandLineCompiler libtoolCompiler,\r
+            boolean newEnvironment, Environment env) {\r
+        super(command, identifierArg, sourceExtensions, headerExtensions,\r
+                outputSuffix, libtool, libtoolCompiler, newEnvironment, env);\r
+    }\r
+    /**\r
+     * \r
+     * This method may be used to get two distinct compiler configurations, one\r
+     * for compiling the specified file and producing a precompiled header\r
+     * file, and a second for compiling other files using the precompiled\r
+     * header file.\r
+     * \r
+     * The last (preferrably only) include directive in the prototype file will\r
+     * be used to mark the boundary between pre-compiled and normally compiled\r
+     * headers.\r
+     * \r
+     * @param config\r
+     *            base configuration\r
+     * @param prototype\r
+     *            A source file (for example, stdafx.cpp) that is used to build\r
+     *            the precompiled header file. @returns null if precompiled\r
+     *            headers are not supported or a two element array containing\r
+     *            the precompiled header generation configuration and the\r
+     *            consuming configuration\r
+     *  \r
+     */\r
+    public CompilerConfiguration[] createPrecompileConfigurations(\r
+            CompilerConfiguration config, File prototype, String[] exceptFiles) {\r
+        //\r
+        //   cast should success or someone is passing us a configuration\r
+        //      that was prepared by another processor\r
+        //\r
+        CommandLineCompilerConfiguration cmdLineConfig = (CommandLineCompilerConfiguration) config;\r
+        //\r
+        //   parse prototype file to determine last header\r
+        //\r
+        Parser parser = createParser(prototype);\r
+        String[] includes;\r
+        try {\r
+            Reader reader = new BufferedReader(new FileReader(prototype));\r
+            parser.parse(reader);\r
+            includes = parser.getIncludes();\r
+        } catch (IOException ex) {\r
+            throw new BuildException(\r
+                    "Error parsing precompiled header protoype: "\r
+                            + prototype.toString() + ":" + ex.toString());\r
+        }\r
+        if (includes.length == 0) {\r
+            throw new BuildException("Precompiled header prototype: "\r
+                    + prototype.toString()\r
+                    + " does not contain any include directives.");\r
+        }\r
+        CompilerConfiguration[] configs = new CompilerConfiguration[2];\r
+        configs[0] = createPrecompileGeneratingConfig(cmdLineConfig, prototype,\r
+                includes[0]);\r
+        configs[1] = createPrecompileUsingConfig(cmdLineConfig, prototype,\r
+                includes[0], exceptFiles);\r
+        return configs;\r
+    }\r
+    abstract protected CompilerConfiguration createPrecompileGeneratingConfig(\r
+            CommandLineCompilerConfiguration baseConfig, File prototype,\r
+            String lastInclude);\r
+    abstract protected CompilerConfiguration createPrecompileUsingConfig(\r
+            CommandLineCompilerConfiguration baseConfig, File prototype,\r
+            String lastInclude, String[] exceptFiles);\r
+}\r