]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/os390/OS390Linker.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / Cpptasks / net / sf / antcontrib / cpptasks / os390 / OS390Linker.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.os390;\r
18import java.io.File;\r
19import java.io.FileOutputStream;\r
20import java.io.IOException;\r
21import java.util.Vector;\r
22\r
23import net.sf.antcontrib.cpptasks.CCTask;\r
24import net.sf.antcontrib.cpptasks.CUtil;\r
25import net.sf.antcontrib.cpptasks.compiler.CommandLineLinker;\r
26import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration;\r
27import net.sf.antcontrib.cpptasks.compiler.LinkType;\r
28import net.sf.antcontrib.cpptasks.compiler.Linker;\r
29import net.sf.antcontrib.cpptasks.types.LibrarySet;\r
30import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;\r
31\r
32import org.apache.tools.ant.BuildException;\r
33/**\r
34 * Adapter for the IBM (R) OS/390 (tm) Linker\r
35 * \r
36 * @author Hiram Chirino (cojonudo14@hotmail.com)\r
37 */\r
38public final class OS390Linker extends CommandLineLinker {\r
39 private static final OS390Linker datasetLinker = new OS390Linker();\r
40 private static final OS390Linker dllLinker = new OS390Linker("", ".dll");\r
41 private static final OS390Linker instance = new OS390Linker("", "");\r
42 public static OS390Linker getDataSetInstance() {\r
43 return datasetLinker;\r
44 }\r
45 public static OS390Linker getInstance() {\r
46 return instance;\r
47 }\r
48 private boolean isADatasetLinker;\r
49 File outputFile;\r
50 private String outputPrefix;\r
51 CCTask task;\r
52 private OS390Linker() {\r
53 super("cxx", "/bogus", new String[]{".o", ".a", ".lib", ".xds"},\r
54 new String[]{".dll", ".x"}, ".xds", false, null);\r
55 this.outputPrefix = "";\r
56 this.isADatasetLinker = true;\r
57 }\r
58 private OS390Linker(String outputPrefix, String outputSuffix) {\r
59 super("cxx", "/bogus", new String[]{".o", ".a", ".lib", ".x"},\r
60 new String[]{".dll"}, outputSuffix, false, null);\r
61 this.outputPrefix = outputPrefix;\r
62 this.isADatasetLinker = false;\r
63 }\r
64 protected void addBase(long base, Vector args) {\r
65 }\r
66 protected void addFixed(Boolean fixed, Vector args) {\r
67 }\r
68 protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args, Boolean defaultflag) {\r
69 if (linkType.isSharedLibrary()) {\r
70 args.addElement("-W");\r
71 args.addElement("l,DLL");\r
72 }\r
73 }\r
74 protected void addIncremental(boolean incremental, Vector args) {\r
75 }\r
76 /*\r
77 * @see CommandLineLinker#addLibrarySets(LibrarySet[], Vector, Vector,\r
78 * Vector)\r
79 */\r
80 protected String[] addLibrarySets(CCTask task, LibrarySet[] libsets,\r
81 Vector preargs, Vector midargs, Vector endargs) {\r
82 // If yo want to link against a library sitting in a dataset and\r
83 // not in the HFS, you can just use the //'dataset' notation\r
84 // to specify it. e.g:\r
85 // <libset dir="." libs="//'MQM.V5R2M0.SCSQLOAD'"/>\r
86 //\r
87 // We have to have special handling here because the file is not\r
88 // on the normal filesystem so the task will not noramly include it\r
89 // as part of the link command.\r
90 if (libsets != null) {\r
91 for (int i = 0; i < libsets.length; i++) {\r
92 String libs[] = libsets[i].getLibs();\r
93 for (int j = 0; j < libs.length; j++) {\r
94 if (libs[j].startsWith("//")) {\r
95 endargs.addElement("-l");\r
96 endargs.addElement(libs[j]);\r
97 } else if (libsets[i].getDataset() != null) {\r
98 String ds = libsets[i].getDataset();\r
99 endargs.addElement("//'" + ds + "(" + libs[j] + ")'");\r
100 }\r
101 }\r
102 }\r
103 }\r
104 return super.addLibrarySets(task, libsets, preargs, midargs, endargs);\r
105 }\r
106 protected void addMap(boolean map, Vector args) {\r
107 }\r
108 protected void addStack(int stack, Vector args) {\r
109 }\r
110 protected void addEntry(String entry, Vector args) {\r
111 }\r
112 \r
113 public String getCommandFileSwitch(String commandFile) {\r
114 return "@" + commandFile;\r
115 }\r
116 public File[] getLibraryPath() {\r
117 return CUtil.getPathFromEnvironment("LIB", ";");\r
118 }\r
119 \r
120 public String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {\r
121 StringBuffer buf = new StringBuffer();\r
122 String[] patterns = new String[libnames.length * 3];\r
123 int offset = addLibraryPatterns(libnames, buf, "lib", ".a", patterns, 0);\r
124 offset = addLibraryPatterns(libnames, buf, "", ".x", patterns, offset);\r
125 offset = addLibraryPatterns(libnames, buf, "", ".o", patterns, offset);\r
126 return patterns;\r
127 }\r
128 \r
129 private static int addLibraryPatterns(String[] libnames, StringBuffer buf,\r
130 String prefix, String extension, String[] patterns, int offset) {\r
131 for (int i = 0; i < libnames.length; i++) {\r
132 buf.setLength(0);\r
133 buf.append(prefix);\r
134 buf.append(libnames[i]);\r
135 buf.append(extension);\r
136 patterns[offset + i] = buf.toString();\r
137 }\r
138 return offset + libnames.length;\r
139 }\r
140 \r
141 public Linker getLinker(LinkType linkType) {\r
142 if (this == datasetLinker)\r
143 return datasetLinker;\r
144 if (linkType.isSharedLibrary())\r
145 return dllLinker;\r
146 return instance;\r
147 }\r
148 public int getMaximumCommandLength() {\r
149 return Integer.MAX_VALUE;\r
150 }\r
151 public String getOutputFileName(String baseName) {\r
152 return outputPrefix + super.getOutputFileName(baseName);\r
153 }\r
154 protected String[] getOutputFileSwitch(CCTask task, String outputFile) {\r
155 if (isADatasetLinker && task.getDataset() != null) {\r
156 String ds = task.getDataset();\r
157 outputFile = "//'" + ds + "(" + outputFile + ")'";\r
158 }\r
159 return getOutputFileSwitch(outputFile);\r
160 }\r
161 public String[] getOutputFileSwitch(String outputFile) {\r
162 return new String[]{"-o", outputFile};\r
163 }\r
164 public boolean isCaseSensitive() {\r
165 return OS390Processor.isCaseSensitive();\r
166 }\r
167 /*\r
168 * @see CommandLineLinker#link(Task, File, String[],\r
169 * CommandLineLinkerConfiguration)\r
170 */\r
171 public void link(CCTask task, File outputFile, String[] sourceFiles,\r
172 CommandLineLinkerConfiguration config) throws BuildException {\r
173 this.task = task;\r
174 this.outputFile = outputFile;\r
175 if (isADatasetLinker) {\r
176 int p = outputFile.getName().indexOf(".");\r
177 if (p >= 0) {\r
178 String newname = outputFile.getName().substring(0, p);\r
179 outputFile = new File(outputFile.getParent(), newname);\r
180 }\r
181 }\r
182 super.link(task, outputFile, sourceFiles, config);\r
183 }\r
184 /*\r
185 * @see CommandLineLinker#runCommand(Task, File, String[])\r
186 */\r
187 protected int runCommand(CCTask task, File workingDir, String[] cmdline)\r
188 throws BuildException {\r
189 int rc = super.runCommand(task, workingDir, cmdline);\r
190 // create the .xds file if everything was ok.\r
191 if (rc == 0) {\r
192 try {\r
193 outputFile.delete();\r
194 new FileOutputStream(outputFile).close();\r
195 } catch (IOException e) {\r
196 throw new BuildException(e.getMessage());\r
197 }\r
198 }\r
199 return rc;\r
200 }\r
201}\r