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