3 * Copyright 2002-2004 The Ant-Contrib project
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package net
.sf
.antcontrib
.cpptasks
.os400
;
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
;
32 * Adapter for the IBM (R) OS/390 (tm) Linker
34 * @author Hiram Chirino (cojonudo14@hotmail.com)
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() {
43 public static IccLinker
getInstance() {
46 private boolean isADatasetLinker
;
48 private String outputPrefix
;
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;
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;
62 protected void addBase(long base
, Vector args
) {
64 protected void addFixed(Boolean fixed
, Vector args
) {
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");
72 protected void addIncremental(boolean incremental
, Vector args
) {
75 * @see CommandLineLinker#addLibrarySets(LibrarySet[], Vector, Vector,
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'"/>
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
] + ")'");
102 return super.addLibrarySets(task
, libsets
, preargs
, midargs
, endargs
);
104 protected void addMap(boolean map
, Vector args
) {
106 protected void addStack(int stack
, Vector args
) {
109 * @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addEntry(int, java.util.Vector)
111 protected void addEntry(String entry
, Vector args
) {
114 public String
getCommandFileSwitch(String commandFile
) {
115 return "@" + commandFile
;
117 public File
[] getLibraryPath() {
118 return CUtil
.getPathFromEnvironment("LIB", ";");
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
);
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
++) {
134 buf
.append(libnames
[i
]);
135 buf
.append(extension
);
136 patterns
[offset
+ i
] = buf
.toString();
138 return offset
+ libnames
.length
;
142 public Linker
getLinker(LinkType linkType
) {
143 if (this == datasetLinker
)
144 return datasetLinker
;
145 if (linkType
.isSharedLibrary())
149 public int getMaximumCommandLength() {
150 return Integer
.MAX_VALUE
;
152 protected String
[] getOutputFileSwitch(CCTask task
, String outputFile
) {
153 if (isADatasetLinker
&& task
.getDataset() != null) {
154 String ds
= task
.getDataset();
155 outputFile
= "//'" + ds
+ "(" + outputFile
+ ")'";
157 return getOutputFileSwitch(outputFile
);
159 public String
[] getOutputFileSwitch(String outputFile
) {
160 return new String
[]{"-o", outputFile
};
162 public boolean isCaseSensitive() {
163 return IccProcessor
.isCaseSensitive();
166 * @see CommandLineLinker#link(Task, File, String[],
167 * CommandLineLinkerConfiguration)
169 public void link(CCTask task
, File outputFile
, String
[] sourceFiles
,
170 CommandLineLinkerConfiguration config
) throws BuildException
{
172 this.outputFile
= outputFile
;
173 if (isADatasetLinker
) {
174 int p
= outputFile
.getName().indexOf(".");
176 String newname
= outputFile
.getName().substring(0, p
);
177 outputFile
= new File(outputFile
.getParent(), newname
);
180 super.link(task
, outputFile
, sourceFiles
, config
);
183 * @see CommandLineLinker#runCommand(Task, File, String[])
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.
192 new FileOutputStream(outputFile
).close();
193 } catch (IOException e
) {
194 throw new BuildException(e
.getMessage());
199 public String
xgetOutputFileName(String baseName
) {
200 return outputPrefix
+ super.getOutputFileName(baseName
);