Initial import.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
*
|
||||
* 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.borland;
|
||||
import java.io.File;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.compiler.CommandLineCompilerConfiguration;
|
||||
import net.sf.antcontrib.cpptasks.compiler.CompilerConfiguration;
|
||||
import net.sf.antcontrib.cpptasks.compiler.LinkType;
|
||||
import net.sf.antcontrib.cpptasks.compiler.Linker;
|
||||
import net.sf.antcontrib.cpptasks.compiler.PrecompilingCommandLineCCompiler;
|
||||
import net.sf.antcontrib.cpptasks.compiler.Processor;
|
||||
import net.sf.antcontrib.cpptasks.OptimizationEnum;
|
||||
|
||||
import org.apache.tools.ant.types.Environment;
|
||||
/**
|
||||
* Adapter for the Borland(r) C/C++ compiler.
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public class BorlandCCompiler extends PrecompilingCommandLineCCompiler {
|
||||
private static final String[] headerExtensions = new String[]{".h", ".hpp",
|
||||
".inl"};
|
||||
private static final String[] sourceExtensions = new String[]{".c", ".cc",
|
||||
".cpp", ".cxx", ".c++"};
|
||||
private static final BorlandCCompiler instance = new BorlandCCompiler(
|
||||
false, null);
|
||||
public static BorlandCCompiler getInstance() {
|
||||
return instance;
|
||||
}
|
||||
private BorlandCCompiler(boolean newEnvironment, Environment env) {
|
||||
super("bcc32", "--version", sourceExtensions, headerExtensions, ".obj", 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,
|
||||
final Boolean defaultflag) {
|
||||
args.addElement("-c");
|
||||
//
|
||||
// turn off compiler autodependency since
|
||||
// we do it ourselves
|
||||
args.addElement("-X");
|
||||
if (exceptions) {
|
||||
args.addElement("-x");
|
||||
} else {
|
||||
args.addElement("-x-");
|
||||
}
|
||||
if (multithreaded) {
|
||||
args.addElement("-tWM");
|
||||
}
|
||||
if (debug) {
|
||||
args.addElement("-Od");
|
||||
args.addElement("-v");
|
||||
} else {
|
||||
if (optimization != null) {
|
||||
if (optimization.isSpeed()) {
|
||||
args.addElement("-O1");
|
||||
} else {
|
||||
if (optimization.isSpeed()) {
|
||||
args.addElement("-O2");
|
||||
} else {
|
||||
if (optimization.isNoOptimization()) {
|
||||
args.addElement("-Od");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rtti != null && !rtti.booleanValue()) {
|
||||
args.addElement("-RT-");
|
||||
}
|
||||
}
|
||||
protected void addWarningSwitch(Vector args, int level) {
|
||||
BorlandProcessor.addWarningSwitch(args, level);
|
||||
}
|
||||
public Processor changeEnvironment(boolean newEnvironment, Environment env) {
|
||||
if (newEnvironment || env != null) {
|
||||
return new BorlandCCompiler(newEnvironment, env);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
protected CompilerConfiguration createPrecompileGeneratingConfig(
|
||||
CommandLineCompilerConfiguration baseConfig, File prototype,
|
||||
String lastInclude) {
|
||||
String[] additionalArgs = new String[]{"-H=" + lastInclude, "-Hc"};
|
||||
return new CommandLineCompilerConfiguration(baseConfig, additionalArgs,
|
||||
null, true);
|
||||
}
|
||||
protected CompilerConfiguration createPrecompileUsingConfig(
|
||||
CommandLineCompilerConfiguration baseConfig, File prototype,
|
||||
String lastInclude, String[] exceptFiles) {
|
||||
String[] additionalArgs = new String[]{"-Hu"};
|
||||
return new CommandLineCompilerConfiguration(baseConfig, additionalArgs,
|
||||
exceptFiles, false);
|
||||
}
|
||||
protected void getDefineSwitch(StringBuffer buffer, String define,
|
||||
String value) {
|
||||
BorlandProcessor.getDefineSwitch(buffer, define, value);
|
||||
}
|
||||
protected File[] getEnvironmentIncludePath() {
|
||||
return BorlandProcessor.getEnvironmentPath("bcc32", 'I',
|
||||
new String[]{"..\\include"});
|
||||
}
|
||||
protected String getIncludeDirSwitch(String includeDir) {
|
||||
return BorlandProcessor.getIncludeDirSwitch("-I", includeDir);
|
||||
}
|
||||
public Linker getLinker(LinkType type) {
|
||||
return BorlandLinker.getInstance().getLinker(type);
|
||||
}
|
||||
public int getMaximumCommandLength() {
|
||||
return 1024;
|
||||
}
|
||||
protected void getUndefineSwitch(StringBuffer buffer, String define) {
|
||||
BorlandProcessor.getUndefineSwitch(buffer, define);
|
||||
}
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
*
|
||||
* 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.borland;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.parser.AbstractParser;
|
||||
import net.sf.antcontrib.cpptasks.parser.AbstractParserState;
|
||||
import net.sf.antcontrib.cpptasks.parser.LetterState;
|
||||
import net.sf.antcontrib.cpptasks.parser.WhitespaceOrLetterState;
|
||||
/**
|
||||
* A parser that paths from a borland cfg file
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public final class BorlandCfgParser extends AbstractParser {
|
||||
private AbstractParserState newLineState;
|
||||
private final Vector path = new Vector();
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public BorlandCfgParser(char switchChar) {
|
||||
//
|
||||
// a quoted path (-I"some path")
|
||||
// doesn't end till a close quote and will be abandoned
|
||||
// if a new line is encountered first
|
||||
//
|
||||
AbstractParserState quote = new CfgFilenameState(this, new char[]{'"'});
|
||||
//
|
||||
// an unquoted path (-Ic:\borland\include)
|
||||
// ends at the first space or new line
|
||||
AbstractParserState unquote = new CfgFilenameState(this, new char[]{
|
||||
' ', '\n', '\r'});
|
||||
AbstractParserState quoteBranch = new QuoteBranchState(this, quote,
|
||||
unquote);
|
||||
AbstractParserState toNextSwitch = new ConsumeToSpaceOrNewLine(this);
|
||||
AbstractParserState switchState = new LetterState(this, switchChar,
|
||||
quoteBranch, toNextSwitch);
|
||||
newLineState = new WhitespaceOrLetterState(this, '-', switchState);
|
||||
}
|
||||
public void addFilename(String include) {
|
||||
path.addElement(include);
|
||||
}
|
||||
public AbstractParserState getNewLineState() {
|
||||
return newLineState;
|
||||
}
|
||||
public String[] parsePath(Reader reader) throws IOException {
|
||||
path.setSize(0);
|
||||
super.parse(reader);
|
||||
String[] retval = new String[path.size()];
|
||||
path.copyInto(retval);
|
||||
return retval;
|
||||
}
|
||||
}
|
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
*
|
||||
* 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.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;
|
||||
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.CCTask;
|
||||
import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration;
|
||||
import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;
|
||||
|
||||
/**
|
||||
* Adapter for the Borland(r) tlib Librarian
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public class BorlandLibrarian extends CommandLineLinker {
|
||||
private static final BorlandLibrarian instance = new BorlandLibrarian();
|
||||
public static BorlandLibrarian getInstance() {
|
||||
return instance;
|
||||
}
|
||||
private BorlandLibrarian() {
|
||||
super("tlib", "--version", new String[]{".obj"}, new String[0], ".lib", false,
|
||||
null);
|
||||
}
|
||||
protected void addBase(long base, Vector args) {
|
||||
}
|
||||
protected void addFixed(Boolean fixed, Vector args) {
|
||||
}
|
||||
protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args, Boolean defaultflag) {
|
||||
}
|
||||
protected void addIncremental(boolean incremental, Vector args) {
|
||||
}
|
||||
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) {
|
||||
}
|
||||
|
||||
protected String getCommandFileSwitch(String cmdFile) {
|
||||
return BorlandProcessor.getCommandFileSwitch(cmdFile);
|
||||
}
|
||||
public File[] getLibraryPath() {
|
||||
return CUtil.getPathFromEnvironment("LIB", ";");
|
||||
}
|
||||
public String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {
|
||||
return BorlandProcessor.getLibraryPatterns(libnames, libType);
|
||||
}
|
||||
public Linker getLinker(LinkType type) {
|
||||
return BorlandLinker.getInstance().getLinker(type);
|
||||
}
|
||||
public int getMaximumCommandLength() {
|
||||
return 1024;
|
||||
}
|
||||
public String[] getOutputFileSwitch(String outFile) {
|
||||
return BorlandProcessor.getOutputFileSwitch(outFile);
|
||||
}
|
||||
public boolean isCaseSensitive() {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
*
|
||||
* 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.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;
|
||||
import net.sf.antcontrib.cpptasks.compiler.LinkType;
|
||||
import net.sf.antcontrib.cpptasks.compiler.Linker;
|
||||
import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;
|
||||
|
||||
/**
|
||||
* Adapter for the Borland(r) ilink32 linker
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public final class BorlandLinker extends CommandLineLinker {
|
||||
private static final BorlandLinker dllLinker = new BorlandLinker(".dll");
|
||||
private static final BorlandLinker instance = new BorlandLinker(".exe");
|
||||
public static BorlandLinker getInstance() {
|
||||
return instance;
|
||||
}
|
||||
private BorlandLinker(String outputSuffix) {
|
||||
super("ilink32", "-r", new String[]{".obj", ".lib", ".res"},
|
||||
new String[]{".map", ".pdb", ".lnk"}, outputSuffix, false, null);
|
||||
}
|
||||
protected void addBase(long base, Vector args) {
|
||||
if (base >= 0) {
|
||||
String baseAddr = Long.toHexString(base);
|
||||
args.addElement("-b:" + baseAddr);
|
||||
}
|
||||
}
|
||||
protected void addFixed(Boolean fixed, Vector args) {
|
||||
}
|
||||
protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args, Boolean defaultflag) {
|
||||
if (linkType.isExecutable()) {
|
||||
if (linkType.isSubsystemConsole()) {
|
||||
args.addElement("/ap");
|
||||
} else {
|
||||
if (linkType.isSubsystemGUI()) {
|
||||
args.addElement("/Tpe");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (linkType.isSharedLibrary()) {
|
||||
args.addElement("/Tpd");
|
||||
args.addElement("/Gi");
|
||||
}
|
||||
}
|
||||
protected void addIncremental(boolean incremental, Vector args) {
|
||||
}
|
||||
protected void addMap(boolean map, Vector args) {
|
||||
if (!map) {
|
||||
args.addElement("-x");
|
||||
}
|
||||
}
|
||||
protected void addStack(int stack, Vector args) {
|
||||
if (stack >= 0) {
|
||||
String stackStr = Integer.toHexString(stack);
|
||||
args.addElement("-S:" + stackStr);
|
||||
}
|
||||
}
|
||||
/* (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 String getIdentifier() {
|
||||
return "Borland Linker";
|
||||
}
|
||||
public File[] getLibraryPath() {
|
||||
return BorlandProcessor.getEnvironmentPath("ilink32", 'L',
|
||||
new String[]{"..\\lib"});
|
||||
}
|
||||
public String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {
|
||||
return BorlandProcessor.getLibraryPatterns(libnames, libType);
|
||||
}
|
||||
public Linker getLinker(LinkType type) {
|
||||
if (type.isStaticLibrary()) {
|
||||
return BorlandLibrarian.getInstance();
|
||||
}
|
||||
if (type.isSharedLibrary()) {
|
||||
return dllLinker;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
public int getMaximumCommandLength() {
|
||||
return 1024;
|
||||
}
|
||||
public String[] getOutputFileSwitch(String outFile) {
|
||||
return BorlandProcessor.getOutputFileSwitch(outFile);
|
||||
}
|
||||
protected String getStartupObject(LinkType linkType) {
|
||||
if (linkType.isSharedLibrary()) {
|
||||
return "c0d32.obj";
|
||||
}
|
||||
if (linkType.isSubsystemGUI()) {
|
||||
return "c0w32.obj";
|
||||
}
|
||||
if (linkType.isSubsystemConsole()) {
|
||||
return "c0x32.obj";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public boolean isCaseSensitive() {
|
||||
return BorlandProcessor.isCaseSensitive();
|
||||
}
|
||||
/**
|
||||
* 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();
|
||||
Vector execArgs = new Vector(preargs.length + endargs.length + 10
|
||||
+ sourceFiles.length);
|
||||
execArgs.addElement(this.getCommand());
|
||||
for (int i = 0; i < preargs.length; i++) {
|
||||
execArgs.addElement(preargs[i]);
|
||||
}
|
||||
for (int i = 0; i < endargs.length; i++) {
|
||||
execArgs.addElement(endargs[i]);
|
||||
}
|
||||
//
|
||||
// see if the input files have any known startup obj files
|
||||
//
|
||||
String startup = null;
|
||||
for (int i = 0; i < sourceFiles.length; i++) {
|
||||
String filename = new File(sourceFiles[i]).getName().toLowerCase();
|
||||
if (startup != null && filename.substring(0, 2).equals("c0")
|
||||
&& filename.substring(3, 5).equals("32")
|
||||
&& filename.substring(filename.length() - 4).equals(".obj")) {
|
||||
startup = sourceFiles[i];
|
||||
}
|
||||
}
|
||||
//
|
||||
// c0w32.obj, c0x32.obj or c0d32.obj depending on
|
||||
// link type
|
||||
if (startup == null) {
|
||||
startup = config.getStartupObject();
|
||||
}
|
||||
execArgs.addElement(startup);
|
||||
Vector resFiles = new Vector();
|
||||
Vector libFiles = new Vector();
|
||||
String defFile = null;
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = 0; i < sourceFiles.length; i++) {
|
||||
String last4 = sourceFiles[i]
|
||||
.substring(sourceFiles[i].length() - 4).toLowerCase();
|
||||
if (last4.equals(".def")) {
|
||||
defFile = quoteFilename(buf, sourceFiles[i]);
|
||||
} else {
|
||||
if (last4.equals(".res")) {
|
||||
resFiles.addElement(quoteFilename(buf, sourceFiles[i]));
|
||||
} else {
|
||||
if (last4.equals(".lib")) {
|
||||
libFiles.addElement(quoteFilename(buf, sourceFiles[i]));
|
||||
} else {
|
||||
execArgs.addElement(quoteFilename(buf, sourceFiles[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// output file name
|
||||
//
|
||||
String outputFileName = new File(outputDir, outputName).toString();
|
||||
execArgs.addElement("," + quoteFilename(buf, outputFileName));
|
||||
if (config.getMap()) {
|
||||
int lastPeriod = outputFileName.lastIndexOf('.');
|
||||
String mapName;
|
||||
if (lastPeriod < outputFileName.length() - 4) {
|
||||
mapName = outputFileName + ".map";
|
||||
} else {
|
||||
mapName = outputFileName.substring(0, lastPeriod) + ".map";
|
||||
}
|
||||
execArgs.addElement("," + quoteFilename(buf, mapName) + ",");
|
||||
} else {
|
||||
execArgs.addElement(",,");
|
||||
}
|
||||
//
|
||||
// add all the libraries
|
||||
//
|
||||
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(",,");
|
||||
} else {
|
||||
execArgs.addElement("," + quoteFilename(buf, defFile) + ",");
|
||||
}
|
||||
Enumeration resEnum = resFiles.elements();
|
||||
while (resEnum.hasMoreElements()) {
|
||||
String resName = (String) resEnum.nextElement();
|
||||
execArgs.addElement(quoteFilename(buf, resName));
|
||||
}
|
||||
String[] execArguments = new String[execArgs.size()];
|
||||
execArgs.copyInto(execArguments);
|
||||
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");
|
||||
}
|
||||
}
|
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
*
|
||||
* 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.borland;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.Vector;
|
||||
import java.io.FileWriter;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.CUtil;
|
||||
import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;
|
||||
/**
|
||||
* A add-in class for Borland(r) processor adapters
|
||||
*
|
||||
*
|
||||
*/
|
||||
public final class BorlandProcessor {
|
||||
public static void addWarningSwitch(Vector args, int level) {
|
||||
switch (level) {
|
||||
case 0 :
|
||||
args.addElement("-w-");
|
||||
break;
|
||||
case 5 :
|
||||
args.addElement("-w!");
|
||||
break;
|
||||
default :
|
||||
args.addElement("-w");
|
||||
break;
|
||||
}
|
||||
}
|
||||
public static String getCommandFileSwitch(String cmdFile) {
|
||||
StringBuffer buf = new StringBuffer("@");
|
||||
quoteFile(buf, cmdFile);
|
||||
return buf.toString();
|
||||
}
|
||||
public static 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);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This method extracts path information from the appropriate .cfg file in
|
||||
* the install directory.
|
||||
*
|
||||
* @param toolName
|
||||
* Tool name, for example, "bcc32", "brc32", "ilink32"
|
||||
* @param switchChar
|
||||
* Command line switch character, for example "L" for libraries
|
||||
* @param defaultRelativePaths
|
||||
* default paths relative to executable directory
|
||||
* @return path
|
||||
*/
|
||||
public static File[] getEnvironmentPath(String toolName, char switchChar,
|
||||
String[] defaultRelativePath) {
|
||||
if (toolName == null) {
|
||||
throw new NullPointerException("toolName");
|
||||
}
|
||||
if (defaultRelativePath == null) {
|
||||
throw new NullPointerException("defaultRelativePath");
|
||||
}
|
||||
String[] path = defaultRelativePath;
|
||||
File exeDir = CUtil.getExecutableLocation(toolName + ".exe");
|
||||
if (exeDir != null) {
|
||||
File cfgFile = new File(exeDir, toolName + ".cfg");
|
||||
if (cfgFile.exists()) {
|
||||
try {
|
||||
Reader reader = new BufferedReader(new FileReader(cfgFile));
|
||||
BorlandCfgParser cfgParser = new BorlandCfgParser(
|
||||
switchChar);
|
||||
path = cfgParser.parsePath(reader);
|
||||
reader.close();
|
||||
} catch (IOException ex) {
|
||||
//
|
||||
// could be logged
|
||||
//
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// if can't find the executable,
|
||||
// assume current directory to resolve relative paths
|
||||
//
|
||||
exeDir = new File(System.getProperty("user.dir"));
|
||||
}
|
||||
int nonExistant = 0;
|
||||
File[] resourcePath = new File[path.length];
|
||||
for (int i = 0; i < path.length; i++) {
|
||||
resourcePath[i] = new File(path[i]);
|
||||
if (!resourcePath[i].isAbsolute()) {
|
||||
resourcePath[i] = new File(exeDir, path[i]);
|
||||
}
|
||||
//
|
||||
// if any of the entries do not exist or are
|
||||
// not directories, null them out
|
||||
if (!(resourcePath[i].exists() && resourcePath[i].isDirectory())) {
|
||||
resourcePath[i] = null;
|
||||
nonExistant++;
|
||||
}
|
||||
}
|
||||
//
|
||||
// if there were some non-existant or non-directory
|
||||
// entries in the configuration file then
|
||||
// create a shorter array
|
||||
if (nonExistant > 0) {
|
||||
File[] culled = new File[resourcePath.length - nonExistant];
|
||||
int index = 0;
|
||||
for (int i = 0; i < resourcePath.length; i++) {
|
||||
if (resourcePath[i] != null) {
|
||||
culled[index++] = resourcePath[i];
|
||||
}
|
||||
}
|
||||
resourcePath = culled;
|
||||
}
|
||||
return resourcePath;
|
||||
}
|
||||
public static String getIncludeDirSwitch(String includeOption,
|
||||
String includeDir) {
|
||||
StringBuffer buf = new StringBuffer(includeOption);
|
||||
quoteFile(buf, includeDir);
|
||||
return buf.toString();
|
||||
}
|
||||
public static String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
String[] patterns = new String[libnames.length];
|
||||
for (int i = 0; i < libnames.length; i++) {
|
||||
buf.setLength(0);
|
||||
buf.append(libnames[i]);
|
||||
buf.append(".lib");
|
||||
patterns[i] = buf.toString();
|
||||
}
|
||||
return patterns;
|
||||
}
|
||||
public static String[] getOutputFileSwitch(String outFile) {
|
||||
return new String[0];
|
||||
}
|
||||
public static void getUndefineSwitch(StringBuffer buffer, String define) {
|
||||
buffer.append("-U");
|
||||
buffer.append(define);
|
||||
}
|
||||
public static boolean isCaseSensitive() {
|
||||
return false;
|
||||
}
|
||||
private static void quoteFile(StringBuffer buf, String outPath) {
|
||||
if (outPath.indexOf(' ') >= 0) {
|
||||
buf.append('\"');
|
||||
buf.append(outPath);
|
||||
buf.append('\"');
|
||||
} else {
|
||||
buf.append(outPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = outputFile.getName();
|
||||
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() {
|
||||
}
|
||||
}
|
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
*
|
||||
* 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.borland;
|
||||
import java.io.File;
|
||||
import java.util.Vector;
|
||||
import net.sf.antcontrib.cpptasks.CCTask;
|
||||
import net.sf.antcontrib.cpptasks.compiler.CommandLineCompiler;
|
||||
import net.sf.antcontrib.cpptasks.compiler.CommandLineCompilerConfiguration;
|
||||
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.compiler.ProgressMonitor;
|
||||
import net.sf.antcontrib.cpptasks.parser.CParser;
|
||||
import net.sf.antcontrib.cpptasks.parser.Parser;
|
||||
import net.sf.antcontrib.cpptasks.OptimizationEnum;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.types.Environment;
|
||||
/**
|
||||
* Adapter for the Borland(r) brc32 Resource compiler.
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public class BorlandResourceCompiler extends CommandLineCompiler {
|
||||
private static final BorlandResourceCompiler instance = new BorlandResourceCompiler(
|
||||
false, null);
|
||||
public static BorlandResourceCompiler getInstance() {
|
||||
return instance;
|
||||
}
|
||||
private BorlandResourceCompiler(boolean newEnvironment, Environment env) {
|
||||
super("brc32", "c:\\__bogus\\__bogus.rc", new String[]{".rc"},
|
||||
new String[]{".h", ".hpp", ".inl"}, ".res", 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,
|
||||
final Boolean defaultflag) {
|
||||
//
|
||||
// compile only
|
||||
//
|
||||
args.addElement("-r");
|
||||
}
|
||||
protected void addWarningSwitch(Vector args, int level) {
|
||||
}
|
||||
public Processor changeEnvironment(boolean newEnvironment, Environment env) {
|
||||
if (newEnvironment || env != null) {
|
||||
return new BorlandResourceCompiler(newEnvironment, env);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public void compile(CCTask task, File outputDir, String[] sourceFiles,
|
||||
String[] args, String[] endArgs, boolean relentless,
|
||||
CommandLineCompilerConfiguration config, ProgressMonitor monitor)
|
||||
throws BuildException {
|
||||
super.compile(task, outputDir, sourceFiles, args, endArgs, relentless,
|
||||
config, monitor);
|
||||
}
|
||||
/**
|
||||
* The include parser for C will work just fine, but we didn't want to
|
||||
* inherit from CommandLineCCompiler
|
||||
*/
|
||||
protected Parser createParser(File source) {
|
||||
return new CParser();
|
||||
}
|
||||
protected int getArgumentCountPerInputFile() {
|
||||
return 2;
|
||||
}
|
||||
protected 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);
|
||||
}
|
||||
}
|
||||
protected File[] getEnvironmentIncludePath() {
|
||||
return BorlandProcessor.getEnvironmentPath("brc32", 'i',
|
||||
new String[]{"..\\include"});
|
||||
}
|
||||
protected String getIncludeDirSwitch(String includeDir) {
|
||||
return BorlandProcessor.getIncludeDirSwitch("-i", includeDir);
|
||||
}
|
||||
protected String getInputFileArgument(File outputDir, String filename,
|
||||
int index) {
|
||||
if (index == 0) {
|
||||
String outputFileName = getOutputFileName(filename);
|
||||
String fullOutputName = new File(outputDir, outputFileName)
|
||||
.toString();
|
||||
return "-fo" + fullOutputName;
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
public Linker getLinker(LinkType type) {
|
||||
return BorlandLinker.getInstance().getLinker(type);
|
||||
}
|
||||
public int getMaximumCommandLength() {
|
||||
return 1024;
|
||||
}
|
||||
protected int getMaximumInputFilesPerCommand() {
|
||||
return 1;
|
||||
}
|
||||
protected int getTotalArgumentLengthForInputFile(File outputDir,
|
||||
String inputFile) {
|
||||
String arg1 = getInputFileArgument(outputDir, inputFile, 0);
|
||||
String arg2 = getInputFileArgument(outputDir, inputFile, 1);
|
||||
return arg1.length() + arg2.length() + 2;
|
||||
}
|
||||
protected void getUndefineSwitch(StringBuffer buffer, String define) {
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
*
|
||||
* 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.borland;
|
||||
import net.sf.antcontrib.cpptasks.parser.AbstractParser;
|
||||
import net.sf.antcontrib.cpptasks.parser.AbstractParserState;
|
||||
import net.sf.antcontrib.cpptasks.parser.FilenameState;
|
||||
public class CfgFilenameState extends FilenameState {
|
||||
private char terminator;
|
||||
public CfgFilenameState(AbstractParser parser, char[] terminators) {
|
||||
super(parser, terminators);
|
||||
terminator = terminators[0];
|
||||
}
|
||||
public AbstractParserState consume(char ch) {
|
||||
//
|
||||
// if a ';' is encountered then
|
||||
// close the previous filename by sending a
|
||||
// recognized terminator to our super class
|
||||
// and stay in this state for more filenamese
|
||||
if (ch == ';') {
|
||||
super.consume(terminator);
|
||||
return this;
|
||||
}
|
||||
AbstractParserState newState = super.consume(ch);
|
||||
//
|
||||
// change null (consume to end of line)
|
||||
// to look for next switch character
|
||||
if (newState == null) {
|
||||
newState = getParser().getNewLineState();
|
||||
}
|
||||
return newState;
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
*
|
||||
* 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.borland;
|
||||
import net.sf.antcontrib.cpptasks.parser.AbstractParser;
|
||||
import net.sf.antcontrib.cpptasks.parser.AbstractParserState;
|
||||
public class ConsumeToSpaceOrNewLine extends AbstractParserState {
|
||||
public ConsumeToSpaceOrNewLine(AbstractParser parser) {
|
||||
super(parser);
|
||||
}
|
||||
public AbstractParserState consume(char ch) {
|
||||
if (ch == ' ' || ch == '\t' || ch == '\n') {
|
||||
return getParser().getNewLineState();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
*
|
||||
* 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.borland;
|
||||
import net.sf.antcontrib.cpptasks.parser.AbstractParser;
|
||||
import net.sf.antcontrib.cpptasks.parser.AbstractParserState;
|
||||
public class QuoteBranchState extends AbstractParserState {
|
||||
private AbstractParserState quote;
|
||||
private AbstractParserState unquote;
|
||||
public QuoteBranchState(AbstractParser parser, AbstractParserState quote,
|
||||
AbstractParserState unquote) {
|
||||
super(parser);
|
||||
this.quote = quote;
|
||||
this.unquote = unquote;
|
||||
}
|
||||
public AbstractParserState consume(char ch) {
|
||||
if (ch == '"') {
|
||||
return quote;
|
||||
}
|
||||
return unquote.consume(ch);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user