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
.os390
;
19 import java
.util
.Vector
;
21 import net
.sf
.antcontrib
.cpptasks
.CUtil
;
22 import net
.sf
.antcontrib
.cpptasks
.CompilerDef
;
23 import net
.sf
.antcontrib
.cpptasks
.compiler
.AbstractCompiler
;
24 import net
.sf
.antcontrib
.cpptasks
.compiler
.CommandLineCCompiler
;
25 import net
.sf
.antcontrib
.cpptasks
.compiler
.LinkType
;
26 import net
.sf
.antcontrib
.cpptasks
.compiler
.Linker
;
27 import net
.sf
.antcontrib
.cpptasks
.compiler
.Processor
;
28 import net
.sf
.antcontrib
.cpptasks
.types
.DefineArgument
;
29 import net
.sf
.antcontrib
.cpptasks
.types
.UndefineArgument
;
30 import net
.sf
.antcontrib
.cpptasks
.OptimizationEnum
;
33 import org
.apache
.tools
.ant
.types
.Environment
;
35 * Adapter for the IBM (R) OS/390 (tm) C++ Compiler
37 * @author Hiram Chirino (cojonudo14@hotmail.com)
39 public class OS390CCompiler
extends CommandLineCCompiler
{
40 private static final AbstractCompiler instance
= new OS390CCompiler(false,
42 public static AbstractCompiler
getInstance() {
45 private OS390CCompiler(boolean newEnvironment
, Environment env
) {
46 super("cxx", null, new String
[]{".c", ".cc", ".cpp", ".cxx", ".c++",
47 ".s"}, new String
[]{".h", ".hpp"}, ".o", false, null,
50 protected void addImpliedArgs(final Vector args
,
52 final boolean multithreaded
,
53 final boolean exceptions
,
54 final LinkType linkType
,
56 final OptimizationEnum optimization
,
57 final Boolean defaultflag
) {
58 // Specifies that only compilations and assemblies be done.
59 // Link-edit is not done
60 args
.addElement("-c");
61 args
.addElement("-W");
62 args
.addElement("c,NOEXPMAC,NOSHOWINC");
64 * if (exceptions) { args.addElement("/GX"); }
67 args
.addElement("-g");
68 args
.addElement("-D");
69 args
.addElement("_DEBUG");
71 * if (multithreaded) { args.addElement("/D_MT"); if (staticLink) {
72 * args.addElement("/MTd"); } else { args.addElement("/MDd");
73 * args.addElement("/D_DLL"); } } else { args.addElement("/MLd"); }
76 args
.addElement("-D");
77 args
.addElement("NEBUG");
79 * if (multithreaded) { args.addElement("/D_MT"); if (staticLink) {
80 * args.addElement("/MT"); } else { args.addElement("/MD");
81 * args.addElement("/D_DLL"); } } else { args.addElement("/ML"); }
85 protected void addWarningSwitch(Vector args
, int level
) {
86 OS390Processor
.addWarningSwitch(args
, level
);
89 * The buildDefineArguments implementation CommandLineCCompiler is not good
90 * for us because os390 defines are give by -D definex instead of
91 * /Ddefinex, 2 args not 1! since we implement this ourslefs, we do not
92 * have to implement the getDefineSwitch() and the getUndefineSwitch().
94 protected void buildDefineArguments(CompilerDef
[] defs
, Vector args
) {
96 // assume that we aren't inheriting defines from containing <cc>
98 UndefineArgument
[] merged
= defs
[0].getActiveDefines();
99 for (int i
= 1; i
< defs
.length
; i
++) {
101 // if we are inheriting, merge the specific defines with the
102 // containing defines
103 merged
= DefineArgument
.merge(defs
[i
].getActiveDefines(), merged
);
105 StringBuffer buf
= new StringBuffer(30);
106 for (int i
= 0; i
< merged
.length
; i
++) {
108 UndefineArgument current
= merged
[i
];
109 if (current
.isDefine()) {
110 args
.addElement("-D");
111 buf
.append(current
.getName());
112 if (current
.getValue() != null
113 && current
.getValue().length() > 0) {
115 buf
.append(current
.getValue());
117 args
.addElement(buf
.toString());
119 args
.addElement("-U");
120 args
.addElement(current
.getName());
124 public Processor
changeEnvironment(boolean newEnvironment
, Environment env
) {
125 if (newEnvironment
|| env
!= null) {
126 return new OS390CCompiler(newEnvironment
, env
);
131 * @see CommandLineCompiler#getDefineSwitch(StringBuffer, String, String)
133 protected void getDefineSwitch(StringBuffer buffer
, String define
,
136 protected File
[] getEnvironmentIncludePath() {
137 return CUtil
.getPathFromEnvironment("INCLUDE", ":");
139 protected String
getIncludeDirSwitch(String includeDir
) {
140 return OS390Processor
.getIncludeDirSwitch(includeDir
);
142 public Linker
getLinker(LinkType type
) {
143 return OS390Linker
.getInstance().getLinker(type
);
145 public int getMaximumCommandLength() {
146 return Integer
.MAX_VALUE
;
148 /* Only compile one file at time for now */
149 protected int getMaximumInputFilesPerCommand() {
150 return Integer
.MAX_VALUE
;
153 * @see CommandLineCompiler#getUndefineSwitch(StringBuffer, String)
155 protected void getUndefineSwitch(StringBuffer buffer
, String define
) {