summaryrefslogtreecommitdiff
path: root/src/main/java/net/sf/antcontrib/cpptasks/sun
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/sf/antcontrib/cpptasks/sun')
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/sun/C89CCompiler.java108
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/sun/C89Linker.java132
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/sun/C89Processor.java116
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/sun/ForteCCCompiler.java130
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/sun/ForteCCLinker.java100
5 files changed, 586 insertions, 0 deletions
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/sun/C89CCompiler.java b/src/main/java/net/sf/antcontrib/cpptasks/sun/C89CCompiler.java
new file mode 100644
index 0000000..4ac8ac1
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/sun/C89CCompiler.java
@@ -0,0 +1,108 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.sun;
+import java.io.File;
+import java.util.Vector;
+
+import net.sf.antcontrib.cpptasks.CUtil;
+import net.sf.antcontrib.cpptasks.compiler.AbstractCompiler;
+import net.sf.antcontrib.cpptasks.compiler.CommandLineCCompiler;
+import net.sf.antcontrib.cpptasks.compiler.LinkType;
+import net.sf.antcontrib.cpptasks.compiler.Linker;
+import net.sf.antcontrib.cpptasks.compiler.Processor;
+import net.sf.antcontrib.cpptasks.OptimizationEnum;
+
+
+import org.apache.tools.ant.types.Environment;
+/**
+ * Adapter for the Sun C89 C++ Compiler
+ *
+ * @author Hiram Chirino (cojonudo14@hotmail.com)
+ */
+public class C89CCompiler extends CommandLineCCompiler {
+ private static final AbstractCompiler instance = new C89CCompiler(false,
+ null);
+ public static AbstractCompiler getInstance() {
+ return instance;
+ }
+ private C89CCompiler(boolean newEnvironment, Environment env) {
+ super("c89", null, new String[]{".c", ".cc", ".cpp", ".cxx", ".c++"},
+ new String[]{".h", ".hpp"}, ".o", false, null, newEnvironment,
+ env);
+ }
+ protected void addImpliedArgs(
+ final Vector args,
+ final boolean debug,
+ final boolean multithreaded,
+ final boolean exceptions,
+ final LinkType linkType,
+ final Boolean rtti,
+ final OptimizationEnum optimization) {
+ // Specifies that only compilations and assemblies be done.
+ args.addElement("-c");
+ /*
+ * if (exceptions) { args.addElement("/GX"); }
+ */
+ if (debug) {
+ args.addElement("-g");
+ args.addElement("-D_DEBUG");
+ /*
+ * if (multithreaded) { args.addElement("/D_MT"); if (staticLink) {
+ * args.addElement("/MTd"); } else { args.addElement("/MDd");
+ * args.addElement("/D_DLL"); } } else { args.addElement("/MLd"); }
+ */
+ } else {
+ args.addElement("-DNDEBUG");
+ /*
+ * if (multithreaded) { args.addElement("/D_MT"); if (staticLink) {
+ * args.addElement("/MT"); } else { args.addElement("/MD");
+ * args.addElement("/D_DLL"); } } else { args.addElement("/ML"); }
+ */
+ }
+ }
+ protected void addWarningSwitch(Vector args, int level) {
+ C89Processor.addWarningSwitch(args, level);
+ }
+ public Processor changeEnvironment(boolean newEnvironment, Environment env) {
+ if (newEnvironment || env != null) {
+ return new C89CCompiler(newEnvironment, env);
+ }
+ return this;
+ }
+ protected void getDefineSwitch(StringBuffer buf, String define, String value) {
+ C89Processor.getDefineSwitch(buf, define, value);
+ }
+ protected File[] getEnvironmentIncludePath() {
+ return CUtil.getPathFromEnvironment("INCLUDE", ":");
+ }
+ protected String getIncludeDirSwitch(String includeDir) {
+ return C89Processor.getIncludeDirSwitch(includeDir);
+ }
+ public Linker getLinker(LinkType type) {
+ return C89Linker.getInstance().getLinker(type);
+ }
+ public int getMaximumCommandLength() {
+ return Integer.MAX_VALUE;
+ }
+ /* Only compile one file at time for now */
+ protected int getMaximumInputFilesPerCommand() {
+ return 1;
+ }
+ protected void getUndefineSwitch(StringBuffer buf, String define) {
+ C89Processor.getUndefineSwitch(buf, define);
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/sun/C89Linker.java b/src/main/java/net/sf/antcontrib/cpptasks/sun/C89Linker.java
new file mode 100644
index 0000000..6c41c89
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/sun/C89Linker.java
@@ -0,0 +1,132 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.sun;
+import java.io.File;
+import java.util.Vector;
+
+import net.sf.antcontrib.cpptasks.CCTask;
+import net.sf.antcontrib.cpptasks.CUtil;
+import net.sf.antcontrib.cpptasks.compiler.CommandLineLinker;
+import net.sf.antcontrib.cpptasks.compiler.LinkType;
+import net.sf.antcontrib.cpptasks.compiler.Linker;
+import net.sf.antcontrib.cpptasks.types.LibrarySet;
+import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;
+import net.sf.antcontrib.cpptasks.VersionInfo;
+
+/**
+ * Adapter for the Sun C89 Linker
+ *
+ * @author Hiram Chirino (cojonudo14@hotmail.com)
+ */
+public final class C89Linker extends CommandLineLinker {
+ private static final C89Linker dllLinker = new C89Linker("lib", ".so");
+ private static final C89Linker instance = new C89Linker("", "");
+ public static C89Linker getInstance() {
+ return instance;
+ }
+ private String outputPrefix;
+ private C89Linker(String outputPrefix, String outputSuffix) {
+ super("ld", "/bogus", new String[]{".o", ".a", ".lib", ".x"},
+ new String[]{}, outputSuffix, false, null);
+ this.outputPrefix = outputPrefix;
+ }
+ protected void addBase(long base, Vector args) {
+ }
+ protected void addFixed(Boolean fixed, Vector args) {
+ }
+ protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args) {
+ if (linkType.isSharedLibrary()) {
+ args.addElement("-G");
+ }
+ }
+ protected void addIncremental(boolean incremental, Vector args) {
+ }
+ public String[] addLibrarySets(CCTask task, LibrarySet[] libsets,
+ Vector preargs, Vector midargs, Vector endargs) {
+ super.addLibrarySets(task, libsets, preargs, midargs, endargs);
+ StringBuffer buf = new StringBuffer("-l");
+ for (int i = 0; i < libsets.length; i++) {
+ LibrarySet set = libsets[i];
+ File libdir = set.getDir(null);
+ String[] libs = set.getLibs();
+ if (libdir != null) {
+ endargs.addElement("-L");
+ endargs.addElement(libdir.getAbsolutePath());
+ }
+ for (int j = 0; j < libs.length; j++) {
+ //
+ // reset the buffer to just "-l"
+ //
+ buf.setLength(2);
+ //
+ // add the library name
+ buf.append(libs[j]);
+ //
+ // add the argument to the list
+ endargs.addElement(buf.toString());
+ }
+ }
+ return null;
+ }
+ protected void addMap(boolean map, Vector args) {
+ }
+ protected void addStack(int stack, Vector args) {
+ }
+ /* (non-Javadoc)
+ * @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addEntry(int, java.util.Vector)
+ */
+ protected void addEntry(String entry, Vector args) {
+ }
+
+ public String getCommandFileSwitch(String commandFile) {
+ return "@" + commandFile;
+ }
+ public File[] getLibraryPath() {
+ return CUtil.getPathFromEnvironment("LIB", ";");
+ }
+ public String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {
+ return C89Processor.getLibraryPatterns(libnames, libType);
+ }
+ public Linker getLinker(LinkType linkType) {
+ if (linkType.isSharedLibrary()) {
+ return dllLinker;
+ }
+ /*
+ * if(linkType.isStaticLibrary()) { return
+ * OS390Librarian.getInstance(); }
+ */
+ return instance;
+ }
+ public int getMaximumCommandLength() {
+ return Integer.MAX_VALUE;
+ }
+ public String[] getOutputFileNames(String baseName, VersionInfo versionInfo) {
+ String[] baseNames = super.getOutputFileNames(baseName, versionInfo);
+ if (outputPrefix.length() > 0) {
+ for(int i = 0; i < baseNames.length; i++) {
+ baseNames[i] = outputPrefix + baseNames[i];
+ }
+ }
+ return baseNames;
+ }
+ public String[] getOutputFileSwitch(String outputFile) {
+ return new String[]{"-o", outputFile};
+ }
+ public boolean isCaseSensitive() {
+ return C89Processor.isCaseSensitive();
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/sun/C89Processor.java b/src/main/java/net/sf/antcontrib/cpptasks/sun/C89Processor.java
new file mode 100644
index 0000000..343293a
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/sun/C89Processor.java
@@ -0,0 +1,116 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.sun;
+import java.util.Vector;
+import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;
+
+/**
+ * A add-in class for Sun C89 compilers and linkers
+ *
+ * @author Hiram Chirino (cojonudo14@hotmail.com)
+ */
+public class C89Processor {
+ private static int addLibraryPatterns(String[] libnames, StringBuffer buf,
+ String prefix, String extension, String[] patterns, int offset) {
+ for (int i = 0; i < libnames.length; i++) {
+ buf.setLength(0);
+ buf.append(prefix);
+ buf.append(libnames[i]);
+ buf.append(extension);
+ patterns[offset + i] = buf.toString();
+ }
+ return offset + libnames.length;
+ }
+ public static void addWarningSwitch(Vector args, int level) {
+ switch (level) {
+ /*
+ * case 0: args.addElement("/W0"); break;
+ *
+ * case 1: args.addElement("/W1"); break;
+ *
+ * case 2: break;
+ *
+ * case 3: args.addElement("/W3"); break;
+ *
+ * case 4: args.addElement("/W4"); break;
+ */
+ }
+ }
+ public static String getCommandFileSwitch(String cmdFile) {
+ StringBuffer buf = new StringBuffer("@");
+ if (cmdFile.indexOf(' ') >= 0) {
+ buf.append('\"');
+ buf.append(cmdFile);
+ buf.append('\"');
+ } else {
+ buf.append(cmdFile);
+ }
+ return buf.toString();
+ }
+ public static void getDefineSwitch(StringBuffer buf, String define,
+ String value) {
+ buf.setLength(0);
+ buf.append("-D");
+ buf.append(define);
+ if (value != null && value.length() > 0) {
+ buf.append('=');
+ buf.append(value);
+ }
+ }
+ public static String getIncludeDirSwitch(String includeDir) {
+ return "-I" + includeDir;
+ }
+ public static String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {
+ StringBuffer buf = new StringBuffer();
+ int patternCount = libnames.length*2;
+ if (libType != null) {
+ patternCount = libnames.length;
+ }
+ String[] patterns = new String[patternCount];
+ int offset = 0;
+ if (libType == null || "static".equals(libType.getValue())) {
+ offset = addLibraryPatterns(libnames, buf, "lib", ".a", patterns, 0);
+ }
+ if (libType == null || !"static".equals(libType.getValue())) {
+ offset = addLibraryPatterns(libnames, buf, "lib", ".so", patterns,
+ offset);
+ }
+ return patterns;
+ }
+ public static String[] getOutputFileSwitch(String outPath) {
+ StringBuffer buf = new StringBuffer("-o ");
+ if (outPath.indexOf(' ') >= 0) {
+ buf.append('\"');
+ buf.append(outPath);
+ buf.append('\"');
+ } else {
+ buf.append(outPath);
+ }
+ String[] retval = new String[]{buf.toString()};
+ return retval;
+ }
+ public static void getUndefineSwitch(StringBuffer buf, String define) {
+ buf.setLength(0);
+ buf.append("-U");
+ buf.append(define);
+ }
+ public static boolean isCaseSensitive() {
+ return true;
+ }
+ private C89Processor() {
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/sun/ForteCCCompiler.java b/src/main/java/net/sf/antcontrib/cpptasks/sun/ForteCCCompiler.java
new file mode 100644
index 0000000..9422e49
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/sun/ForteCCCompiler.java
@@ -0,0 +1,130 @@
+/*
+ *
+ * Copyright 2001-2007 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.sun;
+import java.io.File;
+import java.util.Vector;
+
+import net.sf.antcontrib.cpptasks.CUtil;
+import net.sf.antcontrib.cpptasks.compiler.LinkType;
+import net.sf.antcontrib.cpptasks.compiler.Linker;
+import net.sf.antcontrib.cpptasks.gcc.GccCompatibleCCompiler;
+import net.sf.antcontrib.cpptasks.OptimizationEnum;
+/**
+ * Adapter for the Sun (r) Forte (tm) C++ compiler
+ *
+ * @author Curt Arnold
+ */
+public final class ForteCCCompiler extends GccCompatibleCCompiler {
+ private final static String[] headerExtensions = new String[]{".h", ".hpp",
+ ".inl"};
+ private final static String[] sourceExtensions = new String[]{".c", ".cc",
+ ".cxx", ".cpp", ".c++", ".i", ".s"};
+
+ private static final ForteCCCompiler instance = new ForteCCCompiler("CC",
+ sourceExtensions, headerExtensions);
+ /**
+ * Gets singleton instance of this class
+ */
+ public static ForteCCCompiler getInstance() {
+ return instance;
+ }
+ private String identifier;
+ private File[] includePath;
+ /**
+ * Private constructor. Use ForteCCCompiler.getInstance() to get singleton
+ * instance of this class.
+ */
+ private ForteCCCompiler(String command, String[] sourceExtensions,
+ String[] headerExtensions) {
+ super(command, "-V", sourceExtensions, headerExtensions, false, null,
+ false, null);
+ }
+ public void addImpliedArgs(final Vector args,
+ final boolean debug,
+ final boolean multithreaded,
+ final boolean exceptions,
+ final LinkType linkType,
+ final Boolean rtti,
+ final OptimizationEnum optimization) {
+ args.addElement("-c");
+ if (debug) {
+ args.addElement("-g");
+ }
+ if (optimization != null) {
+ if (optimization.isSpeed()) {
+ args.addElement("-xO2");
+ }
+ }
+ if (rtti != null) {
+ if (rtti.booleanValue()) {
+ args.addElement("-features=rtti");
+ } else {
+ args.addElement("-features=no%rtti");
+ }
+ }
+ if (multithreaded) {
+ args.addElement("-mt");
+ }
+ if (linkType.isSharedLibrary()) {
+ args.addElement("-KPIC");
+ }
+
+ }
+ public void addWarningSwitch(Vector args, int level) {
+ switch (level) {
+ case 0 :
+ args.addElement("-w");
+ break;
+ case 1 :
+ case 2 :
+ break;
+ case 3 :
+ args.addElement("+w");
+ break;
+ case 4 :
+ args.addElement("+w2");
+ break;
+ case 5 :
+ args.addElement("+w2");
+ args.addElement("-xwe");
+ }
+ }
+ public File[] getEnvironmentIncludePath() {
+ if (includePath == null) {
+ File ccLoc = CUtil.getExecutableLocation("CC");
+ if (ccLoc != null) {
+ File compilerIncludeDir = new File(
+ new File(ccLoc, "../include").getAbsolutePath());
+ if (compilerIncludeDir.exists()) {
+ includePath = new File[2];
+ includePath[0] = compilerIncludeDir;
+ }
+ }
+ if (includePath == null) {
+ includePath = new File[1];
+ }
+ includePath[includePath.length - 1] = new File("/usr/include");
+ }
+ return includePath;
+ }
+ public Linker getLinker(LinkType linkType) {
+ return ForteCCLinker.getInstance().getLinker(linkType);
+ }
+ public int getMaximumCommandLength() {
+ return Integer.MAX_VALUE;
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/sun/ForteCCLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/sun/ForteCCLinker.java
new file mode 100644
index 0000000..47d2155
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/sun/ForteCCLinker.java
@@ -0,0 +1,100 @@
+/*
+ *
+ * Copyright 2001-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.sun;
+import java.io.File;
+import java.util.Vector;
+
+import net.sf.antcontrib.cpptasks.CUtil;
+import net.sf.antcontrib.cpptasks.compiler.LinkType;
+import net.sf.antcontrib.cpptasks.compiler.Linker;
+import net.sf.antcontrib.cpptasks.gcc.AbstractLdLinker;
+/**
+ * Adapter for Sun (r) Forte(tm) C++ Linker
+ *
+ * @author Curt Arnold
+ */
+public final class ForteCCLinker extends AbstractLdLinker {
+ private static final String[] discardFiles = new String[]{".dll", ".so",
+ ".sl"};
+ private static final String[] objFiles = new String[]{".o", ".a", ".lib"};
+ private static final ForteCCLinker arLinker = new ForteCCLinker("CC",
+ objFiles, discardFiles, "lib", ".a");
+ private static final ForteCCLinker dllLinker = new ForteCCLinker("CC",
+ objFiles, discardFiles, "lib", ".so");
+ private static final ForteCCLinker instance = new ForteCCLinker("CC",
+ objFiles, discardFiles, "", "");
+ public static ForteCCLinker getInstance() {
+ return instance;
+ }
+ private File[] libDirs;
+ private ForteCCLinker(String command, String[] extensions,
+ String[] ignoredExtensions, String outputPrefix, String outputSuffix) {
+ super(command, "-V", extensions, ignoredExtensions, outputPrefix,
+ outputSuffix, false, null);
+ }
+ public void addImpliedArgs(boolean debug, LinkType linkType, Vector args) {
+ if (debug) {
+ args.addElement("-g");
+ }
+ if (linkType.isStaticRuntime()) {
+ args.addElement("-static");
+ }
+ if (linkType.isSharedLibrary()) {
+ args.addElement("-G");
+ }
+ if (linkType.isStaticLibrary()) {
+ args.addElement("-xar");
+ }
+ }
+ public void addIncremental(boolean incremental, Vector args) {
+ /*
+ * if (incremental) { args.addElement("-xidlon"); } else {
+ * args.addElement("-xidloff"); }
+ */
+ }
+ /**
+ * Returns library path.
+ *
+ */
+ public File[] getLibraryPath() {
+ if (libDirs == null) {
+ File CCloc = CUtil.getExecutableLocation("CC");
+ if (CCloc != null) {
+ File compilerLib = new File(new File(CCloc, "../lib")
+ .getAbsolutePath());
+ if (compilerLib.exists()) {
+ libDirs = new File[2];
+ libDirs[0] = compilerLib;
+ }
+ }
+ if (libDirs == null) {
+ libDirs = new File[1];
+ }
+ }
+ libDirs[libDirs.length - 1] = new File("/usr/lib");
+ return libDirs;
+ }
+ public Linker getLinker(LinkType type) {
+ if (type.isStaticLibrary()) {
+ return arLinker;
+ }
+ if (type.isSharedLibrary()) {
+ return dllLinker;
+ }
+ return instance;
+ }
+}