]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/borland/BorlandLibrarian.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / Cpptasks / net / sf / antcontrib / cpptasks / borland / BorlandLibrarian.java
diff --git a/Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/borland/BorlandLibrarian.java b/Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/borland/BorlandLibrarian.java
new file mode 100644 (file)
index 0000000..5fb3eb0
--- /dev/null
@@ -0,0 +1,200 @@
+/*\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.borland;\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.Vector;\r
+import org.apache.tools.ant.BuildException;\r
+\r
+import net.sf.antcontrib.cpptasks.CUtil;\r
+import net.sf.antcontrib.cpptasks.compiler.CommandLineLinker;\r
+import net.sf.antcontrib.cpptasks.compiler.LinkType;\r
+import net.sf.antcontrib.cpptasks.compiler.Linker;\r
+import net.sf.antcontrib.cpptasks.CCTask;\r
+import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration;\r
+import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;\r
+\r
+/**\r
+ * Adapter for the Borland(r) tlib Librarian\r
+ * \r
+ * @author Curt Arnold\r
+ */\r
+public class BorlandLibrarian extends CommandLineLinker {\r
+    private static final BorlandLibrarian instance = new BorlandLibrarian();\r
+    public static BorlandLibrarian getInstance() {\r
+        return instance;\r
+    }\r
+    private BorlandLibrarian() {\r
+        super("tlib", "--version", new String[]{".obj"}, new String[0], ".lib", false,\r
+                null);\r
+    }\r
+    protected void addBase(long base, Vector args) {\r
+    }\r
+    protected void addFixed(Boolean fixed, Vector args) {\r
+    }\r
+    protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args, Boolean defaultflag) {\r
+    }\r
+    protected void addIncremental(boolean incremental, Vector args) {\r
+    }\r
+    protected void addMap(boolean map, Vector args) {\r
+    }\r
+    protected void addStack(int stack, Vector args) {\r
+    }\r
+    /* (non-Javadoc)\r
+     * @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addEntry(int, java.util.Vector)\r
+     */\r
+    protected void addEntry(String entry, Vector args) {\r
+    }\r
+    \r
+    protected String getCommandFileSwitch(String cmdFile) {\r
+        return BorlandProcessor.getCommandFileSwitch(cmdFile);\r
+    }\r
+    public File[] getLibraryPath() {\r
+        return CUtil.getPathFromEnvironment("LIB", ";");\r
+    }\r
+    public String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {\r
+        return BorlandProcessor.getLibraryPatterns(libnames, libType);\r
+    }\r
+    public Linker getLinker(LinkType type) {\r
+        return BorlandLinker.getInstance().getLinker(type);\r
+    }\r
+    public int getMaximumCommandLength() {\r
+        return 1024;\r
+    }\r
+    public String[] getOutputFileSwitch(String outFile) {\r
+        return BorlandProcessor.getOutputFileSwitch(outFile);\r
+    }\r
+    public boolean isCaseSensitive() {\r
+        return BorlandProcessor.isCaseSensitive();\r
+    }\r
+    /**\r
+     * Gets identifier for the linker.\r
+     * \r
+     * TLIB will lockup when attempting to get version\r
+     * information.  Since the Librarian version isn't critical\r
+     * just return a stock response.\r
+     */\r
+    public String getIdentifier() {\r
+       return "TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation";\r
+    }\r
+    \r
+    /**\r
+     * Prepares argument list for exec command.\r
+     * \r
+     * @param outputFile\r
+     *            linker output file\r
+     * @param sourceFiles\r
+     *            linker input files (.obj, .o, .res)\r
+     * @param args\r
+     *            linker arguments\r
+     * @return arguments for runTask\r
+     */\r
+    protected String[] prepareArguments(\r
+               CCTask task,\r
+               String outputDir, \r
+                       String outputName,\r
+            String[] sourceFiles, \r
+                       CommandLineLinkerConfiguration config) {\r
+       String[] preargs = config.getPreArguments();\r
+        String[] endargs = config.getEndArguments();\r
+        StringBuffer buf = new StringBuffer();\r
+        Vector execArgs = new Vector(preargs.length + endargs.length + 10\r
+                + sourceFiles.length);\r
+        \r
+        execArgs.addElement(this.getCommand());\r
+        String outputFileName = new File(outputDir, outputName).toString();\r
+        execArgs.addElement(quoteFilename(buf, outputFileName));\r
+\r
+        for (int i = 0; i < preargs.length; i++) {\r
+            execArgs.addElement(preargs[i]);\r
+        }\r
+\r
+        //\r
+        //   add a place-holder for page size\r
+        //\r
+        int pageSizeIndex = execArgs.size();\r
+        execArgs.addElement(null);\r
+        \r
+        int objBytes = 0;\r
+        \r
+        for (int i = 0; i < sourceFiles.length; i++) {\r
+            String last4 = sourceFiles[i]\r
+                    .substring(sourceFiles[i].length() - 4).toLowerCase();\r
+            if (last4.equals(".def")) {\r
+            } else {\r
+                if (last4.equals(".res")) {\r
+                } else {\r
+                    if (last4.equals(".lib")) {\r
+                    } else {\r
+                        execArgs.addElement("+" + quoteFilename(buf, sourceFiles[i]));\r
+                        objBytes += new File(sourceFiles[i]).length();\r
+                    }\r
+                }\r
+            }\r
+        }\r
+        \r
+        for (int i = 0; i < endargs.length; i++) {\r
+            execArgs.addElement(endargs[i]);\r
+        }\r
+        \r
+        String[] execArguments = new String[execArgs.size()];\r
+        execArgs.copyInto(execArguments);\r
+\r
+       int minPageSize = objBytes >> 16;\r
+       int pageSize = 0;\r
+       for(int i = 4; i <= 15; i++) {\r
+               pageSize = 1 << i;\r
+               if (pageSize > minPageSize) break;\r
+       }\r
+        execArguments[pageSizeIndex] = "/P" + Integer.toString(pageSize);\r
+        \r
+        return execArguments;\r
+    }\r
+    \r
+    /**\r
+     * Prepares argument list to execute the linker using a response file.\r
+     * \r
+     * @param outputFile\r
+     *            linker output file\r
+     * @param args\r
+     *            output of prepareArguments\r
+     * @return arguments for runTask\r
+     */\r
+    protected String[] prepareResponseFile(File outputFile, String[] args)\r
+            throws IOException {\r
+       return BorlandProcessor.prepareResponseFile(outputFile, args, " & \n");\r
+    }\r
+    \r
+    /**\r
+     * Builds a library\r
+     *\r
+     */\r
+    public void link(CCTask task,\r
+                     File outputFile,\r
+                     String[] sourceFiles,\r
+                     CommandLineLinkerConfiguration config)\r
+                     throws BuildException\r
+    {\r
+       //\r
+       //  delete any existing library\r
+       outputFile.delete();\r
+       //\r
+       //  build a new library\r
+       super.link(task, outputFile, sourceFiles, config);\r
+    }\r
+    \r
+}\r