+++ /dev/null
-/*\r
- * \r
- * Copyright 2002-2004 The Ant-Contrib project\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package net.sf.antcontrib.cpptasks.borland;\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.util.Enumeration;\r
-import java.util.Vector;\r
-\r
-import net.sf.antcontrib.cpptasks.CCTask;\r
-import net.sf.antcontrib.cpptasks.compiler.CommandLineLinker;\r
-import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration;\r
-import net.sf.antcontrib.cpptasks.compiler.LinkType;\r
-import net.sf.antcontrib.cpptasks.compiler.Linker;\r
-import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;\r
-\r
-/**\r
- * Adapter for the Borland(r) ilink32 linker\r
- * \r
- * @author Curt Arnold\r
- */\r
-public final class BorlandLinker extends CommandLineLinker {\r
- private static final BorlandLinker dllLinker = new BorlandLinker(".dll");\r
- private static final BorlandLinker instance = new BorlandLinker(".exe");\r
- public static BorlandLinker getInstance() {\r
- return instance;\r
- }\r
- private BorlandLinker(String outputSuffix) {\r
- super("ilink32", "-r", new String[]{".obj", ".lib", ".res"},\r
- new String[]{".map", ".pdb", ".lnk"}, outputSuffix, false, null);\r
- }\r
- protected void addBase(long base, Vector args) {\r
- if (base >= 0) {\r
- String baseAddr = Long.toHexString(base);\r
- args.addElement("-b:" + baseAddr);\r
- }\r
- }\r
- protected void addFixed(Boolean fixed, Vector args) {\r
- }\r
- protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args, Boolean defaultflag) {\r
- if (linkType.isExecutable()) {\r
- if (linkType.isSubsystemConsole()) {\r
- args.addElement("/ap");\r
- } else {\r
- if (linkType.isSubsystemGUI()) {\r
- args.addElement("/Tpe");\r
- }\r
- }\r
- }\r
- if (linkType.isSharedLibrary()) {\r
- args.addElement("/Tpd");\r
- args.addElement("/Gi");\r
- }\r
- }\r
- protected void addIncremental(boolean incremental, Vector args) {\r
- }\r
- protected void addMap(boolean map, Vector args) {\r
- if (!map) {\r
- args.addElement("-x");\r
- }\r
- }\r
- protected void addStack(int stack, Vector args) {\r
- if (stack >= 0) {\r
- String stackStr = Integer.toHexString(stack);\r
- args.addElement("-S:" + stackStr);\r
- }\r
- }\r
- /* (non-Javadoc)\r
- * @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addEntry(int, java.util.Vector)\r
- */\r
- protected void addEntry(String entry, Vector args) {\r
- }\r
- \r
- public String getCommandFileSwitch(String commandFile) {\r
- return "@" + commandFile;\r
- }\r
- public String getIdentifier() {\r
- return "Borland Linker";\r
- }\r
- public File[] getLibraryPath() {\r
- return BorlandProcessor.getEnvironmentPath("ilink32", 'L',\r
- new String[]{"..\\lib"});\r
- }\r
- public String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {\r
- return BorlandProcessor.getLibraryPatterns(libnames, libType);\r
- }\r
- public Linker getLinker(LinkType type) {\r
- if (type.isStaticLibrary()) {\r
- return BorlandLibrarian.getInstance();\r
- }\r
- if (type.isSharedLibrary()) {\r
- return dllLinker;\r
- }\r
- return instance;\r
- }\r
- public int getMaximumCommandLength() {\r
- return 1024;\r
- }\r
- public String[] getOutputFileSwitch(String outFile) {\r
- return BorlandProcessor.getOutputFileSwitch(outFile);\r
- }\r
- protected String getStartupObject(LinkType linkType) {\r
- if (linkType.isSharedLibrary()) {\r
- return "c0d32.obj";\r
- }\r
- if (linkType.isSubsystemGUI()) {\r
- return "c0w32.obj";\r
- }\r
- if (linkType.isSubsystemConsole()) {\r
- return "c0x32.obj";\r
- }\r
- return null;\r
- }\r
- public boolean isCaseSensitive() {\r
- return BorlandProcessor.isCaseSensitive();\r
- }\r
- /**\r
- * Prepares argument list for exec command.\r
- * \r
- * @param outputFile\r
- * linker output file\r
- * @param sourceFiles\r
- * linker input files (.obj, .o, .res)\r
- * @param args\r
- * linker arguments\r
- * @return arguments for runTask\r
- */\r
- protected String[] prepareArguments(\r
- CCTask task,\r
- String outputDir, \r
- String outputName,\r
- String[] sourceFiles, \r
- CommandLineLinkerConfiguration config) {\r
- String[] preargs = config.getPreArguments();\r
- String[] endargs = config.getEndArguments();\r
- Vector execArgs = new Vector(preargs.length + endargs.length + 10\r
- + sourceFiles.length);\r
- execArgs.addElement(this.getCommand());\r
- for (int i = 0; i < preargs.length; i++) {\r
- execArgs.addElement(preargs[i]);\r
- }\r
- for (int i = 0; i < endargs.length; i++) {\r
- execArgs.addElement(endargs[i]);\r
- }\r
- //\r
- // see if the input files have any known startup obj files\r
- //\r
- String startup = null;\r
- for (int i = 0; i < sourceFiles.length; i++) {\r
- String filename = new File(sourceFiles[i]).getName().toLowerCase();\r
- if (startup != null && filename.substring(0, 2).equals("c0")\r
- && filename.substring(3, 5).equals("32")\r
- && filename.substring(filename.length() - 4).equals(".obj")) {\r
- startup = sourceFiles[i];\r
- }\r
- }\r
- //\r
- // c0w32.obj, c0x32.obj or c0d32.obj depending on\r
- // link type\r
- if (startup == null) {\r
- startup = config.getStartupObject();\r
- }\r
- execArgs.addElement(startup);\r
- Vector resFiles = new Vector();\r
- Vector libFiles = new Vector();\r
- String defFile = null;\r
- StringBuffer buf = new StringBuffer();\r
- for (int i = 0; i < sourceFiles.length; i++) {\r
- String last4 = sourceFiles[i]\r
- .substring(sourceFiles[i].length() - 4).toLowerCase();\r
- if (last4.equals(".def")) {\r
- defFile = quoteFilename(buf, sourceFiles[i]);\r
- } else {\r
- if (last4.equals(".res")) {\r
- resFiles.addElement(quoteFilename(buf, sourceFiles[i]));\r
- } else {\r
- if (last4.equals(".lib")) {\r
- libFiles.addElement(quoteFilename(buf, sourceFiles[i]));\r
- } else {\r
- execArgs.addElement(quoteFilename(buf, sourceFiles[i]));\r
- }\r
- }\r
- }\r
- }\r
- //\r
- // output file name\r
- //\r
- String outputFileName = new File(outputDir, outputName).toString();\r
- execArgs.addElement("," + quoteFilename(buf, outputFileName));\r
- if (config.getMap()) {\r
- int lastPeriod = outputFileName.lastIndexOf('.');\r
- String mapName;\r
- if (lastPeriod < outputFileName.length() - 4) {\r
- mapName = outputFileName + ".map";\r
- } else {\r
- mapName = outputFileName.substring(0, lastPeriod) + ".map";\r
- }\r
- execArgs.addElement("," + quoteFilename(buf, mapName) + ",");\r
- } else {\r
- execArgs.addElement(",,");\r
- }\r
- //\r
- // add all the libraries\r
- //\r
- Enumeration libEnum = libFiles.elements();\r
- boolean hasImport32 = false;\r
- boolean hasCw32 = false;\r
- while (libEnum.hasMoreElements()) {\r
- String libName = (String) libEnum.nextElement();\r
- if (libName.equalsIgnoreCase("import32.lib")) {\r
- hasImport32 = true;\r
- }\r
- if (libName.equalsIgnoreCase("cw32.lib")) {\r
- hasImport32 = true;\r
- }\r
- execArgs.addElement(quoteFilename(buf, libName));\r
- }\r
- if (!hasCw32) {\r
- execArgs.addElement(quoteFilename(buf, "cw32.lib"));\r
- }\r
- if (!hasImport32) {\r
- execArgs.addElement(quoteFilename(buf, "import32.lib"));\r
- }\r
- if (defFile == null) {\r
- execArgs.addElement(",,");\r
- } else {\r
- execArgs.addElement("," + quoteFilename(buf, defFile) + ",");\r
- }\r
- Enumeration resEnum = resFiles.elements();\r
- while (resEnum.hasMoreElements()) {\r
- String resName = (String) resEnum.nextElement();\r
- execArgs.addElement(quoteFilename(buf, resName));\r
- }\r
- String[] execArguments = new String[execArgs.size()];\r
- execArgs.copyInto(execArguments);\r
- return execArguments;\r
- }\r
- /**\r
- * Prepares argument list to execute the linker using a response file.\r
- * \r
- * @param outputFile\r
- * linker output file\r
- * @param args\r
- * output of prepareArguments\r
- * @return arguments for runTask\r
- */\r
- protected String[] prepareResponseFile(File outputFile, String[] args)\r
- throws IOException {\r
- return BorlandProcessor.prepareResponseFile(outputFile, args, " + \n");\r
- }\r
-}\r