From: Curt A. <ca...@us...> - 2002-09-14 04:44:53
|
Update of /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/gcc In directory usw-pr-cvs1:/tmp/cvs-serv18567/src/net/sf/antcontrib/cpptasks/gcc Modified Files: GccCompatibleCCompiler.java GccCCompiler.java Log Message: env child element for compilers (but not linkers, that will be tomorrow) Index: GccCompatibleCCompiler.java =================================================================== RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/gcc/GccCompatibleCCompiler.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GccCompatibleCCompiler.java 11 Sep 2002 03:52:41 -0000 1.7 --- GccCompatibleCCompiler.java 14 Sep 2002 04:44:50 -0000 1.8 *************** *** 60,63 **** --- 60,64 ---- import net.sf.antcontrib.cpptasks.compiler.CommandLineCCompiler; import net.sf.antcontrib.cpptasks.compiler.LinkType; + import org.apache.tools.ant.types.Environment; /** *************** *** 68,172 **** * @author Curt Arnold */ ! public abstract class GccCompatibleCCompiler extends CommandLineCCompiler ! { ! private final static String[] sourceExtensions = new String[] { ".c", ".cc", ".cpp", ".cxx", ".c++", ".i", ".f", ".for" }; ! private final static String[] headerExtensions = new String[] { ".h", ".hpp", ".inl" }; ! ! ! /** ! * Private constructor. Use GccCCompiler.getInstance() to get ! * singleton instance of this class. ! */ ! protected GccCompatibleCCompiler(String command, ! String identifierArg, ! String[] sourceExtensions, ! String[] headerExtensions, ! boolean libtool, GccCompatibleCCompiler libtoolCompiler) { ! super(command, identifierArg,sourceExtensions, headerExtensions, ! libtool ? ".fo" : ".o", libtool, libtoolCompiler); ! } ! ! /** ! * Private constructor. Use GccCCompiler.getInstance() to get ! * singleton instance of this class. ! */ ! protected GccCompatibleCCompiler(String command, ! String identifierArg, ! boolean libtool, GccCompatibleCCompiler libtoolCompiler) { ! super(command, identifierArg,sourceExtensions, headerExtensions, ! libtool ? ".fo" : ".o", libtool, libtoolCompiler); ! } ! ! ! public String getIncludeDirSwitch(String includeDir) { ! return "-I" + includeDir; ! } ! ! protected File[] getEnvironmentIncludePath() { ! return CUtil.getPathFromEnvironment("INCLUDE", ":"); ! } ! public void addWarningSwitch(Vector args, int level) { ! switch(level) { ! case 0: ! args.addElement("-w"); ! break; ! case 5: ! args.addElement("-Werror"); ! break; ! default: ! args.addElement("-W"); ! break; ! } ! } ! public void addImpliedArgs(Vector args, boolean debug, ! boolean multithreaded, boolean exceptions, LinkType linkType) { ! // ! // -fPIC is too much trouble ! // users have to manually add it for ! // operating systems that make sense ! // ! args.addElement("-c"); ! if(debug) { ! args.addElement("-g"); ! } ! if (getIdentifier().indexOf("mingw") >= 0) { ! if (linkType.isSubsystemConsole()) { ! args.addElement("-mconsole"); ! } ! if (linkType.isSubsystemGUI()) { ! args.addElement("-mwindows"); ! } ! } ! } ! public void getDefineSwitch(StringBuffer buffer,String define, String value) { ! buffer.append("-D"); ! buffer.append(define); ! if(value != null && value.length() > 0) { ! buffer.append('='); ! buffer.append(value); ! } ! } ! public void getUndefineSwitch(StringBuffer buffer, String define) { ! buffer.append("-U"); ! buffer.append(define); ! } ! /** ! * Adds an include path to the command. ! */ ! public void addIncludePath(String path, Vector cmd) ! { ! cmd.addElement("-I" + path); ! } } --- 69,205 ---- * @author Curt Arnold */ ! public abstract class GccCompatibleCCompiler extends CommandLineCCompiler { ! private final static String[] sourceExtensions = ! new String[] { ! ".c", ! ".cc", ! ".cpp", ! ".cxx", ! ".c++", ! ".i", ! ".f", ! ".for" }; ! private final static String[] headerExtensions = ! new String[] { ".h", ".hpp", ".inl" }; + /** + * Private constructor. Use GccCCompiler.getInstance() to get + * singleton instance of this class. + */ + protected GccCompatibleCCompiler( + String command, + String identifierArg, + String[] sourceExtensions, + String[] headerExtensions, + boolean libtool, + GccCompatibleCCompiler libtoolCompiler, + boolean newEnvironment, + Environment env) { + super( + command, + identifierArg, + sourceExtensions, + headerExtensions, + libtool ? ".fo" : ".o", + libtool, + libtoolCompiler, + newEnvironment, + env); + } ! /** ! * Private constructor. Use GccCCompiler.getInstance() to get ! * singleton instance of this class. ! */ ! protected GccCompatibleCCompiler( ! String command, ! String identifierArg, ! boolean libtool, ! GccCompatibleCCompiler libtoolCompiler, ! boolean newEnvironment, Environment env) { ! super( ! command, ! identifierArg, ! sourceExtensions, ! headerExtensions, ! libtool ? ".fo" : ".o", ! libtool, ! libtoolCompiler, ! newEnvironment, ! env); ! } ! public String getIncludeDirSwitch(String includeDir) { ! return "-I" + includeDir; ! } ! protected File[] getEnvironmentIncludePath() { ! return CUtil.getPathFromEnvironment("INCLUDE", ":"); ! } + public void addWarningSwitch(Vector args, int level) { + switch (level) { + case 0 : + args.addElement("-w"); + break; ! case 5 : ! args.addElement("-Werror"); ! break; ! default : ! args.addElement("-W"); ! break; ! } ! } ! public void addImpliedArgs( ! Vector args, ! boolean debug, ! boolean multithreaded, ! boolean exceptions, ! LinkType linkType) { ! // ! // -fPIC is too much trouble ! // users have to manually add it for ! // operating systems that make sense ! // ! args.addElement("-c"); ! if (debug) { ! args.addElement("-g"); ! } ! if (getIdentifier().indexOf("mingw") >= 0) { ! if (linkType.isSubsystemConsole()) { ! args.addElement("-mconsole"); ! } ! if (linkType.isSubsystemGUI()) { ! args.addElement("-mwindows"); ! } ! } ! } + public void getDefineSwitch( + StringBuffer buffer, + String define, + String value) { + buffer.append("-D"); + buffer.append(define); + if (value != null && value.length() > 0) { + buffer.append('='); + buffer.append(value); + } + } + public void getUndefineSwitch(StringBuffer buffer, String define) { + buffer.append("-U"); + buffer.append(define); + } ! /** ! * Adds an include path to the command. ! */ ! public void addIncludePath(String path, Vector cmd) { ! cmd.addElement("-I" + path); ! } } Index: GccCCompiler.java =================================================================== RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/gcc/GccCCompiler.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** GccCCompiler.java 10 Sep 2002 02:28:54 -0000 1.21 --- GccCCompiler.java 14 Sep 2002 04:44:50 -0000 1.22 *************** *** 60,67 **** import net.sf.antcontrib.cpptasks.compiler.LinkType; import net.sf.antcontrib.cpptasks.compiler.Linker; ! import net.sf.antcontrib.cpptasks.parser.Parser; import net.sf.antcontrib.cpptasks.parser.CParser; import net.sf.antcontrib.cpptasks.parser.FortranParser; import org.apache.tools.ant.BuildException; /** --- 60,69 ---- 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.parser.CParser; import net.sf.antcontrib.cpptasks.parser.FortranParser; + import net.sf.antcontrib.cpptasks.parser.Parser; import org.apache.tools.ant.BuildException; + import org.apache.tools.ant.types.Environment; /** *************** *** 70,263 **** * @author Adam Murdoch */ ! public final class GccCCompiler extends GccCompatibleCCompiler ! { ! private String identifier; ! private File[] includePath; ! private boolean isPICMeaningful = true; ! ! private final static String[] sourceExtensions = new String[] { ".c", ".cc", ".cpp", ".cxx", ".c++", ".i", ".f", ".for" }; ! private final static String[] headerExtensions = new String[] { ".h", ".hpp", ".inl" }; ! private static final GccCCompiler instance = ! new GccCCompiler("gcc", sourceExtensions, headerExtensions, false, ! new GccCCompiler("gcc", sourceExtensions, headerExtensions, true, null)); ! private static final GccCCompiler cppInstance = ! new GccCCompiler("c++",sourceExtensions, headerExtensions,false, ! new GccCCompiler("c++", sourceExtensions, headerExtensions,true, null)); ! private static final GccCCompiler gppInstance = ! new GccCCompiler("g++", sourceExtensions, headerExtensions,false, ! new GccCCompiler("g++", sourceExtensions, headerExtensions, true, null)); ! private static final GccCCompiler g77Instance = ! new GccCCompiler("g77", sourceExtensions, headerExtensions,false, ! new GccCCompiler("g77", sourceExtensions, headerExtensions, true, null)); ! /** ! * Private constructor. Use GccCCompiler.getInstance() to get ! * singleton instance of this class. ! */ ! private GccCCompiler(String command, ! String[] sourceExtensions, ! String[] headerExtensions, ! boolean isLibtool, GccCCompiler libtoolCompiler) { ! super(command, null, sourceExtensions, headerExtensions, isLibtool, libtoolCompiler); ! isPICMeaningful = System.getProperty("os.name").indexOf("Windows") < 0; ! } ! /** ! * Gets gcc adapter ! */ ! public static GccCCompiler getInstance() { ! return instance; ! } ! /** ! * Gets c++ adapter ! */ ! public static GccCCompiler getCppInstance() { ! return cppInstance; ! } ! /** ! * Gets gpp adapter ! */ ! public static GccCCompiler getGppInstance() { ! return gppInstance; ! } ! /** ! * Gets g77 adapter ! */ ! public static GccCCompiler getG77Instance() { ! return g77Instance; ! } ! public void addImpliedArgs(Vector args, boolean debug, ! boolean multithreaded, boolean exceptions, LinkType linkType) { ! super.addImpliedArgs(args,debug,multithreaded,exceptions, ! linkType); ! ! if(isPICMeaningful && linkType.isSharedLibrary()) { ! args.addElement("-fPIC"); ! } ! } ! public File[] getEnvironmentIncludePath() { ! if(includePath == null) { ! // ! // construct default include path from machine id and version id ! // ! String[] defaultInclude = new String[1]; ! StringBuffer buf = new StringBuffer("/lib/"); ! buf.append(GccProcessor.getMachine()); ! buf.append('/'); ! buf.append(GccProcessor.getVersion()); ! buf.append("/include"); ! defaultInclude[0] = buf.toString(); ! // ! // read specs file and look for -istart and -idirafter ! // ! String[] specs = GccProcessor.getSpecs(); ! String[][] optionValues = GccProcessor.parseSpecs(specs,"*cpp:", new String[] { "-isystem ", "-idirafter " }); ! // ! // if no entries were found, then use a default path ! // ! if(optionValues[0].length == 0 && optionValues[1].length == 0) { ! optionValues[0] = new String[] { ! "/usr/local/include", ! "/usr/include", ! "/usr/include/win32api" }; ! } ! // ! // remove mingw entries. ! // For MinGW compiles this will mean the ! // location of the sys includes will be ! // wrong in dependencies.xml ! // but that should have no significant effect ! for (int i = 0; i < optionValues.length; i++) { ! for (int j = 0; j < optionValues[i].length; j++) { ! if(optionValues[i][j].indexOf("mingw") > 0) { ! optionValues[i][j] = null; ! } ! } ! } ! // ! // if cygwin then ! // we have to prepend location of gcc32 ! // and .. to start of absolute filenames to ! // have something that will exist in the ! // windows filesystem ! if(GccProcessor.isCygwin()) { ! GccProcessor.convertCygwinFilenames(optionValues[0]); ! GccProcessor.convertCygwinFilenames(optionValues[1]); ! GccProcessor.convertCygwinFilenames(defaultInclude); ! } ! int count = CUtil.checkDirectoryArray(optionValues[0]); ! count += CUtil.checkDirectoryArray(optionValues[1]); ! count += CUtil.checkDirectoryArray(defaultInclude); ! includePath = new File[count]; ! int index = 0; ! for (int i = 0; i < optionValues.length; i++) { ! for (int j = 0; j < optionValues[i].length; j++) { ! if (optionValues[i][j] != null) { ! includePath[index++] = new File(optionValues[i][j]); ! } ! } ! } ! for (int i = 0; i < defaultInclude.length; i++) { ! if (defaultInclude[i] != null) { ! includePath[index++] = new File(defaultInclude[i]); ! } ! } ! } ! return (File[]) includePath.clone(); ! } ! public String getIdentifier() throws BuildException { ! if (identifier == null) { ! StringBuffer buf; ! if(getLibtool()) { ! buf = new StringBuffer("libtool "); ! } else { ! buf = new StringBuffer(' '); ! } ! buf.append(getCommand()); ! buf.append(' '); ! buf.append(GccProcessor.getVersion()); ! buf.append(' '); ! buf.append(GccProcessor.getMachine()); ! identifier = buf.toString(); ! } ! return identifier; ! } ! public Linker getLinker(LinkType linkType) { ! return GccLinker.getInstance().getLinker(linkType); ! } ! /** ! * Create parser to determine dependencies. ! * ! * Will create appropriate parser (C++, FORTRAN) based on file extension. ! * ! */ ! protected Parser createParser(File source) { ! if (source != null) { ! String sourceName = source.getName(); ! int lastDot = sourceName.lastIndexOf('.'); ! if (lastDot >= 0 && lastDot + 1 < sourceName.length()) { ! char afterDot = sourceName.charAt(lastDot + 1); ! if (afterDot == 'f' || afterDot == 'F') { ! return new FortranParser(); ! } ! } ! } ! return new CParser(); ! } } --- 72,359 ---- * @author Adam Murdoch */ ! public final class GccCCompiler extends GccCompatibleCCompiler { ! private String identifier; ! private File[] includePath; ! private boolean isPICMeaningful = true; ! private final static String[] sourceExtensions = ! new String[] { ! ".c", ! ".cc", ! ".cpp", ! ".cxx", ! ".c++", ! ".i", ! ".f", ! ".for" }; ! private final static String[] headerExtensions = ! new String[] { ".h", ".hpp", ".inl" }; + private static final GccCCompiler instance = + new GccCCompiler( + "gcc", + sourceExtensions, + headerExtensions, + false, + new GccCCompiler( + "gcc", + sourceExtensions, + headerExtensions, + true, + null, + false, + null), + false, + null); + private static final GccCCompiler cppInstance = + new GccCCompiler( + "c++", + sourceExtensions, + headerExtensions, + false, + new GccCCompiler( + "c++", + sourceExtensions, + headerExtensions, + true, + null, + false, + null), + false, + null); + private static final GccCCompiler gppInstance = + new GccCCompiler( + "g++", + sourceExtensions, + headerExtensions, + false, + new GccCCompiler( + "g++", + sourceExtensions, + headerExtensions, + true, + null, + false, + null), + false, + null); + private static final GccCCompiler g77Instance = + new GccCCompiler( + "g77", + sourceExtensions, + headerExtensions, + false, + new GccCCompiler( + "g77", + sourceExtensions, + headerExtensions, + true, + null, + false, + null), + false, + null); ! /** ! * Private constructor. Use GccCCompiler.getInstance() to get ! * singleton instance of this class. ! */ ! private GccCCompiler( ! String command, ! String[] sourceExtensions, ! String[] headerExtensions, ! boolean isLibtool, ! GccCCompiler libtoolCompiler, ! boolean newEnvironment, ! Environment env) { ! super( ! command, ! null, ! sourceExtensions, ! headerExtensions, ! isLibtool, ! libtoolCompiler, ! newEnvironment, ! env); ! isPICMeaningful = System.getProperty("os.name").indexOf("Windows") < 0; ! } ! /** ! * Gets gcc adapter ! */ ! public static GccCCompiler getInstance() { ! return instance; ! } ! /** ! * Gets c++ adapter ! */ ! public static GccCCompiler getCppInstance() { ! return cppInstance; ! } ! /** ! * Gets gpp adapter ! */ ! public static GccCCompiler getGppInstance() { ! return gppInstance; ! } ! /** ! * Gets g77 adapter ! */ ! public static GccCCompiler getG77Instance() { ! return g77Instance; ! } ! public void addImpliedArgs( ! Vector args, ! boolean debug, ! boolean multithreaded, ! boolean exceptions, ! LinkType linkType) { ! super.addImpliedArgs(args, debug, multithreaded, exceptions, linkType); + if (isPICMeaningful && linkType.isSharedLibrary()) { + args.addElement("-fPIC"); + } + } ! public File[] getEnvironmentIncludePath() { ! if (includePath == null) { ! // ! // construct default include path from machine id and version id ! // ! String[] defaultInclude = new String[1]; ! StringBuffer buf = new StringBuffer("/lib/"); ! buf.append(GccProcessor.getMachine()); ! buf.append('/'); ! buf.append(GccProcessor.getVersion()); ! buf.append("/include"); ! defaultInclude[0] = buf.toString(); ! // ! // read specs file and look for -istart and -idirafter ! // ! String[] specs = GccProcessor.getSpecs(); ! String[][] optionValues = ! GccProcessor.parseSpecs( ! specs, ! "*cpp:", ! new String[] { "-isystem ", "-idirafter " }); ! // ! // if no entries were found, then use a default path ! // ! if (optionValues[0].length == 0 && optionValues[1].length == 0) { ! optionValues[0] = ! new String[] { ! "/usr/local/include", ! "/usr/include", ! "/usr/include/win32api" }; ! } ! // ! // remove mingw entries. ! // For MinGW compiles this will mean the ! // location of the sys includes will be ! // wrong in dependencies.xml ! // but that should have no significant effect ! for (int i = 0; i < optionValues.length; i++) { ! for (int j = 0; j < optionValues[i].length; j++) { ! if (optionValues[i][j].indexOf("mingw") > 0) { ! optionValues[i][j] = null; ! } ! } ! } ! // ! // if cygwin then ! // we have to prepend location of gcc32 ! // and .. to start of absolute filenames to ! // have something that will exist in the ! // windows filesystem ! if (GccProcessor.isCygwin()) { ! GccProcessor.convertCygwinFilenames(optionValues[0]); ! GccProcessor.convertCygwinFilenames(optionValues[1]); ! GccProcessor.convertCygwinFilenames(defaultInclude); ! } ! int count = CUtil.checkDirectoryArray(optionValues[0]); ! count += CUtil.checkDirectoryArray(optionValues[1]); ! count += CUtil.checkDirectoryArray(defaultInclude); ! includePath = new File[count]; ! int index = 0; ! for (int i = 0; i < optionValues.length; i++) { ! for (int j = 0; j < optionValues[i].length; j++) { ! if (optionValues[i][j] != null) { ! includePath[index++] = new File(optionValues[i][j]); ! } ! } ! } ! for (int i = 0; i < defaultInclude.length; i++) { ! if (defaultInclude[i] != null) { ! includePath[index++] = new File(defaultInclude[i]); ! } ! } ! } ! return (File[]) includePath.clone(); ! } + public String getIdentifier() throws BuildException { + if (identifier == null) { + StringBuffer buf; + if (getLibtool()) { + buf = new StringBuffer("libtool "); + } else { + buf = new StringBuffer(' '); + } + buf.append(getCommand()); + buf.append(' '); + buf.append(GccProcessor.getVersion()); + buf.append(' '); + buf.append(GccProcessor.getMachine()); + identifier = buf.toString(); + } + return identifier; + } ! public Linker getLinker(LinkType linkType) { ! return GccLinker.getInstance().getLinker(linkType); ! } ! /** ! * Create parser to determine dependencies. ! * ! * Will create appropriate parser (C++, FORTRAN) based on file extension. ! * ! */ ! protected Parser createParser(File source) { ! if (source != null) { ! String sourceName = source.getName(); ! int lastDot = sourceName.lastIndexOf('.'); ! if (lastDot >= 0 && lastDot + 1 < sourceName.length()) { ! char afterDot = sourceName.charAt(lastDot + 1); ! if (afterDot == 'f' || afterDot == 'F') { ! return new FortranParser(); ! } ! } ! } ! return new CParser(); ! } ! public Processor changeEnvironment( ! boolean newEnvironment, ! Environment env) { ! if (newEnvironment || env != null) { ! return new GccCCompiler( ! getCommand(), ! this.getSourceExtensions(), ! this.getHeaderExtensions(), ! this.getLibtool(), ! (GccCCompiler) this.getLibtoolCompiler(), ! newEnvironment, ! env); ! } ! return this; ! } } |