Update of /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/borland In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30384/src/net/sf/antcontrib/cpptasks/borland Modified Files: BorlandProcessor.java BorlandLinker.java BorlandCCompiler.java BorlandLibrarian.java Log Message: Fixes for Borland compilation (bug 938336) Index: BorlandProcessor.java =================================================================== RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/borland/BorlandProcessor.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** BorlandProcessor.java 28 Feb 2004 20:00:01 -0000 1.15 --- BorlandProcessor.java 20 Apr 2004 04:21:39 -0000 1.16 *************** *** 22,25 **** --- 22,26 ---- import java.io.Reader; import java.util.Vector; + import java.io.FileWriter; import net.sf.antcontrib.cpptasks.CUtil; *************** *** 168,171 **** --- 169,217 ---- } } + + /** + * Prepares argument list to execute the linker using a response file. + * + * @param outputFile + * linker output file + * @param args + * output of prepareArguments + * @return arguments for runTask + */ + public static String[] prepareResponseFile(File outputFile, + String[] args, + String continuation) + throws IOException { + String baseName = CUtil.getBasename(outputFile); + File commandFile = new File(outputFile.getParent(), baseName + ".lnk"); + FileWriter writer = new FileWriter(commandFile); + for (int i = 1; i < args.length - 1; i++) { + writer.write(args[i]); + // + // if either the current argument ends with + // or next argument starts with a comma then + // don't split the line + if (args[i].endsWith(",") || args[i + 1].startsWith(",")) { + writer.write(' '); + } else { + // + // split the line to make it more readable + // + writer.write(continuation); + } + } + // + // write the last argument + // + if (args.length > 1) { + writer.write(args[args.length - 1]); + } + writer.close(); + String[] execArgs = new String[2]; + execArgs[0] = args[0]; + execArgs[1] = getCommandFileSwitch(commandFile.toString()); + return execArgs; + } + private BorlandProcessor() { } Index: BorlandLinker.java =================================================================== RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/borland/BorlandLinker.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** BorlandLinker.java 28 Feb 2004 20:00:01 -0000 1.17 --- BorlandLinker.java 20 Apr 2004 04:21:39 -0000 1.18 *************** *** 17,26 **** package net.sf.antcontrib.cpptasks.borland; import java.io.File; - import java.io.FileWriter; import java.io.IOException; import java.util.Enumeration; import java.util.Vector; ! import net.sf.antcontrib.cpptasks.CUtil; import net.sf.antcontrib.cpptasks.compiler.CommandLineLinker; import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration; --- 17,25 ---- package net.sf.antcontrib.cpptasks.borland; import java.io.File; import java.io.IOException; import java.util.Enumeration; import java.util.Vector; ! import net.sf.antcontrib.cpptasks.CCTask; import net.sf.antcontrib.cpptasks.compiler.CommandLineLinker; import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration; *************** *** 62,65 **** --- 61,65 ---- if (linkType.isSharedLibrary()) { args.addElement("/Tpd"); + args.addElement("/Gi"); } } *************** *** 131,136 **** * @return arguments for runTask */ ! protected String[] prepareArguments(String outputDir, String outputName, ! String[] sourceFiles, CommandLineLinkerConfiguration config) { String[] preargs = config.getPreArguments(); String[] endargs = config.getEndArguments(); --- 131,140 ---- * @return arguments for runTask */ ! protected String[] prepareArguments( ! CCTask task, ! String outputDir, ! String outputName, ! String[] sourceFiles, ! CommandLineLinkerConfiguration config) { String[] preargs = config.getPreArguments(); String[] endargs = config.getEndArguments(); *************** *** 205,212 **** --- 209,230 ---- // Enumeration libEnum = libFiles.elements(); + boolean hasImport32 = false; + boolean hasCw32 = false; while (libEnum.hasMoreElements()) { String libName = (String) libEnum.nextElement(); + if (libName.equalsIgnoreCase("import32.lib")) { + hasImport32 = true; + } + if (libName.equalsIgnoreCase("cw32.lib")) { + hasImport32 = true; + } execArgs.addElement(quoteFilename(buf, libName)); } + if (!hasCw32) { + execArgs.addElement(quoteFilename(buf, "cw32.lib")); + } + if (!hasImport32) { + execArgs.addElement(quoteFilename(buf, "import32.lib")); + } if (defFile == null) { execArgs.addElement(",,"); *************** *** 234,266 **** protected String[] prepareResponseFile(File outputFile, String[] args) throws IOException { ! String baseName = CUtil.getBasename(outputFile); ! File commandFile = new File(outputFile.getParent(), baseName + ".lnk"); ! FileWriter writer = new FileWriter(commandFile); ! for (int i = 1; i < args.length - 1; i++) { ! writer.write(args[i]); ! // ! // if either the current argument ends with ! // or next argument starts with a comma then ! // don't split the line ! if (args[i].endsWith(",") || args[i + 1].startsWith(",")) { ! writer.write(' '); ! } else { ! // ! // split the line to make it more readable ! // ! writer.write(" + \n"); ! } ! } ! // ! // write the last argument ! // ! if (args.length > 1) { ! writer.write(args[args.length - 1]); ! } ! writer.close(); ! String[] execArgs = new String[2]; ! execArgs[0] = args[0]; ! execArgs[1] = getCommandFileSwitch(commandFile.toString()); ! return execArgs; } } --- 252,256 ---- protected String[] prepareResponseFile(File outputFile, String[] args) throws IOException { ! return BorlandProcessor.prepareResponseFile(outputFile, args, " + \n"); } } Index: BorlandCCompiler.java =================================================================== RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/borland/BorlandCCompiler.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** BorlandCCompiler.java 28 Feb 2004 20:00:01 -0000 1.15 --- BorlandCCompiler.java 20 Apr 2004 04:21:39 -0000 1.16 *************** *** 43,47 **** } private BorlandCCompiler(boolean newEnvironment, Environment env) { ! super("bcc32", "-?", sourceExtensions, headerExtensions, ".obj", false, null, newEnvironment, env); } --- 43,47 ---- } private BorlandCCompiler(boolean newEnvironment, Environment env) { ! super("bcc32", "--version", sourceExtensions, headerExtensions, ".obj", false, null, newEnvironment, env); } Index: BorlandLibrarian.java =================================================================== RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/borland/BorlandLibrarian.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** BorlandLibrarian.java 28 Feb 2004 20:00:01 -0000 1.15 --- BorlandLibrarian.java 20 Apr 2004 04:21:39 -0000 1.16 *************** *** 17,21 **** --- 17,23 ---- package net.sf.antcontrib.cpptasks.borland; import java.io.File; + import java.io.IOException; import java.util.Vector; + import org.apache.tools.ant.BuildException; import net.sf.antcontrib.cpptasks.CUtil; *************** *** 23,26 **** --- 25,31 ---- import net.sf.antcontrib.cpptasks.compiler.LinkType; import net.sf.antcontrib.cpptasks.compiler.Linker; + import net.sf.antcontrib.cpptasks.CCTask; + import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration; + /** * Adapter for the Borland(r) tlib Librarian *************** *** 34,38 **** } private BorlandLibrarian() { ! super("tlib", null, new String[]{".obj"}, new String[0], ".lib", false, null); } --- 39,43 ---- } private BorlandLibrarian() { ! super("tlib", "--version", new String[]{".obj"}, new String[0], ".lib", false, null); } *************** *** 70,72 **** --- 75,193 ---- return BorlandProcessor.isCaseSensitive(); } + /** + * Gets identifier for the linker. + * + * TLIB will lockup when attempting to get version + * information. Since the Librarian version isn't critical + * just return a stock response. + */ + public String getIdentifier() { + return "TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation"; + } + + /** + * Prepares argument list for exec command. + * + * @param outputFile + * linker output file + * @param sourceFiles + * linker input files (.obj, .o, .res) + * @param args + * linker arguments + * @return arguments for runTask + */ + protected String[] prepareArguments( + CCTask task, + String outputDir, + String outputName, + String[] sourceFiles, + CommandLineLinkerConfiguration config) { + String[] preargs = config.getPreArguments(); + String[] endargs = config.getEndArguments(); + StringBuffer buf = new StringBuffer(); + Vector execArgs = new Vector(preargs.length + endargs.length + 10 + + sourceFiles.length); + + execArgs.addElement(this.getCommand()); + String outputFileName = new File(outputDir, outputName).toString(); + execArgs.addElement(quoteFilename(buf, outputFileName)); + + for (int i = 0; i < preargs.length; i++) { + execArgs.addElement(preargs[i]); + } + + // + // add a place-holder for page size + // + int pageSizeIndex = execArgs.size(); + execArgs.addElement(null); + + int objBytes = 0; + + for (int i = 0; i < sourceFiles.length; i++) { + String last4 = sourceFiles[i] + .substring(sourceFiles[i].length() - 4).toLowerCase(); + if (last4.equals(".def")) { + } else { + if (last4.equals(".res")) { + } else { + if (last4.equals(".lib")) { + } else { + execArgs.addElement("+" + quoteFilename(buf, sourceFiles[i])); + objBytes += new File(sourceFiles[i]).length(); + } + } + } + } + + for (int i = 0; i < endargs.length; i++) { + execArgs.addElement(endargs[i]); + } + + String[] execArguments = new String[execArgs.size()]; + execArgs.copyInto(execArguments); + + int minPageSize = objBytes >> 16; + int pageSize = 0; + for(int i = 4; i <= 15; i++) { + pageSize = 1 << i; + if (pageSize > minPageSize) break; + } + execArguments[pageSizeIndex] = "/P" + Integer.toString(pageSize); + + return execArguments; + } + + /** + * Prepares argument list to execute the linker using a response file. + * + * @param outputFile + * linker output file + * @param args + * output of prepareArguments + * @return arguments for runTask + */ + protected String[] prepareResponseFile(File outputFile, String[] args) + throws IOException { + return BorlandProcessor.prepareResponseFile(outputFile, args, " & \n"); + } + + /** + * Builds a library + * + */ + public void link(CCTask task, + File outputFile, + String[] sourceFiles, + CommandLineLinkerConfiguration config) + throws BuildException + { + // + // delete any existing library + outputFile.delete(); + // + // build a new library + super.link(task, outputFile, sourceFiles, config); + } + } |