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