]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/os400/IccLinker.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / Cpptasks / net / sf / antcontrib / cpptasks / os400 / IccLinker.java
diff --git a/Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/os400/IccLinker.java b/Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/os400/IccLinker.java
new file mode 100644 (file)
index 0000000..5e4e2f2
--- /dev/null
@@ -0,0 +1,202 @@
+/*\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.os400;\r
+import java.io.File;\r
+import java.io.FileOutputStream;\r
+import java.io.IOException;\r
+import java.util.Vector;\r
+import net.sf.antcontrib.cpptasks.CCTask;\r
+import net.sf.antcontrib.cpptasks.CUtil;\r
+import net.sf.antcontrib.cpptasks.compiler.CommandLineLinker;\r
+import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration;\r
+import net.sf.antcontrib.cpptasks.compiler.LinkType;\r
+import net.sf.antcontrib.cpptasks.compiler.Linker;\r
+import net.sf.antcontrib.cpptasks.types.LibrarySet;\r
+import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;\r
+import org.apache.tools.ant.BuildException;\r
+/**\r
+ * Adapter for the IBM (R) OS/390 (tm) Linker\r
+ * \r
+ * @author Hiram Chirino (cojonudo14@hotmail.com)\r
+ */\r
+public final class IccLinker extends CommandLineLinker {\r
+    private static final IccLinker datasetLinker = new IccLinker();\r
+    private static final IccLinker dllLinker = new IccLinker("", ".dll");\r
+    private static final IccLinker instance = new IccLinker("", "");\r
+    public static IccLinker getDataSetInstance() {\r
+        return datasetLinker;\r
+    }\r
+    public static IccLinker getInstance() {\r
+        return instance;\r
+    }\r
+    private boolean isADatasetLinker;\r
+    File outputFile;\r
+    private String outputPrefix;\r
+    CCTask task;\r
+    private IccLinker() {\r
+        super("icc", "/bogus", new String[]{".o", ".a", ".lib", ".xds"},\r
+                new String[]{".dll", ".x"}, ".xds", false, null);\r
+        this.outputPrefix = "";\r
+        this.isADatasetLinker = true;\r
+    }\r
+    private IccLinker(String outputPrefix, String outputSuffix) {\r
+        super("icc", "/bogus", new String[]{".o", ".a", ".lib", ".x"},\r
+                new String[]{".dll"}, outputSuffix, false, null);\r
+        this.outputPrefix = outputPrefix;\r
+        this.isADatasetLinker = false;\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
+        if (linkType.isSharedLibrary()) {\r
+            args.addElement("-W");\r
+            args.addElement("l,DLL");\r
+        }\r
+    }\r
+    protected void addIncremental(boolean incremental, Vector args) {\r
+    }\r
+    /*\r
+     * @see CommandLineLinker#addLibrarySets(LibrarySet[], Vector, Vector,\r
+     *      Vector)\r
+     */\r
+    protected String[] addLibrarySets(CCTask task, LibrarySet[] libsets,\r
+            Vector preargs, Vector midargs, Vector endargs) {\r
+        // If yo want to link against a library sitting in a dataset and\r
+        // not in the HFS, you can just use the //'dataset' notation\r
+        // to specify it. e.g:\r
+        // <libset dir="." libs="//'MQM.V5R2M0.SCSQLOAD'"/>\r
+        //\r
+        // We have to have special handling here because the file is not\r
+        // on the normal filesystem so the task will not noramly include it\r
+        // as part of the link command.\r
+        if (libsets != null) {\r
+            for (int i = 0; i < libsets.length; i++) {\r
+                String libs[] = libsets[i].getLibs();\r
+                for (int j = 0; j < libs.length; j++) {\r
+                    if (libs[j].startsWith("//")) {\r
+                        endargs.addElement("-l");\r
+                        endargs.addElement(libs[j]);\r
+                    } else if (libsets[i].getDataset() != null) {\r
+                        String ds = libsets[i].getDataset();\r
+                        endargs.addElement("//'" + ds + "(" + libs[j] + ")'");\r
+                    }\r
+                }\r
+            }\r
+        }\r
+        return super.addLibrarySets(task, libsets, preargs, midargs, endargs);\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
+    public String getCommandFileSwitch(String commandFile) {\r
+        return "@" + commandFile;\r
+    }\r
+    public File[] getLibraryPath() {\r
+        return CUtil.getPathFromEnvironment("LIB", ";");\r
+    }\r
+    public String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {\r
+        StringBuffer buf = new StringBuffer();\r
+        String[] patterns = new String[libnames.length * 3];\r
+        int offset = addLibraryPatterns(libnames, buf, "lib", ".a", patterns, 0);\r
+        offset = addLibraryPatterns(libnames, buf, "", ".x", patterns, offset);\r
+        offset = addLibraryPatterns(libnames, buf, "", ".o", patterns, offset);\r
+        return patterns;\r
+    }\r
+    \r
+    private static int addLibraryPatterns(String[] libnames, StringBuffer buf,\r
+            String prefix, String extension, String[] patterns, int offset) {\r
+        for (int i = 0; i < libnames.length; i++) {\r
+            buf.setLength(0);\r
+            buf.append(prefix);\r
+            buf.append(libnames[i]);\r
+            buf.append(extension);\r
+            patterns[offset + i] = buf.toString();\r
+        }\r
+        return offset + libnames.length;\r
+    }\r
+    \r
+    \r
+    public Linker getLinker(LinkType linkType) {\r
+        if (this == datasetLinker)\r
+            return datasetLinker;\r
+        if (linkType.isSharedLibrary())\r
+            return dllLinker;\r
+        return instance;\r
+    }\r
+    public int getMaximumCommandLength() {\r
+        return Integer.MAX_VALUE;\r
+    }\r
+    protected String[] getOutputFileSwitch(CCTask task, String outputFile) {\r
+        if (isADatasetLinker && task.getDataset() != null) {\r
+            String ds = task.getDataset();\r
+            outputFile = "//'" + ds + "(" + outputFile + ")'";\r
+        }\r
+        return getOutputFileSwitch(outputFile);\r
+    }\r
+    public String[] getOutputFileSwitch(String outputFile) {\r
+        return new String[]{"-o", outputFile};\r
+    }\r
+    public boolean isCaseSensitive() {\r
+        return IccProcessor.isCaseSensitive();\r
+    }\r
+    /*\r
+     * @see CommandLineLinker#link(Task, File, String[],\r
+     *      CommandLineLinkerConfiguration)\r
+     */\r
+    public void link(CCTask task, File outputFile, String[] sourceFiles,\r
+            CommandLineLinkerConfiguration config) throws BuildException {\r
+        this.task = task;\r
+        this.outputFile = outputFile;\r
+        if (isADatasetLinker) {\r
+            int p = outputFile.getName().indexOf(".");\r
+            if (p >= 0) {\r
+                String newname = outputFile.getName().substring(0, p);\r
+                outputFile = new File(outputFile.getParent(), newname);\r
+            }\r
+        }\r
+        super.link(task, outputFile, sourceFiles, config);\r
+    }\r
+    /*\r
+     * @see CommandLineLinker#runCommand(Task, File, String[])\r
+     */\r
+    protected int runCommand(CCTask task, File workingDir, String[] cmdline)\r
+            throws BuildException {\r
+        int rc = super.runCommand(task, workingDir, cmdline);\r
+        // create the .xds file if everything was ok.\r
+        if (rc == 0) {\r
+            try {\r
+                outputFile.delete();\r
+                new FileOutputStream(outputFile).close();\r
+            } catch (IOException e) {\r
+                throw new BuildException(e.getMessage());\r
+            }\r
+        }\r
+        return rc;\r
+    }\r
+    public String xgetOutputFileName(String baseName) {\r
+        return outputPrefix + super.getOutputFileName(baseName);\r
+    }\r
+}\r