Restructuring for better separation of Tool packages.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1674 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
42
Tools/Java/Source/Common/Common.msa
Normal file
42
Tools/Java/Source/Common/Common.msa
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" >
|
||||
<MsaHeader>
|
||||
<ModuleName>Common Java Classes</ModuleName>
|
||||
<ModuleType>TOOL</ModuleType>
|
||||
<GuidValue>9D0ACB3E-4CE1-4228-98FF-85E64B0A4EC8</GuidValue>
|
||||
<Version>2.0</Version>
|
||||
<Abstract>This is the EFI/Tiano Tool Resources Module</Abstract>
|
||||
<Description>
|
||||
This Module provides the EFI/Tiano Tools that are used to create EFI/Tiano
|
||||
Modules and Platform Binary Files (PBF)
|
||||
These tools require compilation only once if the Developer Workstation and
|
||||
the Developer's choice of HOST tool chain are stable. If the developer
|
||||
updates either the OS or the HOST tool chain, these tools should be rebuilt.
|
||||
</Description>
|
||||
<Copyright>Copyright 2005-2006, Intel Corporation</Copyright>
|
||||
<License>
|
||||
All rights reserved.
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the
|
||||
BSD License which accompanies this distribution. The full text of the
|
||||
license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
</License>
|
||||
<Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
|
||||
</MsaHeader>
|
||||
<ModuleDefinitions>
|
||||
<SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>
|
||||
<BinaryModule>false</BinaryModule>
|
||||
<OutputFileBasename>NULL</OutputFileBasename>
|
||||
</ModuleDefinitions>
|
||||
<SourceFiles>
|
||||
<Filename>build.xml</Filename>
|
||||
<Filename>org/tianocore/exception/EdkException.java</Filename>
|
||||
<Filename>org/tianocore/logger/DefaultLogger.java</Filename>
|
||||
<Filename>org/tianocore/logger/EdkLog.java</Filename>
|
||||
<Filename>org/tianocore/logger/LogMethod.java</Filename>
|
||||
</SourceFiles>
|
||||
</ModuleSurfaceArea>
|
46
Tools/Java/Source/Common/build.xml
Normal file
46
Tools/Java/Source/Common/build.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
-->
|
||||
<project name="Common" default="Common_Jar" basedir=".">
|
||||
|
||||
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
|
||||
<property environment="env"/>
|
||||
<property name="WORKSPACE" value="${env.WORKSPACE}"/>
|
||||
<property name="buildDir" value="build"/>
|
||||
<property name="installLocation" value="${WORKSPACE}/Tools/Jars"/>
|
||||
<target name="Common_Jar" depends="install"/>
|
||||
<target name="source">
|
||||
<mkdir dir="${buildDir}"/>
|
||||
<javac srcdir="." destdir="${buildDir}">
|
||||
<compilerarg value="-Xlint"/>
|
||||
</javac>
|
||||
</target>
|
||||
<target name="clean">
|
||||
<delete dir="${buildDir}"/>
|
||||
</target>
|
||||
<target name="cleanall">
|
||||
<delete dir="${buildDir}"/>
|
||||
<delete file="${installLocation}/Common.jar"/>
|
||||
<if>
|
||||
<available file="${installLocation}/Common.jar"/>
|
||||
<then>
|
||||
<echo message="You must manually remove the file: ${installLocation}/Common.jar"/>
|
||||
<echo message="Java has already loaded the file, and cannot remove it within ANT!"/>
|
||||
</then>
|
||||
</if>
|
||||
</target>
|
||||
<target name="install" depends="source">
|
||||
<jar destfile="${installLocation}/Common.jar"
|
||||
basedir="${buildDir}"
|
||||
includes="**"
|
||||
/>
|
||||
</target>
|
||||
</project>
|
83
Tools/Java/Source/Common/org/tianocore/common/cache/FileTimeStamp.java
vendored
Normal file
83
Tools/Java/Source/Common/org/tianocore/common/cache/FileTimeStamp.java
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
/** @file
|
||||
This file is to define the FileTimeStamp class for speeding up the dependency check.
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
package org.tianocore.common.cache;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
FileTimeStamp class is used to cache the time stamp of accessing file, which
|
||||
will speed up the dependency check for build
|
||||
**/
|
||||
public class FileTimeStamp {
|
||||
//
|
||||
// cache the modified timestamp of files accessed, to speed up the depencey check
|
||||
//
|
||||
private static Map<String, Long> timeStampCache = new HashMap<String, Long>();
|
||||
|
||||
/**
|
||||
Get the time stamp of given file. It will try the cache first and then
|
||||
get from file system if no time stamp of the file is cached.
|
||||
|
||||
@param file File name
|
||||
|
||||
@return long The time stamp of the file
|
||||
**/
|
||||
synchronized public static long get(String file) {
|
||||
long timeStamp = 0;
|
||||
|
||||
Long value = timeStampCache.get(file);
|
||||
if (value != null) {
|
||||
timeStamp = value.longValue();
|
||||
} else {
|
||||
timeStamp = new File(file).lastModified();
|
||||
timeStampCache.put(file, new Long(timeStamp));
|
||||
}
|
||||
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
/**
|
||||
Force update the time stamp for the given file
|
||||
|
||||
@param file File name
|
||||
@param timeStamp The time stamp of the file
|
||||
**/
|
||||
synchronized public static void update(String file, long timeStamp) {
|
||||
timeStampCache.put(file, new Long(timeStamp));
|
||||
}
|
||||
|
||||
/**
|
||||
Force update the time stamp for the given file
|
||||
|
||||
@param file File name
|
||||
**/
|
||||
synchronized public static void update(String file) {
|
||||
long timeStamp = new File(file).lastModified();
|
||||
timeStampCache.put(file, new Long(timeStamp));
|
||||
}
|
||||
|
||||
/**
|
||||
Check if the time stamp of given file has been cached for not
|
||||
|
||||
@param file The file name
|
||||
|
||||
@return boolean
|
||||
**/
|
||||
synchronized public static boolean containsKey(String file) {
|
||||
return timeStampCache.containsKey(file);
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
/** @file
|
||||
EdkDefinitions Class.
|
||||
|
||||
EdkDefinitions class incldes the common EDK definitions which are used
|
||||
by the Tools.
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
package org.tianocore.common.definitions;
|
||||
|
||||
/**
|
||||
This class includes the common EDK definitions.
|
||||
**/
|
||||
public class EdkDefinitions {
|
||||
///
|
||||
/// MODULE_TYPE definitions
|
||||
///
|
||||
public final static String MODULE_TYPE_BASE = "BASE";
|
||||
public final static String MODULE_TYPE_SEC = "SEC";
|
||||
public final static String MODULE_TYPE_PEI_CORE = "PEI_CORE";
|
||||
public final static String MODULE_TYPE_PEIM = "PEIM";
|
||||
public final static String MODULE_TYPE_DXE_CORE = "DXE_CORE";
|
||||
public final static String MODULE_TYPE_DXE_DRIVER = "DXE_DRIVER";
|
||||
public final static String MODULE_TYPE_DXE_RUNTIME_DRIVER = "DXE_RUNTIME_DRIVER";
|
||||
public final static String MODULE_TYPE_DXE_SMM_DRIVER = "DXE_SMM_DRIVER";
|
||||
public final static String MODULE_TYPE_DXE_SAL_DRIVER = "DXE_SAL_DRIVER";
|
||||
public final static String MODULE_TYPE_UEFI_DRIVER = "UEFI_DRIVER";
|
||||
public final static String MODULE_TYPE_UEFI_APPLICATION = "UEFI_APPLICATION";
|
||||
public final static String MODULE_TYPE_USER_DEFINED = "USER_DEFINED";
|
||||
public final static String MODULE_TYPE_TOOL = "TOOL";
|
||||
|
||||
///
|
||||
/// Extension definitions for each of module types
|
||||
///
|
||||
public final static String ModuleTypeExtensions[][] = {
|
||||
{ MODULE_TYPE_BASE, ".FFS" },
|
||||
{ MODULE_TYPE_SEC, ".SEC" },
|
||||
{ MODULE_TYPE_PEI_CORE, ".PEI" },
|
||||
{ MODULE_TYPE_PEIM, ".PEI" },
|
||||
{ MODULE_TYPE_DXE_CORE, ".DXE" },
|
||||
{ MODULE_TYPE_DXE_DRIVER, ".DXE" },
|
||||
{ MODULE_TYPE_DXE_RUNTIME_DRIVER, ".DXE" },
|
||||
{ MODULE_TYPE_DXE_SMM_DRIVER, ".DXE" },
|
||||
{ MODULE_TYPE_DXE_SAL_DRIVER, ".DXE" },
|
||||
{ MODULE_TYPE_UEFI_DRIVER, ".DXE" },
|
||||
{ MODULE_TYPE_UEFI_APPLICATION, ".APP" },
|
||||
{ MODULE_TYPE_USER_DEFINED, ".FFS" },
|
||||
{ MODULE_TYPE_TOOL, ".FFS" }
|
||||
};
|
||||
|
||||
///
|
||||
/// FFS_TYPE definitions
|
||||
///
|
||||
public final static int EFI_FV_FILETYPE_ALL = 0x00;
|
||||
public final static int EFI_FV_FILETYPE_RAW = 0x01;
|
||||
public final static int EFI_FV_FILETYPE_FREEFORM = 0x02;
|
||||
public final static int EFI_FV_FILETYPE_SECURITY_CORE = 0x03;
|
||||
public final static int EFI_FV_FILETYPE_PEI_CORE = 0x04;
|
||||
public final static int EFI_FV_FILETYPE_DXE_CORE = 0x05;
|
||||
public final static int EFI_FV_FILETYPE_PEIM = 0x06;
|
||||
public final static int EFI_FV_FILETYPE_DRIVER = 0x07;
|
||||
public final static int EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER = 0x08;
|
||||
public final static int EFI_FV_FILETYPE_APPLICATION = 0x09;
|
||||
public final static int EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE = 0x0B;
|
||||
public final static int EFI_FV_FILETYPE_FFS_PAD = 0xF0;
|
||||
|
||||
///
|
||||
/// SECTION_TYPE definitions
|
||||
///
|
||||
public final static String EFI_SECTION_COMPRESSION = "EFI_SECTION_COMPRESSION";
|
||||
public final static String EFI_SECTION_GUID_DEFINED = "EFI_SECTION_GUID_DEFINED";
|
||||
public final static String EFI_SECTION_PE32 = "EFI_SECTION_PE32";
|
||||
public final static String EFI_SECTION_PIC = "EFI_SECTION_PIC";
|
||||
public final static String EFI_SECTION_TE = "EFI_SECTION_TE";
|
||||
public final static String EFI_SECTION_DXE_DEPEX = "EFI_SECTION_DXE_DEPEX";
|
||||
public final static String EFI_SECTION_VERSION = "EFI_SECTION_VERSION";
|
||||
public final static String EFI_SECTION_USER_INTERFACE = "EFI_SECTION_USER_INTERFACE";
|
||||
public final static String EFI_SECTION_COMPATIBILITY16 = "EFI_SECTION_COMPATIBILITY16";
|
||||
public final static String EFI_SECTION_FIRMWARE_VOLUME_IMAGE = "EFI_SECTION_FIRMWARE_VOLUME_IMAGE";
|
||||
public final static String EFI_SECTION_FREEFORM_SUBTYPE_GUID = "EFI_SECTION_FREEFORM_SUBTYPE_GUID";
|
||||
public final static String EFI_SECTION_RAW = "EFI_SECTION_RAW";
|
||||
public final static String EFI_SECTION_PEI_DEPEX = "EFI_SECTION_PEI_DEPEX";
|
||||
|
||||
///
|
||||
/// Extension definitions for each of section types
|
||||
///
|
||||
public final static String SectionTypeExtensions[][] = {
|
||||
{ EFI_SECTION_COMPRESSION, ".sec" },
|
||||
{ EFI_SECTION_GUID_DEFINED, ".sec" },
|
||||
{ EFI_SECTION_PE32, ".pe32" },
|
||||
{ EFI_SECTION_PIC, ".pic" },
|
||||
{ EFI_SECTION_TE, ".tes" },
|
||||
{ EFI_SECTION_DXE_DEPEX, ".dpx" },
|
||||
{ EFI_SECTION_VERSION, ".ver" },
|
||||
{ EFI_SECTION_USER_INTERFACE, ".ui" },
|
||||
{ EFI_SECTION_COMPATIBILITY16, ".sec" },
|
||||
{ EFI_SECTION_FIRMWARE_VOLUME_IMAGE, ".sec" },
|
||||
{ EFI_SECTION_FREEFORM_SUBTYPE_GUID, ".sec" },
|
||||
{ EFI_SECTION_RAW, ".sec" },
|
||||
{ EFI_SECTION_PEI_DEPEX, ".dpx" }
|
||||
};
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
/** @file
|
||||
ToolDefinitions Class.
|
||||
|
||||
ToolDefinitions class incldes the common Tool definitions.
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
package org.tianocore.common.definitions;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
This class includes the common Tool definitions.
|
||||
**/
|
||||
public class ToolDefinitions {
|
||||
///
|
||||
/// Line separator (carriage return-line feed, CRLF)
|
||||
///
|
||||
public final static String LINE_SEPARATOR = "\r\n";
|
||||
|
||||
///
|
||||
/// Framework Database (FrameworkDatabase.db) file path
|
||||
///
|
||||
public final static String FRAMEWORK_DATABASE_FILE_PATH =
|
||||
"Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db";
|
||||
|
||||
///
|
||||
/// Target (target.txt) file path
|
||||
///
|
||||
public final static String TARGET_FILE_PATH =
|
||||
"Tools" + File.separatorChar + "Conf" + File.separatorChar + "target.txt";
|
||||
|
||||
///
|
||||
/// Default Tools Definition (tools_def.txt) file path
|
||||
///
|
||||
public final static String DEFAULT_TOOLS_DEF_FILE_PATH =
|
||||
"Tools" + File.separatorChar + "Conf" + File.separatorChar + "tools_def.txt";
|
||||
|
||||
///
|
||||
/// Extension names for SPD, FPD, and MSA
|
||||
///
|
||||
public final static String SPD_EXTENSION = ".spd";
|
||||
public final static String FPD_EXTENSION = ".fpd";
|
||||
public final static String MSA_EXTENSION = ".msa";
|
||||
|
||||
///
|
||||
/// Tool Chain Elements in the Tools Definition file
|
||||
///
|
||||
public final static String TOOLS_DEF_ELEMENT_TARGET = "TARGET";
|
||||
public final static String TOOLS_DEF_ELEMENT_TOOLCHAIN = "TOOLCHAIN";
|
||||
public final static String TOOLS_DEF_ELEMENT_ARCH = "ARCH";
|
||||
public final static String TOOLS_DEF_ELEMENT_TOOLCODE = "TOOLCODE";
|
||||
public final static String TOOLS_DEF_ELEMENT_ATTRIBUTE = "ATTRIBUTE";
|
||||
|
||||
///
|
||||
/// Index of Tool Chain elements in the Tools Definition file
|
||||
///
|
||||
public final static int TOOLS_DEF_ELEMENT_INDEX_TARGET = 0;
|
||||
public final static int TOOLS_DEF_ELEMENT_INDEX_TOOLCHAIN = 1;
|
||||
public final static int TOOLS_DEF_ELEMENT_INDEX_ARCH = 2;
|
||||
public final static int TOOLS_DEF_ELEMENT_INDEX_TOOLCODE = 3;
|
||||
public final static int TOOLS_DEF_ELEMENT_INDEX_ATTRIBUTE = 4;
|
||||
public final static int TOOLS_DEF_ELEMENT_INDEX_MAXIMUM = 5;
|
||||
|
||||
///
|
||||
/// Tool Chain Attributes in the Tools Definition file
|
||||
///
|
||||
public final static String TOOLS_DEF_ATTRIBUTE_NAME = "NAME";
|
||||
public final static String TOOLS_DEF_ATTRIBUTE_PATH = "PATH";
|
||||
public final static String TOOLS_DEF_ATTRIBUTE_DPATH = "DPATH";
|
||||
public final static String TOOLS_DEF_ATTRIBUTE_SPATH = "SPATH";
|
||||
public final static String TOOLS_DEF_ATTRIBUTE_EXT = "EXT";
|
||||
public final static String TOOLS_DEF_ATTRIBUTE_FAMILY = "FAMILY";
|
||||
public final static String TOOLS_DEF_ATTRIBUTE_FLAGS = "FLAGS";
|
||||
|
||||
///
|
||||
/// Tool Chain Families in the Tools Definition file
|
||||
///
|
||||
public final static String TOOLS_DEF_FAMILY_MSFT = "MSFT";
|
||||
public final static String TOOLS_DEF_FAMILY_INTEL = "INTEL";
|
||||
public final static String TOOLS_DEF_FAMILY_GCC = "GCC";
|
||||
|
||||
///
|
||||
/// Key name in the Target file
|
||||
///
|
||||
public final static String TARGET_KEY_ACTIVE_PLATFORM = "ACTIVE_PLATFORM";
|
||||
public final static String TARGET_KEY_TARGET = "TARGET";
|
||||
public final static String TARGET_KEY_TOOLCHAIN = "TOOL_CHAIN_TAG";
|
||||
public final static String TARGET_KEY_ARCH = "TARGET_ARCH";
|
||||
public final static String TARGET_KEY_TOOLS_DEF = "TOOL_CHAIN_CONF";
|
||||
public final static String TARGET_KEY_MULTIPLE_THREAD = "MULTIPLE_THREAD";
|
||||
public final static String TARGET_KEY_MAX_CONCURRENT_THREAD_NUMBER
|
||||
= "MAX_CONCURRENT_THREAD_NUMBER";
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
Module Name:
|
||||
EdkException.java
|
||||
|
||||
Abstract:
|
||||
|
||||
--*/
|
||||
|
||||
package org.tianocore.common.exception;
|
||||
|
||||
public class EdkException extends Exception {
|
||||
static final long serialVersionUID = -8494188017252114029L;
|
||||
|
||||
public static boolean isPrintStack = false;
|
||||
|
||||
public EdkException(String message) {
|
||||
super("[EdkException]:" + message);
|
||||
}
|
||||
|
||||
public EdkException(String message, boolean traceStack) {
|
||||
super(message);
|
||||
|
||||
}
|
||||
|
||||
public EdkException(){
|
||||
super();
|
||||
}
|
||||
|
||||
public EdkException(Exception e, String message){
|
||||
super("[EdkException]:" + message);
|
||||
if (isPrintStack){
|
||||
this.setStackTrace(e.getStackTrace());
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
public static void setIsprintStack (boolean flag){
|
||||
isPrintStack = flag;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
Module Name:
|
||||
DefaultLogger.java
|
||||
|
||||
Abstract:
|
||||
|
||||
--*/
|
||||
|
||||
package org.tianocore.common.logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
class DefaultLogger implements LogMethod {
|
||||
private Logger logger = Logger.global;
|
||||
private static Level[] levelMap = {
|
||||
Level.SEVERE, Level.WARNING, Level.INFO, Level.FINE, Level.ALL
|
||||
};
|
||||
|
||||
public DefaultLogger() {
|
||||
}
|
||||
|
||||
public void putMessage(Object msgSource, int msgLevel, String msg) {
|
||||
if (msgLevel < 0 || msgLevel > levelMap.length) {
|
||||
msgLevel = 2;
|
||||
}
|
||||
logger.log(levelMap[msgLevel], msg);
|
||||
}
|
||||
|
||||
public void flushToFile(File file){
|
||||
|
||||
}
|
||||
}
|
112
Tools/Java/Source/Common/org/tianocore/common/logger/EdkLog.java
Normal file
112
Tools/Java/Source/Common/org/tianocore/common/logger/EdkLog.java
Normal file
@ -0,0 +1,112 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
Module Name:
|
||||
EdkLogger.java
|
||||
|
||||
Abstract:
|
||||
|
||||
--*/
|
||||
package org.tianocore.common.logger;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class EdkLog {
|
||||
public static final String always = "ALWAYS";
|
||||
|
||||
public static final String error = "ERROR";
|
||||
|
||||
public static final String warning = "WARNING";
|
||||
|
||||
public static final String info = "INFO";
|
||||
|
||||
public static final String verbose = "VERBOSE";
|
||||
|
||||
public static final String debug = "DEBUG";
|
||||
|
||||
public static final int EDK_ALWAYS = -1;
|
||||
|
||||
public static final int EDK_ERROR = 0;
|
||||
|
||||
public static final int EDK_WARNING = 1;
|
||||
|
||||
public static final int EDK_INFO = 2;
|
||||
|
||||
public static final int EDK_VERBOSE = 3;
|
||||
|
||||
public static final int EDK_DEBUG = 4;
|
||||
|
||||
private static int logLevel = EDK_INFO;
|
||||
|
||||
private static LogMethod logger = new DefaultLogger();
|
||||
|
||||
public static void log(int level, String message) {
|
||||
if (level <= logLevel) {
|
||||
logger.putMessage(null, level, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void log(String message) {
|
||||
if (EDK_INFO <= logLevel) {
|
||||
logger.putMessage(null, EDK_INFO, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void log(Object o, int level, String message) {
|
||||
if (level <= logLevel) {
|
||||
logger.putMessage(o, level, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void log(Object o, String message) {
|
||||
if (EDK_INFO <= logLevel) {
|
||||
logger.putMessage(o, EDK_INFO, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void flushLogToFile(File file) {
|
||||
logger.flushToFile(file);
|
||||
}
|
||||
|
||||
public static void setLogger(LogMethod l) {
|
||||
logger = l;
|
||||
}
|
||||
|
||||
public static void setLogLevel(int level) {
|
||||
logLevel = level;
|
||||
}
|
||||
|
||||
public static void setLogLevel(String level) {
|
||||
if (level == null) {
|
||||
return;
|
||||
}
|
||||
String levelStr = level.trim();
|
||||
if (levelStr.equalsIgnoreCase(error)) {
|
||||
logLevel = EDK_ERROR;
|
||||
}
|
||||
if (levelStr.equalsIgnoreCase(debug)) {
|
||||
logLevel = EDK_DEBUG;
|
||||
}
|
||||
if (levelStr.equalsIgnoreCase(info)) {
|
||||
logLevel = EDK_INFO;
|
||||
}
|
||||
if (levelStr.equalsIgnoreCase(verbose)) {
|
||||
logLevel = EDK_VERBOSE;
|
||||
}
|
||||
if (levelStr.equalsIgnoreCase(warning)) {
|
||||
logLevel = EDK_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getLogLevel() {
|
||||
return logLevel;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
Module Name:
|
||||
LogMethod.java
|
||||
|
||||
Abstract:
|
||||
|
||||
--*/
|
||||
|
||||
package org.tianocore.common.logger;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public interface LogMethod {
|
||||
public void putMessage(Object msgSource, int msgLevel, String msg);
|
||||
|
||||
public void flushToFile(File file);
|
||||
}
|
53
Tools/Java/Source/ContextTool/build.xml
Normal file
53
Tools/Java/Source/ContextTool/build.xml
Normal file
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
-->
|
||||
<project name="ContextTool" default="ContextTool" basedir=".">
|
||||
|
||||
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
|
||||
<property environment="env"/>
|
||||
<property name="WORKSPACE" value="${env.WORKSPACE}"/>
|
||||
<path id="classpath">
|
||||
<fileset dir="${WORKSPACE}/Tools/Jars" includes="SurfaceArea.jar"/>
|
||||
<fileset dir="${WORKSPACE}/Tools/Jars" includes="Common.jar"/>
|
||||
<fileset dir="${env.XMLBEANS_HOME}/lib" includes="*.jar"/>
|
||||
</path>
|
||||
<property name="buildDir" value="build"/>
|
||||
<property name="installLocation" value="${WORKSPACE}/Tools/Jars"/>
|
||||
<target name="ContextTool" depends="install"/>
|
||||
<target name="source">
|
||||
<mkdir dir="${buildDir}"/>
|
||||
<javac srcdir="." destdir="${buildDir}">
|
||||
<classpath refid="classpath"/>
|
||||
<compilerarg value="-Xlint"/>
|
||||
</javac>
|
||||
</target>
|
||||
<target name="clean">
|
||||
<delete dir="${buildDir}"/>
|
||||
</target>
|
||||
<target name="cleanall">
|
||||
<delete dir="${buildDir}"/>
|
||||
<delete file="${installLocation}/ContextTool.jar"/>
|
||||
<if>
|
||||
<available file="${installLocation}/ContextTool.jar"/>
|
||||
<then>
|
||||
<echo message="You must manually remove the file: ${installLocation}/ContextTool.jar"/>
|
||||
<echo message="Java has already loaded the file, and cannot remove it within ANT!"/>
|
||||
</then>
|
||||
</if>
|
||||
</target>
|
||||
<target name="install" depends="source">
|
||||
<jar destfile="${installLocation}/ContextTool.jar"
|
||||
basedir="${buildDir}"
|
||||
includes="**"
|
||||
/>
|
||||
</target>
|
||||
</project>
|
||||
|
@ -0,0 +1,29 @@
|
||||
/** @file
|
||||
File is ContextMain class .
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
**/
|
||||
package org.tianocore.context;
|
||||
|
||||
public class ContextMain {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
if(ParseParameter.checkParameter(args) == false){
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
if (TargetFile.parsePath("target.txt") == false) {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
System.out.printf("%n%s", "Target.txt generate successfully!");
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
/** @file
|
||||
File is HelpInfo class which is used to output the usage info.
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
**/
|
||||
|
||||
package org.tianocore.context;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class HelpInfo {
|
||||
|
||||
|
||||
/**
|
||||
* output the tools usage guide
|
||||
* @param no input parameter
|
||||
* @return no return value
|
||||
**/
|
||||
public static void outputUsageInfo() {
|
||||
System.out.printf("\n%s", DescripationString);
|
||||
System.out.printf("\n%s", UsageInfoString);
|
||||
System.out.printf("\n%s", DetailOfOptionString);
|
||||
|
||||
for (int i = 0; i < settingnum; i++) {
|
||||
outputSubUsageInfo(UsageString[i], UsageStringInfo[i]);
|
||||
}
|
||||
|
||||
System.out.printf("\n%s", ExampleString);
|
||||
}
|
||||
|
||||
/**
|
||||
* output the usage info which bases on cmd option
|
||||
* @param String str1 : the cmd option
|
||||
* String str2 : the detail of cmd option
|
||||
* @return no return value
|
||||
**/
|
||||
private static void outputSubUsageInfo(String str1, String str2) {
|
||||
|
||||
splitString(str2);
|
||||
System.out.printf("\n%4s %-30s %s", "", str1, List.get(0));
|
||||
for (int i=1; i<List.size(); i++){
|
||||
System.out.printf("\n%4s %-30s %s", "", "", List.get(i));
|
||||
}
|
||||
List.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* according to the output width, split the detail info
|
||||
* @param String str :the detail info
|
||||
* @return no return value
|
||||
**/
|
||||
private static void splitString(String str) {
|
||||
int strlength = str.length();
|
||||
if (strlength > MaxSrtingLength) {
|
||||
String[] tokens = str.split("[ ]", 0);
|
||||
String tempstr = null;
|
||||
int templength = 0;
|
||||
int start = 0;
|
||||
int end = 0;
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
if ((templength = end + tokens[i].length() + 1) < (MaxSrtingLength + start)) {
|
||||
end = templength;
|
||||
} else {
|
||||
tempstr = str.substring(start, end);
|
||||
List.add(tempstr);
|
||||
start = end;
|
||||
i = i - 1;
|
||||
}
|
||||
}
|
||||
tempstr = str.substring(start, end - 1);
|
||||
List.add(tempstr);
|
||||
} else {
|
||||
List.add(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static LinkedList<String> List = new LinkedList<String>();
|
||||
|
||||
private static final int MaxSrtingLength = 40;
|
||||
|
||||
private static final int settingnum = 7;
|
||||
|
||||
private static final String DescripationString = "The purpose of this tool is modifying the settings in target.txt";
|
||||
|
||||
private static final String UsageInfoString = "Usage: ContextTool [-option1] [args] [-option2] [args] ...";
|
||||
|
||||
private static final String DetailOfOptionString = "Where options include:";
|
||||
|
||||
private static final String ExampleString = "Example: ContextTool -a IA32 IA64 EBC -c Tools/Conf/tools_def.txt -t DEBUG -n GCC -p EdkNt32Pkg/Nt32.fpd -m 2\n";
|
||||
|
||||
private static final String HString = "-h";
|
||||
|
||||
private static final String HStringInfo = "print usage info";
|
||||
|
||||
private static final String AString = "-a <list of Arch>";
|
||||
|
||||
private static final String AStringInfo = "what kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM. Multiple values can be specified on a single line, using space to separate the values.";
|
||||
|
||||
private static final String CString = "-c <tool_definition_file.txt>";
|
||||
|
||||
private static final String CStringInfo = "Assign a txt file with the relative path to WORKSPACE, which specify the tools to use for the build and must be located in the path: WORKSPACE/Tools/Conf/. If no file is specified, the default filename is \"tools_def.txt\"";
|
||||
|
||||
private static final String NString = "-n <list of TagNames>";
|
||||
|
||||
private static final String NStringInfo = "Specify the TagName, such as GCC, MSFT, which are defined in the \"tool_definition_file.txt\"";
|
||||
|
||||
private static final String PString = "-p <*.fpd>";
|
||||
|
||||
private static final String PStringInfo = "Specify the WORKSPACE relative Path and Filename of platform FPD file that will be used for the build.";
|
||||
|
||||
private static final String TString = "-t <list of Build Targets>";
|
||||
|
||||
private static final String TStringInfo = "What kind of the version is the binary target, such as DEBUG, RELEASE. Multiple values can be specified on a single line, using space to separate the values.";
|
||||
|
||||
private static final String MString = "-m <num of Threads>";
|
||||
|
||||
private static final String MStringInfo = "number should GE 0. 0 clears both MULTIPLE_THREAD and MAX_CONCURRENT_THREAD_NUMBER, others enable MULTIPLE_THREAD and set MAX_CONCURRENT_THREAD_NUMBER.";
|
||||
|
||||
private static final String[] UsageString = { HString, AString, CString,
|
||||
NString, PString, TString, MString };
|
||||
|
||||
private static final String[] UsageStringInfo = { HStringInfo, AStringInfo,
|
||||
CStringInfo, NStringInfo, PStringInfo, TStringInfo, MStringInfo };
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
/** @file
|
||||
File is ParseParameter class which is used to parse the validity of user's input args
|
||||
and standardize them.
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
**/
|
||||
package org.tianocore.context;
|
||||
|
||||
public class ParseParameter {
|
||||
|
||||
|
||||
/**
|
||||
* check the validity of user's input args
|
||||
* @param args -- user's input
|
||||
* @return true or false
|
||||
**/
|
||||
public static boolean checkParameter(String[] args) {
|
||||
|
||||
if(args.length == 0){
|
||||
HelpInfo.outputUsageInfo();
|
||||
return false;
|
||||
} else {
|
||||
if( args[0].charAt(0) != '-' ){
|
||||
HelpInfo.outputUsageInfo();
|
||||
return false;
|
||||
}
|
||||
for(int i=0; i<args.length; i++){
|
||||
if( (args[i].compareToIgnoreCase("-h") == 0) ||
|
||||
(args[i].startsWith("-") && ((args[i].charAt(1) != 'a') && (args[i].charAt(1) != 'c')
|
||||
&& (args[i].charAt(1) != 'n') && (args[i].charAt(1) != 'p') && (args[i].charAt(1) != 't') && (args[i].charAt(1) != 'm')))){
|
||||
HelpInfo.outputUsageInfo();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
standardizeParameter(args);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* standardize user's input args
|
||||
* @param args -- user's input
|
||||
* @return no return value
|
||||
**/
|
||||
private static void standardizeParameter(String[] args) {
|
||||
|
||||
//
|
||||
// the parameters's length are same.
|
||||
//
|
||||
length = pstr.length();
|
||||
|
||||
StringBuffer InputData = new StringBuffer();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
InputData.append(args[i]);
|
||||
InputData.append(" ");
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
while (i < InputData.length()) {
|
||||
int j = InputData.indexOf("-", i + 1);
|
||||
if (j == -1)
|
||||
j = InputData.length();
|
||||
|
||||
String argstr = InputData.substring(i, j);
|
||||
|
||||
if (argstr.charAt(1) == 'p') {
|
||||
pstr += argstr.substring(2);
|
||||
// pstr += "\n";
|
||||
} else if (argstr.charAt(1) == 't') {
|
||||
tstr += argstr.substring(2);
|
||||
// tstr += "\n";
|
||||
} else if (argstr.charAt(1) == 'a') {
|
||||
astr += argstr.substring(2);
|
||||
// astr += "\n";
|
||||
} else if (argstr.charAt(1) == 'c') {
|
||||
cstr += argstr.substring(2);
|
||||
// cstr += "\n";
|
||||
} else if (argstr.charAt(1) == 'n') {
|
||||
nstr += argstr.substring(2);
|
||||
// nstr += "\n";
|
||||
} else if (argstr.charAt(1) == 'm') {
|
||||
mstr += argstr.substring(2);
|
||||
// mstr += "\n";
|
||||
if (argstr.charAt(3) == '0'){
|
||||
mestr += " Disable";
|
||||
} else {
|
||||
mestr += " Enable";
|
||||
}
|
||||
}
|
||||
i = j;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static int length = 0;
|
||||
public static String pstr = new String("ACTIVE_PLATFORM = ");
|
||||
public static String tstr = new String("TARGET = ");
|
||||
public static String astr = new String("TARGET_ARCH = ");
|
||||
public static String cstr = new String("TOOL_CHAIN_CONF = ");
|
||||
public static String nstr = new String("TOOL_CHAIN_TAG = ");
|
||||
public static String mstr = new String("MAX_CONCURRENT_THREAD_NUMBER = ");
|
||||
public static String mestr = new String("MULTIPLE_THREAD = ");
|
||||
|
||||
}
|
@ -0,0 +1,497 @@
|
||||
/** @file
|
||||
File is TargetFile class which is used to generate the new target.txt.
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
**/
|
||||
package org.tianocore.context;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
public class TargetFile {
|
||||
|
||||
/**
|
||||
* check the validity of path and file
|
||||
* @param String filename : the name of target file
|
||||
* @return true or false
|
||||
**/
|
||||
public static boolean parsePath(String filename) {
|
||||
|
||||
String workspacePath = System.getenv("WORKSPACE");
|
||||
|
||||
Fd = new File(workspacePath + File.separator + "Tools" + File.separator + "Conf" + File.separator + filename);
|
||||
|
||||
if (Fd.exists() == true) {
|
||||
if (createTempFile(filename + "tmp") == false) {
|
||||
return false;
|
||||
}
|
||||
if (readwriteFile() == false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
try {
|
||||
Fd.createNewFile();
|
||||
} catch (IOException e) {
|
||||
System.out.printf("%n%s", "Create the file:target.txt failed!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
TargetFile.writeFile(Fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* create a empty temp file, which is located at the same directory with target file
|
||||
* @param String filename : the name of target temp file
|
||||
* @return true or false
|
||||
**/
|
||||
private static boolean createTempFile(String filename) {
|
||||
|
||||
String workspacePath = System.getenv("WORKSPACE");
|
||||
|
||||
TempFd = new File(workspacePath + File.separator + "Tools" + File.separator + "Conf" + File.separator + filename);
|
||||
|
||||
if (TempFd.exists() == true) {
|
||||
if (TempFd.delete() == false) {
|
||||
System.out.println("\n# delete file failed !");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
TempFd.createNewFile();
|
||||
} catch (IOException e) {
|
||||
System.out.printf("%n%s",
|
||||
"Create the temp file:target.txttmp failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* read from target.txt and write to target.txttmp, del target.txt, rename
|
||||
* @param no paremeter
|
||||
* @return true or false
|
||||
**/
|
||||
private static boolean readwriteFile() {
|
||||
|
||||
if (Fd.canRead() != true)
|
||||
return false;
|
||||
|
||||
BufferedReader br = null;
|
||||
BufferedWriter bw = null;
|
||||
String textLine = null;
|
||||
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(Fd));
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out
|
||||
.println("\n# create the BufferedReader failed, because can't find the file:target.txt!");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
bw = new BufferedWriter(new FileWriter(TempFd));
|
||||
} catch (IOException e) {
|
||||
System.out.println("\n# create the BufferedWriter failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
//TARGET_ARCH must be in front of TARGET!!! according to the target.txt
|
||||
//
|
||||
try {
|
||||
while ((textLine = br.readLine()) != null) {
|
||||
//
|
||||
// the line is composed of Space
|
||||
//
|
||||
if (textLine.trim().compareToIgnoreCase("") == 0) {
|
||||
bw.write(textLine);
|
||||
bw.newLine();
|
||||
}
|
||||
//
|
||||
// the line starts with "#", and no "="
|
||||
//
|
||||
else if ((textLine.trim().charAt(0) == '#') && (textLine.indexOf("=") == -1)){
|
||||
bw.write(textLine);
|
||||
bw.newLine();
|
||||
} else {
|
||||
//
|
||||
//modify at the first time, and there should be *ACTIVE_PLATFORM*=* in the line
|
||||
//
|
||||
if (textLine.indexOf("ACTIVE_PLATFORM") != -1) {
|
||||
if(pflag == true){
|
||||
if(textLine.trim().charAt(0) == '#'){
|
||||
if(ParseParameter.pstr.length() > ParseParameter.length) {
|
||||
bw.write(ParseParameter.pstr);
|
||||
bw.newLine();
|
||||
pflag = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(ParseParameter.pstr.length() > ParseParameter.length) {
|
||||
bw.write(ParseParameter.pstr);
|
||||
} else {
|
||||
bw.write(textLine);
|
||||
}
|
||||
bw.newLine();
|
||||
pflag = false;
|
||||
}
|
||||
} else if (textLine.indexOf("TARGET_ARCH") != -1) {
|
||||
if(aflag == true){
|
||||
if(textLine.trim().charAt(0) == '#'){
|
||||
if(ParseParameter.astr.length() > ParseParameter.length) {
|
||||
bw.write(ParseParameter.astr);
|
||||
bw.newLine();
|
||||
aflag = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(ParseParameter.astr.length() > ParseParameter.length) {
|
||||
bw.write(ParseParameter.astr);
|
||||
} else {
|
||||
bw.write(textLine);
|
||||
}
|
||||
bw.newLine();
|
||||
aflag = false;
|
||||
}
|
||||
} else if (textLine.indexOf("TARGET") != -1) {
|
||||
if(tflag == true){
|
||||
if(textLine.trim().charAt(0) == '#'){
|
||||
if(ParseParameter.tstr.length() > ParseParameter.length) {
|
||||
bw.write(ParseParameter.tstr);
|
||||
bw.newLine();
|
||||
tflag = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(ParseParameter.tstr.length() > ParseParameter.length) {
|
||||
bw.write(ParseParameter.tstr);
|
||||
} else {
|
||||
bw.write(textLine);
|
||||
}
|
||||
bw.newLine();
|
||||
tflag = false;
|
||||
}
|
||||
} else if (textLine.indexOf("TOOL_CHAIN_CONF") != -1) {
|
||||
if(cflag == true){
|
||||
if(textLine.trim().charAt(0) == '#'){
|
||||
if(ParseParameter.cstr.length() > ParseParameter.length) {
|
||||
bw.write(ParseParameter.cstr);
|
||||
bw.newLine();
|
||||
cflag = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(ParseParameter.cstr.length() > ParseParameter.length) {
|
||||
bw.write(ParseParameter.cstr);
|
||||
} else {
|
||||
bw.write(textLine);
|
||||
}
|
||||
bw.newLine();
|
||||
cflag = false;
|
||||
}
|
||||
} else if (textLine.indexOf("TOOL_CHAIN_TAG") != -1) {
|
||||
if(nflag == true){
|
||||
if(textLine.trim().charAt(0) == '#'){
|
||||
if(ParseParameter.nstr.length() > ParseParameter.length) {
|
||||
bw.write(ParseParameter.nstr);
|
||||
bw.newLine();
|
||||
nflag = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(ParseParameter.nstr.length() > ParseParameter.length) {
|
||||
bw.write(ParseParameter.nstr);
|
||||
} else {
|
||||
bw.write(textLine);
|
||||
}
|
||||
bw.newLine();
|
||||
nflag = false;
|
||||
}
|
||||
} else if (textLine.indexOf("MAX_CONCURRENT_THREAD_NUMBER") != -1) {
|
||||
if(mflag == true){
|
||||
if(textLine.trim().charAt(0) == '#'){
|
||||
if(ParseParameter.mstr.length() > ParseParameter.length) {
|
||||
bw.write(ParseParameter.mstr);
|
||||
bw.newLine();
|
||||
mflag = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(ParseParameter.mstr.length() > ParseParameter.length) {
|
||||
bw.write(ParseParameter.mstr);
|
||||
} else {
|
||||
bw.write(textLine);
|
||||
}
|
||||
bw.newLine();
|
||||
mflag = false;
|
||||
}
|
||||
}else if (textLine.indexOf("MULTIPLE_THREAD") != -1) {
|
||||
if(meflag == true){
|
||||
if(textLine.trim().charAt(0) == '#'){
|
||||
if(ParseParameter.mestr.length() > ParseParameter.length) {
|
||||
bw.write(ParseParameter.mestr);
|
||||
bw.newLine();
|
||||
meflag = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(ParseParameter.mestr.length() > ParseParameter.length) {
|
||||
bw.write(ParseParameter.mestr);
|
||||
} else {
|
||||
bw.write(textLine);
|
||||
}
|
||||
bw.newLine();
|
||||
meflag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
//user maybe delete the line *ACTIVE_PLATFORM*=*
|
||||
//
|
||||
if( (pflag == true) && (ParseParameter.pstr.length() > ParseParameter.length) ){
|
||||
bw.write(ParseParameter.pstr);
|
||||
bw.newLine();
|
||||
} else if ( (tflag == true) && (ParseParameter.tstr.length() > ParseParameter.length) ){
|
||||
bw.write(ParseParameter.tstr);
|
||||
bw.newLine();
|
||||
} else if ( (aflag == true) && (ParseParameter.astr.length() > ParseParameter.length) ){
|
||||
bw.write(ParseParameter.astr);
|
||||
bw.newLine();
|
||||
} else if ( (cflag == true) && (ParseParameter.cstr.length() > ParseParameter.length) ){
|
||||
bw.write(ParseParameter.cstr);
|
||||
bw.newLine();
|
||||
} else if ( (nflag == true) && (ParseParameter.nstr.length() > ParseParameter.length) ){
|
||||
bw.write(ParseParameter.nstr);
|
||||
bw.newLine();
|
||||
} else if ( (meflag == true) && (ParseParameter.mestr.length() > ParseParameter.length) ){
|
||||
bw.write(ParseParameter.mestr);
|
||||
bw.newLine();
|
||||
} else if ( (mflag == true) && (ParseParameter.mstr.length() > ParseParameter.length) ){
|
||||
bw.write(ParseParameter.mstr);
|
||||
bw.newLine();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("\n# read or write file error!");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
br.close();
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
System.out
|
||||
.println("\n# close BufferedReader&BufferedWriter error");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Fd.delete() == false) {
|
||||
System.out.println("\n# delete file failed !");
|
||||
return false;
|
||||
}
|
||||
if (TempFd.renameTo(Fd) == false) {
|
||||
System.out.println("\n# rename file failed !");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* according to user's input args, write the file directly
|
||||
* @param File fd : the File of the target file
|
||||
* @return true or false
|
||||
**/
|
||||
private static boolean writeFile(File fd) {
|
||||
|
||||
if (fd.canWrite() != true)
|
||||
return false;
|
||||
|
||||
FileOutputStream outputFile = null;
|
||||
try {
|
||||
outputFile = new FileOutputStream(fd);
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out
|
||||
.println("\n# can't find the file when open the output stream !");
|
||||
return false;
|
||||
}
|
||||
FileChannel outputChannel = outputFile.getChannel();
|
||||
|
||||
ByteBuffer[] buffers = new ByteBuffer[7];
|
||||
buffers[0] = ByteBuffer.allocate(ParseParameter.pstr.toString().length());
|
||||
buffers[1] = ByteBuffer.allocate(ParseParameter.tstr.toString().length());
|
||||
buffers[2] = ByteBuffer.allocate(ParseParameter.astr.toString().length());
|
||||
buffers[3] = ByteBuffer.allocate(ParseParameter.cstr.toString().length());
|
||||
buffers[4] = ByteBuffer.allocate(ParseParameter.nstr.toString().length());
|
||||
buffers[5] = ByteBuffer.allocate(ParseParameter.mestr.toString().length());
|
||||
buffers[6] = ByteBuffer.allocate(ParseParameter.mstr.toString().length());
|
||||
|
||||
buffers[0].put(ParseParameter.pstr.toString().getBytes()).flip();
|
||||
buffers[1].put(ParseParameter.tstr.toString().getBytes()).flip();
|
||||
buffers[2].put(ParseParameter.astr.toString().getBytes()).flip();
|
||||
buffers[3].put(ParseParameter.cstr.toString().getBytes()).flip();
|
||||
buffers[4].put(ParseParameter.nstr.toString().getBytes()).flip();
|
||||
buffers[5].put(ParseParameter.mestr.toString().getBytes()).flip();
|
||||
buffers[6].put(ParseParameter.mstr.toString().getBytes()).flip();
|
||||
|
||||
try {
|
||||
ByteBuffer bufofCP = ByteBuffer.allocate(Copyright.length());
|
||||
bufofCP.put(Copyright.getBytes()).flip();
|
||||
outputChannel.write(bufofCP);
|
||||
|
||||
ByteBuffer bufofFI = ByteBuffer.allocate(Fileinfo.length());
|
||||
bufofFI.put(Fileinfo.getBytes()).flip();
|
||||
outputChannel.write(bufofFI);
|
||||
|
||||
ByteBuffer buffer0 = ByteBuffer.allocate(pusage.length());
|
||||
buffer0.put(pusage.getBytes()).flip();
|
||||
outputChannel.write(buffer0);
|
||||
outputChannel.write(buffers[0]);
|
||||
|
||||
ByteBuffer buffer1 = ByteBuffer.allocate(tusage.length());
|
||||
buffer1.put(tusage.getBytes()).flip();
|
||||
outputChannel.write(buffer1);
|
||||
outputChannel.write(buffers[1]);
|
||||
|
||||
ByteBuffer buffer2 = ByteBuffer.allocate(ausage.length());
|
||||
buffer2.put(ausage.getBytes()).flip();
|
||||
outputChannel.write(buffer2);
|
||||
outputChannel.write(buffers[2]);
|
||||
|
||||
ByteBuffer buffer3 = ByteBuffer.allocate(cusage.length());
|
||||
buffer3.put(cusage.getBytes()).flip();
|
||||
outputChannel.write(buffer3);
|
||||
outputChannel.write(buffers[3]);
|
||||
|
||||
ByteBuffer buffer4 = ByteBuffer.allocate(nusage.length());
|
||||
buffer4.put(nusage.getBytes()).flip();
|
||||
outputChannel.write(buffer4);
|
||||
outputChannel.write(buffers[4]);
|
||||
|
||||
ByteBuffer buffer5 = ByteBuffer.allocate(meusage.length());
|
||||
buffer4.put(meusage.getBytes()).flip();
|
||||
outputChannel.write(buffer5);
|
||||
outputChannel.write(buffers[5]);
|
||||
|
||||
ByteBuffer buffer6 = ByteBuffer.allocate(musage.length());
|
||||
buffer4.put(musage.getBytes()).flip();
|
||||
outputChannel.write(buffer6);
|
||||
outputChannel.write(buffers[6]);
|
||||
|
||||
outputFile.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("\n# The operations of file failed !");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
///
|
||||
/// point to target.txttmp, a temp file, which is created and deleted during the tool's runtime.
|
||||
///
|
||||
private static File TempFd;
|
||||
|
||||
///
|
||||
/// point to target.txt.
|
||||
///
|
||||
private static File Fd;
|
||||
|
||||
///
|
||||
/// when the flag is true, the corresponding str should be add at the end of file.
|
||||
///
|
||||
private static boolean pflag = true;
|
||||
private static boolean tflag = true;
|
||||
private static boolean aflag = true;
|
||||
private static boolean cflag = true;
|
||||
private static boolean nflag = true;
|
||||
private static boolean mflag = true;
|
||||
private static boolean meflag = true;
|
||||
|
||||
private static final String Copyright = "#\n"
|
||||
+ "# Copyright (c) 2006, Intel Corporation\n"
|
||||
+ "#\n"
|
||||
+ "# All rights reserved. This program and the accompanying materials\n"
|
||||
+ "# are licensed and made available under the terms and conditions of the BSD License\n"
|
||||
+ "# which accompanies this distribution. The full text of the license may be found at\n"
|
||||
+ "# http://opensource.org/licenses/bsd-license.php\n"
|
||||
+ "\n"
|
||||
+ "# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN \"AS IS\" BASIS,\n"
|
||||
+ "# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\n";
|
||||
|
||||
private static final String Fileinfo = "#\n"
|
||||
+ "# Filename: target.template\n"
|
||||
+ "#\n"
|
||||
+ "# ALL Paths are Relative to WORKSPACE\n"
|
||||
+ "\n"
|
||||
+ "# Separate multiple LIST entries with a SINGLE SPACE character, do not use comma characters.\n"
|
||||
+ "# Un-set an option by either commenting out the line, or not setting a value.\n";
|
||||
|
||||
private static final String pusage = "#\n"
|
||||
+ "# PROPERTY Type Use Description\n"
|
||||
+ "# ---------------- -------- -------- -----------------------------------------------------------\n"
|
||||
+ "# ACTIVE_PLATFORM Filename Recommended Specify the WORKSPACE relative Path and Filename\n"
|
||||
+ "# of the platform FPD file that will be used for the build\n"
|
||||
+ "# This line is required if and only if the current working\n"
|
||||
+ "# directory does not contain one or more FPD files.\n";
|
||||
|
||||
private static final String tusage = "\n\n"
|
||||
+ "# TARGET List Optional Zero or more of the following: DEBUG, RELEASE, \n"
|
||||
+ "# UserDefined; separated by a space character. \n"
|
||||
+ "# If the line is missing or no value is specified, all\n"
|
||||
+ "# valid targets specified in the FPD file will attempt \n"
|
||||
+ "# to be built. The following line will build all platform\n"
|
||||
+ "# targets.\n";
|
||||
|
||||
private static final String ausage = "\n\n"
|
||||
+ "# TARGET_ARCH List Optional What kind of architecture is the binary being target for.\n"
|
||||
+ "# One, or more, of the following, IA32, IA64, X64, EBC or ARM.\n"
|
||||
+ "# Multiple values can be specified on a single line, using \n"
|
||||
+ "# space charaters to separate the values. These are used \n"
|
||||
+ "# during the parsing of an FPD file, restricting the build\n"
|
||||
+ "# output target(s.)\n"
|
||||
+ "# The Build Target ARCH is determined by a logical AND of:\n"
|
||||
+ "# FPD BuildOptions: <SupportedArchitectures> tag\n"
|
||||
+ "# If not specified, then all valid architectures specified \n"
|
||||
+ "# in the FPD file, for which tools are available, will be \n"
|
||||
+ "# built.\n";
|
||||
|
||||
private static final String cusage = "\n\n"
|
||||
+ "# TOOL_DEFINITION_FILE Filename Optional Specify the name of the filename to use for specifying \n"
|
||||
+ "# the tools to use for the build. If not specified, \n"
|
||||
+ "# tools_def.txt will be used for the build. This file \n"
|
||||
+ "# MUST be located in the WORKSPACE/Tools/Conf directory.\n";
|
||||
|
||||
private static final String nusage = "\n\n"
|
||||
+ "# TAGNAME List Optional Specify the name(s) of the tools_def.txt TagName to use.\n"
|
||||
+ "# If not specified, all applicable TagName tools will be \n"
|
||||
+ "# used for the build. The list uses space character separation.\n";
|
||||
|
||||
private static final String musage = "\n\n"
|
||||
+ "# MULTIPLE_THREAD FLAG Optional Flag to enable multi-thread build. If not specified, default\n"
|
||||
+ "# is \"Disable\". If your computer is multi-core or multiple CPUs,\n"
|
||||
+ "# enabling this feature will bring much benefit. For multi-thread\n"
|
||||
+ "# built, the log will write to ${BUILD_DIR}/build.log.\n"
|
||||
+ "# This feature is only for PLATFORM build, and clean, cleanall or\n"
|
||||
+ "# stand-alone module build is still using the normal way.\n";
|
||||
private static final String meusage = "\n\n"
|
||||
+ "# MAX_CONCURRENT_THREAD_NUMBER NUMBER Optional The number of concurrent threads. Default is 2. Recommend to\n"
|
||||
+ "# set this value to one more than the number of your compurter\n"
|
||||
+ "# cores or CPUs.\n";
|
||||
}
|
219
Tools/Java/Source/Cpptasks/CppTasks.msa
Normal file
219
Tools/Java/Source/Cpptasks/CppTasks.msa
Normal file
@ -0,0 +1,219 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" >
|
||||
<MsaHeader>
|
||||
<ModuleName>CppTasks</ModuleName>
|
||||
<ModuleType>TOOL</ModuleType>
|
||||
<GuidValue>A1DF0266-4962-478e-83C0-F84BE46F11FE</GuidValue>
|
||||
<Version>2.0</Version>
|
||||
<Abstract>This is the EFI/Tiano Tool CppTasks</Abstract>
|
||||
<Description>
|
||||
This is a customized cpptasks which includes EFI extensions for
|
||||
static and dynamic linking, assembly and acp compiles
|
||||
</Description>
|
||||
<Copyright>Copyright 2005-2006, Intel Corporation</Copyright>
|
||||
<License>
|
||||
All rights reserved.
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the
|
||||
BSD License which accompanies this distribution. The full text of the
|
||||
license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
</License>
|
||||
<Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
|
||||
</MsaHeader>
|
||||
<ModuleDefinitions>
|
||||
<SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>
|
||||
<BinaryModule>false</BinaryModule>
|
||||
<OutputFileBasename>NULL</OutputFileBasename>
|
||||
</ModuleDefinitions>
|
||||
<SourceFiles>
|
||||
<Filename>build.xml</Filename>
|
||||
<Filename>cpptasks.mf</Filename>
|
||||
<Filename>cpptasks.tasks</Filename>
|
||||
<Filename>cpptasks.types</Filename>
|
||||
<Filename>javadoc.xml</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/AboutCCTask.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/ArchEnum.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/arm/ADSCCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/arm/ADSLibrarian.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/arm/ADSLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/AslcompilerDef.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/AslcompilerEnum.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/AssemblerDef.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/AssemblerEnum.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/borland/BorlandCCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/borland/BorlandCfgParser.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/borland/BorlandLibrarian.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/borland/BorlandLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/borland/BorlandProcessor.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/borland/BorlandResourceCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/borland/CfgFilenameState.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/borland/ConsumeToSpaceOrNewLine.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/borland/QuoteBranchState.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/CCTask.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/CCTaskProgressMonitor.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compaq/CompaqVisualFortranCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compaq/CompaqVisualFortranLibrarian.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compaq/CompaqVisualFortranLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/AbstractAslcompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/AbstractAssembler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/AbstractCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/AbstractLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/AbstractProcessor.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/Aslcompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/AslcompilerConfiguration.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/Assembler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/AssemblerConfiguration.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/CaptureStreamHandler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/CommandLineAslcompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/CommandLineAslcompilerConfiguration.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/CommandLineAssembler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/CommandLineAssemblerConfiguration.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/CommandLineCCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/CommandLineCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/CommandLineCompilerConfiguration.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/CommandLineFortranCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/CommandLineLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/CommandLineLinkerConfiguration.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/Compiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/CompilerConfiguration.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/Linker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/LinkerConfiguration.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/LinkType.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/PrecompilingCommandLineCCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/PrecompilingCommandLineCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/PrecompilingCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/Processor.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/ProcessorConfiguration.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/compiler/ProgressMonitor.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/CompilerDef.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/CompilerEnum.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/CompilerParam.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/CPUEnum.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/CUtil.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/DependencyInfo.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/DependencyTable.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/devstudio/DevStudioAslcompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/devstudio/DevStudioAssembler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/devstudio/DevStudioCCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/devstudio/DevStudioCompatibleCCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/devstudio/DevStudioCompatibleLibrarian.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/devstudio/DevStudioCompatibleLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/devstudio/DevStudioLibrarian.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/devstudio/DevStudioLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/devstudio/DevStudioMIDLCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/devstudio/DevStudioProcessor.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/devstudio/DevStudioResourceCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/DistributerDef.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/DistributerMap.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/DistributerProtocolEnum.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/FileVisitor.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/AbstractArLibrarian.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/AbstractLdLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/cross/GccCCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/cross/GccLibrarian.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/cross/GccLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/cross/GccProcessor.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/cross/GppLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/cross/LdLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccCCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccLibrarian.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccProcessor.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GppLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/LdLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/GccAssembler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/GccCCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/GccCompatibleCCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/GccLibrarian.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/GccLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/GccProcessor.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/GppLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/gcc/LdLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/hp/aCCCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/hp/aCCLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/ibm/VisualAgeCCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/ibm/VisualAgeLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/intel/IntelLinux32CCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/intel/IntelLinux32Linker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/intel/IntelLinux64CCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/intel/IntelLinux64Linker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/intel/IntelProcessor.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/intel/IntelWin32Aslcompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/intel/IntelWin32CCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/intel/IntelWin32Librarian.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/intel/IntelWin32Linker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/intel/IntelWin64CCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/LinkerDef.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/LinkerEnum.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/LinkerParam.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/ObjectFileCollector.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/OptimizationEnum.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/os390/OS390CCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/os390/OS390Linker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/os390/OS390Processor.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/os400/IccCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/os400/IccLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/os400/IccProcessor.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/OSFamilyEnum.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/OutputTypeEnum.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/parser/AbstractParser.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/parser/AbstractParserState.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/parser/BranchState.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/parser/CaseInsensitiveLetterState.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/parser/CParser.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/parser/FilenameState.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/parser/FortranParser.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/parser/LetterState.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/parser/Parser.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/parser/PostE.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/parser/WhitespaceOrCaseInsensitiveLetterState.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/parser/WhitespaceOrLetterState.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/PrecompileDef.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/PrecompileExceptDef.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/ProcessorDef.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/ProcessorEnumValue.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/ProcessorParam.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/RuntimeType.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/SourceHistory.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/SubsystemEnum.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/sun/C89CCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/sun/C89Linker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/sun/C89Processor.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/sun/ForteCCCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/sun/ForteCCLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/TargetDef.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/TargetHistory.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/TargetHistoryTable.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/TargetInfo.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/TargetMatcher.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/ti/ClxxCCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/ti/ClxxLibrarian.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/ti/ClxxLinker.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/AslcompilerArgument.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/AssemblerArgument.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/CommandLineArgument.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/CompilerArgument.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/ConditionalFileSet.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/ConditionalPath.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/DefineArgument.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/DefineSet.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/FlexLong.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/IncludePath.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/LibrarySet.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/LibraryTypeEnum.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/LinkerArgument.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/SystemIncludePath.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/SystemLibrarySet.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/types/UndefineArgument.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/userdefine/CommandLineUserDefine.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/userdefine/UserDefineArgument.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/userdefine/UserDefineCompiler.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/userdefine/UserDefineDef.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/userdefine/UserDefineMapping.java</Filename>
|
||||
<Filename>net/sf/antcontrib/cpptasks/VersionInfo.java</Filename>
|
||||
</SourceFiles>
|
||||
</ModuleSurfaceArea>
|
56
Tools/Java/Source/Cpptasks/build.xml
Normal file
56
Tools/Java/Source/Cpptasks/build.xml
Normal file
@ -0,0 +1,56 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
-->
|
||||
<project name="CppTasks" default="CppTasks" basedir=".">
|
||||
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
|
||||
<property environment="env"/>
|
||||
<property name="workspace" value="${env.WORKSPACE}"/>
|
||||
<property name="buildDir" value="build"/>
|
||||
<property name="installLocation" value="${workspace}/Tools/Jars"/>
|
||||
<target name="CppTasks" depends="install"/>
|
||||
<target name="init">
|
||||
<uptodate property="jar.newer" targetfile="${installLocation}/cpptasks.jar">
|
||||
<srcfiles dir="net" includes="**"/>
|
||||
</uptodate>
|
||||
</target>
|
||||
<target name="source" depends="init" unless="jar.newer">
|
||||
<mkdir dir="${buildDir}"/>
|
||||
<javac srcdir="net" destdir="${buildDir}" source="1.4">
|
||||
<classpath>
|
||||
<fileset dir="${workspace}/Tools/Jars">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
<target name="clean">
|
||||
<delete dir="${buildDir}"/>
|
||||
</target>
|
||||
<target name="cleanall">
|
||||
<delete dir="${buildDir}"/>
|
||||
<delete file="${installLocation}/cpptasks.jar"/>
|
||||
<if>
|
||||
<available file="${installLocation}/cpptasks.jar"/>
|
||||
<then>
|
||||
<echo message="You must manually remove the file: ${installLocation}/cpptasks.jar"/>
|
||||
<echo message="Java has already loaded the file, and cannot remove it within ANT!"/>
|
||||
</then>
|
||||
</if>
|
||||
</target>
|
||||
<target name="install" depends="source" unless="jar.newer">
|
||||
<copy file="cpptasks.tasks" toDir="${buildDir}"/>
|
||||
<copy file="cpptasks.types" toDir="${buildDir}"/>
|
||||
<jar destfile="${installLocation}/cpptasks.jar"
|
||||
basedir="${buildDir}"
|
||||
includes="**"
|
||||
/>
|
||||
</target>
|
||||
</project>
|
7
Tools/Java/Source/Cpptasks/cpptasks.mf
Normal file
7
Tools/Java/Source/Cpptasks/cpptasks.mf
Normal file
@ -0,0 +1,7 @@
|
||||
Manifest-Version: 2.0
|
||||
Main-Class: net.sf.antcontrib.cpptasks.AboutCCTask
|
||||
|
||||
Name: CCTask
|
||||
Implementation-Vendor: Ant-Contrib project
|
||||
Implementation-Version: 1.0
|
||||
Implementation-Title: Compile and link tasks for Apache Ant
|
1
Tools/Java/Source/Cpptasks/cpptasks.tasks
Normal file
1
Tools/Java/Source/Cpptasks/cpptasks.tasks
Normal file
@ -0,0 +1 @@
|
||||
cc=net.sf.antcontrib.cpptasks.CCTask
|
9
Tools/Java/Source/Cpptasks/cpptasks.types
Normal file
9
Tools/Java/Source/Cpptasks/cpptasks.types
Normal file
@ -0,0 +1,9 @@
|
||||
defineset=net.sf.antcontrib.cpptasks.types.DefineSet
|
||||
compiler=net.sf.antcontrib.cpptasks.CompilerDef
|
||||
linker=net.sf.antcontrib.cpptasks.LinkerDef
|
||||
assembler=net.sf.antcontrib.cpptasks.AssemblerDef
|
||||
aslcompiler=net.sf.antcontrib.cpptasks.AslcompilerDef
|
||||
targetplatform=net.sf.antcontrib.cpptasks.TargetDef
|
||||
versioninfo=net.sf.antcontrib.cpptasks.VersionInfo
|
||||
distributer=net.sf.antcontrib.cpptasks.DistributerDef
|
||||
command=net.sf.antcontrib.cpptasks.userdefine.UserDefineDef
|
30
Tools/Java/Source/Cpptasks/javadoc.xml
Normal file
30
Tools/Java/Source/Cpptasks/javadoc.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
-->
|
||||
<project default="javadoc">
|
||||
<target name="javadoc">
|
||||
|
||||
<javadoc packagenames="net.sf.antcontrib.*"
|
||||
useexternalfile="yes"
|
||||
sourcepath="."
|
||||
destdir="doc"
|
||||
author="true"
|
||||
version="true"
|
||||
source="1.3"
|
||||
locale="en_US"
|
||||
windowtitle="cpptasks API"
|
||||
doctitle="cpptasks">
|
||||
<group title="CCTasks" packages="net.sf.antcontrib.cpptasks" />
|
||||
|
||||
<bottom>Copyright @2001-2005 Ant-Contrib project. All Rights Reserved.</bottom>
|
||||
</javadoc>
|
||||
</target>
|
||||
</project>
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* The equivalent of a Help About
|
||||
* run "java -jar cpptasks.jar" to read
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public class AboutCCTask {
|
||||
/**
|
||||
* display identification message and exit
|
||||
*
|
||||
* @param args ignored
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
System.out.println("CCTask: Compile and link task for Apache Ant 1.5 or later\n");
|
||||
System.out.println("Copyright (c) 2002-2004, The Ant-Contrib project.\n");
|
||||
System.out.println("http://sf.net/projects/ant-contrib\n");
|
||||
System.out.println("Licensed under the Apache Software License 2.0");
|
||||
System.out.println("available at http://www.apache.org/licenses/LICENSE-2.0\n");
|
||||
System.out.println("This software is not a product of the");
|
||||
System.out.println("of the Apache Software Foundation and no");
|
||||
System.out.println("endorsement or promotion is implied.\n");
|
||||
System.out.println("THIS SOFTWARE IS PROVIDED 'AS-IS', See");
|
||||
System.out.println("http://www.apache.org/LICENSE for additional");
|
||||
System.out.println("disclaimers.\n");
|
||||
System.out.println("To use:");
|
||||
System.out.println("\tPlace cpptasks.jar into lib directory of Ant 1.5 or later.");
|
||||
System.out.println("\tAdd <taskdef resource=\"cpptasks.tasks\"/> and");
|
||||
System.out.println("\t\t<typedef resource=\"cpptasks.types\"/> to build.xml");
|
||||
System.out.println("Add <cc/>, <compiler/>, <linker/>, <assembler/> and <aslcompiler> elements.");
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 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;
|
||||
|
||||
import org.apache.tools.ant.types.EnumeratedAttribute;
|
||||
|
||||
/**
|
||||
* Enumeration of cpu architecture types.
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*
|
||||
*/
|
||||
public final class ArchEnum
|
||||
extends EnumeratedAttribute {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Set by default to "pentium3"
|
||||
*
|
||||
* @see java.lang.Object#Object()
|
||||
*/
|
||||
public ArchEnum() {
|
||||
setValue("pentium3");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets list of acceptable values.
|
||||
*
|
||||
* @see org.apache.tools.ant.types.EnumeratedAttribute#getValues()
|
||||
*/
|
||||
public String[] getValues() {
|
||||
/**
|
||||
* Class initializer.
|
||||
*/
|
||||
return new String[] {
|
||||
"i386",
|
||||
"i486",
|
||||
"i586",
|
||||
"i686",
|
||||
"pentium",
|
||||
"pentium-mmx",
|
||||
"pentiumpro",
|
||||
"pentium2",
|
||||
"pentium3",
|
||||
"pentium4",
|
||||
"k6",
|
||||
"k6-2",
|
||||
"k6-3",
|
||||
"athlon",
|
||||
"athlon-tbird",
|
||||
"athlon-4",
|
||||
"athlon-xp",
|
||||
"athlon-mp",
|
||||
"winchip-c6",
|
||||
"winchip2",
|
||||
"c3"};
|
||||
}
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2001-2005 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;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.compiler.Aslcompiler;
|
||||
import net.sf.antcontrib.cpptasks.compiler.Processor;
|
||||
import net.sf.antcontrib.cpptasks.intel.IntelWin32Aslcompiler;
|
||||
import net.sf.antcontrib.cpptasks.types.AslcompilerArgument;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
/**
|
||||
* A asl compiler definition. asl compiler elements may be placed either as
|
||||
* children of a cc element or the project element. A asl compiler element with
|
||||
* an id attribute may be referenced from asl compiler elements with refid or
|
||||
* extends attributes.
|
||||
*
|
||||
*/
|
||||
public final class AslcompilerDef extends ProcessorDef {
|
||||
|
||||
private Boolean defaultflag = new Boolean(true);
|
||||
|
||||
public AslcompilerDef () {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a asl compiler command-line arg.
|
||||
*/
|
||||
public void addConfiguredAslcompilerArg(AslcompilerArgument arg) {
|
||||
if (isReference()) {
|
||||
throw noChildrenAllowed();
|
||||
}
|
||||
addConfiguredProcessorArg(arg);
|
||||
}
|
||||
|
||||
public void execute() throws org.apache.tools.ant.BuildException {
|
||||
throw new org.apache.tools.ant.BuildException(
|
||||
"Not an actual task, but looks like one for documentation purposes");
|
||||
}
|
||||
|
||||
public final Boolean getDefaultflag(AslcompilerDef[] defaultProviders,
|
||||
int index) {
|
||||
if (isReference()) {
|
||||
return ((AslcompilerDef) getCheckedRef(AslcompilerDef.class,
|
||||
"AslcompilerDef")).getDefaultflag(defaultProviders,
|
||||
index);
|
||||
}
|
||||
return defaultflag;
|
||||
}
|
||||
|
||||
public Processor getProcessor() {
|
||||
Processor processor = super.getProcessor();
|
||||
if (processor == null) {
|
||||
processor = IntelWin32Aslcompiler.getInstance();
|
||||
}
|
||||
return processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets r type.
|
||||
*
|
||||
* <table width="100%" border="1"> <thead>Supported ASL Compilers</thead>
|
||||
* <tr>
|
||||
* <td>iasl (default)</td>
|
||||
* <td>Intel ACPI Source Language</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>asl</td>
|
||||
* <td>Microsoft ACPI Source Language</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
*/
|
||||
public void setName(AslcompilerEnum name) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
Aslcompiler aslcompiler = name.getAslcompiler();
|
||||
setProcessor(aslcompiler);
|
||||
}
|
||||
|
||||
protected void setProcessor(Processor proc) throws BuildException {
|
||||
try {
|
||||
super.setProcessor((Aslcompiler) proc);
|
||||
} catch (ClassCastException ex) {
|
||||
throw new BuildException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables default flags.
|
||||
*
|
||||
* @param defaultflag
|
||||
* if true, default flags will add to command line.
|
||||
*
|
||||
*/
|
||||
public void setDefaultflag(boolean defaultflag) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.defaultflag = booleanValueOf(defaultflag);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2001-2005 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;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.compiler.Aslcompiler;
|
||||
import net.sf.antcontrib.cpptasks.devstudio.DevStudioAslcompiler;
|
||||
import net.sf.antcontrib.cpptasks.intel.IntelWin32Aslcompiler;
|
||||
|
||||
import org.apache.tools.ant.types.EnumeratedAttribute;
|
||||
|
||||
/**
|
||||
* Enumeration of supported ASL Compilers
|
||||
*
|
||||
* <table width="100%" border="1"> <thead>Supported ASL Compilers </thead>
|
||||
* <tr>
|
||||
* <td>iasl (default)</td>
|
||||
* <td>Intel ACPI Source Language</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>asl</td>
|
||||
* <td>Microsoft ACPI Source Language</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
*/
|
||||
public class AslcompilerEnum extends EnumeratedAttribute {
|
||||
private final static ProcessorEnumValue[] aslcompiler = new ProcessorEnumValue[] {
|
||||
new ProcessorEnumValue("iasl", IntelWin32Aslcompiler
|
||||
.getInstance()),
|
||||
new ProcessorEnumValue("asl", DevStudioAslcompiler
|
||||
.getInstance()), };
|
||||
|
||||
public Aslcompiler getAslcompiler() {
|
||||
return (Aslcompiler) aslcompiler[getIndex()].getProcessor();
|
||||
}
|
||||
|
||||
public String[] getValues() {
|
||||
return ProcessorEnumValue.getValues(aslcompiler);
|
||||
}
|
||||
}
|
@ -0,0 +1,237 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2001-2005 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;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.compiler.Assembler;
|
||||
import net.sf.antcontrib.cpptasks.compiler.Processor;
|
||||
import net.sf.antcontrib.cpptasks.gcc.GccAssembler;
|
||||
import net.sf.antcontrib.cpptasks.types.AssemblerArgument;
|
||||
import net.sf.antcontrib.cpptasks.types.ConditionalPath;
|
||||
import net.sf.antcontrib.cpptasks.types.IncludePath;
|
||||
import net.sf.antcontrib.cpptasks.types.SystemIncludePath;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
|
||||
/**
|
||||
* A assembler definition. Assembler elements may be placed either as children
|
||||
* of a cc element or the project element. A assembler element with an id
|
||||
* attribute may be referenced from assembler elements with refid or extends
|
||||
* attributes.
|
||||
*
|
||||
*/
|
||||
public final class AssemblerDef extends ProcessorDef {
|
||||
|
||||
private final Vector includePaths = new Vector();
|
||||
|
||||
private final Vector sysIncludePaths = new Vector();
|
||||
|
||||
private Boolean defaultflag = new Boolean(true);
|
||||
|
||||
public AssemblerDef () {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a assembler command-line arg.
|
||||
*/
|
||||
public void addConfiguredAssemblerArg(AssemblerArgument arg) {
|
||||
if (isReference()) {
|
||||
throw noChildrenAllowed();
|
||||
}
|
||||
addConfiguredProcessorArg(arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an include path.
|
||||
*/
|
||||
public IncludePath createIncludePath() {
|
||||
Project p = getProject();
|
||||
if (p == null) {
|
||||
throw new java.lang.IllegalStateException("project must be set");
|
||||
}
|
||||
if (isReference()) {
|
||||
throw noChildrenAllowed();
|
||||
}
|
||||
IncludePath path = new IncludePath(p);
|
||||
includePaths.addElement(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an include path.
|
||||
*/
|
||||
public SystemIncludePath createSysIncludePath() {
|
||||
Project p = getProject();
|
||||
if (p == null) {
|
||||
throw new java.lang.IllegalStateException("project must be set");
|
||||
}
|
||||
if (isReference()) {
|
||||
throw noChildrenAllowed();
|
||||
}
|
||||
SystemIncludePath path = new SystemIncludePath(p);
|
||||
sysIncludePaths.addElement(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a <includepath>or <sysincludepath> if specify the file attribute
|
||||
*
|
||||
* @throws BuildException
|
||||
* if the specify file not exist
|
||||
*/
|
||||
protected void loadFile(Vector activePath, File file) throws BuildException {
|
||||
FileReader fileReader;
|
||||
BufferedReader in;
|
||||
String str;
|
||||
if (!file.exists()) {
|
||||
throw new BuildException("The file " + file + " is not existed");
|
||||
}
|
||||
try {
|
||||
fileReader = new FileReader(file);
|
||||
in = new BufferedReader(fileReader);
|
||||
while ((str = in.readLine()) != null) {
|
||||
if (str.trim() == "") {
|
||||
continue;
|
||||
}
|
||||
str = getProject().replaceProperties(str);
|
||||
activePath.addElement(str.trim());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new BuildException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void execute() throws org.apache.tools.ant.BuildException {
|
||||
throw new org.apache.tools.ant.BuildException(
|
||||
"Not an actual task, but looks like one for documentation purposes");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assembler-specific include path.
|
||||
*/
|
||||
public String[] getActiveIncludePaths() {
|
||||
if (isReference()) {
|
||||
return ((AssemblerDef) getCheckedRef(AssemblerDef.class,
|
||||
"AssemblerDef")).getActiveIncludePaths();
|
||||
}
|
||||
return getActivePaths(includePaths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assembler-specific sysinclude path.
|
||||
*/
|
||||
public String[] getActiveSysIncludePaths() {
|
||||
if (isReference()) {
|
||||
return ((AssemblerDef) getCheckedRef(AssemblerDef.class,
|
||||
"AssemblerDef")).getActiveSysIncludePaths();
|
||||
}
|
||||
return getActivePaths(sysIncludePaths);
|
||||
}
|
||||
|
||||
private String[] getActivePaths(Vector paths) {
|
||||
Project p = getProject();
|
||||
if (p == null) {
|
||||
throw new java.lang.IllegalStateException("project not set");
|
||||
}
|
||||
Vector activePaths = new Vector(paths.size());
|
||||
for (int i = 0; i < paths.size(); i++) {
|
||||
ConditionalPath path = (ConditionalPath) paths.elementAt(i);
|
||||
if (path.isActive(p)) {
|
||||
if (path.getFile() == null) {
|
||||
String[] pathEntries = path.list();
|
||||
for (int j = 0; j < pathEntries.length; j++) {
|
||||
activePaths.addElement(pathEntries[j]);
|
||||
}
|
||||
} else {
|
||||
loadFile(activePaths, path.getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
String[] pathNames = new String[activePaths.size()];
|
||||
activePaths.copyInto(pathNames);
|
||||
return pathNames;
|
||||
}
|
||||
|
||||
public final Boolean getDefaultflag(AssemblerDef[] defaultProviders,
|
||||
int index) {
|
||||
if (isReference()) {
|
||||
return ((AssemblerDef) getCheckedRef(AssemblerDef.class,
|
||||
"AssemblerDef")).getDefaultflag(defaultProviders,
|
||||
index);
|
||||
}
|
||||
return defaultflag;
|
||||
}
|
||||
|
||||
public Processor getProcessor() {
|
||||
Processor processor = super.getProcessor();
|
||||
if (processor == null) {
|
||||
processor = GccAssembler.getInstance();
|
||||
}
|
||||
return processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets r type.
|
||||
*
|
||||
* <table width="100%" border="1"> <thead>Supported assemblers</thead>
|
||||
* <tr>
|
||||
* <td>gcc (default)</td>
|
||||
* <td>GAS assembler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>masm</td>
|
||||
* <td>MASM assembler</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
*/
|
||||
public void setName(AssemblerEnum name) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
Assembler assembler = name.getAssembler();
|
||||
setProcessor(assembler);
|
||||
}
|
||||
|
||||
protected void setProcessor(Processor proc) throws BuildException {
|
||||
try {
|
||||
super.setProcessor((Assembler) proc);
|
||||
} catch (ClassCastException ex) {
|
||||
throw new BuildException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables default flags.
|
||||
*
|
||||
* @param defaultflag
|
||||
* if true, default flags will add to command line.
|
||||
*
|
||||
*/
|
||||
public void setDefaultflag(boolean defaultflag) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.defaultflag = booleanValueOf(defaultflag);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2001-2005 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;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.compiler.Assembler;
|
||||
import net.sf.antcontrib.cpptasks.devstudio.DevStudioAssembler;
|
||||
import net.sf.antcontrib.cpptasks.gcc.GccAssembler;
|
||||
|
||||
import org.apache.tools.ant.types.EnumeratedAttribute;
|
||||
|
||||
/**
|
||||
* Enumeration of supported assemblers
|
||||
*
|
||||
* <table width="100%" border="1"> <thead>Supported assemblers </thead>
|
||||
* <tr>
|
||||
* <td>gas (default)</td>
|
||||
* <td>GAS assembler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>masm</td>
|
||||
* <td>MASM assembler</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
*/
|
||||
public class AssemblerEnum extends EnumeratedAttribute {
|
||||
private final static ProcessorEnumValue[] assemblers = new ProcessorEnumValue[] {
|
||||
new ProcessorEnumValue("gas", GccAssembler.getInstance()),
|
||||
new ProcessorEnumValue("masm", DevStudioAssembler
|
||||
.getInstance()), };
|
||||
|
||||
public Assembler getAssembler() {
|
||||
return (Assembler) assemblers[getIndex()].getProcessor();
|
||||
}
|
||||
|
||||
public String[] getValues() {
|
||||
return ProcessorEnumValue.getValues(assemblers);
|
||||
}
|
||||
}
|
1749
Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/CCTask.java
Normal file
1749
Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/CCTask.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,56 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration;
|
||||
import net.sf.antcontrib.cpptasks.compiler.ProgressMonitor;
|
||||
public class CCTaskProgressMonitor implements ProgressMonitor {
|
||||
private ProcessorConfiguration config;
|
||||
private TargetHistoryTable history;
|
||||
private long lastCommit = -1;
|
||||
public CCTaskProgressMonitor(TargetHistoryTable history) {
|
||||
this.history = history;
|
||||
}
|
||||
public void finish(ProcessorConfiguration config, boolean normal) {
|
||||
long current = System.currentTimeMillis();
|
||||
if ((current - lastCommit) > 120000) {
|
||||
try {
|
||||
history.commit();
|
||||
lastCommit = System.currentTimeMillis();
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
public void progress(String[] sources) {
|
||||
history.update(config, sources);
|
||||
long current = System.currentTimeMillis();
|
||||
if ((current - lastCommit) > 120000) {
|
||||
try {
|
||||
history.commit();
|
||||
lastCommit = current;
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
public void start(ProcessorConfiguration config) {
|
||||
if (lastCommit < 0) {
|
||||
lastCommit = System.currentTimeMillis();
|
||||
}
|
||||
this.config = config;
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 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;
|
||||
|
||||
import org.apache.tools.ant.types.EnumeratedAttribute;
|
||||
|
||||
/**
|
||||
* Enumeration of cpu types.
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*
|
||||
*/
|
||||
public final class CPUEnum
|
||||
extends EnumeratedAttribute {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Set by default to "pentium3"
|
||||
*
|
||||
* @see java.lang.Object#Object()
|
||||
*/
|
||||
public CPUEnum() {
|
||||
setValue("pentium3");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets list of acceptable values.
|
||||
*
|
||||
* @see org.apache.tools.ant.types.EnumeratedAttribute#getValues()
|
||||
*/
|
||||
public String[] getValues() {
|
||||
return new String[] {
|
||||
"i386",
|
||||
"i486",
|
||||
"i586",
|
||||
"i686",
|
||||
"pentium",
|
||||
"pentium-mmx",
|
||||
"pentiumpro",
|
||||
"pentium2",
|
||||
"pentium3",
|
||||
"pentium4",
|
||||
"k6",
|
||||
"k6-2",
|
||||
"k6-3",
|
||||
"athlon",
|
||||
"athlon-tbird",
|
||||
"athlon-4",
|
||||
"athlon-xp",
|
||||
"athlon-mp",
|
||||
"winchip-c6",
|
||||
"winchip2",
|
||||
"c3" };
|
||||
}
|
||||
|
||||
}
|
461
Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/CUtil.java
Normal file
461
Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/CUtil.java
Normal file
@ -0,0 +1,461 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.taskdefs.Execute;
|
||||
import org.apache.tools.ant.taskdefs.LogStreamHandler;
|
||||
import org.apache.tools.ant.types.Commandline;
|
||||
import org.apache.tools.ant.types.Environment;
|
||||
/**
|
||||
* Some utilities used by the CC and Link tasks.
|
||||
*
|
||||
* @author Adam Murdoch
|
||||
*/
|
||||
public class CUtil {
|
||||
/**
|
||||
* A class that splits a white-space, comma-separated list into a String
|
||||
* array. Used for task attributes.
|
||||
*/
|
||||
public static final class StringArrayBuilder {
|
||||
private String[] _value;
|
||||
public StringArrayBuilder(String value) {
|
||||
// Split the defines up
|
||||
StringTokenizer tokens = new StringTokenizer(value, ", ");
|
||||
Vector vallist = new Vector();
|
||||
while (tokens.hasMoreTokens()) {
|
||||
String val = tokens.nextToken().trim();
|
||||
if (val.length() == 0) {
|
||||
continue;
|
||||
}
|
||||
vallist.addElement(val);
|
||||
}
|
||||
_value = new String[vallist.size()];
|
||||
vallist.copyInto(_value);
|
||||
}
|
||||
public String[] getValue() {
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds the elements of the array to the given vector
|
||||
*/
|
||||
public static void addAll(Vector dest, Object[] src) {
|
||||
if (src == null) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < src.length; i++) {
|
||||
dest.addElement(src[i]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks a array of names for non existent or non directory entries and
|
||||
* nulls them out.
|
||||
*
|
||||
* @return Count of non-null elements
|
||||
*/
|
||||
public static int checkDirectoryArray(String[] names) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
if (names[i] != null) {
|
||||
File dir = new File(names[i]);
|
||||
if (dir.exists() && dir.isDirectory()) {
|
||||
count++;
|
||||
} else {
|
||||
names[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
/**
|
||||
* Extracts the basename of a file, removing the extension, if present
|
||||
*/
|
||||
public static String getBasename(File file) {
|
||||
String path = file.getPath();
|
||||
// Remove the extension
|
||||
String basename = file.getName();
|
||||
int pos = basename.lastIndexOf('.');
|
||||
if (pos != -1) {
|
||||
basename = basename.substring(0, pos);
|
||||
}
|
||||
return basename;
|
||||
}
|
||||
/**
|
||||
* Gets the parent directory for the executable file name using the current
|
||||
* directory and system executable path
|
||||
*
|
||||
* @param exeName
|
||||
* Name of executable such as "cl.exe"
|
||||
* @return parent directory or null if not located
|
||||
*/
|
||||
public static File getExecutableLocation(String exeName) {
|
||||
//
|
||||
// must add current working directory to the
|
||||
// from of the path from the "path" environment variable
|
||||
File currentDir = new File(System.getProperty("user.dir"));
|
||||
if (new File(currentDir, exeName).exists()) {
|
||||
return currentDir;
|
||||
}
|
||||
File[] envPath = CUtil.getPathFromEnvironment("PATH",
|
||||
File.pathSeparator);
|
||||
for (int i = 0; i < envPath.length; i++) {
|
||||
if (new File(envPath[i], exeName).exists()) {
|
||||
return envPath[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Extracts the parent of a file
|
||||
*/
|
||||
public static String getParentPath(String path) {
|
||||
int pos = path.lastIndexOf(File.separator);
|
||||
if (pos <= 0) {
|
||||
return null;
|
||||
}
|
||||
return path.substring(0, pos);
|
||||
}
|
||||
/**
|
||||
* Returns an array of File for each existing directory in the specified
|
||||
* environment variable
|
||||
*
|
||||
* @param envVariable
|
||||
* environment variable name such as "LIB" or "INCLUDE"
|
||||
* @param delim
|
||||
* delimitor used to separate parts of the path, typically ";"
|
||||
* or ":"
|
||||
* @return array of File's for each part that is an existing directory
|
||||
*/
|
||||
public static File[] getPathFromEnvironment(String envVariable, String delim) {
|
||||
// OS/4000 does not support the env command.
|
||||
if (System.getProperty("os.name").equals("OS/400"))
|
||||
return new File[]{};
|
||||
Vector osEnv = Execute.getProcEnvironment();
|
||||
String match = envVariable.concat("=");
|
||||
for (Enumeration e = osEnv.elements(); e.hasMoreElements();) {
|
||||
String entry = ((String) e.nextElement()).trim();
|
||||
if (entry.length() > match.length()) {
|
||||
String entryFrag = entry.substring(0, match.length());
|
||||
if (entryFrag.equalsIgnoreCase(match)) {
|
||||
String path = entry.substring(match.length());
|
||||
return parsePath(path, delim);
|
||||
}
|
||||
}
|
||||
}
|
||||
File[] noPath = new File[0];
|
||||
return noPath;
|
||||
}
|
||||
/**
|
||||
* Returns a relative path for the targetFile relative to the base
|
||||
* directory.
|
||||
*
|
||||
* @param canonicalBase
|
||||
* base directory as returned by File.getCanonicalPath()
|
||||
* @param targetFile
|
||||
* target file
|
||||
* @return relative path of target file. Returns targetFile if there were
|
||||
* no commonalities between the base and the target
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public static String getRelativePath(String base, File targetFile) {
|
||||
try {
|
||||
//
|
||||
// remove trailing file separator
|
||||
//
|
||||
String canonicalBase = base;
|
||||
if (base.charAt(base.length() - 1) == File.separatorChar) {
|
||||
canonicalBase = base.substring(0, base.length() - 1);
|
||||
}
|
||||
//
|
||||
// get canonical name of target and remove trailing separator
|
||||
//
|
||||
String canonicalTarget;
|
||||
if (System.getProperty("os.name").equals("OS/400"))
|
||||
canonicalTarget = targetFile.getPath();
|
||||
else
|
||||
canonicalTarget = targetFile.getCanonicalPath();
|
||||
if (canonicalTarget.charAt(canonicalTarget.length() - 1) == File.separatorChar) {
|
||||
canonicalTarget = canonicalTarget.substring(0, canonicalTarget
|
||||
.length() - 1);
|
||||
}
|
||||
if (canonicalTarget.equals(canonicalBase)) {
|
||||
return ".";
|
||||
}
|
||||
//
|
||||
// see if the prefixes are the same
|
||||
//
|
||||
if (canonicalBase.substring(0, 2).equals("\\\\")) {
|
||||
//
|
||||
// UNC file name, if target file doesn't also start with same
|
||||
// server name, don't go there
|
||||
int endPrefix = canonicalBase.indexOf('\\', 2);
|
||||
String prefix1 = canonicalBase.substring(0, endPrefix);
|
||||
String prefix2 = canonicalTarget.substring(0, endPrefix);
|
||||
if (!prefix1.equals(prefix2)) {
|
||||
return canonicalTarget;
|
||||
}
|
||||
} else {
|
||||
if (canonicalBase.substring(1, 3).equals(":\\")) {
|
||||
int endPrefix = 2;
|
||||
String prefix1 = canonicalBase.substring(0, endPrefix);
|
||||
String prefix2 = canonicalTarget.substring(0, endPrefix);
|
||||
if (!prefix1.equals(prefix2)) {
|
||||
return canonicalTarget;
|
||||
}
|
||||
} else {
|
||||
if (canonicalBase.charAt(0) == '/') {
|
||||
if (canonicalTarget.charAt(0) != '/') {
|
||||
return canonicalTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
char separator = File.separatorChar;
|
||||
int lastSeparator = -1;
|
||||
int minLength = canonicalBase.length();
|
||||
if (canonicalTarget.length() < minLength) {
|
||||
minLength = canonicalTarget.length();
|
||||
}
|
||||
int firstDifference = minLength + 1;
|
||||
//
|
||||
// walk to the shorter of the two paths
|
||||
// finding the last separator they have in common
|
||||
for (int i = 0; i < minLength; i++) {
|
||||
if (canonicalTarget.charAt(i) == canonicalBase.charAt(i)) {
|
||||
if (canonicalTarget.charAt(i) == separator) {
|
||||
lastSeparator = i;
|
||||
}
|
||||
} else {
|
||||
firstDifference = lastSeparator + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
StringBuffer relativePath = new StringBuffer(50);
|
||||
//
|
||||
// walk from the first difference to the end of the base
|
||||
// adding "../" for each separator encountered
|
||||
//
|
||||
if (canonicalBase.length() > firstDifference) {
|
||||
relativePath.append("..");
|
||||
for (int i = firstDifference; i < canonicalBase.length(); i++) {
|
||||
if (canonicalBase.charAt(i) == separator) {
|
||||
relativePath.append(separator);
|
||||
relativePath.append("..");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (canonicalTarget.length() > firstDifference) {
|
||||
//
|
||||
// append the rest of the target
|
||||
//
|
||||
//
|
||||
if (relativePath.length() > 0) {
|
||||
relativePath.append(separator);
|
||||
}
|
||||
relativePath.append(canonicalTarget.substring(firstDifference));
|
||||
}
|
||||
return relativePath.toString();
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
return targetFile.toString();
|
||||
}
|
||||
public static boolean isActive(Project p, String ifCond, String unlessCond)
|
||||
throws BuildException {
|
||||
if (ifCond != null) {
|
||||
String ifValue = p.getProperty(ifCond);
|
||||
if (ifValue == null) {
|
||||
return false;
|
||||
} else {
|
||||
if (ifValue.equals("false") || ifValue.equals("no")) {
|
||||
throw new BuildException("if condition \"" + ifCond
|
||||
+ "\" has suspicious value \"" + ifValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (unlessCond != null) {
|
||||
String unlessValue = p.getProperty(unlessCond);
|
||||
if (unlessValue != null) {
|
||||
if (unlessValue.equals("false") || unlessValue.equals("no")) {
|
||||
throw new BuildException("unless condition \"" + unlessCond
|
||||
+ "\" has suspicious value \"" + unlessValue);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Parse a string containing directories into an File[]
|
||||
*
|
||||
* @param path
|
||||
* path string, for example ".;c:\something\include"
|
||||
* @param delim
|
||||
* delimiter, typically ; or :
|
||||
*/
|
||||
public static File[] parsePath(String path, String delim) {
|
||||
Vector libpaths = new Vector();
|
||||
int delimPos = 0;
|
||||
for (int startPos = 0; startPos < path.length(); startPos = delimPos
|
||||
+ delim.length()) {
|
||||
delimPos = path.indexOf(delim, startPos);
|
||||
if (delimPos < 0) {
|
||||
delimPos = path.length();
|
||||
}
|
||||
//
|
||||
// don't add an entry for zero-length paths
|
||||
//
|
||||
if (delimPos > startPos) {
|
||||
String dirName = path.substring(startPos, delimPos);
|
||||
File dir = new File(dirName);
|
||||
if (dir.exists() && dir.isDirectory()) {
|
||||
libpaths.addElement(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
File[] paths = new File[libpaths.size()];
|
||||
libpaths.copyInto(paths);
|
||||
return paths;
|
||||
}
|
||||
/**
|
||||
* This method is exposed so test classes can overload and test the
|
||||
* arguments without actually spawning the compiler
|
||||
*/
|
||||
public static int runCommand(CCTask task, File workingDir,
|
||||
String[] cmdline, boolean newEnvironment, Environment env)
|
||||
throws BuildException {
|
||||
try {
|
||||
task.log(Commandline.toString(cmdline), Project.MSG_VERBOSE);
|
||||
Execute exe = new Execute(new LogStreamHandler(task,
|
||||
Project.MSG_INFO, Project.MSG_ERR));
|
||||
if (System.getProperty("os.name").equals("OS/390"))
|
||||
exe.setVMLauncher(false);
|
||||
exe.setAntRun(task.getProject());
|
||||
exe.setCommandline(cmdline);
|
||||
exe.setWorkingDirectory(workingDir);
|
||||
if (env != null) {
|
||||
String[] environment = env.getVariables();
|
||||
if (environment != null) {
|
||||
for (int i = 0; i < environment.length; i++) {
|
||||
task.log("Setting environment variable: "
|
||||
+ environment[i], Project.MSG_VERBOSE);
|
||||
}
|
||||
}
|
||||
exe.setEnvironment(environment);
|
||||
}
|
||||
exe.setNewenvironment(newEnvironment);
|
||||
return exe.execute();
|
||||
} catch (java.io.IOException exc) {
|
||||
throw new BuildException("Could not launch " + cmdline[0] + ": "
|
||||
+ exc, task.getLocation());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Compares the contents of 2 arrays for equaliy.
|
||||
*/
|
||||
public static boolean sameList(Object[] a, Object[] b) {
|
||||
if (a == null || b == null || a.length != b.length) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
if (!a[i].equals(b[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Compares the contents of an array and a Vector for equality.
|
||||
*/
|
||||
public static boolean sameList(Vector v, Object[] a) {
|
||||
if (v == null || a == null || v.size() != a.length) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
Object o = a[i];
|
||||
if (!o.equals(v.elementAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Compares the contents of an array and a Vector for set equality. Assumes
|
||||
* input array and vector are sets (i.e. no duplicate entries)
|
||||
*/
|
||||
public static boolean sameSet(Object[] a, Vector b) {
|
||||
if (a == null || b == null || a.length != b.size()) {
|
||||
return false;
|
||||
}
|
||||
if (a.length == 0) {
|
||||
return true;
|
||||
}
|
||||
// Convert the array into a set
|
||||
Hashtable t = new Hashtable();
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
t.put(a[i], a[i]);
|
||||
}
|
||||
for (int i = 0; i < b.size(); i++) {
|
||||
Object o = b.elementAt(i);
|
||||
if (t.remove(o) == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return (t.size() == 0);
|
||||
}
|
||||
/**
|
||||
* Converts a vector to a string array.
|
||||
*/
|
||||
public static String[] toArray(Vector src) {
|
||||
String[] retval = new String[src.size()];
|
||||
src.copyInto(retval);
|
||||
return retval;
|
||||
}
|
||||
/**
|
||||
* Replaces any embedded quotes in the string so that the value can be
|
||||
* placed in an attribute in an XML file
|
||||
*
|
||||
* @param attrValue
|
||||
* value to be expressed
|
||||
* @return equivalent attribute literal
|
||||
*
|
||||
*/
|
||||
public static String xmlAttribEncode(String attrValue) {
|
||||
int quotePos = attrValue.indexOf('\"');
|
||||
if (quotePos < 0) {
|
||||
return attrValue;
|
||||
}
|
||||
int startPos = 0;
|
||||
StringBuffer buf = new StringBuffer(attrValue.length() + 20);
|
||||
while (quotePos >= 0) {
|
||||
buf.append(attrValue.substring(startPos, quotePos));
|
||||
buf.append(""");
|
||||
startPos = quotePos + 1;
|
||||
quotePos = attrValue.indexOf('\"', startPos);
|
||||
}
|
||||
buf.append(attrValue.substring(startPos));
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,556 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.compiler.CommandLineCompiler;
|
||||
import net.sf.antcontrib.cpptasks.compiler.Compiler;
|
||||
import net.sf.antcontrib.cpptasks.compiler.Processor;
|
||||
import net.sf.antcontrib.cpptasks.gcc.GccCCompiler;
|
||||
import net.sf.antcontrib.cpptasks.types.CompilerArgument;
|
||||
import net.sf.antcontrib.cpptasks.types.ConditionalPath;
|
||||
import net.sf.antcontrib.cpptasks.types.DefineSet;
|
||||
import net.sf.antcontrib.cpptasks.types.IncludePath;
|
||||
import net.sf.antcontrib.cpptasks.types.SystemIncludePath;
|
||||
import net.sf.antcontrib.cpptasks.types.UndefineArgument;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.types.EnumeratedAttribute;
|
||||
import org.apache.tools.ant.*;
|
||||
/**
|
||||
* A compiler definition. compiler elements may be placed either as children of
|
||||
* a cc element or the project element. A compiler element with an id attribute
|
||||
* may be referenced from compiler elements with refid or extends attributes.
|
||||
*
|
||||
* @author Adam Murdoch
|
||||
*/
|
||||
public final class CompilerDef extends ProcessorDef {
|
||||
/**
|
||||
* Enumerated attribute with the values "none", "severe", "default",
|
||||
* "production", "diagnostic", and "failtask".
|
||||
*/
|
||||
public static class WarningLevel extends EnumeratedAttribute {
|
||||
public String[] getValues() {
|
||||
return new String[]{"none", "severe", "default", "production",
|
||||
"diagnostic", "aserror"};
|
||||
}
|
||||
}
|
||||
/** The source file sets. */
|
||||
private final Vector defineSets = new Vector();
|
||||
private Boolean exceptions;
|
||||
private Boolean rtti;
|
||||
private final Vector includePaths = new Vector();
|
||||
private Boolean multithreaded;
|
||||
private final Vector precompileDefs = new Vector();
|
||||
private final Vector sysIncludePaths = new Vector();
|
||||
private OptimizationEnum optimization;
|
||||
private int warnings = -1;
|
||||
private Boolean defaultflag = new Boolean(true);
|
||||
public CompilerDef() {
|
||||
}
|
||||
/**
|
||||
* Adds a compiler command-line arg.
|
||||
*/
|
||||
public void addConfiguredCompilerArg(CompilerArgument arg) {
|
||||
if (isReference()) {
|
||||
throw noChildrenAllowed();
|
||||
}
|
||||
addConfiguredProcessorArg(arg);
|
||||
}
|
||||
/**
|
||||
* Adds a compiler command-line arg.
|
||||
*/
|
||||
public void addConfiguredCompilerParam(CompilerParam param) {
|
||||
if (isReference()) {
|
||||
throw noChildrenAllowed();
|
||||
}
|
||||
addConfiguredProcessorParam(param);
|
||||
}
|
||||
/**
|
||||
* Adds a defineset.
|
||||
*/
|
||||
public void addConfiguredDefineset(DefineSet defs) {
|
||||
if (defs == null) {
|
||||
throw new NullPointerException("defs");
|
||||
}
|
||||
if (isReference()) {
|
||||
throw noChildrenAllowed();
|
||||
}
|
||||
defineSets.addElement(defs);
|
||||
}
|
||||
/**
|
||||
* Creates an include path.
|
||||
*/
|
||||
public IncludePath createIncludePath() {
|
||||
Project p = getProject();
|
||||
if (p == null) {
|
||||
throw new java.lang.IllegalStateException("project must be set");
|
||||
}
|
||||
if (isReference()) {
|
||||
throw noChildrenAllowed();
|
||||
}
|
||||
IncludePath path = new IncludePath(p);
|
||||
includePaths.addElement(path);
|
||||
return path;
|
||||
}
|
||||
/**
|
||||
* Add a <includepath>or <sysincludepath> if specify the file
|
||||
* attribute
|
||||
*
|
||||
* @throws BuildException
|
||||
* if the specify file not exist
|
||||
*/
|
||||
protected void loadFile(Vector activePath,File file) throws BuildException {
|
||||
FileReader fileReader;
|
||||
BufferedReader in;
|
||||
String str;
|
||||
if (! file.exists()){
|
||||
throw new BuildException("The file " + file + " is not existed");
|
||||
}
|
||||
try {
|
||||
fileReader = new FileReader(file);
|
||||
in = new BufferedReader(fileReader);
|
||||
while ( (str = in.readLine()) != null ){
|
||||
if(str.trim() == ""){
|
||||
continue ;
|
||||
}
|
||||
str = getProject().replaceProperties(str);
|
||||
activePath.addElement(str.trim());
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
throw new BuildException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies precompilation prototype file and exclusions.
|
||||
*
|
||||
*/
|
||||
public PrecompileDef createPrecompile() throws BuildException {
|
||||
Project p = getProject();
|
||||
if (isReference()) {
|
||||
throw noChildrenAllowed();
|
||||
}
|
||||
PrecompileDef precomp = new PrecompileDef();
|
||||
precomp.setProject(p);
|
||||
precompileDefs.addElement(precomp);
|
||||
return precomp;
|
||||
}
|
||||
/**
|
||||
* Creates a system include path. Locations and timestamps of files located
|
||||
* using the system include paths are not used in dependency analysis.
|
||||
*
|
||||
*
|
||||
* Standard include locations should not be specified. The compiler
|
||||
* adapters should recognized the settings from the appropriate environment
|
||||
* variables or configuration files.
|
||||
*/
|
||||
public SystemIncludePath createSysIncludePath() {
|
||||
Project p = getProject();
|
||||
if (p == null) {
|
||||
throw new java.lang.IllegalStateException("project must be set");
|
||||
}
|
||||
if (isReference()) {
|
||||
throw noChildrenAllowed();
|
||||
}
|
||||
SystemIncludePath path = new SystemIncludePath(p);
|
||||
sysIncludePaths.addElement(path);
|
||||
return path;
|
||||
}
|
||||
public void execute() throws org.apache.tools.ant.BuildException {
|
||||
throw new org.apache.tools.ant.BuildException(
|
||||
"Not an actual task, but looks like one for documentation purposes");
|
||||
}
|
||||
public UndefineArgument[] getActiveDefines() {
|
||||
Project p = getProject();
|
||||
if (p == null) {
|
||||
throw new java.lang.IllegalStateException(
|
||||
"project must be set before this call");
|
||||
}
|
||||
if (isReference()) {
|
||||
return ((CompilerDef) getCheckedRef(CompilerDef.class,
|
||||
"CompilerDef")).getActiveDefines();
|
||||
}
|
||||
Vector actives = new Vector();
|
||||
for (int i = 0; i < defineSets.size(); i++) {
|
||||
DefineSet currentSet = (DefineSet) defineSets.elementAt(i);
|
||||
UndefineArgument[] defines = currentSet.getDefines();
|
||||
for (int j = 0; j < defines.length; j++) {
|
||||
if (defines[j].isActive(p)) {
|
||||
actives.addElement(defines[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
UndefineArgument[] retval = new UndefineArgument[actives.size()];
|
||||
actives.copyInto(retval);
|
||||
return retval;
|
||||
}
|
||||
/**
|
||||
* Returns the compiler-specific include path.
|
||||
*/
|
||||
public String[] getActiveIncludePaths() {
|
||||
if (isReference()) {
|
||||
return ((CompilerDef) getCheckedRef(CompilerDef.class,
|
||||
"CompilerDef")).getActiveIncludePaths();
|
||||
}
|
||||
return getActivePaths(includePaths);
|
||||
}
|
||||
private String[] getActivePaths(Vector paths) {
|
||||
Project p = getProject();
|
||||
if (p == null) {
|
||||
throw new java.lang.IllegalStateException("project not set");
|
||||
}
|
||||
Vector activePaths = new Vector(paths.size());
|
||||
for (int i = 0; i < paths.size(); i++) {
|
||||
ConditionalPath path = (ConditionalPath) paths.elementAt(i);
|
||||
if (path.isActive(p)) {
|
||||
if (path.getFile() == null) {
|
||||
String[] pathEntries = path.list();
|
||||
for (int j = 0; j < pathEntries.length; j++) {
|
||||
activePaths.addElement(pathEntries[j]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
loadFile(activePaths, path.getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
String[] pathNames = new String[activePaths.size()];
|
||||
activePaths.copyInto(pathNames);
|
||||
return pathNames;
|
||||
}
|
||||
public PrecompileDef getActivePrecompile(CompilerDef ccElement) {
|
||||
if (isReference()) {
|
||||
return ((CompilerDef) getCheckedRef(CompilerDef.class,
|
||||
"CompilerDef")).getActivePrecompile(ccElement);
|
||||
}
|
||||
PrecompileDef current = null;
|
||||
Enumeration enumPrecompilerDef = precompileDefs.elements();
|
||||
while (enumPrecompilerDef.hasMoreElements()) {
|
||||
current = (PrecompileDef) enumPrecompilerDef.nextElement();
|
||||
if (current.isActive()) {
|
||||
return current;
|
||||
}
|
||||
}
|
||||
CompilerDef extendedDef = (CompilerDef) getExtends();
|
||||
if (extendedDef != null) {
|
||||
current = extendedDef.getActivePrecompile(null);
|
||||
if (current != null) {
|
||||
return current;
|
||||
}
|
||||
}
|
||||
if (ccElement != null && getInherit()) {
|
||||
return ccElement.getActivePrecompile(null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public String[] getActiveSysIncludePaths() {
|
||||
if (isReference()) {
|
||||
return ((CompilerDef) getCheckedRef(CompilerDef.class,
|
||||
"CompilerDef")).getActiveSysIncludePaths();
|
||||
}
|
||||
return getActivePaths(sysIncludePaths);
|
||||
}
|
||||
public final boolean getExceptions(CompilerDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((CompilerDef) getCheckedRef(CompilerDef.class,
|
||||
"CompilerDef")).getExceptions(defaultProviders, index);
|
||||
}
|
||||
if (exceptions != null) {
|
||||
return exceptions.booleanValue();
|
||||
} else {
|
||||
if (defaultProviders != null && index < defaultProviders.length) {
|
||||
return defaultProviders[index].getExceptions(defaultProviders,
|
||||
index + 1);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public final Boolean getRtti(CompilerDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((CompilerDef) getCheckedRef(CompilerDef.class,
|
||||
"CompilerDef")).getRtti(defaultProviders, index);
|
||||
}
|
||||
if (rtti != null) {
|
||||
return rtti;
|
||||
} else {
|
||||
if (defaultProviders != null && index < defaultProviders.length) {
|
||||
return defaultProviders[index].getRtti(defaultProviders,
|
||||
index + 1);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public final Boolean getDefaultflag(CompilerDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((CompilerDef) getCheckedRef(CompilerDef.class,
|
||||
"CompilerDef")).getDefaultflag(defaultProviders, index);
|
||||
}
|
||||
return defaultflag;
|
||||
}
|
||||
public final OptimizationEnum getOptimization(CompilerDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((CompilerDef) getCheckedRef(CompilerDef.class,
|
||||
"CompilerDef")).getOptimization(defaultProviders, index);
|
||||
}
|
||||
if (optimization != null) {
|
||||
return optimization;
|
||||
} else {
|
||||
if (defaultProviders != null && index < defaultProviders.length) {
|
||||
return defaultProviders[index].getOptimization(defaultProviders,
|
||||
index + 1);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean getMultithreaded(CompilerDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((CompilerDef) getCheckedRef(CompilerDef.class,
|
||||
"CompilerDef")).getMultithreaded(defaultProviders, index);
|
||||
}
|
||||
if (multithreaded != null) {
|
||||
return multithreaded.booleanValue();
|
||||
} else {
|
||||
if (defaultProviders != null && index < defaultProviders.length) {
|
||||
return defaultProviders[index].getMultithreaded(
|
||||
defaultProviders, index + 1);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public Processor getProcessor() {
|
||||
Processor processor = super.getProcessor();
|
||||
if (processor == null) {
|
||||
processor = GccCCompiler.getInstance();
|
||||
}
|
||||
if (getLibtool() && processor instanceof CommandLineCompiler) {
|
||||
CommandLineCompiler compiler = (CommandLineCompiler) processor;
|
||||
processor = compiler.getLibtoolCompiler();
|
||||
}
|
||||
return processor;
|
||||
}
|
||||
public int getWarnings(CompilerDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((CompilerDef) getCheckedRef(CompilerDef.class,
|
||||
"CompilerDef")).getWarnings(defaultProviders, index);
|
||||
}
|
||||
if (warnings == -1) {
|
||||
if (defaultProviders != null && index < defaultProviders.length) {
|
||||
return defaultProviders[index].getWarnings(defaultProviders,
|
||||
index + 1);
|
||||
}
|
||||
}
|
||||
return warnings;
|
||||
}
|
||||
/**
|
||||
* Sets the default compiler adapter. Use the "name" attribute when the
|
||||
* compiler is a supported compiler.
|
||||
*
|
||||
* @param classname
|
||||
* fully qualified classname which implements CompilerAdapter
|
||||
*/
|
||||
public void setClassname(String classname) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
super.setClassname(classname);
|
||||
Processor proc = getProcessor();
|
||||
if (!(proc instanceof Compiler)) {
|
||||
throw new BuildException(classname + " does not implement Compiler");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Enables or disables exception support.
|
||||
*
|
||||
* @param exceptions
|
||||
* if true, exceptions are supported.
|
||||
*
|
||||
*/
|
||||
public void setExceptions(boolean exceptions) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.exceptions = booleanValueOf(exceptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables run-time type information.
|
||||
*
|
||||
* @param rtti
|
||||
* if true, run-time type information is supported.
|
||||
*
|
||||
*/
|
||||
public void setRtti(boolean rtti) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.rtti = booleanValueOf(rtti);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables generation of multithreaded code. Unless specified,
|
||||
* multithreaded code generation is enabled.
|
||||
*
|
||||
* @param multi
|
||||
* If true, generated code may be multithreaded.
|
||||
*/
|
||||
public void setMultithreaded(boolean multithreaded) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.multithreaded = booleanValueOf(multithreaded);
|
||||
}
|
||||
/**
|
||||
* Sets compiler type.
|
||||
*
|
||||
*
|
||||
* <table width="100%" border="1"> <thead>Supported compilers </thead>
|
||||
* <tr>
|
||||
* <td>gcc (default)</td>
|
||||
* <td>GCC C++ compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>g++</td>
|
||||
* <td>GCC C++ compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>c++</td>
|
||||
* <td>GCC C++ compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>g77</td>
|
||||
* <td>GNU Fortran compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>msvc</td>
|
||||
* <td>Microsoft Visual C++</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>bcc</td>
|
||||
* <td>Borland C++ Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>msrc</td>
|
||||
* <td>Microsoft Resource Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>brc</td>
|
||||
* <td>Borland Resource Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>df</td>
|
||||
* <td>Compaq Visual Fortran Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>midl</td>
|
||||
* <td>Microsoft MIDL Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>icl</td>
|
||||
* <td>Intel C++ compiler for Windows (IA-32)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>ecl</td>
|
||||
* <td>Intel C++ compiler for Windows (IA-64)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>icc</td>
|
||||
* <td>Intel C++ compiler for Linux (IA-32)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>ecc</td>
|
||||
* <td>Intel C++ compiler for Linux (IA-64)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>CC</td>
|
||||
* <td>Sun ONE C++ compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>aCC</td>
|
||||
* <td>HP aC++ C++ Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>os390</td>
|
||||
* <td>OS390 C Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>os400</td>
|
||||
* <td>Icc Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>sunc89</td>
|
||||
* <td>Sun C89 C Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>xlC</td>
|
||||
* <td>VisualAge C Compiler</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
*/
|
||||
public void setName(CompilerEnum name) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
Compiler compiler = name.getCompiler();
|
||||
setProcessor(compiler);
|
||||
}
|
||||
protected void setProcessor(Processor proc) throws BuildException {
|
||||
try {
|
||||
super.setProcessor((Compiler) proc);
|
||||
} catch (ClassCastException ex) {
|
||||
throw new BuildException(ex);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Enumerated attribute with the values "none", "severe", "default",
|
||||
* "production", "diagnostic", and "failtask".
|
||||
*/
|
||||
public void setWarnings(CompilerDef.WarningLevel level) {
|
||||
warnings = level.getIndex();
|
||||
}
|
||||
/**
|
||||
* Sets optimization level.
|
||||
*
|
||||
* @param value optimization level
|
||||
*/
|
||||
public void setOptimize(OptimizationEnum value) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.optimization = value;
|
||||
}
|
||||
/**
|
||||
* Enables or disables default flags.
|
||||
*
|
||||
* @param defaultflag
|
||||
* if true, default flags will add to command line.
|
||||
*
|
||||
*/
|
||||
public void setDefaultflag(boolean defaultflag) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.defaultflag = booleanValueOf(defaultflag);
|
||||
}
|
||||
}
|
@ -0,0 +1,221 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import net.sf.antcontrib.cpptasks.arm.ADSCCompiler;
|
||||
import net.sf.antcontrib.cpptasks.borland.BorlandCCompiler;
|
||||
import net.sf.antcontrib.cpptasks.borland.BorlandResourceCompiler;
|
||||
import net.sf.antcontrib.cpptasks.compaq.CompaqVisualFortranCompiler;
|
||||
import net.sf.antcontrib.cpptasks.compiler.Compiler;
|
||||
import net.sf.antcontrib.cpptasks.devstudio.DevStudioCCompiler;
|
||||
import net.sf.antcontrib.cpptasks.devstudio.DevStudioMIDLCompiler;
|
||||
import net.sf.antcontrib.cpptasks.devstudio.DevStudioResourceCompiler;
|
||||
import net.sf.antcontrib.cpptasks.gcc.GccCCompiler;
|
||||
import net.sf.antcontrib.cpptasks.hp.aCCCompiler;
|
||||
import net.sf.antcontrib.cpptasks.ibm.VisualAgeCCompiler;
|
||||
import net.sf.antcontrib.cpptasks.intel.IntelLinux32CCompiler;
|
||||
import net.sf.antcontrib.cpptasks.intel.IntelLinux64CCompiler;
|
||||
import net.sf.antcontrib.cpptasks.intel.IntelWin32CCompiler;
|
||||
import net.sf.antcontrib.cpptasks.intel.IntelWin64CCompiler;
|
||||
import net.sf.antcontrib.cpptasks.os390.OS390CCompiler;
|
||||
import net.sf.antcontrib.cpptasks.os400.IccCompiler;
|
||||
import net.sf.antcontrib.cpptasks.sun.C89CCompiler;
|
||||
import net.sf.antcontrib.cpptasks.sun.ForteCCCompiler;
|
||||
import net.sf.antcontrib.cpptasks.ti.ClxxCCompiler;
|
||||
|
||||
import org.apache.tools.ant.types.EnumeratedAttribute;
|
||||
/**
|
||||
* Enumeration of supported compilers
|
||||
*
|
||||
* <table width="100%" border="1"> <thead>Supported compilers </thead>
|
||||
* <tr>
|
||||
* <td>gcc (default)</td>
|
||||
* <td>GCC C++ compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>g++</td>
|
||||
* <td>GCC C++ compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>c++</td>
|
||||
* <td>GCC C++ compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>g77</td>
|
||||
* <td>GNU FORTRAN compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>msvc</td>
|
||||
* <td>Microsoft Visual C++</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>bcc</td>
|
||||
* <td>Borland C++ Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>msrc</td>
|
||||
* <td>Microsoft Resource Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>brc</td>
|
||||
* <td>Borland Resource Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>df</td>
|
||||
* <td>Compaq Visual Fortran Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>midl</td>
|
||||
* <td>Microsoft MIDL Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>icl</td>
|
||||
* <td>Intel C++ compiler for Windows (IA-32)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>ecl</td>
|
||||
* <td>Intel C++ compiler for Windows (IA-64)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>icc</td>
|
||||
* <td>Intel C++ compiler for Linux (IA-32)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>ecc</td>
|
||||
* <td>Intel C++ compiler for Linux (IA-64)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>CC</td>
|
||||
* <td>Sun ONE C++ compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>aCC</td>
|
||||
* <td>HP aC++ C++ Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>os390</td>
|
||||
* <td>OS390 C Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>os400</td>
|
||||
* <td>Icc Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>sunc89</td>
|
||||
* <td>Sun C89 C Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>xlC</td>
|
||||
* <td>VisualAge C Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>cl6x</td>
|
||||
* <td>TI TMS320C6000 Optimizing Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>cl55</td>
|
||||
* <td>TI TMS320C55x Optimizing C/C++ Compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>armcpp</td>
|
||||
* <td>ARM 32-bit C++ compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>armcc</td>
|
||||
* <td>ARM 32-bit C compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>tcpp</td>
|
||||
* <td>ARM 16-bit C++ compiler</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>tcc</td>
|
||||
* <td>ARM 16-bit C compiler</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*
|
||||
*/
|
||||
public class CompilerEnum extends EnumeratedAttribute {
|
||||
private final static ProcessorEnumValue[] compilers = new ProcessorEnumValue[]{
|
||||
new ProcessorEnumValue("gcc", GccCCompiler.getInstance()),
|
||||
new ProcessorEnumValue("g++", GccCCompiler.getGppInstance()),
|
||||
new ProcessorEnumValue("c++", GccCCompiler.getCppInstance()),
|
||||
new ProcessorEnumValue("g77", GccCCompiler.getG77Instance()),
|
||||
new ProcessorEnumValue("msvc", DevStudioCCompiler.getInstance()),
|
||||
new ProcessorEnumValue("bcc", BorlandCCompiler.getInstance()),
|
||||
new ProcessorEnumValue("msrc", DevStudioResourceCompiler
|
||||
.getInstance()),
|
||||
new ProcessorEnumValue("brc", BorlandResourceCompiler.getInstance()),
|
||||
new ProcessorEnumValue("df", CompaqVisualFortranCompiler
|
||||
.getInstance()),
|
||||
new ProcessorEnumValue("midl", DevStudioMIDLCompiler.getInstance()),
|
||||
new ProcessorEnumValue("icl", IntelWin32CCompiler.getInstance()),
|
||||
new ProcessorEnumValue("ecl", IntelWin64CCompiler.getInstance()),
|
||||
new ProcessorEnumValue("icc", IntelLinux32CCompiler.getInstance()),
|
||||
new ProcessorEnumValue("ecc", IntelLinux64CCompiler.getInstance()),
|
||||
new ProcessorEnumValue("CC", ForteCCCompiler.getInstance()),
|
||||
new ProcessorEnumValue("aCC", aCCCompiler.getInstance()),
|
||||
new ProcessorEnumValue("os390", OS390CCompiler.getInstance()),
|
||||
new ProcessorEnumValue("os400", IccCompiler.getInstance()),
|
||||
new ProcessorEnumValue("sunc89", C89CCompiler.getInstance()),
|
||||
new ProcessorEnumValue("xlC", VisualAgeCCompiler.getInstance()),
|
||||
new ProcessorEnumValue("cl6x", ClxxCCompiler.getCl6xInstance()),
|
||||
new ProcessorEnumValue("cl55", ClxxCCompiler.getCl55Instance()),
|
||||
new ProcessorEnumValue("armcc", ADSCCompiler.getArmCC()),
|
||||
new ProcessorEnumValue("armcpp", ADSCCompiler.getArmCpp()),
|
||||
new ProcessorEnumValue("tcc", ADSCCompiler.getThumbCC()),
|
||||
new ProcessorEnumValue("tcpp", ADSCCompiler.getThumbCpp()),
|
||||
// userdefined
|
||||
//new ProcessorEnumValue("userdefine", UserdefineCompiler.getInstance()),
|
||||
// GCC Cross Compilers
|
||||
new ProcessorEnumValue(
|
||||
"sparc-sun-solaris2-gcc",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.sparc_sun_solaris2.GccCCompiler
|
||||
.getInstance()),
|
||||
new ProcessorEnumValue(
|
||||
"sparc-sun-solaris2-g++",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.sparc_sun_solaris2.GccCCompiler
|
||||
.getGppInstance()),
|
||||
new ProcessorEnumValue(
|
||||
"sparc-sun-solaris2-c++",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.sparc_sun_solaris2.GccCCompiler
|
||||
.getCppInstance()),
|
||||
new ProcessorEnumValue(
|
||||
"sparc-sun-solaris2-g77",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.sparc_sun_solaris2.GccCCompiler
|
||||
.getG77Instance()),
|
||||
// GCC Cross Compilers
|
||||
new ProcessorEnumValue("gcc-cross",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.GccCCompiler
|
||||
.getInstance()),
|
||||
new ProcessorEnumValue("g++-cross",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.GccCCompiler
|
||||
.getGppInstance()),
|
||||
new ProcessorEnumValue("c++-cross",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.GccCCompiler
|
||||
.getCppInstance()),
|
||||
new ProcessorEnumValue("g77-cross",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.GccCCompiler
|
||||
.getG77Instance()),};
|
||||
public Compiler getCompiler() {
|
||||
return (Compiler) compilers[getIndex()].getProcessor();
|
||||
}
|
||||
public String[] getValues() {
|
||||
return ProcessorEnumValue.getValues(compilers);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
/*******************************************************************************
|
||||
* Place class description here.
|
||||
*
|
||||
* @author inger
|
||||
* @author <additional author>
|
||||
*
|
||||
* @since
|
||||
******************************************************************************/
|
||||
public class CompilerParam extends ProcessorParam {
|
||||
public CompilerParam() {
|
||||
}
|
||||
public void execute() throws org.apache.tools.ant.BuildException {
|
||||
throw new org.apache.tools.ant.BuildException(
|
||||
"Not an actual task, but looks like one for documentation purposes");
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import java.util.Vector;
|
||||
/**
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public final class DependencyInfo {
|
||||
/**
|
||||
* Last modified time of this file or anything that it depends on.
|
||||
*
|
||||
* Not persisted since almost any change could invalidate it. Initialized
|
||||
* to long.MIN_VALUE on construction.
|
||||
*/
|
||||
private long compositeLastModified;
|
||||
private/* final */String includePathIdentifier;
|
||||
private/* final */String[] includes;
|
||||
private/* final */String source;
|
||||
private/* final */long sourceLastModified;
|
||||
private/* final */String[] sysIncludes;
|
||||
public DependencyInfo(String includePathIdentifier, String source,
|
||||
long sourceLastModified, Vector includes, Vector sysIncludes) {
|
||||
if (source == null) {
|
||||
throw new NullPointerException("source");
|
||||
}
|
||||
if (includePathIdentifier == null) {
|
||||
throw new NullPointerException("includePathIdentifier");
|
||||
}
|
||||
this.source = source;
|
||||
this.sourceLastModified = sourceLastModified;
|
||||
this.includePathIdentifier = includePathIdentifier;
|
||||
this.includes = new String[includes.size()];
|
||||
if (includes.size() == 0) {
|
||||
compositeLastModified = sourceLastModified;
|
||||
} else {
|
||||
includes.copyInto(this.includes);
|
||||
compositeLastModified = Long.MIN_VALUE;
|
||||
}
|
||||
this.sysIncludes = new String[sysIncludes.size()];
|
||||
sysIncludes.copyInto(this.sysIncludes);
|
||||
}
|
||||
/**
|
||||
* Returns the latest modification date of the source or anything that it
|
||||
* depends on.
|
||||
*
|
||||
* @returns the composite lastModified time, returns Long.MIN_VALUE if not
|
||||
* set
|
||||
*/
|
||||
public long getCompositeLastModified() {
|
||||
return compositeLastModified;
|
||||
}
|
||||
public String getIncludePathIdentifier() {
|
||||
return includePathIdentifier;
|
||||
}
|
||||
public String[] getIncludes() {
|
||||
String[] includesClone = (String[]) includes.clone();
|
||||
return includesClone;
|
||||
}
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
public long getSourceLastModified() {
|
||||
return sourceLastModified;
|
||||
}
|
||||
public String[] getSysIncludes() {
|
||||
String[] sysIncludesClone = (String[]) sysIncludes.clone();
|
||||
return sysIncludesClone;
|
||||
}
|
||||
public void setCompositeLastModified(long lastMod) {
|
||||
compositeLastModified = lastMod;
|
||||
}
|
||||
}
|
@ -0,0 +1,609 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import net.sf.antcontrib.cpptasks.compiler.CompilerConfiguration;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
/**
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public final class DependencyTable {
|
||||
/**
|
||||
* This class handles populates the TargetHistory hashtable in response to
|
||||
* SAX parse events
|
||||
*/
|
||||
private class DependencyTableHandler extends DefaultHandler {
|
||||
private File baseDir;
|
||||
private final DependencyTable dependencyTable;
|
||||
private String includePath;
|
||||
private Vector includes;
|
||||
private String source;
|
||||
private long sourceLastModified;
|
||||
private Vector sysIncludes;
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param history
|
||||
* hashtable of TargetHistory keyed by output name
|
||||
* @param outputFiles
|
||||
* existing files in output directory
|
||||
*/
|
||||
private DependencyTableHandler(DependencyTable dependencyTable,
|
||||
File baseDir) {
|
||||
this.dependencyTable = dependencyTable;
|
||||
this.baseDir = baseDir;
|
||||
includes = new Vector();
|
||||
sysIncludes = new Vector();
|
||||
source = null;
|
||||
}
|
||||
public void endElement(String namespaceURI, String localName,
|
||||
String qName) throws SAXException {
|
||||
//
|
||||
// if </source> then
|
||||
// create Dependency object and add to hashtable
|
||||
// if corresponding source file exists and
|
||||
// has the same timestamp
|
||||
//
|
||||
if (qName.equals("source")) {
|
||||
if (source != null && includePath != null) {
|
||||
File existingFile = new File(baseDir, source);
|
||||
//
|
||||
// if the file exists and the time stamp is right
|
||||
// preserve the dependency info
|
||||
if (existingFile.exists()) {
|
||||
//
|
||||
// would have expected exact matches
|
||||
// but was seeing some unexpected difference by
|
||||
// a few tens of milliseconds, as long
|
||||
// as the times are within a second
|
||||
long existingLastModified = existingFile.lastModified();
|
||||
long diff = existingLastModified - sourceLastModified;
|
||||
if (diff >= -500 && diff <= 500) {
|
||||
DependencyInfo dependInfo = new DependencyInfo(
|
||||
includePath, source, sourceLastModified,
|
||||
includes, sysIncludes);
|
||||
dependencyTable.putDependencyInfo(source,
|
||||
dependInfo);
|
||||
}
|
||||
}
|
||||
source = null;
|
||||
includes.setSize(0);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// this causes any <source> elements outside the
|
||||
// scope of an <includePath> to be discarded
|
||||
//
|
||||
if (qName.equals("includePath")) {
|
||||
includePath = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* startElement handler
|
||||
*/
|
||||
public void startElement(String namespaceURI, String localName,
|
||||
String qName, Attributes atts) throws SAXException {
|
||||
//
|
||||
// if includes, then add relative file name to vector
|
||||
//
|
||||
if (qName.equals("include")) {
|
||||
includes.addElement(atts.getValue("file"));
|
||||
} else {
|
||||
if (qName.equals("sysinclude")) {
|
||||
sysIncludes.addElement(atts.getValue("file"));
|
||||
} else {
|
||||
//
|
||||
// if source then
|
||||
// capture source file name,
|
||||
// modification time and reset includes vector
|
||||
//
|
||||
if (qName.equals("source")) {
|
||||
source = atts.getValue("file");
|
||||
sourceLastModified = Long.parseLong(atts
|
||||
.getValue("lastModified"), 16);
|
||||
includes.setSize(0);
|
||||
sysIncludes.setSize(0);
|
||||
} else {
|
||||
if (qName.equals("includePath")) {
|
||||
includePath = atts.getValue("signature");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public abstract class DependencyVisitor {
|
||||
/**
|
||||
* Previews all the children of this source file.
|
||||
*
|
||||
* May be called multiple times as DependencyInfo's for children are
|
||||
* filled in.
|
||||
*
|
||||
* @return true to continue towards recursion into included files
|
||||
*/
|
||||
public abstract boolean preview(DependencyInfo parent,
|
||||
DependencyInfo[] children);
|
||||
/**
|
||||
* Called if the dependency depth exhausted the stack.
|
||||
*/
|
||||
public abstract void stackExhausted();
|
||||
/**
|
||||
* Visits the dependency info.
|
||||
*
|
||||
* @returns true to continue towards recursion into included files
|
||||
*/
|
||||
public abstract boolean visit(DependencyInfo dependInfo);
|
||||
}
|
||||
public class TimestampChecker extends DependencyVisitor {
|
||||
private boolean noNeedToRebuild;
|
||||
private long outputLastModified;
|
||||
private boolean rebuildOnStackExhaustion;
|
||||
public TimestampChecker(final long outputLastModified,
|
||||
boolean rebuildOnStackExhaustion) {
|
||||
this.outputLastModified = outputLastModified;
|
||||
noNeedToRebuild = true;
|
||||
this.rebuildOnStackExhaustion = rebuildOnStackExhaustion;
|
||||
}
|
||||
public boolean getMustRebuild() {
|
||||
return !noNeedToRebuild;
|
||||
}
|
||||
public boolean preview(DependencyInfo parent, DependencyInfo[] children) {
|
||||
int withCompositeTimes = 0;
|
||||
long parentCompositeLastModified = parent.getSourceLastModified();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
if (children[i] != null) {
|
||||
//
|
||||
// expedient way to determine if a child forces us to
|
||||
// rebuild
|
||||
//
|
||||
visit(children[i]);
|
||||
long childCompositeLastModified = children[i]
|
||||
.getCompositeLastModified();
|
||||
if (childCompositeLastModified != Long.MIN_VALUE) {
|
||||
withCompositeTimes++;
|
||||
if (childCompositeLastModified > parentCompositeLastModified) {
|
||||
parentCompositeLastModified = childCompositeLastModified;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (withCompositeTimes == children.length) {
|
||||
parent.setCompositeLastModified(parentCompositeLastModified);
|
||||
}
|
||||
//
|
||||
// may have been changed by an earlier call to visit()
|
||||
//
|
||||
return noNeedToRebuild;
|
||||
}
|
||||
public void stackExhausted() {
|
||||
if (rebuildOnStackExhaustion) {
|
||||
noNeedToRebuild = false;
|
||||
}
|
||||
}
|
||||
public boolean visit(DependencyInfo dependInfo) {
|
||||
if (noNeedToRebuild) {
|
||||
if (dependInfo.getSourceLastModified() > outputLastModified
|
||||
|| dependInfo.getCompositeLastModified() > outputLastModified) {
|
||||
noNeedToRebuild = false;
|
||||
}
|
||||
}
|
||||
//
|
||||
// only need to process the children if
|
||||
// it has not yet been determined whether
|
||||
// we need to rebuild and the composite modified time
|
||||
// has not been determined for this file
|
||||
return noNeedToRebuild
|
||||
&& dependInfo.getCompositeLastModified() == Long.MIN_VALUE;
|
||||
}
|
||||
}
|
||||
private/* final */File baseDir;
|
||||
private String baseDirPath;
|
||||
/**
|
||||
* a hashtable of DependencyInfo[] keyed by output file name
|
||||
*/
|
||||
private final Hashtable dependencies = new Hashtable();
|
||||
/** The file the cache was loaded from. */
|
||||
private/* final */File dependenciesFile;
|
||||
/** Flag indicating whether the cache should be written back to file. */
|
||||
private boolean dirty;
|
||||
/**
|
||||
* Creates a target history table from dependencies.xml in the prject
|
||||
* directory, if it exists. Otherwise, initializes the dependencies empty.
|
||||
*
|
||||
* @param task
|
||||
* task used for logging history load errors
|
||||
* @param baseDir
|
||||
* output directory for task
|
||||
*/
|
||||
public DependencyTable(File baseDir) {
|
||||
if (baseDir == null) {
|
||||
throw new NullPointerException("baseDir");
|
||||
}
|
||||
this.baseDir = baseDir;
|
||||
try {
|
||||
baseDirPath = baseDir.getCanonicalPath();
|
||||
} catch (IOException ex) {
|
||||
baseDirPath = baseDir.toString();
|
||||
}
|
||||
dirty = false;
|
||||
//
|
||||
// load any existing dependencies from file
|
||||
dependenciesFile = new File(baseDir, "dependencies.xml");
|
||||
}
|
||||
public void commit(CCTask task) {
|
||||
//
|
||||
// if not dirty, no need to update file
|
||||
//
|
||||
if (dirty) {
|
||||
//
|
||||
// walk through dependencies to get vector of include paths
|
||||
// identifiers
|
||||
//
|
||||
Vector includePaths = getIncludePaths();
|
||||
//
|
||||
//
|
||||
// write dependency file
|
||||
//
|
||||
try {
|
||||
FileOutputStream outStream = new FileOutputStream(
|
||||
dependenciesFile);
|
||||
OutputStreamWriter streamWriter;
|
||||
//
|
||||
// Early VM's may not have UTF-8 support
|
||||
// fallback to default code page which
|
||||
// "should" be okay unless there are
|
||||
// non ASCII file names
|
||||
String encodingName = "UTF-8";
|
||||
try {
|
||||
streamWriter = new OutputStreamWriter(outStream, "UTF-8");
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
streamWriter = new OutputStreamWriter(outStream);
|
||||
encodingName = streamWriter.getEncoding();
|
||||
}
|
||||
BufferedWriter writer = new BufferedWriter(streamWriter);
|
||||
writer.write("<?xml version='1.0' encoding='");
|
||||
writer.write(encodingName);
|
||||
writer.write("'?>\n");
|
||||
writer.write("<dependencies>\n");
|
||||
StringBuffer buf = new StringBuffer();
|
||||
Enumeration includePathEnum = includePaths.elements();
|
||||
while (includePathEnum.hasMoreElements()) {
|
||||
writeIncludePathDependencies((String) includePathEnum
|
||||
.nextElement(), writer, buf);
|
||||
}
|
||||
writer.write("</dependencies>\n");
|
||||
writer.close();
|
||||
dirty = false;
|
||||
} catch (IOException ex) {
|
||||
task.log("Error writing " + dependenciesFile.toString() + ":"
|
||||
+ ex.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns an enumerator of DependencyInfo's
|
||||
*/
|
||||
public Enumeration elements() {
|
||||
return dependencies.elements();
|
||||
}
|
||||
/**
|
||||
* This method returns a DependencyInfo for the specific source file and
|
||||
* include path identifier
|
||||
*
|
||||
*/
|
||||
public DependencyInfo getDependencyInfo(String sourceRelativeName,
|
||||
String includePathIdentifier) {
|
||||
DependencyInfo dependInfo = null;
|
||||
DependencyInfo[] dependInfos = (DependencyInfo[]) dependencies
|
||||
.get(sourceRelativeName);
|
||||
if (dependInfos != null) {
|
||||
for (int i = 0; i < dependInfos.length; i++) {
|
||||
dependInfo = dependInfos[i];
|
||||
if (dependInfo.getIncludePathIdentifier().equals(
|
||||
includePathIdentifier)) {
|
||||
return dependInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private Vector getIncludePaths() {
|
||||
Vector includePaths = new Vector();
|
||||
DependencyInfo[] dependInfos;
|
||||
Enumeration dependenciesEnum = dependencies.elements();
|
||||
while (dependenciesEnum.hasMoreElements()) {
|
||||
dependInfos = (DependencyInfo[]) dependenciesEnum.nextElement();
|
||||
for (int i = 0; i < dependInfos.length; i++) {
|
||||
DependencyInfo dependInfo = dependInfos[i];
|
||||
boolean matchesExisting = false;
|
||||
final String dependIncludePath = dependInfo
|
||||
.getIncludePathIdentifier();
|
||||
Enumeration includePathEnum = includePaths.elements();
|
||||
while (includePathEnum.hasMoreElements()) {
|
||||
if (dependIncludePath.equals(includePathEnum.nextElement())) {
|
||||
matchesExisting = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!matchesExisting) {
|
||||
includePaths.addElement(dependIncludePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
return includePaths;
|
||||
}
|
||||
public void load() throws IOException, ParserConfigurationException,
|
||||
SAXException {
|
||||
dependencies.clear();
|
||||
if (dependenciesFile.exists()) {
|
||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||
factory.setValidating(false);
|
||||
SAXParser parser = factory.newSAXParser();
|
||||
parser.parse(dependenciesFile, new DependencyTableHandler(this,
|
||||
baseDir));
|
||||
dirty = false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Determines if the specified target needs to be rebuilt.
|
||||
*
|
||||
* This task may result in substantial IO as files are parsed to determine
|
||||
* their dependencies
|
||||
*/
|
||||
public boolean needsRebuild(CCTask task, TargetInfo target,
|
||||
int dependencyDepth) {
|
||||
// look at any files where the compositeLastModified
|
||||
// is not known, but the includes are known
|
||||
//
|
||||
boolean mustRebuild = false;
|
||||
CompilerConfiguration compiler = (CompilerConfiguration) target
|
||||
.getConfiguration();
|
||||
String includePathIdentifier = compiler.getIncludePathIdentifier();
|
||||
File[] sources = target.getSources();
|
||||
DependencyInfo[] dependInfos = new DependencyInfo[sources.length];
|
||||
long outputLastModified = target.getOutput().lastModified();
|
||||
//
|
||||
// try to solve problem using existing dependency info
|
||||
// (not parsing any new files)
|
||||
//
|
||||
DependencyInfo[] stack = new DependencyInfo[50];
|
||||
boolean rebuildOnStackExhaustion = true;
|
||||
if (dependencyDepth >= 0) {
|
||||
if (dependencyDepth < 50) {
|
||||
stack = new DependencyInfo[dependencyDepth];
|
||||
}
|
||||
rebuildOnStackExhaustion = false;
|
||||
}
|
||||
TimestampChecker checker = new TimestampChecker(outputLastModified,
|
||||
rebuildOnStackExhaustion);
|
||||
for (int i = 0; i < sources.length && !mustRebuild; i++) {
|
||||
File source = sources[i];
|
||||
String relative = CUtil.getRelativePath(baseDirPath, source);
|
||||
DependencyInfo dependInfo = getDependencyInfo(relative,
|
||||
includePathIdentifier);
|
||||
if (dependInfo == null) {
|
||||
task.log("Parsing " + relative, Project.MSG_VERBOSE);
|
||||
dependInfo = parseIncludes(task, compiler, source);
|
||||
}
|
||||
walkDependencies(task, dependInfo, compiler, stack, checker);
|
||||
mustRebuild = checker.getMustRebuild();
|
||||
}
|
||||
return mustRebuild;
|
||||
}
|
||||
public DependencyInfo parseIncludes(CCTask task,
|
||||
CompilerConfiguration compiler, File source) {
|
||||
DependencyInfo dependInfo = compiler.parseIncludes(task, baseDir,
|
||||
source);
|
||||
String relativeSource = CUtil.getRelativePath(baseDirPath, source);
|
||||
putDependencyInfo(relativeSource, dependInfo);
|
||||
return dependInfo;
|
||||
}
|
||||
private void putDependencyInfo(String key, DependencyInfo dependInfo) {
|
||||
//
|
||||
// optimistic, add new value
|
||||
//
|
||||
DependencyInfo[] old = (DependencyInfo[]) dependencies.put(key,
|
||||
new DependencyInfo[]{dependInfo});
|
||||
dirty = true;
|
||||
//
|
||||
// something was already there
|
||||
//
|
||||
if (old != null) {
|
||||
//
|
||||
// see if the include path matches a previous entry
|
||||
// if so replace it
|
||||
String includePathIdentifier = dependInfo
|
||||
.getIncludePathIdentifier();
|
||||
for (int i = 0; i < old.length; i++) {
|
||||
DependencyInfo oldDepend = old[i];
|
||||
if (oldDepend.getIncludePathIdentifier().equals(
|
||||
includePathIdentifier)) {
|
||||
old[i] = dependInfo;
|
||||
dependencies.put(key, old);
|
||||
return;
|
||||
}
|
||||
}
|
||||
//
|
||||
// no match prepend the new entry to the array
|
||||
// of dependencies for the file
|
||||
DependencyInfo[] combined = new DependencyInfo[old.length + 1];
|
||||
combined[0] = dependInfo;
|
||||
for (int i = 0; i < old.length; i++) {
|
||||
combined[i + 1] = old[i];
|
||||
}
|
||||
dependencies.put(key, combined);
|
||||
}
|
||||
return;
|
||||
}
|
||||
public void walkDependencies(CCTask task, DependencyInfo dependInfo,
|
||||
CompilerConfiguration compiler, DependencyInfo[] stack,
|
||||
DependencyVisitor visitor) throws BuildException {
|
||||
//
|
||||
// visit this node
|
||||
// if visit returns true then
|
||||
// visit the referenced include and sysInclude dependencies
|
||||
//
|
||||
if (visitor.visit(dependInfo)) {
|
||||
//
|
||||
// find first null entry on stack
|
||||
//
|
||||
int stackPosition = -1;
|
||||
for (int i = 0; i < stack.length; i++) {
|
||||
if (stack[i] == null) {
|
||||
stackPosition = i;
|
||||
stack[i] = dependInfo;
|
||||
break;
|
||||
} else {
|
||||
//
|
||||
// if we have appeared early in the calling history
|
||||
// then we didn't exceed the criteria
|
||||
if (stack[i] == dependInfo) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (stackPosition == -1) {
|
||||
visitor.stackExhausted();
|
||||
return;
|
||||
}
|
||||
//
|
||||
// locate dependency infos
|
||||
//
|
||||
String[] includes = dependInfo.getIncludes();
|
||||
String includePathIdentifier = compiler.getIncludePathIdentifier();
|
||||
DependencyInfo[] includeInfos = new DependencyInfo[includes.length];
|
||||
for (int i = 0; i < includes.length; i++) {
|
||||
DependencyInfo includeInfo = getDependencyInfo(includes[i],
|
||||
includePathIdentifier);
|
||||
includeInfos[i] = includeInfo;
|
||||
}
|
||||
//
|
||||
// preview with only the already available dependency infos
|
||||
//
|
||||
if (visitor.preview(dependInfo, includeInfos)) {
|
||||
//
|
||||
// now need to fill in the missing DependencyInfos
|
||||
//
|
||||
int missingCount = 0;
|
||||
for (int i = 0; i < includes.length; i++) {
|
||||
if (includeInfos[i] == null) {
|
||||
missingCount++;
|
||||
task.log("Parsing " + includes[i], Project.MSG_VERBOSE);
|
||||
// If the include is part of a UNC don't go building a
|
||||
// relative file name.
|
||||
File src = includes[i].startsWith("\\\\") ? new File(
|
||||
includes[i]) : new File(baseDir, includes[i]);
|
||||
DependencyInfo includeInfo = parseIncludes(task,
|
||||
compiler, src);
|
||||
includeInfos[i] = includeInfo;
|
||||
}
|
||||
}
|
||||
//
|
||||
// if it passes a review the second time
|
||||
// then recurse into all the children
|
||||
if (missingCount == 0
|
||||
|| visitor.preview(dependInfo, includeInfos)) {
|
||||
//
|
||||
// recurse into
|
||||
//
|
||||
for (int i = 0; i < includeInfos.length; i++) {
|
||||
DependencyInfo includeInfo = includeInfos[i];
|
||||
walkDependencies(task, includeInfo, compiler, stack,
|
||||
visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
stack[stackPosition] = null;
|
||||
}
|
||||
}
|
||||
private void writeDependencyInfo(BufferedWriter writer, StringBuffer buf,
|
||||
DependencyInfo dependInfo) throws IOException {
|
||||
String[] includes = dependInfo.getIncludes();
|
||||
String[] sysIncludes = dependInfo.getSysIncludes();
|
||||
//
|
||||
// if the includes have not been evaluted then
|
||||
// it is not worth our time saving it
|
||||
// and trying to distiguish between files with
|
||||
// no dependencies and those with undetermined dependencies
|
||||
buf.setLength(0);
|
||||
buf.append(" <source file=\"");
|
||||
buf.append(CUtil.xmlAttribEncode(dependInfo.getSource()));
|
||||
buf.append("\" lastModified=\"");
|
||||
buf.append(Long.toHexString(dependInfo.getSourceLastModified()));
|
||||
buf.append("\">\n");
|
||||
writer.write(buf.toString());
|
||||
for (int i = 0; i < includes.length; i++) {
|
||||
buf.setLength(0);
|
||||
buf.append(" <include file=\"");
|
||||
buf.append(CUtil.xmlAttribEncode(includes[i]));
|
||||
buf.append("\"/>\n");
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
for (int i = 0; i < sysIncludes.length; i++) {
|
||||
buf.setLength(0);
|
||||
buf.append(" <sysinclude file=\"");
|
||||
buf.append(CUtil.xmlAttribEncode(sysIncludes[i]));
|
||||
buf.append("\"/>\n");
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
writer.write(" </source>\n");
|
||||
return;
|
||||
}
|
||||
private void writeIncludePathDependencies(String includePathIdentifier,
|
||||
BufferedWriter writer, StringBuffer buf) throws IOException {
|
||||
//
|
||||
// include path element
|
||||
//
|
||||
buf.setLength(0);
|
||||
buf.append(" <includePath signature=\"");
|
||||
buf.append(CUtil.xmlAttribEncode(includePathIdentifier));
|
||||
buf.append("\">\n");
|
||||
writer.write(buf.toString());
|
||||
Enumeration dependenciesEnum = dependencies.elements();
|
||||
while (dependenciesEnum.hasMoreElements()) {
|
||||
DependencyInfo[] dependInfos = (DependencyInfo[]) dependenciesEnum
|
||||
.nextElement();
|
||||
for (int i = 0; i < dependInfos.length; i++) {
|
||||
DependencyInfo dependInfo = dependInfos[i];
|
||||
//
|
||||
// if this is for the same include path
|
||||
// then output the info
|
||||
if (dependInfo.getIncludePathIdentifier().equals(
|
||||
includePathIdentifier)) {
|
||||
writeDependencyInfo(writer, buf, dependInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.write(" </includePath>\n");
|
||||
}
|
||||
}
|
@ -0,0 +1,243 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 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;
|
||||
|
||||
|
||||
import org.apache.tools.ant.types.DataType;
|
||||
import org.apache.tools.ant.types.Reference;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Distributed build information (Non-functional prototype).
|
||||
*
|
||||
*/
|
||||
public final class DistributerDef
|
||||
extends DataType {
|
||||
/**
|
||||
* if property.
|
||||
*/
|
||||
private String ifCond;
|
||||
|
||||
/**
|
||||
* unless property.
|
||||
*/
|
||||
private String unlessCond;
|
||||
|
||||
/**
|
||||
* hosts.
|
||||
*
|
||||
*/
|
||||
private String hosts;
|
||||
|
||||
/**
|
||||
* Protocol.
|
||||
*
|
||||
*/
|
||||
private DistributerProtocolEnum protocol;
|
||||
|
||||
/**
|
||||
* Not sure what this is.
|
||||
*/
|
||||
private int tcpCork;
|
||||
|
||||
/**
|
||||
* user name.
|
||||
*/
|
||||
private String user;
|
||||
|
||||
/**
|
||||
* local to remote file name maps.
|
||||
*/
|
||||
private final Vector maps = new Vector();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*/
|
||||
public DistributerDef() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by documentation generator.
|
||||
*/
|
||||
public void execute() {
|
||||
throw new org.apache.tools.ant.BuildException(
|
||||
"Not an actual task, but looks like one for documentation purposes");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the if and unless conditions (if any) are
|
||||
* satisfied.
|
||||
* @return true if definition is active.
|
||||
*/
|
||||
public boolean isActive() {
|
||||
return CUtil.isActive(getProject(), ifCond, unlessCond);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an id that can be used to reference this element.
|
||||
*
|
||||
* @param id
|
||||
* id
|
||||
*/
|
||||
public void setId(final String id) {
|
||||
//
|
||||
// this is actually accomplished by a different
|
||||
// mechanism, but we can document it
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property name for the 'if' condition.
|
||||
*
|
||||
* The define will be ignored unless the property is defined.
|
||||
*
|
||||
* The value of the property is insignificant, but values that would imply
|
||||
* misinterpretation ("false", "no") will throw an exception when
|
||||
* evaluated.
|
||||
*
|
||||
* @param propName
|
||||
* property name
|
||||
*/
|
||||
public void setIf(final String propName) {
|
||||
ifCond = propName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies that this element should behave as if the content of the
|
||||
* element with the matching id attribute was inserted at this location. If
|
||||
* specified, no other attributes should be specified.
|
||||
* @param r reference name
|
||||
*/
|
||||
public void setRefid(final Reference r) {
|
||||
super.setRefid(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the property name for the 'unless' condition.
|
||||
*
|
||||
* If named property is set, the define will be ignored.
|
||||
*
|
||||
* The value of the property is insignificant, but values that would imply
|
||||
* misinterpretation ("false", "no") of the behavior will throw an
|
||||
* exception when evaluated.
|
||||
*
|
||||
* @param propName
|
||||
* name of property
|
||||
*/
|
||||
public void setUnless(final String propName) {
|
||||
unlessCond = propName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets hosts.
|
||||
* @return hosts, may be null.
|
||||
*
|
||||
*/
|
||||
public String getHosts() {
|
||||
if (isReference()) {
|
||||
DistributerDef refDistributer = (DistributerDef)
|
||||
getCheckedRef(DistributerDef.class,
|
||||
"DistributerDef");
|
||||
return refDistributer.getHosts();
|
||||
}
|
||||
return hosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets tcp cork.
|
||||
* @return TCP_CORK value.
|
||||
*
|
||||
*/
|
||||
public int getTcpcork() {
|
||||
if (isReference()) {
|
||||
DistributerDef refDistributer = (DistributerDef)
|
||||
getCheckedRef(DistributerDef.class,
|
||||
"DistributerDef");
|
||||
return refDistributer.getTcpcork();
|
||||
}
|
||||
return tcpCork;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets protocol.
|
||||
* @return protocol, may be null.
|
||||
*
|
||||
*/
|
||||
public DistributerProtocolEnum getProtocol() {
|
||||
if (isReference()) {
|
||||
DistributerDef refDistributer = (DistributerDef)
|
||||
getCheckedRef(DistributerDef.class,
|
||||
"DistributerDef");
|
||||
return refDistributer.getProtocol();
|
||||
}
|
||||
return protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets hosts.
|
||||
* @param value new value
|
||||
*/
|
||||
public void setHosts(final String value) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
hosts = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets TCP_CORK value.
|
||||
* @param value new value
|
||||
*/
|
||||
public void setTcpcork(final int value) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
tcpCork = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets protocol.
|
||||
* @param value new value
|
||||
*/
|
||||
public void setProtocol(final DistributerProtocolEnum value) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
protocol = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Local to remote filename maps.
|
||||
* @return new map
|
||||
*/
|
||||
public DistributerMap createMap() {
|
||||
DistributerMap map = new DistributerMap();
|
||||
map.setProject(getProject());
|
||||
maps.addElement(map);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets remote user name.
|
||||
* @param value user name
|
||||
*/
|
||||
public void setUser(final String value) {
|
||||
user = value;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,218 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 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;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.types.DataType;
|
||||
|
||||
/**
|
||||
* Local to remote filename mapping (Experimental).
|
||||
*
|
||||
*/
|
||||
public final class DistributerMap
|
||||
extends DataType {
|
||||
/**
|
||||
* if property.
|
||||
*/
|
||||
private String ifCond;
|
||||
|
||||
/**
|
||||
* unless property.
|
||||
*/
|
||||
private String unlessCond;
|
||||
|
||||
/**
|
||||
* local directory name.
|
||||
*
|
||||
*/
|
||||
private File localName;
|
||||
|
||||
/**
|
||||
* Canonical local file name.
|
||||
*/
|
||||
private String canonicalPath;
|
||||
|
||||
/**
|
||||
* remote name.
|
||||
*
|
||||
*/
|
||||
private String remoteName;
|
||||
|
||||
/**
|
||||
* Separator (/ or \) character on remote system.
|
||||
*/
|
||||
private char remoteSeparator = File.separatorChar;
|
||||
|
||||
/**
|
||||
* hosts that for which this map is valid.
|
||||
*
|
||||
*/
|
||||
private String hosts;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*/
|
||||
public DistributerMap() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by documentation generator.
|
||||
*/
|
||||
public void execute() {
|
||||
throw new org.apache.tools.ant.BuildException(
|
||||
"Not an actual task, but looks like one for documentation purposes");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the if and unless conditions (if any) are
|
||||
* satisfied.
|
||||
*
|
||||
* @return true if this object is active.
|
||||
*/
|
||||
public boolean isActive() {
|
||||
return CUtil.isActive(getProject(), ifCond, unlessCond);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property name for the 'if' condition.
|
||||
*
|
||||
* This object will be ignored unless the property is defined.
|
||||
*
|
||||
* The value of the property is insignificant, but values that would imply
|
||||
* misinterpretation ("false", "no") will throw an exception when
|
||||
* evaluated.
|
||||
*
|
||||
* @param propName
|
||||
* property name
|
||||
*/
|
||||
public void setIf(final String propName) {
|
||||
ifCond = propName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the property name for the 'unless' condition.
|
||||
*
|
||||
* If named property is set, the define will be ignored.
|
||||
*
|
||||
* The value of the property is insignificant, but values that would imply
|
||||
* misinterpretation ("false", "no") of the behavior will throw an
|
||||
* exception when evaluated.
|
||||
*
|
||||
* @param propName
|
||||
* name of property
|
||||
*/
|
||||
public void setUnless(final String propName) {
|
||||
unlessCond = propName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets local directory.
|
||||
* @return local directory, may be null.
|
||||
*
|
||||
*/
|
||||
public File getLocal() {
|
||||
return localName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets remote name for directory.
|
||||
* @return remote name, may be null.
|
||||
*
|
||||
*/
|
||||
public String getRemote() {
|
||||
return remoteName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the local file name to the remote name for the same file.
|
||||
*
|
||||
* @param host host
|
||||
* @param localFile local file
|
||||
* @return remote name for local file, null if unknown.
|
||||
*/
|
||||
public String toRemote(final String host, final File localFile) {
|
||||
if (remoteName != null
|
||||
&& (hosts == null || hosts.indexOf(host) >= 0)) {
|
||||
try {
|
||||
String canonical = localFile.getCanonicalPath();
|
||||
if (canonical.startsWith(canonicalPath)) {
|
||||
if (isActive()) {
|
||||
return remoteName
|
||||
+ canonical.substring(canonicalPath.length()).replace(File.
|
||||
separatorChar, remoteSeparator);
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets local directory for base of mapping.
|
||||
*
|
||||
* @param value value
|
||||
*/
|
||||
public void setLocal(final File value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException("value");
|
||||
}
|
||||
if (value.exists() && !value.isDirectory()) {
|
||||
throw new BuildException("local should be a directory");
|
||||
}
|
||||
localName = value;
|
||||
try {
|
||||
canonicalPath = localName.getCanonicalPath();
|
||||
} catch (IOException ex) {
|
||||
throw new BuildException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets remote name for directory.
|
||||
* @param value remote name for directory
|
||||
*/
|
||||
public void setRemote(final String value) {
|
||||
remoteName = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the separator character (/ or \) for the remote system.
|
||||
* @param value separator character
|
||||
*/
|
||||
public void setRemoteSeparator(final String value) {
|
||||
if (value != null && value.length() != 1) {
|
||||
throw new BuildException("remote separator must be a single character");
|
||||
}
|
||||
remoteSeparator = value.charAt(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets hosts for which this mapping is valid.
|
||||
*
|
||||
* @param value hosts
|
||||
*/
|
||||
public void setHosts(final String value) {
|
||||
hosts = value;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 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;
|
||||
|
||||
import org.apache.tools.ant.types.EnumeratedAttribute;
|
||||
|
||||
/**
|
||||
* Distributer prococol names (experimental).
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*
|
||||
*/
|
||||
public final class DistributerProtocolEnum
|
||||
extends EnumeratedAttribute {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Set by default to "distcc"
|
||||
*
|
||||
* @see java.lang.Object#Object()
|
||||
*/
|
||||
public DistributerProtocolEnum() {
|
||||
setValue("distcc");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets list of acceptable values.
|
||||
*
|
||||
* @see org.apache.tools.ant.types.EnumeratedAttribute#getValues()
|
||||
*/
|
||||
public String[] getValues() {
|
||||
return new String[] {
|
||||
"distcc",
|
||||
"ssh"};
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
/**
|
||||
* An abstract class implemented to walk over the fileset members of a
|
||||
* ProcessorDef
|
||||
*/
|
||||
public interface FileVisitor {
|
||||
abstract void visit(File parentDir, String filename) throws BuildException;
|
||||
}
|
@ -0,0 +1,549 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import java.io.File;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
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.compiler.Processor;
|
||||
import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration;
|
||||
import net.sf.antcontrib.cpptasks.gcc.GccLinker;
|
||||
import net.sf.antcontrib.cpptasks.types.FlexLong;
|
||||
import net.sf.antcontrib.cpptasks.types.LibrarySet;
|
||||
import net.sf.antcontrib.cpptasks.types.LinkerArgument;
|
||||
import net.sf.antcontrib.cpptasks.types.SystemLibrarySet;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.types.FlexInteger;
|
||||
/**
|
||||
* A linker definition. linker elements may be placed either as children of a
|
||||
* cc element or the project element. A linker element with an id attribute may
|
||||
* be referenced by linker elements with refid or extends attributes.
|
||||
*
|
||||
* @author Adam Murdoch
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public class LinkerDef extends ProcessorDef {
|
||||
private long base;
|
||||
private String entry;
|
||||
private Boolean fixed;
|
||||
private Boolean incremental;
|
||||
private final Vector librarySets = new Vector();
|
||||
private Boolean map;
|
||||
private int stack;
|
||||
private final Vector sysLibrarySets = new Vector();
|
||||
private final Vector versionInfos = new Vector();
|
||||
private Boolean defaultflag = new Boolean(true);
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @see java.lang.Object#Object()
|
||||
*/
|
||||
public LinkerDef() {
|
||||
base = -1;
|
||||
stack = -1;
|
||||
}
|
||||
private void addActiveLibrarySet(Project project, Vector libsets,
|
||||
Vector srcSets) {
|
||||
Enumeration srcenum = srcSets.elements();
|
||||
while (srcenum.hasMoreElements()) {
|
||||
LibrarySet set = (LibrarySet) srcenum.nextElement();
|
||||
if (set.isActive(project)) {
|
||||
libsets.addElement(set);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void addActiveSystemLibrarySets(Project project, Vector libsets) {
|
||||
addActiveLibrarySet(project, libsets, sysLibrarySets);
|
||||
}
|
||||
private void addActiveUserLibrarySets(Project project, Vector libsets) {
|
||||
addActiveLibrarySet(project, libsets, librarySets);
|
||||
}
|
||||
/**
|
||||
* Adds a linker command-line arg.
|
||||
*/
|
||||
public void addConfiguredLinkerArg(LinkerArgument arg) {
|
||||
addConfiguredProcessorArg(arg);
|
||||
}
|
||||
/**
|
||||
* Adds a compiler command-line arg.
|
||||
*/
|
||||
public void addConfiguredLinkerParam(LinkerParam param) {
|
||||
if (isReference()) {
|
||||
throw noChildrenAllowed();
|
||||
}
|
||||
addConfiguredProcessorParam(param);
|
||||
}
|
||||
/**
|
||||
* Adds a system library set.
|
||||
*/
|
||||
public void addLibset(LibrarySet libset) {
|
||||
if (isReference()) {
|
||||
throw super.noChildrenAllowed();
|
||||
}
|
||||
if (libset == null) {
|
||||
throw new NullPointerException("libset");
|
||||
}
|
||||
librarySets.addElement(libset);
|
||||
}
|
||||
/**
|
||||
* Adds a system library set.
|
||||
*/
|
||||
public void addSyslibset(SystemLibrarySet libset) {
|
||||
if (isReference()) {
|
||||
throw super.noChildrenAllowed();
|
||||
}
|
||||
if (libset == null) {
|
||||
throw new NullPointerException("libset");
|
||||
}
|
||||
sysLibrarySets.addElement(libset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds desriptive version information to be included in the
|
||||
* generated file. The first active version info block will
|
||||
* be used.
|
||||
*/
|
||||
public void addConfiguredVersioninfo(VersionInfo newVersionInfo) {
|
||||
if (isReference()) {
|
||||
throw noChildrenAllowed();
|
||||
}
|
||||
newVersionInfo.setProject(this.getProject());
|
||||
versionInfos.addElement(newVersionInfo);
|
||||
}
|
||||
|
||||
public ProcessorConfiguration createConfiguration(CCTask task,
|
||||
LinkType linkType, ProcessorDef baseDef, TargetDef targetPlatform) {
|
||||
//
|
||||
// must combine some local context (the linkType)
|
||||
// with the referenced element
|
||||
//
|
||||
// get a pointer to the definition (either local or referenced)
|
||||
ProcessorDef thisDef = this;
|
||||
if (isReference()) {
|
||||
thisDef = ((ProcessorDef) getCheckedRef(ProcessorDef.class,
|
||||
"ProcessorDef"));
|
||||
}
|
||||
//
|
||||
// find the appropriate processor (combines local linkType
|
||||
// with possibly remote linker name)
|
||||
Processor proc = getProcessor();
|
||||
proc = proc.getLinker(linkType);
|
||||
ProcessorDef[] defaultProviders = getDefaultProviders(baseDef);
|
||||
return proc.createConfiguration(task, linkType, defaultProviders,
|
||||
thisDef, targetPlatform);
|
||||
}
|
||||
public void execute() throws org.apache.tools.ant.BuildException {
|
||||
throw new org.apache.tools.ant.BuildException(
|
||||
"Not an actual task, but looks like one for documentation purposes");
|
||||
}
|
||||
/**
|
||||
* Returns an array of active library sets for this linker definition.
|
||||
*/
|
||||
public LibrarySet[] getActiveLibrarySets(LinkerDef[] defaultProviders,
|
||||
int index) {
|
||||
if (isReference()) {
|
||||
return ((LinkerDef) getCheckedRef(LinkerDef.class, "LinkerDef"))
|
||||
.getActiveUserLibrarySets(defaultProviders, index);
|
||||
}
|
||||
Project p = getProject();
|
||||
Vector libsets = new Vector();
|
||||
for (int i = index; i < defaultProviders.length; i++) {
|
||||
defaultProviders[i].addActiveUserLibrarySets(p, libsets);
|
||||
defaultProviders[i].addActiveSystemLibrarySets(p, libsets);
|
||||
}
|
||||
addActiveUserLibrarySets(p, libsets);
|
||||
addActiveSystemLibrarySets(p, libsets);
|
||||
LibrarySet[] sets = new LibrarySet[libsets.size()];
|
||||
libsets.copyInto(sets);
|
||||
return sets;
|
||||
}
|
||||
/**
|
||||
* Returns an array of active library sets for this linker definition.
|
||||
*/
|
||||
public LibrarySet[] getActiveSystemLibrarySets(
|
||||
LinkerDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((LinkerDef) getCheckedRef(LinkerDef.class, "LinkerDef"))
|
||||
.getActiveUserLibrarySets(defaultProviders, index);
|
||||
}
|
||||
Project p = getProject();
|
||||
Vector libsets = new Vector();
|
||||
for (int i = index; i < defaultProviders.length; i++) {
|
||||
defaultProviders[i].addActiveSystemLibrarySets(p, libsets);
|
||||
}
|
||||
addActiveSystemLibrarySets(p, libsets);
|
||||
LibrarySet[] sets = new LibrarySet[libsets.size()];
|
||||
libsets.copyInto(sets);
|
||||
return sets;
|
||||
}
|
||||
/**
|
||||
* Returns an array of active library sets for this linker definition.
|
||||
*/
|
||||
public LibrarySet[] getActiveUserLibrarySets(LinkerDef[] defaultProviders,
|
||||
int index) {
|
||||
if (isReference()) {
|
||||
return ((LinkerDef) getCheckedRef(LinkerDef.class, "LinkerDef"))
|
||||
.getActiveUserLibrarySets(defaultProviders, index);
|
||||
}
|
||||
Project p = getProject();
|
||||
Vector libsets = new Vector();
|
||||
for (int i = index; i < defaultProviders.length; i++) {
|
||||
defaultProviders[i].addActiveUserLibrarySets(p, libsets);
|
||||
}
|
||||
addActiveUserLibrarySets(p, libsets);
|
||||
LibrarySet[] sets = new LibrarySet[libsets.size()];
|
||||
libsets.copyInto(sets);
|
||||
return sets;
|
||||
}
|
||||
public long getBase(LinkerDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((LinkerDef) getCheckedRef(LinkerDef.class, "LinkerDef"))
|
||||
.getBase(defaultProviders, index);
|
||||
}
|
||||
if (base <= 0) {
|
||||
if (defaultProviders != null && index < defaultProviders.length) {
|
||||
return defaultProviders[index].getBase(defaultProviders,
|
||||
index + 1);
|
||||
}
|
||||
}
|
||||
return base;
|
||||
}
|
||||
public Boolean getFixed(LinkerDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((LinkerDef) getCheckedRef(LinkerDef.class, "LinkerDef"))
|
||||
.getFixed(defaultProviders, index);
|
||||
}
|
||||
if (fixed == null) {
|
||||
if (defaultProviders != null && index < defaultProviders.length) {
|
||||
return defaultProviders[index].getFixed(defaultProviders,
|
||||
index + 1);
|
||||
}
|
||||
}
|
||||
return fixed;
|
||||
}
|
||||
public boolean getIncremental(LinkerDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((LinkerDef) getCheckedRef(LinkerDef.class, "LinkerDef"))
|
||||
.getIncremental(defaultProviders, index);
|
||||
}
|
||||
if (incremental != null) {
|
||||
return incremental.booleanValue();
|
||||
}
|
||||
if (defaultProviders != null && index < defaultProviders.length) {
|
||||
return defaultProviders[index].getIncremental(defaultProviders, index + 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean getMap(LinkerDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((LinkerDef) getCheckedRef(LinkerDef.class, "LinkerDef"))
|
||||
.getMap(defaultProviders, index);
|
||||
}
|
||||
if (map != null) {
|
||||
return map.booleanValue();
|
||||
}
|
||||
if (defaultProviders != null && index < defaultProviders.length) {
|
||||
return defaultProviders[index].getMap(defaultProviders, index + 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public final Boolean getDefaultflag(LinkerDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((LinkerDef) getCheckedRef(LinkerDef.class,
|
||||
"LinkerDef")).getDefaultflag(defaultProviders, index);
|
||||
}
|
||||
return defaultflag;
|
||||
}
|
||||
public String getEntry(LinkerDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((LinkerDef) getCheckedRef(LinkerDef.class, "LinkerDef"))
|
||||
.getEntry(defaultProviders, index);
|
||||
}
|
||||
if (entry != null) {
|
||||
return entry;
|
||||
}
|
||||
if (defaultProviders != null && index < defaultProviders.length) {
|
||||
return defaultProviders[index].getEntry(defaultProviders, index + 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Processor getProcessor() {
|
||||
Linker linker = (Linker) super.getProcessor();
|
||||
if (linker == null) {
|
||||
linker = GccLinker.getInstance();
|
||||
}
|
||||
if (getLibtool() && linker instanceof CommandLineLinker) {
|
||||
CommandLineLinker cmdLineLinker = (CommandLineLinker) linker;
|
||||
linker = cmdLineLinker.getLibtoolLinker();
|
||||
}
|
||||
return linker;
|
||||
}
|
||||
public int getStack(LinkerDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((LinkerDef) getCheckedRef(LinkerDef.class, "LinkerDef"))
|
||||
.getStack(defaultProviders, index);
|
||||
}
|
||||
if (stack < 0) {
|
||||
if (defaultProviders != null && index < defaultProviders.length) {
|
||||
return defaultProviders[index].getStack(defaultProviders,
|
||||
index + 1);
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
/**
|
||||
* Sets the base address. May be specified in either decimal or hex.
|
||||
*
|
||||
* @param base
|
||||
* base address
|
||||
*
|
||||
*/
|
||||
public void setBase(FlexLong base) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.base = base.longValue();
|
||||
}
|
||||
/**
|
||||
* Sets the starting address.
|
||||
*
|
||||
* @param name
|
||||
* function name
|
||||
*/
|
||||
public void setEntry(String entry) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.entry = entry;
|
||||
}
|
||||
/**
|
||||
* If true, marks the file to be loaded only at its preferred address.
|
||||
*/
|
||||
public void setFixed(boolean fixed) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.fixed = booleanValueOf(fixed);
|
||||
}
|
||||
/**
|
||||
* If true, allows incremental linking.
|
||||
*
|
||||
*/
|
||||
public void setIncremental(boolean incremental) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.incremental = booleanValueOf(incremental);
|
||||
}
|
||||
/**
|
||||
* If set to true, a map file will be produced.
|
||||
*/
|
||||
public void setMap(boolean map) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.map = booleanValueOf(map);
|
||||
}
|
||||
/**
|
||||
* Sets linker type.
|
||||
*
|
||||
*
|
||||
* <table width="100%" border="1"> <thead>Supported linkers </thead>
|
||||
* <tr>
|
||||
* <td>gcc</td>
|
||||
* <td>Gcc Linker</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>g++</td>
|
||||
* <td>G++ Linker</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>ld</td>
|
||||
* <td>Ld Linker</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>ar</td>
|
||||
* <td>Gcc Librarian</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>msvc</td>
|
||||
* <td>Microsoft Linker</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>bcc</td>
|
||||
* <td>Borland Linker</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>df</td>
|
||||
* <td>Compaq Visual Fortran Linker</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>icl</td>
|
||||
* <td>Intel Linker for Windows (IA-32)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>ecl</td>
|
||||
* <td>Intel Linker for Windows (IA-64)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>icc</td>
|
||||
* <td>Intel Linker for Linux (IA-32)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>ecc</td>
|
||||
* <td>Intel Linker for Linux (IA-64)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>CC</td>
|
||||
* <td>Sun ONE Linker</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>aCC</td>
|
||||
* <td>HP aC++ Linker</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>os390</td>
|
||||
* <td>OS390 Linker</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>os390batch</td>
|
||||
* <td>OS390 Linker</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>os400</td>
|
||||
* <td>IccLinker</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>sunc89</td>
|
||||
* <td>C89 Linker</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>xlC</td>
|
||||
* <td>VisualAge Linker</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
*/
|
||||
public void setName(LinkerEnum name) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
Linker linker = name.getLinker();
|
||||
super.setProcessor(linker);
|
||||
}
|
||||
protected void setProcessor(Processor proc) throws BuildException {
|
||||
Linker linker = null;
|
||||
if (proc instanceof Linker) {
|
||||
linker = (Linker) proc;
|
||||
} else {
|
||||
LinkType linkType = new LinkType();
|
||||
linker = proc.getLinker(linkType);
|
||||
}
|
||||
super.setProcessor(linker);
|
||||
}
|
||||
/**
|
||||
* Sets stack size in bytes.
|
||||
*/
|
||||
public void setStack(FlexInteger stack) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.stack = stack.intValue();
|
||||
}
|
||||
public void visitSystemLibraries(Linker linker, FileVisitor libraryVisitor) {
|
||||
Project p = getProject();
|
||||
if (p == null) {
|
||||
throw new java.lang.IllegalStateException("project must be set");
|
||||
}
|
||||
if (isReference()) {
|
||||
LinkerDef master = ((LinkerDef) getCheckedRef(LinkerDef.class,
|
||||
"Linker"));
|
||||
master.visitSystemLibraries(linker, libraryVisitor);
|
||||
} else {
|
||||
//
|
||||
// if this linker extends another,
|
||||
// visit its libraries first
|
||||
//
|
||||
LinkerDef extendsDef = (LinkerDef) getExtends();
|
||||
if (extendsDef != null) {
|
||||
extendsDef.visitSystemLibraries(linker, libraryVisitor);
|
||||
}
|
||||
if (sysLibrarySets.size() > 0) {
|
||||
File[] libpath = linker.getLibraryPath();
|
||||
for (int i = 0; i < sysLibrarySets.size(); i++) {
|
||||
LibrarySet set = (LibrarySet) sysLibrarySets.elementAt(i);
|
||||
if (set.isActive(p)) {
|
||||
set.visitLibraries(p, linker, libpath,
|
||||
libraryVisitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void visitUserLibraries(Linker linker, FileVisitor libraryVisitor) {
|
||||
Project p = getProject();
|
||||
if (p == null) {
|
||||
throw new java.lang.IllegalStateException("project must be set");
|
||||
}
|
||||
if (isReference()) {
|
||||
LinkerDef master = ((LinkerDef) getCheckedRef(LinkerDef.class,
|
||||
"Linker"));
|
||||
master.visitUserLibraries(linker, libraryVisitor);
|
||||
} else {
|
||||
//
|
||||
// if this linker extends another,
|
||||
// visit its libraries first
|
||||
//
|
||||
LinkerDef extendsDef = (LinkerDef) getExtends();
|
||||
if (extendsDef != null) {
|
||||
extendsDef.visitUserLibraries(linker, libraryVisitor);
|
||||
}
|
||||
//
|
||||
// visit the user libraries
|
||||
//
|
||||
if (librarySets.size() > 0) {
|
||||
File[] libpath = linker.getLibraryPath();
|
||||
for (int i = 0; i < librarySets.size(); i++) {
|
||||
LibrarySet set = (LibrarySet) librarySets.elementAt(i);
|
||||
if (set.isActive(p)) {
|
||||
set.visitLibraries(p, linker, libpath,
|
||||
libraryVisitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Enables or disables default flags.
|
||||
*
|
||||
* @param defaultflag
|
||||
* if true, default flags will add to command line.
|
||||
*
|
||||
*/
|
||||
public void setDefaultflag(boolean defaultflag) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.defaultflag = booleanValueOf(defaultflag);
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import net.sf.antcontrib.cpptasks.arm.ADSLinker;
|
||||
import net.sf.antcontrib.cpptasks.borland.BorlandLinker;
|
||||
import net.sf.antcontrib.cpptasks.compaq.CompaqVisualFortranLinker;
|
||||
import net.sf.antcontrib.cpptasks.compiler.Linker;
|
||||
import net.sf.antcontrib.cpptasks.devstudio.DevStudioLinker;
|
||||
import net.sf.antcontrib.cpptasks.gcc.GccLibrarian;
|
||||
import net.sf.antcontrib.cpptasks.gcc.GccLinker;
|
||||
import net.sf.antcontrib.cpptasks.gcc.GppLinker;
|
||||
import net.sf.antcontrib.cpptasks.gcc.LdLinker;
|
||||
import net.sf.antcontrib.cpptasks.hp.aCCLinker;
|
||||
import net.sf.antcontrib.cpptasks.ibm.VisualAgeLinker;
|
||||
import net.sf.antcontrib.cpptasks.intel.IntelLinux32Linker;
|
||||
import net.sf.antcontrib.cpptasks.intel.IntelLinux64Linker;
|
||||
import net.sf.antcontrib.cpptasks.intel.IntelWin32Linker;
|
||||
import net.sf.antcontrib.cpptasks.os390.OS390Linker;
|
||||
import net.sf.antcontrib.cpptasks.os400.IccLinker;
|
||||
import net.sf.antcontrib.cpptasks.sun.C89Linker;
|
||||
import net.sf.antcontrib.cpptasks.sun.ForteCCLinker;
|
||||
import net.sf.antcontrib.cpptasks.ti.ClxxLinker;
|
||||
import org.apache.tools.ant.types.EnumeratedAttribute;
|
||||
/**
|
||||
* Enumeration of supported linkers
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*
|
||||
*/
|
||||
public class LinkerEnum extends EnumeratedAttribute {
|
||||
private final static ProcessorEnumValue[] linkers = new ProcessorEnumValue[]{
|
||||
new ProcessorEnumValue("gcc", GccLinker.getInstance()),
|
||||
new ProcessorEnumValue("g++", GppLinker.getInstance()),
|
||||
new ProcessorEnumValue("ld", LdLinker.getInstance()),
|
||||
new ProcessorEnumValue("ar", GccLibrarian.getInstance()),
|
||||
new ProcessorEnumValue("msvc", DevStudioLinker.getInstance()),
|
||||
new ProcessorEnumValue("bcc", BorlandLinker.getInstance()),
|
||||
new ProcessorEnumValue("df", CompaqVisualFortranLinker
|
||||
.getInstance()),
|
||||
new ProcessorEnumValue("icl", IntelWin32Linker.getInstance()),
|
||||
new ProcessorEnumValue("ecl", IntelWin32Linker.getInstance()),
|
||||
new ProcessorEnumValue("icc", IntelLinux32Linker.getInstance()),
|
||||
new ProcessorEnumValue("ecc", IntelLinux64Linker.getInstance()),
|
||||
new ProcessorEnumValue("CC", ForteCCLinker.getInstance()),
|
||||
new ProcessorEnumValue("aCC", aCCLinker.getInstance()),
|
||||
new ProcessorEnumValue("os390", OS390Linker.getInstance()),
|
||||
new ProcessorEnumValue("os390batch", OS390Linker
|
||||
.getDataSetInstance()),
|
||||
new ProcessorEnumValue("os400", IccLinker.getInstance()),
|
||||
new ProcessorEnumValue("sunc89", C89Linker.getInstance()),
|
||||
new ProcessorEnumValue("xlC", VisualAgeLinker.getInstance()),
|
||||
new ProcessorEnumValue("cl6x", ClxxLinker.getCl6xInstance()),
|
||||
new ProcessorEnumValue("cl55", ClxxLinker.getCl55Instance()),
|
||||
new ProcessorEnumValue("armcc", ADSLinker.getInstance()),
|
||||
new ProcessorEnumValue("armcpp", ADSLinker.getInstance()),
|
||||
new ProcessorEnumValue("tcc", ADSLinker.getInstance()),
|
||||
new ProcessorEnumValue("tcpp", ADSLinker.getInstance()),
|
||||
// gcc cross compilers
|
||||
new ProcessorEnumValue(
|
||||
"sparc-sun-solaris2-gcc",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.sparc_sun_solaris2.GccLinker
|
||||
.getInstance()),
|
||||
new ProcessorEnumValue(
|
||||
"sparc-sun-solaris2-g++",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.sparc_sun_solaris2.GppLinker
|
||||
.getInstance()),
|
||||
new ProcessorEnumValue(
|
||||
"sparc-sun-solaris2-ld",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.sparc_sun_solaris2.LdLinker
|
||||
.getInstance()),
|
||||
new ProcessorEnumValue(
|
||||
"sparc-sun-solaris2-ar",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.sparc_sun_solaris2.GccLibrarian
|
||||
.getInstance()),
|
||||
new ProcessorEnumValue("gcc-cross",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.GccLinker
|
||||
.getInstance()),
|
||||
new ProcessorEnumValue("g++-cross",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.GppLinker
|
||||
.getInstance()),
|
||||
new ProcessorEnumValue("ld-cross",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.LdLinker.getInstance()),
|
||||
new ProcessorEnumValue("ar-cross",
|
||||
net.sf.antcontrib.cpptasks.gcc.cross.GccLibrarian
|
||||
.getInstance()),};
|
||||
public Linker getLinker() {
|
||||
return (Linker) linkers[getIndex()].getProcessor();
|
||||
}
|
||||
public String[] getValues() {
|
||||
return ProcessorEnumValue.getValues(linkers);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
/*******************************************************************************
|
||||
* Place class description here.
|
||||
*
|
||||
* @author inger
|
||||
* @author <additional author>
|
||||
*
|
||||
* @since
|
||||
******************************************************************************/
|
||||
public class LinkerParam extends ProcessorParam {
|
||||
public LinkerParam() {
|
||||
}
|
||||
public void execute() throws org.apache.tools.ant.BuildException {
|
||||
throw new org.apache.tools.ant.BuildException(
|
||||
"Not an actual task, but looks like one for documentation purposes");
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 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;
|
||||
|
||||
import org.apache.tools.ant.types.EnumeratedAttribute;
|
||||
|
||||
/**
|
||||
* Enumeration of cpu types.
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*
|
||||
*/
|
||||
public final class OSFamilyEnum
|
||||
extends EnumeratedAttribute {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Set by default to "pentium3"
|
||||
*
|
||||
* @see java.lang.Object#Object()
|
||||
*/
|
||||
public OSFamilyEnum() {
|
||||
setValue("windows");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets list of acceptable values.
|
||||
*
|
||||
* @see org.apache.tools.ant.types.EnumeratedAttribute#getValues()
|
||||
*/
|
||||
public String[] getValues() {
|
||||
return new String[] {
|
||||
"windows",
|
||||
"dos",
|
||||
"mac",
|
||||
"unix",
|
||||
"netware",
|
||||
"os/2",
|
||||
"tandem",
|
||||
"win9x",
|
||||
"z/os",
|
||||
"os/400",
|
||||
"openvms"};
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import java.io.File;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.compiler.Linker;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
/**
|
||||
* Collects object files for the link step.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public final class ObjectFileCollector implements FileVisitor {
|
||||
private final Vector files;
|
||||
private final Linker linker;
|
||||
public ObjectFileCollector(Linker linker, Vector files) {
|
||||
this.linker = linker;
|
||||
this.files = files;
|
||||
}
|
||||
public void visit(File parentDir, String filename) throws BuildException {
|
||||
int bid = linker.bid(filename);
|
||||
if (bid >= 1) {
|
||||
files.addElement(new File(parentDir, filename));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 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;
|
||||
|
||||
import org.apache.tools.ant.types.EnumeratedAttribute;
|
||||
|
||||
/**
|
||||
* Enumeration of optimization levels (experimental).
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*
|
||||
*/
|
||||
public final class OptimizationEnum
|
||||
extends EnumeratedAttribute {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Set by default to "speed"
|
||||
*
|
||||
* @see java.lang.Object#Object()
|
||||
*/
|
||||
public OptimizationEnum() {
|
||||
setValue("speed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets list of acceptable values.
|
||||
*
|
||||
* @see org.apache.tools.ant.types.EnumeratedAttribute#getValues()
|
||||
*/
|
||||
public String[] getValues() {
|
||||
return new String[] {
|
||||
"none",
|
||||
"size",
|
||||
"minimal",
|
||||
"speed",
|
||||
"full",
|
||||
"aggressive",
|
||||
"extreme",
|
||||
"unsafe"
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Is size optimized.
|
||||
* @return boolean true if size is optimized.
|
||||
*/
|
||||
public boolean isSize() {
|
||||
return "speed".equals(getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Is speed optimized.
|
||||
* @return boolean true if speed is optimized.
|
||||
*/
|
||||
public boolean isSpeed() {
|
||||
return !isSize() && !isNoOptimization();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is no optimization performed.
|
||||
* @return boolean true if no optimization is performed.
|
||||
*/
|
||||
public boolean isNoOptimization() {
|
||||
return "none".equals(getValue());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import org.apache.tools.ant.types.EnumeratedAttribute;
|
||||
/**
|
||||
* Enumeration of supported subsystems
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*
|
||||
*/
|
||||
public class OutputTypeEnum extends EnumeratedAttribute {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Set by default to "executable"
|
||||
*
|
||||
* @see java.lang.Object#Object()
|
||||
*/
|
||||
public OutputTypeEnum() {
|
||||
setValue("executable");
|
||||
}
|
||||
/**
|
||||
* Gets list of acceptable values
|
||||
*
|
||||
* @see org.apache.tools.ant.types.EnumeratedAttribute#getValues()
|
||||
*/
|
||||
public String[] getValues() {
|
||||
return new String[]{"executable", // executable program
|
||||
"plugin", // plugin module
|
||||
"shared", // dynamically linkable module
|
||||
"static" // convenience library
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,215 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import java.io.File;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.types.ConditionalFileSet;
|
||||
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.DirectoryScanner;
|
||||
import org.apache.tools.ant.types.DataType;
|
||||
/**
|
||||
* An element that specifies a prototype file and rules for source files that
|
||||
* should not use precompiled headers
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public final class PrecompileDef extends DataType {
|
||||
private final Vector exceptSets = new Vector();
|
||||
private String ifCond;
|
||||
/**
|
||||
* Directory of prototype file
|
||||
*/
|
||||
private File prototype = new File("stdafx.cpp");
|
||||
private String unlessCond;
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*/
|
||||
public PrecompileDef() {
|
||||
}
|
||||
/**
|
||||
* Method used by PrecompileExceptDef to add exception set to
|
||||
* PrecompileDef.
|
||||
*/
|
||||
public void appendExceptFileSet(ConditionalFileSet exceptSet) {
|
||||
exceptSet.setProject(getProject());
|
||||
exceptSets.addElement(exceptSet);
|
||||
}
|
||||
/**
|
||||
* Adds filesets that specify files that should not be processed with
|
||||
* precompiled headers enabled.
|
||||
*
|
||||
* @param exceptSet
|
||||
* FileSet specify files that should not be processed with
|
||||
* precompiled headers enabled.
|
||||
*/
|
||||
public PrecompileExceptDef createExcept() {
|
||||
return new PrecompileExceptDef(this);
|
||||
}
|
||||
public void execute() throws org.apache.tools.ant.BuildException {
|
||||
throw new org.apache.tools.ant.BuildException(
|
||||
"Not an actual task, but looks like one for documentation purposes");
|
||||
}
|
||||
public String[] getExceptFiles() {
|
||||
PrecompileDef ref = getRef();
|
||||
if (ref != null) {
|
||||
return ref.getExceptFiles();
|
||||
}
|
||||
if (exceptSets.size() == 0) {
|
||||
return new String[0];
|
||||
}
|
||||
Project p = getProject();
|
||||
String[] exceptFiles = null;
|
||||
Enumeration setEnum = exceptSets.elements();
|
||||
while (setEnum.hasMoreElements()) {
|
||||
ConditionalFileSet exceptSet = (ConditionalFileSet) setEnum
|
||||
.nextElement();
|
||||
if (exceptSet.isActive()) {
|
||||
DirectoryScanner scanner = exceptSet
|
||||
.getDirectoryScanner(p);
|
||||
String[] scannerFiles = scanner.getIncludedFiles();
|
||||
if (exceptFiles == null) {
|
||||
exceptFiles = scannerFiles;
|
||||
} else {
|
||||
if (scannerFiles.length > 0) {
|
||||
String[] newFiles = new String[exceptFiles.length
|
||||
+ scannerFiles.length];
|
||||
for (int i = 0; i < exceptFiles.length; i++) {
|
||||
newFiles[i] = exceptFiles[i];
|
||||
}
|
||||
int index = exceptFiles.length;
|
||||
for (int i = 0; i < scannerFiles.length; i++) {
|
||||
newFiles[index++] = scannerFiles[i];
|
||||
}
|
||||
exceptFiles = newFiles;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (exceptFiles == null) {
|
||||
exceptFiles = new String[0];
|
||||
}
|
||||
return exceptFiles;
|
||||
}
|
||||
/**
|
||||
* Gets prototype source file
|
||||
*
|
||||
*/
|
||||
public File getPrototype() {
|
||||
PrecompileDef ref = getRef();
|
||||
if (ref != null) {
|
||||
return ref.getPrototype();
|
||||
}
|
||||
return prototype;
|
||||
}
|
||||
private PrecompileDef getRef() {
|
||||
if (isReference()) {
|
||||
return ((PrecompileDef) getCheckedRef(PrecompileDef.class,
|
||||
"PrecompileDef"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public boolean isActive() {
|
||||
boolean isActive = CUtil.isActive(getProject(), ifCond, unlessCond);
|
||||
if (!isActive) {
|
||||
PrecompileDef ref = getRef();
|
||||
if (ref != null) {
|
||||
return ref.isActive();
|
||||
}
|
||||
}
|
||||
return isActive;
|
||||
}
|
||||
/**
|
||||
* Sets a description of the current data type.
|
||||
*/
|
||||
public void setDescription(String desc) {
|
||||
super.setDescription(desc);
|
||||
}
|
||||
/**
|
||||
* Sets an id that can be used to reference this element.
|
||||
*
|
||||
* @param id
|
||||
* id
|
||||
*/
|
||||
public void setId(String id) {
|
||||
//
|
||||
// this is actually accomplished by a different
|
||||
// mechanism, but we can document it
|
||||
//
|
||||
}
|
||||
/**
|
||||
* Set the 'if' condition.
|
||||
*
|
||||
* The processor will be ignored unless the property is defined.
|
||||
*
|
||||
* The value of property is insignificant, but values that would imply
|
||||
* misinterpretation ("false", "no") will throw an exception when
|
||||
* isActive() is evaluated.
|
||||
*
|
||||
* @param propName
|
||||
* name of property
|
||||
*/
|
||||
public void setIf(String propName) {
|
||||
ifCond = propName;
|
||||
}
|
||||
/**
|
||||
* Sets file to precompile.
|
||||
*
|
||||
* Should be a source file that includes only one unguarded header file.
|
||||
* Default value is "stdafx.cpp".
|
||||
*
|
||||
* @param prototype
|
||||
* file path for prototype source file
|
||||
*/
|
||||
public void setPrototype(File prototype) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
if (prototype == null) {
|
||||
throw new NullPointerException("prototype");
|
||||
}
|
||||
this.prototype = prototype;
|
||||
}
|
||||
/**
|
||||
* Specifies that this element should behave as if the content of the
|
||||
* element with the matching id attribute was inserted at this location.
|
||||
*
|
||||
* @param ref
|
||||
* Reference to other element
|
||||
*
|
||||
*/
|
||||
public void setRefid(org.apache.tools.ant.types.Reference ref) {
|
||||
super.setRefid(ref);
|
||||
}
|
||||
/**
|
||||
* Set the 'unless' condition. If named property exists at execution time,
|
||||
* the processor will be ignored.
|
||||
*
|
||||
* Value of property is insignificant, but values that would imply
|
||||
* misinterpretation ("false", "no") of the behavior will throw an
|
||||
* exception when isActive is called.
|
||||
*
|
||||
* @param propName
|
||||
* name of property
|
||||
*/
|
||||
public void setUnless(String propName) {
|
||||
unlessCond = propName;
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.types.ConditionalFileSet;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
/**
|
||||
* Specifies files that should not be compiled using precompiled headers.
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public final class PrecompileExceptDef {
|
||||
private ConditionalFileSet localSet = null;
|
||||
/**
|
||||
* Collection of <fileset>contained by definition
|
||||
*/
|
||||
private PrecompileDef owner;
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*/
|
||||
public PrecompileExceptDef(PrecompileDef owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
/**
|
||||
* Adds filesets that specify files that should not be processed using
|
||||
* precompiled headers.
|
||||
*
|
||||
* @param exceptSet
|
||||
* FileSet specify files that should not be processed with
|
||||
* precompiled headers enabled.
|
||||
*/
|
||||
public void addFileset(ConditionalFileSet exceptSet) {
|
||||
owner.appendExceptFileSet(exceptSet);
|
||||
}
|
||||
public void execute() throws org.apache.tools.ant.BuildException {
|
||||
throw new org.apache.tools.ant.BuildException(
|
||||
"Not an actual task, but looks like one for documentation purposes");
|
||||
}
|
||||
/**
|
||||
* Sets the base-directory
|
||||
*/
|
||||
public void setDir(File dir) throws BuildException {
|
||||
if (localSet == null) {
|
||||
localSet = new ConditionalFileSet();
|
||||
owner.appendExceptFileSet(localSet);
|
||||
}
|
||||
localSet.setDir(dir);
|
||||
}
|
||||
/**
|
||||
* Comma or space separated list of file patterns that should not be
|
||||
* compiled using precompiled headers.
|
||||
*
|
||||
* @param includes
|
||||
* the string containing the include patterns
|
||||
*/
|
||||
public void setIncludes(String includes) {
|
||||
if (localSet == null) {
|
||||
localSet = new ConditionalFileSet();
|
||||
owner.appendExceptFileSet(localSet);
|
||||
}
|
||||
localSet.setIncludes(includes);
|
||||
}
|
||||
}
|
@ -0,0 +1,714 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Vector;
|
||||
import net.sf.antcontrib.cpptasks.compiler.LinkType;
|
||||
import net.sf.antcontrib.cpptasks.compiler.Processor;
|
||||
import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration;
|
||||
import net.sf.antcontrib.cpptasks.types.CommandLineArgument;
|
||||
import net.sf.antcontrib.cpptasks.types.ConditionalFileSet;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.DirectoryScanner;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.types.DataType;
|
||||
import org.apache.tools.ant.types.Environment;
|
||||
import org.apache.tools.ant.types.Reference;
|
||||
/**
|
||||
* An abstract compiler/linker definition.
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public abstract class ProcessorDef extends DataType {
|
||||
/**
|
||||
* Returns the equivalent Boolean object for the specified value
|
||||
*
|
||||
* Equivalent to Boolean.valueOf in JDK 1.4
|
||||
*
|
||||
* @param val
|
||||
* boolean value
|
||||
* @return Boolean.TRUE or Boolean.FALSE
|
||||
*/
|
||||
protected static Boolean booleanValueOf(boolean val) {
|
||||
if (val) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
/**
|
||||
* if true, targets will be built for debugging
|
||||
*/
|
||||
private Boolean debug;
|
||||
private Environment env = null;
|
||||
/**
|
||||
* Reference for "extends" processor definition
|
||||
*/
|
||||
private Reference extendsRef = null;
|
||||
/**
|
||||
* Name of property that must be present or definition will be ignored. May
|
||||
* be null.
|
||||
*/
|
||||
private String ifProp;
|
||||
/**
|
||||
* if true, processor definition inherits values from containing <cc>
|
||||
* element
|
||||
*/
|
||||
private boolean inherit;
|
||||
private Boolean libtool = null;
|
||||
protected boolean newEnvironment = false;
|
||||
/**
|
||||
* Processor.
|
||||
*/
|
||||
private Processor processor;
|
||||
/**
|
||||
* Collection of <compilerarg>or <linkerarg>contained by definition
|
||||
*/
|
||||
private final Vector processorArgs = new Vector();
|
||||
/**
|
||||
* Collection of <compilerparam>or <linkerparam>contained by definition
|
||||
*/
|
||||
private final Vector processorParams = new Vector();
|
||||
/**
|
||||
* if true, all targets will be unconditionally rebuilt
|
||||
*/
|
||||
private Boolean rebuild;
|
||||
/**
|
||||
* Collection of <fileset>contained by definition
|
||||
*/
|
||||
private final Vector srcSets = new Vector();
|
||||
/**
|
||||
* Name of property that if present will cause definition to be ignored.
|
||||
* May be null.
|
||||
*/
|
||||
private String unlessProp;
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*/
|
||||
protected ProcessorDef() throws NullPointerException {
|
||||
inherit = true;
|
||||
}
|
||||
/**
|
||||
* Adds a <compilerarg>or <linkerarg>
|
||||
*
|
||||
* @param arg
|
||||
* command line argument, must not be null
|
||||
* @throws NullPointerException
|
||||
* if arg is null
|
||||
* @throws BuildException
|
||||
* if this definition is a reference
|
||||
*/
|
||||
protected void addConfiguredProcessorArg(CommandLineArgument arg)
|
||||
throws NullPointerException, BuildException {
|
||||
if (arg == null) {
|
||||
throw new NullPointerException("arg");
|
||||
}
|
||||
if (isReference()) {
|
||||
throw noChildrenAllowed();
|
||||
}
|
||||
if(arg.getFile() == null ) {
|
||||
processorArgs.addElement(arg);
|
||||
}
|
||||
else {
|
||||
loadFile(arg.getFile());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Add a <compilerarg>or <linkerarg> if specify the file attribute
|
||||
*
|
||||
* @param arg
|
||||
* command line argument, must not be null
|
||||
* @throws BuildException
|
||||
* if the specify file not exist
|
||||
*/
|
||||
protected void loadFile(File file)
|
||||
throws BuildException {
|
||||
FileReader fileReader;
|
||||
BufferedReader in;
|
||||
String str;
|
||||
if (! file.exists()){
|
||||
throw new BuildException("The file " + file + " is not existed");
|
||||
}
|
||||
try {
|
||||
fileReader = new FileReader(file);
|
||||
in = new BufferedReader(fileReader);
|
||||
while ( (str = in.readLine()) != null ){
|
||||
if(str.trim() == ""){
|
||||
continue ;
|
||||
}
|
||||
str = getProject().replaceProperties(str);
|
||||
CommandLineArgument newarg = new CommandLineArgument();
|
||||
newarg.setValue(str.trim());
|
||||
processorArgs.addElement(newarg);
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
throw new BuildException(e.getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds a <compilerarg>or <linkerarg>
|
||||
*
|
||||
* @param arg
|
||||
* command line argument, must not be null
|
||||
* @throws NullPointerException
|
||||
* if arg is null
|
||||
* @throws BuildException
|
||||
* if this definition is a reference
|
||||
*/
|
||||
protected void addConfiguredProcessorParam(ProcessorParam param)
|
||||
throws NullPointerException, BuildException {
|
||||
if (param == null) {
|
||||
throw new NullPointerException("param");
|
||||
}
|
||||
if (isReference()) {
|
||||
throw noChildrenAllowed();
|
||||
}
|
||||
processorParams.addElement(param);
|
||||
}
|
||||
/**
|
||||
* Add an environment variable to the launched process.
|
||||
*/
|
||||
public void addEnv(Environment.Variable var) {
|
||||
if (env == null) {
|
||||
env = new Environment();
|
||||
}
|
||||
env.addVariable(var);
|
||||
}
|
||||
/**
|
||||
* Adds a source file set.
|
||||
*
|
||||
* Files in these set will be processed by this configuration and will not
|
||||
* participate in the auction.
|
||||
*
|
||||
* @param srcSet
|
||||
* Fileset identifying files that should be processed by this
|
||||
* processor
|
||||
* @throws BuildException
|
||||
* if processor definition is a reference
|
||||
*/
|
||||
public void addFileset(ConditionalFileSet srcSet) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw noChildrenAllowed();
|
||||
}
|
||||
srcSet.setProject(getProject());
|
||||
srcSets.addElement(srcSet);
|
||||
}
|
||||
/**
|
||||
* Creates a configuration
|
||||
*
|
||||
* @param baseDef
|
||||
* reference to def from containing <cc>element, may be null
|
||||
* @return configuration
|
||||
*
|
||||
*/
|
||||
public ProcessorConfiguration createConfiguration(CCTask task,
|
||||
LinkType linkType, ProcessorDef baseDef, TargetDef targetPlatform) {
|
||||
if (isReference()) {
|
||||
return ((ProcessorDef) getCheckedRef(ProcessorDef.class,
|
||||
"ProcessorDef")).createConfiguration(task, linkType,
|
||||
baseDef, targetPlatform);
|
||||
}
|
||||
ProcessorDef[] defaultProviders = getDefaultProviders(baseDef);
|
||||
Processor proc = getProcessor();
|
||||
return proc.createConfiguration(task, linkType, defaultProviders, this, targetPlatform);
|
||||
}
|
||||
/**
|
||||
* Prepares list of processor arguments ( <compilerarg>, <linkerarg>) that
|
||||
* are active for the current project settings.
|
||||
*
|
||||
* @return active compiler arguments
|
||||
*/
|
||||
public CommandLineArgument[] getActiveProcessorArgs() {
|
||||
Project p = getProject();
|
||||
if (p == null) {
|
||||
throw new java.lang.IllegalStateException("project must be set");
|
||||
}
|
||||
if (isReference()) {
|
||||
return ((ProcessorDef) getCheckedRef(ProcessorDef.class,
|
||||
"ProcessorDef")).getActiveProcessorArgs();
|
||||
}
|
||||
Vector activeArgs = new Vector(processorArgs.size());
|
||||
for (int i = 0; i < processorArgs.size(); i++) {
|
||||
CommandLineArgument arg = (CommandLineArgument) processorArgs
|
||||
.elementAt(i);
|
||||
if (arg.isActive(p)) {
|
||||
activeArgs.addElement(arg);
|
||||
}
|
||||
}
|
||||
CommandLineArgument[] array = new CommandLineArgument[activeArgs.size()];
|
||||
activeArgs.copyInto(array);
|
||||
return array;
|
||||
}
|
||||
/**
|
||||
* Prepares list of processor arguments ( <compilerarg>, <linkerarg>) that
|
||||
* are active for the current project settings.
|
||||
*
|
||||
* @return active compiler arguments
|
||||
*/
|
||||
public ProcessorParam[] getActiveProcessorParams() {
|
||||
Project p = getProject();
|
||||
if (p == null) {
|
||||
throw new java.lang.IllegalStateException("project must be set");
|
||||
}
|
||||
if (isReference()) {
|
||||
return ((ProcessorDef) getCheckedRef(ProcessorDef.class,
|
||||
"ProcessorDef")).getActiveProcessorParams();
|
||||
}
|
||||
Vector activeParams = new Vector(processorParams.size());
|
||||
for (int i = 0; i < processorParams.size(); i++) {
|
||||
ProcessorParam param = (ProcessorParam) processorParams
|
||||
.elementAt(i);
|
||||
if (param.isActive(p)) {
|
||||
activeParams.addElement(param);
|
||||
}
|
||||
}
|
||||
ProcessorParam[] array = new ProcessorParam[activeParams.size()];
|
||||
activeParams.copyInto(array);
|
||||
return array;
|
||||
}
|
||||
/**
|
||||
* Gets boolean indicating debug build
|
||||
*
|
||||
* @param defaultProviders
|
||||
* array of ProcessorDef's in descending priority
|
||||
* @param index
|
||||
* index to first element in array that should be considered
|
||||
* @return if true, built targets for debugging
|
||||
*/
|
||||
public boolean getDebug(ProcessorDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((ProcessorDef) getCheckedRef(ProcessorDef.class,
|
||||
"ProcessorDef")).getDebug(defaultProviders, index);
|
||||
}
|
||||
if (debug != null) {
|
||||
return debug.booleanValue();
|
||||
} else {
|
||||
if (defaultProviders != null && index < defaultProviders.length) {
|
||||
return defaultProviders[index].getDebug(defaultProviders,
|
||||
index + 1);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Creates an chain of objects which provide default values in descending
|
||||
* order of significance.
|
||||
*
|
||||
* @param baseDef
|
||||
* corresponding ProcessorDef from CCTask, will be last element
|
||||
* in array unless inherit = false
|
||||
* @return default provider array
|
||||
*
|
||||
*/
|
||||
protected final ProcessorDef[] getDefaultProviders(ProcessorDef baseDef) {
|
||||
ProcessorDef extendsDef = getExtends();
|
||||
Vector chain = new Vector();
|
||||
while (extendsDef != null && !chain.contains(extendsDef)) {
|
||||
chain.addElement(extendsDef);
|
||||
extendsDef = extendsDef.getExtends();
|
||||
}
|
||||
if (baseDef != null && getInherit()) {
|
||||
chain.addElement(baseDef);
|
||||
}
|
||||
ProcessorDef[] defaultProviders = new ProcessorDef[chain.size()];
|
||||
chain.copyInto(defaultProviders);
|
||||
return defaultProviders;
|
||||
}
|
||||
/**
|
||||
* Gets the ProcessorDef specified by the extends attribute
|
||||
*
|
||||
* @return Base ProcessorDef, null if extends is not specified
|
||||
* @throws BuildException
|
||||
* if reference is not same type object
|
||||
*/
|
||||
public ProcessorDef getExtends() throws BuildException {
|
||||
if (extendsRef != null) {
|
||||
Object obj = extendsRef.getReferencedObject(getProject());
|
||||
if (!getClass().isInstance(obj)) {
|
||||
throw new BuildException("Referenced object "
|
||||
+ extendsRef.getRefId() + " not correct type, is "
|
||||
+ obj.getClass().getName() + " should be "
|
||||
+ getClass().getName());
|
||||
}
|
||||
return (ProcessorDef) obj;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Gets the inherit attribute. If the inherit value is true, this processor
|
||||
* definition will inherit default values from the containing <cc>element.
|
||||
*
|
||||
* @return if true then properties from the containing <cc>element are
|
||||
* used.
|
||||
*/
|
||||
public final boolean getInherit() {
|
||||
return inherit;
|
||||
}
|
||||
public boolean getLibtool() {
|
||||
if (libtool != null) {
|
||||
return libtool.booleanValue();
|
||||
}
|
||||
if (isReference()) {
|
||||
return ((ProcessorDef) getCheckedRef(ProcessorDef.class,
|
||||
"ProcessorDef")).getLibtool();
|
||||
}
|
||||
ProcessorDef extendsDef = getExtends();
|
||||
if (extendsDef != null) {
|
||||
return extendsDef.getLibtool();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Obtains the appropriate processor (compiler, linker)
|
||||
*
|
||||
* @return processor
|
||||
*/
|
||||
protected Processor getProcessor() {
|
||||
if (isReference()) {
|
||||
return ((ProcessorDef) getCheckedRef(ProcessorDef.class,
|
||||
"ProcessorDef")).getProcessor();
|
||||
}
|
||||
//
|
||||
// if a processor has not been explicitly set
|
||||
// then may be set by an extended definition
|
||||
if (processor == null) {
|
||||
ProcessorDef extendsDef = getExtends();
|
||||
if (extendsDef != null) {
|
||||
return extendsDef.getProcessor();
|
||||
}
|
||||
}
|
||||
return processor;
|
||||
}
|
||||
/**
|
||||
* Gets a boolean value indicating whether all targets must be rebuilt
|
||||
* regardless of dependency analysis.
|
||||
*
|
||||
* @param defaultProviders
|
||||
* array of ProcessorDef's in descending priority
|
||||
* @param index
|
||||
* index to first element in array that should be considered
|
||||
* @return true if all targets should be rebuilt.
|
||||
*/
|
||||
public boolean getRebuild(ProcessorDef[] defaultProviders, int index) {
|
||||
if (isReference()) {
|
||||
return ((ProcessorDef) getCheckedRef(ProcessorDef.class,
|
||||
"ProcessorDef")).getRebuild(defaultProviders, index);
|
||||
}
|
||||
if (rebuild != null) {
|
||||
return rebuild.booleanValue();
|
||||
} else {
|
||||
if (defaultProviders != null && index < defaultProviders.length) {
|
||||
return defaultProviders[index].getRebuild(defaultProviders,
|
||||
index + 1);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Returns true if the processor definition contains embedded file set
|
||||
* definitions
|
||||
*
|
||||
* @return true if processor definition contains embedded filesets
|
||||
*/
|
||||
public boolean hasFileSets() {
|
||||
if (isReference()) {
|
||||
return ((ProcessorDef) getCheckedRef(ProcessorDef.class,
|
||||
"ProcessorDef")).hasFileSets();
|
||||
}
|
||||
return srcSets.size() > 0;
|
||||
}
|
||||
/**
|
||||
* Determine if this def should be used.
|
||||
*
|
||||
* Definition will be active if the "if" variable (if specified) is set and
|
||||
* the "unless" variable (if specified) is not set and that all reference
|
||||
* or extended definitions are active
|
||||
*
|
||||
* @return true if processor is active
|
||||
* @throws IllegalStateException
|
||||
* if not properly initialized
|
||||
* @throws BuildException
|
||||
* if "if" or "unless" variable contains suspicious values
|
||||
* "false" or "no" which indicates possible confusion
|
||||
*/
|
||||
public boolean isActive() throws BuildException, IllegalStateException {
|
||||
Project project = getProject();
|
||||
if (!CUtil.isActive(project, ifProp, unlessProp)) {
|
||||
return false;
|
||||
}
|
||||
if (isReference()) {
|
||||
if (!((ProcessorDef) getCheckedRef(ProcessorDef.class,
|
||||
"ProcessorDef")).isActive()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//
|
||||
// walk through any extended definitions
|
||||
//
|
||||
ProcessorDef[] defaultProviders = getDefaultProviders(null);
|
||||
for (int i = 0; i < defaultProviders.length; i++) {
|
||||
if (!defaultProviders[i].isActive()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Sets the class name for the adapter. Use the "name" attribute when the
|
||||
* tool is supported.
|
||||
*
|
||||
* @param className
|
||||
* full class name
|
||||
*
|
||||
*/
|
||||
public void setClassname(String className) throws BuildException {
|
||||
Object proc = null;
|
||||
try {
|
||||
Class implClass = ProcessorDef.class.getClassLoader().loadClass(
|
||||
className);
|
||||
try {
|
||||
Method getInstance = implClass.getMethod("getInstance",
|
||||
new Class[0]);
|
||||
proc = getInstance.invoke(null, new Object[0]);
|
||||
} catch (Exception ex) {
|
||||
proc = implClass.newInstance();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new BuildException(ex);
|
||||
}
|
||||
setProcessor((Processor) proc);
|
||||
}
|
||||
/**
|
||||
* If set true, all targets will be built for debugging.
|
||||
*
|
||||
* @param debug
|
||||
* true if targets should be built for debugging
|
||||
* @throws BuildException
|
||||
* if processor definition is a reference
|
||||
*/
|
||||
public void setDebug(boolean debug) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.debug = booleanValueOf(debug);
|
||||
}
|
||||
/**
|
||||
* Sets a description of the current data type.
|
||||
*/
|
||||
public void setDescription(String desc) {
|
||||
super.setDescription(desc);
|
||||
}
|
||||
/**
|
||||
* Specifies that this element extends the element with id attribute with a
|
||||
* matching value. The configuration will be constructed from the settings
|
||||
* of this element, element referenced by extends, and the containing cc
|
||||
* element.
|
||||
*
|
||||
* @param extendsRef
|
||||
* Reference to the extended processor definition.
|
||||
* @throws BuildException
|
||||
* if this processor definition is a reference
|
||||
*/
|
||||
public void setExtends(Reference extendsRef) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.extendsRef = extendsRef;
|
||||
}
|
||||
/**
|
||||
* Sets an id that can be used to reference this element.
|
||||
*
|
||||
* @param id
|
||||
* id
|
||||
*/
|
||||
public void setId(String id) {
|
||||
//
|
||||
// this is actually accomplished by a different
|
||||
// mechanism, but we can document it
|
||||
//
|
||||
}
|
||||
/**
|
||||
* Sets the property name for the 'if' condition.
|
||||
*
|
||||
* The configuration will be ignored unless the property is defined.
|
||||
*
|
||||
* The value of the property is insignificant, but values that would imply
|
||||
* misinterpretation ("false", "no") will throw an exception when
|
||||
* evaluated.
|
||||
*
|
||||
* @param propName
|
||||
* name of property
|
||||
*/
|
||||
public void setIf(String propName) {
|
||||
ifProp = propName;
|
||||
}
|
||||
/**
|
||||
* If inherit has the default value of true, defines, includes and other
|
||||
* settings from the containing <cc>element will be inherited.
|
||||
*
|
||||
* @param inherit
|
||||
* new value
|
||||
* @throws BuildException
|
||||
* if processor definition is a reference
|
||||
*/
|
||||
public void setInherit(boolean inherit) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw super.tooManyAttributes();
|
||||
}
|
||||
this.inherit = inherit;
|
||||
}
|
||||
/**
|
||||
* Set use of libtool.
|
||||
*
|
||||
* If set to true, the "libtool " will be prepended to the command line
|
||||
*
|
||||
* @param libtool
|
||||
* If true, use libtool.
|
||||
*/
|
||||
public void setLibtool(boolean libtool) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.libtool = booleanValueOf(libtool);
|
||||
}
|
||||
/**
|
||||
* Do not propagate old environment when new environment variables are
|
||||
* specified.
|
||||
*/
|
||||
public void setNewenvironment(boolean newenv) {
|
||||
newEnvironment = newenv;
|
||||
}
|
||||
/**
|
||||
* Sets the processor
|
||||
*
|
||||
* @param processor
|
||||
* processor, may not be null.
|
||||
* @throws BuildException
|
||||
* if ProcessorDef is a reference
|
||||
* @throws NullPointerException
|
||||
* if processor is null
|
||||
*/
|
||||
protected void setProcessor(Processor processor) throws BuildException,
|
||||
NullPointerException {
|
||||
if (processor == null) {
|
||||
throw new NullPointerException("processor");
|
||||
}
|
||||
if (isReference()) {
|
||||
throw super.tooManyAttributes();
|
||||
}
|
||||
if (env == null && !newEnvironment) {
|
||||
this.processor = processor;
|
||||
} else {
|
||||
this.processor = processor.changeEnvironment(newEnvironment, env);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* If set true, all targets will be unconditionally rebuilt.
|
||||
*
|
||||
* @param rebuild
|
||||
* if true, rebuild all targets.
|
||||
* @throws BuildException
|
||||
* if processor definition is a reference
|
||||
*/
|
||||
public void setRebuild(boolean rebuild) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
this.rebuild = booleanValueOf(rebuild);
|
||||
}
|
||||
/**
|
||||
* Specifies that this element should behave as if the content of the
|
||||
* element with the matching id attribute was inserted at this location. If
|
||||
* specified, no other attributes or child content should be specified,
|
||||
* other than "if", "unless" and "description".
|
||||
*
|
||||
* @param ref
|
||||
* Reference to other element
|
||||
*
|
||||
*/
|
||||
public void setRefid(org.apache.tools.ant.types.Reference ref) {
|
||||
super.setRefid(ref);
|
||||
}
|
||||
/**
|
||||
* Set the property name for the 'unless' condition.
|
||||
*
|
||||
* If named property is set, the configuration will be ignored.
|
||||
*
|
||||
* The value of the property is insignificant, but values that would imply
|
||||
* misinterpretation ("false", "no") of the behavior will throw an
|
||||
* exception when evaluated.
|
||||
*
|
||||
* @param propName
|
||||
* name of property
|
||||
*/
|
||||
public void setUnless(String propName) {
|
||||
unlessProp = propName;
|
||||
}
|
||||
/**
|
||||
* This method calls the FileVistor's visit function for every file in the
|
||||
* processors definition
|
||||
*
|
||||
* @param visitor
|
||||
* object whose visit method is called for every file
|
||||
*/
|
||||
public void visitFiles(FileVisitor visitor) {
|
||||
Project p = getProject();
|
||||
if (p == null) {
|
||||
throw new java.lang.IllegalStateException(
|
||||
"project must be set before this call");
|
||||
}
|
||||
if (isReference()) {
|
||||
((ProcessorDef) getCheckedRef(ProcessorDef.class, "ProcessorDef"))
|
||||
.visitFiles(visitor);
|
||||
}
|
||||
//
|
||||
// if this processor extends another,
|
||||
// visit its files first
|
||||
//
|
||||
ProcessorDef extendsDef = getExtends();
|
||||
if (extendsDef != null) {
|
||||
extendsDef.visitFiles(visitor);
|
||||
}
|
||||
for (int i = 0; i < srcSets.size(); i++) {
|
||||
ConditionalFileSet srcSet = (ConditionalFileSet) srcSets
|
||||
.elementAt(i);
|
||||
if (srcSet.isActive()) {
|
||||
// Find matching source files
|
||||
DirectoryScanner scanner = srcSet.getDirectoryScanner(p);
|
||||
// Check each source file - see if it needs compilation
|
||||
String[] fileNames = scanner.getIncludedFiles();
|
||||
File parentDir = scanner.getBasedir();
|
||||
for (int j = 0; j < fileNames.length; j++) {
|
||||
String currentFile = fileNames[j];
|
||||
visitor.visit(parentDir, currentFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public Vector getSrcSets() {
|
||||
if (isReference()) {
|
||||
return ((ProcessorDef) getCheckedRef(ProcessorDef.class,
|
||||
"ProcessorDef")).getSrcSets();
|
||||
}
|
||||
return srcSets;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import net.sf.antcontrib.cpptasks.compiler.Processor;
|
||||
/**
|
||||
* One entry in the arrays used by the CompilerEnum and LinkerEnum classes.
|
||||
*
|
||||
* @author Curt Arnold
|
||||
* @see CompilerEnum
|
||||
* @see LinkerEnum
|
||||
*
|
||||
*/
|
||||
public class ProcessorEnumValue {
|
||||
public static String[] getValues(ProcessorEnumValue[] processors) {
|
||||
String[] values = new String[processors.length];
|
||||
for (int i = 0; i < processors.length; i++) {
|
||||
values[i] = processors[i].getName();
|
||||
}
|
||||
return values;
|
||||
}
|
||||
private String name;
|
||||
private Processor processor;
|
||||
public ProcessorEnumValue(String name, Processor processor) {
|
||||
this.name = name;
|
||||
this.processor = processor;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public Processor getProcessor() {
|
||||
return processor;
|
||||
}
|
||||
}
|
@ -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;
|
||||
/*******************************************************************************
|
||||
* Place class description here.
|
||||
*
|
||||
* @author inger
|
||||
* @author <additional author>
|
||||
*
|
||||
* @since
|
||||
******************************************************************************/
|
||||
public class ProcessorParam {
|
||||
private String ifCond;
|
||||
private String name;
|
||||
private String unlessCond;
|
||||
private String value;
|
||||
public ProcessorParam() {
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Returns true if the define's if and unless conditions (if any) are
|
||||
* satisfied.
|
||||
*/
|
||||
public boolean isActive(org.apache.tools.ant.Project p) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
if (ifCond != null && p.getProperty(ifCond) == null) {
|
||||
return false;
|
||||
} else if (unlessCond != null && p.getProperty(unlessCond) != null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Sets the property name for the 'if' condition.
|
||||
*
|
||||
* The argument will be ignored unless the property is defined.
|
||||
*
|
||||
* The value of the property is insignificant, but values that would imply
|
||||
* misinterpretation ("false", "no") will throw an exception when
|
||||
* evaluated.
|
||||
*/
|
||||
public void setIf(String propName) {
|
||||
ifCond = propName;
|
||||
}
|
||||
/**
|
||||
* Specifies relative location of argument on command line. "start" will
|
||||
* place argument at start of command line, "mid" will place argument after
|
||||
* all "start" arguments but before filenames, "end" will place argument
|
||||
* after filenames.
|
||||
*
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
/**
|
||||
* Set the property name for the 'unless' condition.
|
||||
*
|
||||
* If named property is set, the argument will be ignored.
|
||||
*
|
||||
* The value of the property is insignificant, but values that would imply
|
||||
* misinterpretation ("false", "no") of the behavior will throw an
|
||||
* exception when evaluated.
|
||||
*
|
||||
* @param propName
|
||||
* name of property
|
||||
*/
|
||||
public void setUnless(String propName) {
|
||||
unlessCond = propName;
|
||||
}
|
||||
/**
|
||||
* Specifies the string that should appear on the command line. The
|
||||
* argument will be quoted if it contains embedded blanks. Use multiple
|
||||
* arguments to avoid quoting.
|
||||
*
|
||||
*/
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import org.apache.tools.ant.types.EnumeratedAttribute;
|
||||
/**
|
||||
* Enumerated attribute with the values "dynamic" and "static",
|
||||
*/
|
||||
public class RuntimeType extends EnumeratedAttribute {
|
||||
public String[] getValues() {
|
||||
return new String[]{"dynamic", "static"};
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
/**
|
||||
* The history of a source file used to build a target
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public final class SourceHistory {
|
||||
private/* final */long lastModified;
|
||||
private/* final */String relativePath;
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public SourceHistory(String relativePath, long lastModified) {
|
||||
if (relativePath == null) {
|
||||
throw new NullPointerException("relativePath");
|
||||
}
|
||||
this.relativePath = relativePath;
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
public String getAbsolutePath(File baseDir) {
|
||||
try {
|
||||
return new File(baseDir, relativePath).getCanonicalPath();
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
return relativePath;
|
||||
}
|
||||
public long getLastModified() {
|
||||
return lastModified;
|
||||
}
|
||||
public String getRelativePath() {
|
||||
return relativePath;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import org.apache.tools.ant.types.EnumeratedAttribute;
|
||||
/**
|
||||
* Enumeration of supported subsystems
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*
|
||||
*/
|
||||
public final class SubsystemEnum extends EnumeratedAttribute {
|
||||
private final static String[] values = new String[]{"gui", "console",
|
||||
"other"};
|
||||
public SubsystemEnum() {
|
||||
setValue("gui");
|
||||
}
|
||||
public String[] getValues() {
|
||||
return (String[]) values.clone();
|
||||
}
|
||||
}
|
@ -0,0 +1,228 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 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;
|
||||
|
||||
import org.apache.tools.ant.types.DataType;
|
||||
import org.apache.tools.ant.types.Reference;
|
||||
|
||||
/**
|
||||
* Information on the execution platforms for the generated code.
|
||||
* (Non-functional prototype)
|
||||
*
|
||||
*/
|
||||
public final class TargetDef
|
||||
extends DataType {
|
||||
/**
|
||||
* if property.
|
||||
*/
|
||||
private String ifCond;
|
||||
|
||||
/**
|
||||
* unless property.
|
||||
*/
|
||||
private String unlessCond;
|
||||
|
||||
/**
|
||||
* cpu.
|
||||
*
|
||||
*/
|
||||
private CPUEnum cpu;
|
||||
|
||||
/**
|
||||
* architecture.
|
||||
*
|
||||
*/
|
||||
private ArchEnum arch;
|
||||
|
||||
/**
|
||||
* OS Family.
|
||||
*
|
||||
*/
|
||||
private OSFamilyEnum osFamily;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*/
|
||||
public TargetDef() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Bogus method required for documentation generation.
|
||||
*/
|
||||
public void execute() {
|
||||
throw new org.apache.tools.ant.BuildException(
|
||||
"Not an actual task, but looks like one for documentation purposes");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the define's if and unless conditions (if any) are
|
||||
* satisfied.
|
||||
* @return true if active
|
||||
*/
|
||||
public boolean isActive() {
|
||||
return CUtil.isActive(getProject(), ifCond, unlessCond);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a description of the current data type.
|
||||
* @param desc description
|
||||
*/
|
||||
public void setDescription(final String desc) {
|
||||
super.setDescription(desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an id that can be used to reference this element.
|
||||
*
|
||||
* @param id
|
||||
* id
|
||||
*/
|
||||
public void setId(final String id) {
|
||||
//
|
||||
// this is actually accomplished by a different
|
||||
// mechanism, but we can document it
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property name for the 'if' condition.
|
||||
*
|
||||
* The define will be ignored unless the property is defined.
|
||||
*
|
||||
* The value of the property is insignificant, but values that would imply
|
||||
* misinterpretation ("false", "no") will throw an exception when
|
||||
* evaluated.
|
||||
*
|
||||
* @param propName
|
||||
* property name
|
||||
*/
|
||||
public void setIf(final String propName) {
|
||||
ifCond = propName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies that this element should behave as if the content of the
|
||||
* element with the matching id attribute was inserted at this location. If
|
||||
* specified, no other attributes should be specified.
|
||||
* @param r id of referenced target
|
||||
*/
|
||||
public void setRefid(final Reference r) {
|
||||
super.setRefid(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the property name for the 'unless' condition.
|
||||
*
|
||||
* If named property is set, the define will be ignored.
|
||||
*
|
||||
* The value of the property is insignificant, but values that would imply
|
||||
* misinterpretation ("false", "no") of the behavior will throw an
|
||||
* exception when evaluated.
|
||||
*
|
||||
* @param propName
|
||||
* name of property
|
||||
*/
|
||||
public void setUnless(final String propName) {
|
||||
unlessCond = propName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets cpu.
|
||||
* @return cpu, may be null.
|
||||
*
|
||||
*/
|
||||
public CPUEnum getCpu() {
|
||||
if (isReference()) {
|
||||
TargetDef refPlatform = (TargetDef)
|
||||
getCheckedRef(TargetDef.class,
|
||||
"TargetDef");
|
||||
return refPlatform.getCpu();
|
||||
}
|
||||
return cpu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets arch.
|
||||
* @return arch, may be null.
|
||||
*
|
||||
*/
|
||||
public ArchEnum getArch() {
|
||||
if (isReference()) {
|
||||
TargetDef refPlatform = (TargetDef)
|
||||
getCheckedRef(TargetDef.class,
|
||||
"TargetDef");
|
||||
return refPlatform.getArch();
|
||||
}
|
||||
return arch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets operating system family.
|
||||
* @return os family, may be null.
|
||||
*
|
||||
*/
|
||||
public OSFamilyEnum getOsfamily() {
|
||||
if (isReference()) {
|
||||
TargetDef refPlatform = (TargetDef)
|
||||
getCheckedRef(TargetDef.class,
|
||||
"TargetDef");
|
||||
return refPlatform.getOsfamily();
|
||||
}
|
||||
return osFamily;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets preferred cpu, but does not use cpu specific instructions.
|
||||
* @param value new value
|
||||
*/
|
||||
public void setCpu(final CPUEnum value) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
cpu = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets cpu architecture, compiler may use cpu specific instructions.
|
||||
* @param value new value
|
||||
*/
|
||||
public void setArch(final ArchEnum value) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
if (cpu != null) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
arch = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets operating system family.
|
||||
* @param value new value
|
||||
*/
|
||||
public void setOsfamily(final OSFamilyEnum value) {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
if (cpu != null) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
osFamily = value;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
/**
|
||||
* A description of a file built or to be built
|
||||
*/
|
||||
public final class TargetHistory {
|
||||
private/* final */String config;
|
||||
private/* final */String output;
|
||||
private/* final */long outputLastModified;
|
||||
private/* final */SourceHistory[] sources;
|
||||
/**
|
||||
* Constructor from build step
|
||||
*/
|
||||
public TargetHistory(String config, String output, long outputLastModified,
|
||||
SourceHistory[] sources) {
|
||||
if (config == null) {
|
||||
throw new NullPointerException("config");
|
||||
}
|
||||
if (sources == null) {
|
||||
throw new NullPointerException("source");
|
||||
}
|
||||
if (output == null) {
|
||||
throw new NullPointerException("output");
|
||||
}
|
||||
this.config = config;
|
||||
this.output = output;
|
||||
this.outputLastModified = outputLastModified;
|
||||
this.sources = (SourceHistory[]) sources.clone();
|
||||
}
|
||||
public String getOutput() {
|
||||
return output;
|
||||
}
|
||||
public long getOutputLastModified() {
|
||||
return outputLastModified;
|
||||
}
|
||||
public String getProcessorConfiguration() {
|
||||
return config;
|
||||
}
|
||||
public SourceHistory[] getSources() {
|
||||
SourceHistory[] clone = (SourceHistory[]) sources.clone();
|
||||
return clone;
|
||||
}
|
||||
}
|
@ -0,0 +1,426 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
/**
|
||||
* A history of the compiler and linker settings used to build the files in the
|
||||
* same directory as the history.
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public final class TargetHistoryTable {
|
||||
/**
|
||||
* This class handles populates the TargetHistory hashtable in response to
|
||||
* SAX parse events
|
||||
*/
|
||||
private class TargetHistoryTableHandler extends DefaultHandler {
|
||||
private final File baseDir;
|
||||
private String config;
|
||||
private final Hashtable history;
|
||||
private String output;
|
||||
private long outputLastModified;
|
||||
private final Vector sources = new Vector();
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param history
|
||||
* hashtable of TargetHistory keyed by output name
|
||||
* @param outputFiles
|
||||
* existing files in output directory
|
||||
*/
|
||||
private TargetHistoryTableHandler(Hashtable history, File baseDir) {
|
||||
this.history = history;
|
||||
config = null;
|
||||
output = null;
|
||||
this.baseDir = baseDir;
|
||||
}
|
||||
public void endElement(String namespaceURI, String localName,
|
||||
String qName) throws SAXException {
|
||||
//
|
||||
// if </target> then
|
||||
// create TargetHistory object and add to hashtable
|
||||
// if corresponding output file exists and
|
||||
// has the same timestamp
|
||||
//
|
||||
if (qName.equals("target")) {
|
||||
if (config != null && output != null) {
|
||||
File existingFile = new File(baseDir, output);
|
||||
//
|
||||
// if the corresponding files doesn't exist or has a
|
||||
// different
|
||||
// modification time, then discard this record
|
||||
if (existingFile.exists()) {
|
||||
long existingLastModified = existingFile.lastModified();
|
||||
//
|
||||
// would have expected exact time stamps
|
||||
// but have observed slight differences
|
||||
// in return value for multiple evaluations of
|
||||
// lastModified(). Check if times are within
|
||||
// a second
|
||||
long diff = outputLastModified - existingLastModified;
|
||||
if (diff >= -500 && diff <= 500) {
|
||||
SourceHistory[] sourcesArray = new SourceHistory[sources
|
||||
.size()];
|
||||
sources.copyInto(sourcesArray);
|
||||
TargetHistory targetHistory = new TargetHistory(
|
||||
config, output, outputLastModified,
|
||||
sourcesArray);
|
||||
history.put(output, targetHistory);
|
||||
}
|
||||
}
|
||||
}
|
||||
output = null;
|
||||
sources.setSize(0);
|
||||
} else {
|
||||
//
|
||||
// reset config so targets not within a processor element
|
||||
// don't pick up a previous processors signature
|
||||
//
|
||||
if (qName.equals("processor")) {
|
||||
config = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* startElement handler
|
||||
*/
|
||||
public void startElement(String namespaceURI, String localName,
|
||||
String qName, Attributes atts) throws SAXException {
|
||||
//
|
||||
// if sourceElement
|
||||
//
|
||||
if (qName.equals("source")) {
|
||||
String sourceFile = atts.getValue("file");
|
||||
long sourceLastModified = Long.parseLong(atts
|
||||
.getValue("lastModified"), 16);
|
||||
sources.addElement(new SourceHistory(sourceFile,
|
||||
sourceLastModified));
|
||||
} else {
|
||||
//
|
||||
// if <target> element,
|
||||
// grab file name and lastModified values
|
||||
// TargetHistory object will be created in endElement
|
||||
//
|
||||
if (qName.equals("target")) {
|
||||
sources.setSize(0);
|
||||
output = atts.getValue("file");
|
||||
outputLastModified = Long.parseLong(atts
|
||||
.getValue("lastModified"), 16);
|
||||
} else {
|
||||
//
|
||||
// if <processor> element,
|
||||
// grab signature attribute
|
||||
//
|
||||
if (qName.equals("processor")) {
|
||||
config = atts.getValue("signature");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/** Flag indicating whether the cache should be written back to file. */
|
||||
private boolean dirty;
|
||||
/**
|
||||
* a hashtable of TargetHistory's keyed by output file name
|
||||
*/
|
||||
private final Hashtable history = new Hashtable();
|
||||
/** The file the cache was loaded from. */
|
||||
private/* final */File historyFile;
|
||||
private/* final */File outputDir;
|
||||
private String outputDirPath;
|
||||
/**
|
||||
* Creates a target history table from history.xml in the output directory,
|
||||
* if it exists. Otherwise, initializes the history table empty.
|
||||
*
|
||||
* @param task
|
||||
* task used for logging history load errors
|
||||
* @param outputDir
|
||||
* output directory for task
|
||||
*/
|
||||
public TargetHistoryTable(CCTask task, File outputDir)
|
||||
throws BuildException {
|
||||
if (outputDir == null) {
|
||||
throw new NullPointerException("outputDir");
|
||||
}
|
||||
if (!outputDir.isDirectory()) {
|
||||
throw new BuildException("Output directory is not a directory");
|
||||
}
|
||||
if (!outputDir.exists()) {
|
||||
throw new BuildException("Output directory does not exist");
|
||||
}
|
||||
this.outputDir = outputDir;
|
||||
try {
|
||||
outputDirPath = outputDir.getCanonicalPath();
|
||||
} catch (IOException ex) {
|
||||
outputDirPath = outputDir.toString();
|
||||
}
|
||||
//
|
||||
// load any existing history from file
|
||||
// suppressing any records whose corresponding
|
||||
// file does not exist, is zero-length or
|
||||
// last modified dates differ
|
||||
historyFile = new File(outputDir, "history.xml");
|
||||
if (historyFile.exists()) {
|
||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||
factory.setValidating(false);
|
||||
try {
|
||||
SAXParser parser = factory.newSAXParser();
|
||||
parser.parse(historyFile, new TargetHistoryTableHandler(
|
||||
history, outputDir));
|
||||
} catch (Exception ex) {
|
||||
//
|
||||
// a failure on loading this history is not critical
|
||||
// but should be logged
|
||||
task.log("Error reading history.xml: " + ex.toString());
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// create empty history file for identifying new files by last
|
||||
// modified
|
||||
// timestamp comperation (to compare with
|
||||
// System.currentTimeMillis() don't work on Unix, because it
|
||||
// maesure timestamps only in seconds).
|
||||
//
|
||||
try {
|
||||
FileOutputStream outputStream = new FileOutputStream(
|
||||
historyFile);
|
||||
byte[] historyElement = new byte[]{0x3C, 0x68, 0x69, 0x73,
|
||||
0x74, 0x6F, 0x72, 0x79, 0x2F, 0x3E};
|
||||
outputStream.write(historyElement);
|
||||
outputStream.close();
|
||||
} catch (IOException ex) {
|
||||
throw new BuildException("Can't create history file", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void commit() throws IOException {
|
||||
//
|
||||
// if not dirty, no need to update file
|
||||
//
|
||||
if (dirty) {
|
||||
//
|
||||
// build (small) hashtable of config id's in history
|
||||
//
|
||||
Hashtable configs = new Hashtable(20);
|
||||
Enumeration elements = history.elements();
|
||||
while (elements.hasMoreElements()) {
|
||||
TargetHistory targetHistory = (TargetHistory) elements
|
||||
.nextElement();
|
||||
String configId = targetHistory.getProcessorConfiguration();
|
||||
if (configs.get(configId) == null) {
|
||||
configs.put(configId, configId);
|
||||
}
|
||||
}
|
||||
FileOutputStream outStream = new FileOutputStream(historyFile);
|
||||
OutputStreamWriter outWriter;
|
||||
//
|
||||
// early VM's don't support UTF-8 encoding
|
||||
// try and fallback to the default encoding
|
||||
// otherwise
|
||||
String encodingName = "UTF-8";
|
||||
try {
|
||||
outWriter = new OutputStreamWriter(outStream, "UTF-8");
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
outWriter = new OutputStreamWriter(outStream);
|
||||
encodingName = outWriter.getEncoding();
|
||||
}
|
||||
BufferedWriter writer = new BufferedWriter(outWriter);
|
||||
writer.write("<?xml version='1.0' encoding='");
|
||||
writer.write(encodingName);
|
||||
writer.write("'?>\n");
|
||||
writer.write("<history>\n");
|
||||
StringBuffer buf = new StringBuffer(200);
|
||||
Enumeration configEnum = configs.elements();
|
||||
while (configEnum.hasMoreElements()) {
|
||||
String configId = (String) configEnum.nextElement();
|
||||
buf.setLength(0);
|
||||
buf.append(" <processor signature=\"");
|
||||
buf.append(CUtil.xmlAttribEncode(configId));
|
||||
buf.append("\">\n");
|
||||
writer.write(buf.toString());
|
||||
elements = history.elements();
|
||||
while (elements.hasMoreElements()) {
|
||||
TargetHistory targetHistory = (TargetHistory) elements
|
||||
.nextElement();
|
||||
if (targetHistory.getProcessorConfiguration().equals(
|
||||
configId)) {
|
||||
buf.setLength(0);
|
||||
buf.append(" <target file=\"");
|
||||
buf.append(CUtil.xmlAttribEncode(targetHistory
|
||||
.getOutput()));
|
||||
buf.append("\" lastModified=\"");
|
||||
buf.append(Long.toHexString(targetHistory
|
||||
.getOutputLastModified()));
|
||||
buf.append("\">\n");
|
||||
writer.write(buf.toString());
|
||||
SourceHistory[] sourceHistories = targetHistory
|
||||
.getSources();
|
||||
for (int i = 0; i < sourceHistories.length; i++) {
|
||||
buf.setLength(0);
|
||||
buf.append(" <source file=\"");
|
||||
buf.append(CUtil.xmlAttribEncode(sourceHistories[i]
|
||||
.getRelativePath()));
|
||||
buf.append("\" lastModified=\"");
|
||||
buf.append(Long.toHexString(sourceHistories[i]
|
||||
.getLastModified()));
|
||||
buf.append("\"/>\n");
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
writer.write(" </target>\n");
|
||||
}
|
||||
}
|
||||
writer.write(" </processor>\n");
|
||||
}
|
||||
writer.write("</history>\n");
|
||||
writer.close();
|
||||
dirty = false;
|
||||
}
|
||||
}
|
||||
public TargetHistory get(String configId, String outputName) {
|
||||
TargetHistory targetHistory = (TargetHistory) history.get(outputName);
|
||||
if (targetHistory != null) {
|
||||
if (!targetHistory.getProcessorConfiguration().equals(configId)) {
|
||||
targetHistory = null;
|
||||
}
|
||||
}
|
||||
return targetHistory;
|
||||
}
|
||||
public void markForRebuild(Hashtable targetInfos) {
|
||||
Enumeration targetInfoEnum = targetInfos.elements();
|
||||
while (targetInfoEnum.hasMoreElements()) {
|
||||
markForRebuild((TargetInfo) targetInfoEnum.nextElement());
|
||||
}
|
||||
}
|
||||
public void markForRebuild(TargetInfo targetInfo) {
|
||||
//
|
||||
// if it must already be rebuilt, no need to check further
|
||||
//
|
||||
if (!targetInfo.getRebuild()) {
|
||||
TargetHistory history = get(targetInfo.getConfiguration()
|
||||
.toString(), targetInfo.getOutput().getName());
|
||||
if (history == null) {
|
||||
targetInfo.mustRebuild();
|
||||
} else {
|
||||
SourceHistory[] sourceHistories = history.getSources();
|
||||
File[] sources = targetInfo.getSources();
|
||||
if (sourceHistories.length != sources.length) {
|
||||
targetInfo.mustRebuild();
|
||||
} else {
|
||||
for (int i = 0; i < sourceHistories.length
|
||||
&& !targetInfo.getRebuild(); i++) {
|
||||
//
|
||||
// relative file name, must absolutize it on output
|
||||
// directory
|
||||
//
|
||||
boolean foundMatch = false;
|
||||
String historySourcePath = sourceHistories[i]
|
||||
.getAbsolutePath(outputDir);
|
||||
for (int j = 0; j < sources.length; j++) {
|
||||
File targetSource = sources[j];
|
||||
String targetSourcePath = targetSource
|
||||
.getAbsolutePath();
|
||||
if (targetSourcePath.equals(historySourcePath)) {
|
||||
foundMatch = true;
|
||||
if (targetSource.lastModified() != sourceHistories[i]
|
||||
.getLastModified()) {
|
||||
targetInfo.mustRebuild();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!foundMatch) {
|
||||
targetInfo.mustRebuild();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void update(ProcessorConfiguration config, String[] sources) {
|
||||
String configId = config.getIdentifier();
|
||||
String[] onesource = new String[1];
|
||||
String outputName;
|
||||
for (int i = 0; i < sources.length; i++) {
|
||||
onesource[0] = sources[i];
|
||||
outputName = config.getOutputFileName(sources[i]);
|
||||
update(configId, outputName, onesource);
|
||||
}
|
||||
}
|
||||
private void update(String configId, String outputName, String[] sources) {
|
||||
File outputFile = new File(outputDir, outputName);
|
||||
//
|
||||
// if output file doesn't exist or predates the start of the
|
||||
// compile step (most likely a compilation error) then
|
||||
// do not write add a history entry
|
||||
//
|
||||
if (outputFile.exists()
|
||||
&& outputFile.lastModified() >= historyFile.lastModified()) {
|
||||
dirty = true;
|
||||
history.remove(outputName);
|
||||
SourceHistory[] sourceHistories = new SourceHistory[sources.length];
|
||||
for (int i = 0; i < sources.length; i++) {
|
||||
File sourceFile = new File(sources[i]);
|
||||
long lastModified = sourceFile.lastModified();
|
||||
String relativePath = CUtil.getRelativePath(outputDirPath,
|
||||
sourceFile);
|
||||
sourceHistories[i] = new SourceHistory(relativePath,
|
||||
lastModified);
|
||||
}
|
||||
TargetHistory newHistory = new TargetHistory(configId, outputName,
|
||||
outputFile.lastModified(), sourceHistories);
|
||||
history.put(outputName, newHistory);
|
||||
}
|
||||
}
|
||||
public void update(TargetInfo linkTarget) {
|
||||
File outputFile = linkTarget.getOutput();
|
||||
String outputName = outputFile.getName();
|
||||
//
|
||||
// if output file doesn't exist or predates the start of the
|
||||
// compile or link step (most likely a compilation error) then
|
||||
// do not write add a history entry
|
||||
//
|
||||
if (outputFile.exists()
|
||||
&& outputFile.lastModified() >= historyFile.lastModified()) {
|
||||
dirty = true;
|
||||
history.remove(outputName);
|
||||
SourceHistory[] sourceHistories = linkTarget
|
||||
.getSourceHistories(outputDirPath);
|
||||
TargetHistory newHistory = new TargetHistory(linkTarget
|
||||
.getConfiguration().getIdentifier(), outputName, outputFile
|
||||
.lastModified(), sourceHistories);
|
||||
history.put(outputName, newHistory);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration;
|
||||
/**
|
||||
* A description of a file built or to be built
|
||||
*/
|
||||
public final class TargetInfo {
|
||||
private static final File[] emptyFileArray = new File[0];
|
||||
private/* final */ProcessorConfiguration config;
|
||||
private/* final */File output;
|
||||
private boolean rebuild;
|
||||
private/* final */File[] sources;
|
||||
private File[] sysSources;
|
||||
public TargetInfo(ProcessorConfiguration config, File[] sources,
|
||||
File[] sysSources, File output, boolean rebuild) {
|
||||
if (config == null) {
|
||||
throw new NullPointerException("config");
|
||||
}
|
||||
if (sources == null) {
|
||||
throw new NullPointerException("sources");
|
||||
}
|
||||
if (output == null) {
|
||||
throw new NullPointerException("output");
|
||||
}
|
||||
this.config = config;
|
||||
this.sources = (File[]) sources.clone();
|
||||
if (sysSources == null) {
|
||||
this.sysSources = emptyFileArray;
|
||||
} else {
|
||||
this.sysSources = (File[]) sysSources.clone();
|
||||
}
|
||||
this.output = output;
|
||||
this.rebuild = rebuild;
|
||||
//
|
||||
// if the output doesn't exist, must rebuild it
|
||||
//
|
||||
if (!output.exists()) {
|
||||
rebuild = true;
|
||||
}
|
||||
}
|
||||
public String[] getAllSourcePaths() {
|
||||
String[] paths = new String[sysSources.length + sources.length];
|
||||
for (int i = 0; i < sysSources.length; i++) {
|
||||
paths[i] = sysSources[i].toString();
|
||||
}
|
||||
int offset = sysSources.length;
|
||||
for (int i = 0; i < sources.length; i++) {
|
||||
paths[offset + i] = sources[i].toString();
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
public File[] getAllSources() {
|
||||
File[] allSources = new File[sources.length + sysSources.length];
|
||||
for (int i = 0; i < sysSources.length; i++) {
|
||||
allSources[i] = sysSources[i];
|
||||
}
|
||||
int offset = sysSources.length;
|
||||
for (int i = 0; i < sources.length; i++) {
|
||||
allSources[i + offset] = sources[i];
|
||||
}
|
||||
return allSources;
|
||||
}
|
||||
public ProcessorConfiguration getConfiguration() {
|
||||
return config;
|
||||
}
|
||||
public File getOutput() {
|
||||
return output;
|
||||
}
|
||||
public boolean getRebuild() {
|
||||
return rebuild;
|
||||
}
|
||||
/**
|
||||
* Returns an array of SourceHistory objects (contains relative path and
|
||||
* last modified time) for the source[s] of this target
|
||||
*/
|
||||
public SourceHistory[] getSourceHistories(String basePath) {
|
||||
SourceHistory[] histories = new SourceHistory[sources.length];
|
||||
for (int i = 0; i < sources.length; i++) {
|
||||
String relativeName = CUtil.getRelativePath(basePath, sources[i]);
|
||||
long lastModified = sources[i].lastModified();
|
||||
histories[i] = new SourceHistory(relativeName, lastModified);
|
||||
}
|
||||
return histories;
|
||||
}
|
||||
public String[] getSourcePaths() {
|
||||
String[] paths = new String[sources.length];
|
||||
for (int i = 0; i < sources.length; i++) {
|
||||
paths[i] = sources[i].toString();
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
public File[] getSources() {
|
||||
File[] clone = (File[]) sources.clone();
|
||||
return clone;
|
||||
}
|
||||
public String[] getSysSourcePaths() {
|
||||
String[] paths = new String[sysSources.length];
|
||||
for (int i = 0; i < sysSources.length; i++) {
|
||||
paths[i] = sysSources[i].toString();
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
public File[] getSysSources() {
|
||||
File[] clone = (File[]) sysSources.clone();
|
||||
return clone;
|
||||
}
|
||||
public void mustRebuild() {
|
||||
this.rebuild = true;
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
import java.io.File;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.compiler.LinkerConfiguration;
|
||||
import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
/**
|
||||
* This class matches each visited file with an appropriate compiler
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public final class TargetMatcher implements FileVisitor {
|
||||
private LinkerConfiguration linker;
|
||||
private Vector objectFiles;
|
||||
private File outputDir;
|
||||
private ProcessorConfiguration[] processors;
|
||||
private final File sourceFiles[] = new File[1];
|
||||
private Hashtable targets;
|
||||
private CCTask task;
|
||||
public TargetMatcher(CCTask task, File outputDir,
|
||||
ProcessorConfiguration[] processors, LinkerConfiguration linker,
|
||||
Vector objectFiles, Hashtable targets) {
|
||||
this.task = task;
|
||||
this.outputDir = outputDir;
|
||||
this.processors = processors;
|
||||
this.targets = targets;
|
||||
this.linker = linker;
|
||||
this.objectFiles = objectFiles;
|
||||
}
|
||||
public void visit(File parentDir, String filename) throws BuildException {
|
||||
//
|
||||
// see if any processor wants to bid
|
||||
// on this one
|
||||
ProcessorConfiguration selectedCompiler = null;
|
||||
int bid = 0;
|
||||
if (processors != null) {
|
||||
for (int k = 0; k < processors.length; k++) {
|
||||
int newBid = processors[k].bid(filename);
|
||||
if (newBid > bid) {
|
||||
bid = newBid;
|
||||
selectedCompiler = processors[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// no processor interested in file
|
||||
// log diagnostic message
|
||||
if (bid <= 0) {
|
||||
if (linker != null) {
|
||||
int linkerbid = linker.bid(filename);
|
||||
if (linkerbid > 0) {
|
||||
File objFile = new File(parentDir, filename);
|
||||
objectFiles.addElement(objFile);
|
||||
if (linkerbid == 1) {
|
||||
task.log("Unrecognized file type " + objFile.toString()
|
||||
+ " will be passed to linker");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// get output file name
|
||||
//
|
||||
String outputFileName = selectedCompiler
|
||||
.getOutputFileName(filename);
|
||||
//
|
||||
// if there is some output for this task
|
||||
// (that is a source file and not an header file)
|
||||
//
|
||||
if (outputFileName != null) {
|
||||
sourceFiles[0] = new File(parentDir, filename);
|
||||
//
|
||||
// see if the same output file has already been registered
|
||||
//
|
||||
TargetInfo previousTarget = (TargetInfo) targets
|
||||
.get(outputFileName);
|
||||
if (previousTarget == null) {
|
||||
targets.put(outputFileName, new TargetInfo(
|
||||
selectedCompiler, sourceFiles, null, new File(
|
||||
outputDir, outputFileName),
|
||||
selectedCompiler.getRebuild()));
|
||||
} else {
|
||||
if (!previousTarget.getSources()[0].equals(sourceFiles[0])) {
|
||||
StringBuffer builder = new StringBuffer(
|
||||
"Output filename conflict: ");
|
||||
builder.append(outputFileName);
|
||||
builder.append(" would be produced from ");
|
||||
builder.append(previousTarget.getSources()[0]
|
||||
.toString());
|
||||
builder.append(" and ");
|
||||
builder.append(filename);
|
||||
throw new BuildException(builder.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,550 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.types.DataType;
|
||||
import org.apache.tools.ant.types.Reference;
|
||||
|
||||
/**
|
||||
* Version Information. (Non-functional prototype)
|
||||
*
|
||||
*/
|
||||
public class VersionInfo extends DataType {
|
||||
/**
|
||||
* if property.
|
||||
*/
|
||||
private String ifCond;
|
||||
/**
|
||||
* unless property.
|
||||
*/
|
||||
private String unlessCond;
|
||||
|
||||
/**
|
||||
* extends property.
|
||||
*/
|
||||
private String extendsId;
|
||||
|
||||
/**
|
||||
* file version.
|
||||
*
|
||||
*/
|
||||
private String fileVersion;
|
||||
/**
|
||||
* Product version.
|
||||
*
|
||||
*/
|
||||
private String productVersion;
|
||||
/**
|
||||
* file language.
|
||||
*
|
||||
*/
|
||||
private String language;
|
||||
|
||||
/**
|
||||
* comments.
|
||||
*
|
||||
*/
|
||||
private String fileComments;
|
||||
/**
|
||||
* Company name.
|
||||
*
|
||||
*/
|
||||
private String companyName;
|
||||
/**
|
||||
* Description.
|
||||
*
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* internal name.
|
||||
*/
|
||||
private String internalName;
|
||||
/**
|
||||
* legal copyright.
|
||||
*
|
||||
*/
|
||||
private String legalCopyright;
|
||||
/**
|
||||
* legal trademark.
|
||||
*
|
||||
*/
|
||||
private String legalTrademark;
|
||||
/**
|
||||
* original filename.
|
||||
*
|
||||
*/
|
||||
private String originalFilename;
|
||||
/**
|
||||
* private build.
|
||||
*
|
||||
*/
|
||||
private String privateBuild;
|
||||
/**
|
||||
* product name.
|
||||
*
|
||||
*/
|
||||
private String productName;
|
||||
/**
|
||||
* Special build
|
||||
*/
|
||||
private String specialBuild;
|
||||
/**
|
||||
* compatibility version
|
||||
*
|
||||
*/
|
||||
private String compatibilityVersion;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*/
|
||||
public VersionInfo() {
|
||||
}
|
||||
public void execute() throws org.apache.tools.ant.BuildException {
|
||||
throw new org.apache.tools.ant.BuildException(
|
||||
"Not an actual task, but looks like one for documentation purposes");
|
||||
}
|
||||
/**
|
||||
* Returns true if the define's if and unless conditions (if any) are
|
||||
* satisfied.
|
||||
*
|
||||
* @exception BuildException
|
||||
* throws build exception if name is not set
|
||||
*/
|
||||
public final boolean isActive() throws BuildException {
|
||||
return CUtil.isActive(getProject(), ifCond, unlessCond);
|
||||
}
|
||||
/**
|
||||
* Sets an id that can be used to reference this element.
|
||||
*
|
||||
* @param id
|
||||
* id
|
||||
*/
|
||||
public void setId(String id) {
|
||||
//
|
||||
// this is actually accomplished by a different
|
||||
// mechanism, but we can document it
|
||||
//
|
||||
}
|
||||
/**
|
||||
* Sets the name of a version info that this info extends.
|
||||
*
|
||||
* @param id
|
||||
* id
|
||||
*/
|
||||
public void setExtends(String id) {
|
||||
extendsId = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the property name for the 'if' condition.
|
||||
*
|
||||
* The define will be ignored unless the property is defined.
|
||||
*
|
||||
* The value of the property is insignificant, but values that would imply
|
||||
* misinterpretation ("false", "no") will throw an exception when
|
||||
* evaluated.
|
||||
*
|
||||
* @param propName
|
||||
* property name
|
||||
*/
|
||||
public final void setIf(String propName) {
|
||||
ifCond = propName;
|
||||
}
|
||||
/**
|
||||
* Specifies that this element should behave as if the content of the
|
||||
* element with the matching id attribute was inserted at this location. If
|
||||
* specified, no other attributes should be specified.
|
||||
*
|
||||
*/
|
||||
public void setRefid(Reference r) throws BuildException {
|
||||
super.setRefid(r);
|
||||
}
|
||||
/**
|
||||
* Set the property name for the 'unless' condition.
|
||||
*
|
||||
* If named property is set, the define will be ignored.
|
||||
*
|
||||
* The value of the property is insignificant, but values that would imply
|
||||
* misinterpretation ("false", "no") of the behavior will throw an
|
||||
* exception when evaluated.
|
||||
*
|
||||
* @param propName
|
||||
* name of property
|
||||
*/
|
||||
public final void setUnless(String propName) {
|
||||
unlessCond = propName;
|
||||
}
|
||||
/**
|
||||
* Gets file version.
|
||||
* @return file version, may be null.
|
||||
*
|
||||
*/
|
||||
public String getFileversion() {
|
||||
if (isReference()) {
|
||||
VersionInfo refVersion = (VersionInfo)
|
||||
getCheckedRef(VersionInfo.class,
|
||||
"VersionInfo");
|
||||
return refVersion.getFileversion();
|
||||
}
|
||||
return fileVersion;
|
||||
}
|
||||
/**
|
||||
* Gets Product version.
|
||||
* @return product version, may be null
|
||||
*/
|
||||
public String getProductversion() {
|
||||
if (isReference()) {
|
||||
VersionInfo refVersion = (VersionInfo)
|
||||
getCheckedRef(VersionInfo.class,
|
||||
"VersionInfo");
|
||||
return refVersion.getProductversion();
|
||||
}
|
||||
return productVersion;
|
||||
}
|
||||
/**
|
||||
* Gets compatibility version.
|
||||
* @return compatibility version, may be null
|
||||
*/
|
||||
public String getCompatibilityversion() {
|
||||
if (isReference()) {
|
||||
VersionInfo refVersion = (VersionInfo)
|
||||
getCheckedRef(VersionInfo.class,
|
||||
"VersionInfo");
|
||||
return refVersion.getCompatibilityversion();
|
||||
}
|
||||
return compatibilityVersion;
|
||||
}
|
||||
/**
|
||||
* Gets file language, should be an IETF RFC 3066 identifier, for example, en-US.
|
||||
* @return language, may be null.
|
||||
*/
|
||||
public String getLanguage() {
|
||||
if (isReference()) {
|
||||
VersionInfo refVersion = (VersionInfo)
|
||||
getCheckedRef(VersionInfo.class,
|
||||
"VersionInfo");
|
||||
return refVersion.getLanguage();
|
||||
}
|
||||
return language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets comments.
|
||||
* @return comments, may be null.
|
||||
*/
|
||||
public String getFilecomments() {
|
||||
if (isReference()) {
|
||||
VersionInfo refVersion = (VersionInfo)
|
||||
getCheckedRef(VersionInfo.class,
|
||||
"VersionInfo");
|
||||
return refVersion.getFilecomments();
|
||||
}
|
||||
return fileComments;
|
||||
}
|
||||
/**
|
||||
* Gets Company name.
|
||||
* @return company name, may be null.
|
||||
*/
|
||||
public String getCompanyname() {
|
||||
if (isReference()) {
|
||||
VersionInfo refVersion = (VersionInfo)
|
||||
getCheckedRef(VersionInfo.class,
|
||||
"VersionInfo");
|
||||
return refVersion.getCompanyname();
|
||||
}
|
||||
return companyName;
|
||||
}
|
||||
/**
|
||||
* Gets Description.
|
||||
* @return description, may be null.
|
||||
*/
|
||||
public String getDescription() {
|
||||
if (isReference()) {
|
||||
VersionInfo refVersion = (VersionInfo)
|
||||
getCheckedRef(VersionInfo.class,
|
||||
"VersionInfo");
|
||||
return refVersion.getDescription();
|
||||
}
|
||||
return description;
|
||||
}
|
||||
/**
|
||||
* Gets internal name.
|
||||
* @return internal name, may be null.
|
||||
*/
|
||||
public String getInternalname() {
|
||||
if (isReference()) {
|
||||
VersionInfo refVersion = (VersionInfo)
|
||||
getCheckedRef(VersionInfo.class,
|
||||
"VersionInfo");
|
||||
return refVersion.getInternalname();
|
||||
}
|
||||
return internalName;
|
||||
}
|
||||
/**
|
||||
* Gets legal copyright.
|
||||
* @return legal copyright, may be null.
|
||||
*/
|
||||
public String getLegalcopyright() {
|
||||
if (isReference()) {
|
||||
VersionInfo refVersion = (VersionInfo)
|
||||
getCheckedRef(VersionInfo.class,
|
||||
"VersionInfo");
|
||||
return refVersion.getLegalcopyright();
|
||||
}
|
||||
return legalCopyright;
|
||||
}
|
||||
/**
|
||||
* Gets legal trademark.
|
||||
* @return legal trademark, may be null;
|
||||
*/
|
||||
public String getLegaltrademark() {
|
||||
if (isReference()) {
|
||||
VersionInfo refVersion = (VersionInfo)
|
||||
getCheckedRef(VersionInfo.class,
|
||||
"VersionInfo");
|
||||
return refVersion.getLegaltrademark();
|
||||
}
|
||||
return legalTrademark;
|
||||
}
|
||||
/**
|
||||
* Gets original filename.
|
||||
* @return original filename, may be null.
|
||||
*/
|
||||
public String getOriginalfilename() {
|
||||
if (isReference()) {
|
||||
VersionInfo refVersion = (VersionInfo)
|
||||
getCheckedRef(VersionInfo.class,
|
||||
"VersionInfo");
|
||||
return refVersion.getOriginalfilename();
|
||||
}
|
||||
return originalFilename;
|
||||
}
|
||||
/**
|
||||
* Gets private build.
|
||||
* @return private build, may be null.
|
||||
*/
|
||||
public String getPrivatebuild() {
|
||||
if (isReference()) {
|
||||
VersionInfo refVersion = (VersionInfo)
|
||||
getCheckedRef(VersionInfo.class,
|
||||
"VersionInfo");
|
||||
return refVersion.getPrivatebuild();
|
||||
}
|
||||
return privateBuild;
|
||||
}
|
||||
/**
|
||||
* Gets product name.
|
||||
* @return product name, may be null.
|
||||
*/
|
||||
public String getProductname() {
|
||||
if (isReference()) {
|
||||
VersionInfo refVersion = (VersionInfo)
|
||||
getCheckedRef(VersionInfo.class,
|
||||
"VersionInfo");
|
||||
return refVersion.getProductname();
|
||||
}
|
||||
return productName;
|
||||
}
|
||||
/**
|
||||
* Special build
|
||||
* @return special build, may be null.
|
||||
*/
|
||||
public String getSpecialbuild() {
|
||||
if (isReference()) {
|
||||
VersionInfo refVersion = (VersionInfo)
|
||||
getCheckedRef(VersionInfo.class,
|
||||
"VersionInfo");
|
||||
return refVersion.getSpecialbuild();
|
||||
}
|
||||
return specialBuild;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets file version.
|
||||
* @param value new value
|
||||
* @throws BuildException if specified with refid
|
||||
*/
|
||||
public void setFileversion(String value) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
fileVersion = value;
|
||||
}
|
||||
/**
|
||||
* Sets product version.
|
||||
* @param value new value
|
||||
* @throws BuildException if specified with refid
|
||||
*/
|
||||
public void setProductversion(String value) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
productVersion = value;
|
||||
}
|
||||
/**
|
||||
* Sets compatibility version.
|
||||
* @param value new value
|
||||
* @throws BuildException if specified with refid
|
||||
*/
|
||||
public void setCompatibilityversion(String value) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
compatibilityVersion = value;
|
||||
}
|
||||
/**
|
||||
* Sets language.
|
||||
* @param value new value, should be an IETF RFC 3066 language identifier.
|
||||
* @throws BuildException if specified with refid
|
||||
*/
|
||||
public void setLanguage(String value) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
language = value;
|
||||
}
|
||||
/**
|
||||
* Sets comments.
|
||||
* @param value new value
|
||||
* @throws BuildException if specified with refid
|
||||
*/
|
||||
public void setFilecomments(String value) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
fileComments = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets company name.
|
||||
* @param value new value
|
||||
* @throws BuildException if specified with refid
|
||||
*/
|
||||
public void setCompanyname(String value) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
companyName = value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets internal name. Internal name will automatically be
|
||||
* specified from build step, only set this value if
|
||||
* intentionally overriding that value.
|
||||
*
|
||||
* @param value new value
|
||||
* @throws BuildException if specified with refid
|
||||
*/
|
||||
public void setInternalname(String value) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
internalName = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets legal copyright.
|
||||
* @param value new value
|
||||
* @throws BuildException if specified with refid
|
||||
*/
|
||||
public void setLegalcopyright(String value) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
legalCopyright = value;
|
||||
}
|
||||
/**
|
||||
* Sets legal trademark.
|
||||
* @param value new value
|
||||
* @throws BuildException if specified with refid
|
||||
*/
|
||||
public void setLegaltrademark(String value) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
legalTrademark = value;
|
||||
}
|
||||
/**
|
||||
* Sets original name. Only set this value if
|
||||
* intentionally overriding the value from the build set.
|
||||
*
|
||||
* @param value new value
|
||||
* @throws BuildException if specified with refid
|
||||
*/
|
||||
public void setOriginalfilename(String value) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
originalFilename = value;
|
||||
}
|
||||
/**
|
||||
* Sets private build.
|
||||
* @param value new value
|
||||
* @throws BuildException if specified with refid
|
||||
*/
|
||||
public void setPrivatebuild(String value) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
privateBuild = value;
|
||||
}
|
||||
/**
|
||||
* Sets product name.
|
||||
* @param value new value
|
||||
* @throws BuildException if specified with refid
|
||||
*/
|
||||
public void setProductname(String value) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
productName= value;
|
||||
}
|
||||
/**
|
||||
* Sets private build.
|
||||
* @param value new value
|
||||
* @throws BuildException if specified with refid
|
||||
*/
|
||||
public void setSpecialbuild(String value) throws BuildException {
|
||||
if (isReference()) {
|
||||
throw tooManyAttributes();
|
||||
}
|
||||
specialBuild = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes windows resource
|
||||
* @param writer writer, may not be null.
|
||||
* @param project project, may not be null
|
||||
* @param executableName name of executable
|
||||
*/
|
||||
public void writeResource(final Writer writer,
|
||||
final Project p,
|
||||
final String executableName) throws IOException {
|
||||
// TODO:
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,215 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2003-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.arm;
|
||||
import java.io.File;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.CUtil;
|
||||
import net.sf.antcontrib.cpptasks.OptimizationEnum;
|
||||
import net.sf.antcontrib.cpptasks.compiler.CommandLineCCompiler;
|
||||
import net.sf.antcontrib.cpptasks.compiler.LinkType;
|
||||
import net.sf.antcontrib.cpptasks.compiler.Linker;
|
||||
|
||||
import org.apache.tools.ant.types.Environment;
|
||||
/**
|
||||
* Adapter for the ARM C Compilers
|
||||
*
|
||||
* See Doc No: ARM DUI 0151A, Issued: Nov 2001 at
|
||||
* http://www.arm.com/arm/User_Guides?OpenDocument
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*
|
||||
*/
|
||||
public class ADSCCompiler extends CommandLineCCompiler {
|
||||
/**
|
||||
* Header file extensions
|
||||
*/
|
||||
private static final String[] headerExtensions = new String[]{".h", ".hpp",
|
||||
".inl"};
|
||||
/**
|
||||
* Source file extensions
|
||||
*/
|
||||
private static final String[] sourceExtensions = new String[]{".c", ".cc",
|
||||
".cpp", ".cxx", ".c++"};
|
||||
/**
|
||||
* Singleton for ARM 32-bit C compiler
|
||||
*/
|
||||
private static final ADSCCompiler armcc = new ADSCCompiler("armcc", false,
|
||||
null);
|
||||
/**
|
||||
* Singleton for ARM 32-bit C++ compiler
|
||||
*/
|
||||
private static final ADSCCompiler armcpp = new ADSCCompiler("armcpp",
|
||||
false, null);
|
||||
/**
|
||||
* Singleton for ARM 16-bit C compiler
|
||||
*/
|
||||
private static final ADSCCompiler tcc = new ADSCCompiler("tcc", false, null);
|
||||
/**
|
||||
* Singleton for ARM 16-bit C++ compiler
|
||||
*/
|
||||
private static final ADSCCompiler tcpp = new ADSCCompiler("tcpp", false,
|
||||
null);
|
||||
/**
|
||||
* Singleton for ARM 32-bit C compiler
|
||||
*/
|
||||
public static ADSCCompiler getArmCC() {
|
||||
return armcc;
|
||||
}
|
||||
/**
|
||||
* Singleton for ARM 32-bit C++ compiler
|
||||
*/
|
||||
public static ADSCCompiler getArmCpp() {
|
||||
return armcpp;
|
||||
}
|
||||
/**
|
||||
* Singleton for ARM 16-bit C compiler
|
||||
*/
|
||||
public static ADSCCompiler getThumbCC() {
|
||||
return tcpp;
|
||||
}
|
||||
/**
|
||||
* Singleton for ARM 16-bit C++ compiler
|
||||
*/
|
||||
public static ADSCCompiler getThumbCpp() {
|
||||
return tcpp;
|
||||
}
|
||||
private static void quoteFile(StringBuffer buf, String outPath) {
|
||||
if (outPath.indexOf(' ') >= 0) {
|
||||
buf.append('\"');
|
||||
buf.append(outPath);
|
||||
buf.append('\"');
|
||||
} else {
|
||||
buf.append(outPath);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Private constructor
|
||||
*
|
||||
* @param command
|
||||
* executable name
|
||||
* @param newEnvironment
|
||||
* Change environment
|
||||
* @param env
|
||||
* New environment
|
||||
*/
|
||||
private ADSCCompiler(String command, boolean newEnvironment, Environment env) {
|
||||
super(command, "-vsn", sourceExtensions, headerExtensions, ".o", false,
|
||||
null, newEnvironment, env);
|
||||
}
|
||||
/**
|
||||
* Adds command switches for generic configuration options
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineCompiler#addImpliedArgs(java.util.Vector,
|
||||
* boolean, boolean, boolean,
|
||||
* net.sf.antcontrib.cpptasks.compiler.LinkType)
|
||||
*/
|
||||
protected void addImpliedArgs(Vector args,
|
||||
final boolean debug,
|
||||
final boolean multithreaded,
|
||||
final boolean exceptions,
|
||||
final LinkType linkType,
|
||||
final Boolean rtti,
|
||||
final OptimizationEnum optimization,
|
||||
final Boolean defaultflag) {
|
||||
if (debug) {
|
||||
args.addElement("-g");
|
||||
}
|
||||
//
|
||||
// didn't see anything about producing
|
||||
// anything other than executables in the docs
|
||||
if (linkType.isExecutable()) {
|
||||
} else if (linkType.isSharedLibrary()) {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds flags that customize the warnings reported
|
||||
*
|
||||
* Compiler does not appear to have warning levels but ability to turn off
|
||||
* specific errors by explicit switches, could fabricate levels by
|
||||
* prioritizing errors.
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineCompiler#addWarningSwitch(java.util.Vector,
|
||||
* int)
|
||||
*/
|
||||
protected void addWarningSwitch(Vector args, int warnings) {
|
||||
}
|
||||
/**
|
||||
* Add command line options for preprocessor macro
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineCompiler#getDefineSwitch(java.lang.StringBuffer,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
protected void getDefineSwitch(StringBuffer buffer, String define,
|
||||
String value) {
|
||||
buffer.append("-D");
|
||||
buffer.append(define);
|
||||
if (value != null) {
|
||||
buffer.append('=');
|
||||
buffer.append(value);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* ARMINC environment variable contains the default include path
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineCompiler#getEnvironmentIncludePath()
|
||||
*/
|
||||
protected File[] getEnvironmentIncludePath() {
|
||||
return CUtil.getPathFromEnvironment("ARMINC", ";");
|
||||
}
|
||||
/**
|
||||
* Returns command line option to specify include directory
|
||||
*
|
||||
*/
|
||||
protected String getIncludeDirSwitch(String source) {
|
||||
StringBuffer buf = new StringBuffer("-I");
|
||||
quoteFile(buf, source);
|
||||
return buf.toString();
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.Processor#getLinker(net.sf.antcontrib.cpptasks.compiler.LinkType)
|
||||
*/
|
||||
public Linker getLinker(LinkType type) {
|
||||
if (type.isStaticLibrary()) {
|
||||
return ADSLibrarian.getInstance();
|
||||
}
|
||||
if (type.isSharedLibrary()) {
|
||||
return ADSLinker.getDllInstance();
|
||||
}
|
||||
return ADSLinker.getInstance();
|
||||
}
|
||||
/**
|
||||
* Maximum command line length
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineCompiler#getMaximumCommandLength()
|
||||
*/
|
||||
public int getMaximumCommandLength() {
|
||||
return 1000;
|
||||
}
|
||||
/*
|
||||
* Adds command to undefine preprocessor macro
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineCompiler#getUndefineSwitch(java.lang.StringBuffer,
|
||||
* java.lang.String)
|
||||
*/
|
||||
protected void getUndefineSwitch(StringBuffer buffer, String define) {
|
||||
buffer.append("-U");
|
||||
buffer.append(define);
|
||||
}
|
||||
}
|
@ -0,0 +1,160 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2003-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.arm;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Vector;
|
||||
|
||||
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.LibraryTypeEnum;
|
||||
|
||||
/**
|
||||
* Adapter for ARM Librarian
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public class ADSLibrarian extends CommandLineLinker {
|
||||
|
||||
private static final ADSLibrarian instance = new ADSLibrarian();
|
||||
|
||||
public static ADSLibrarian getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private ADSLibrarian()
|
||||
{
|
||||
super("armar",null,
|
||||
new String[] { ".o" }, new String[0], ".lib", false, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addBase(long, java.util.Vector)
|
||||
*/
|
||||
protected void addBase(long base, Vector args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addFixed(java.lang.Boolean, java.util.Vector)
|
||||
*/
|
||||
protected void addFixed(Boolean fixed, Vector args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addImpliedArgs(boolean, net.sf.antcontrib.cpptasks.compiler.LinkType, java.util.Vector)
|
||||
*/
|
||||
protected void addImpliedArgs(
|
||||
boolean debug,
|
||||
LinkType linkType,
|
||||
Vector args,
|
||||
Boolean defaultflag) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addIncremental(boolean, java.util.Vector)
|
||||
*/
|
||||
protected void addIncremental(boolean incremental, Vector args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addMap(boolean, java.util.Vector)
|
||||
*/
|
||||
protected void addMap(boolean map, Vector args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addStack(int, java.util.Vector)
|
||||
*/
|
||||
protected void addStack(int stack, Vector args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addEntry(int, java.util.Vector)
|
||||
*/
|
||||
protected void addEntry(String entry, Vector args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#getCommandFileSwitch(java.lang.String)
|
||||
*/
|
||||
protected String getCommandFileSwitch(String commandFile) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.Linker#getLibraryPath()
|
||||
*/
|
||||
public File[] getLibraryPath() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.Linker#getLibraryPatterns(java.lang.String[])
|
||||
*/
|
||||
public String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.Processor#getLinker(net.sf.antcontrib.cpptasks.compiler.LinkType)
|
||||
*/
|
||||
public Linker getLinker(LinkType linkType) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#getMaximumCommandLength()
|
||||
*/
|
||||
protected int getMaximumCommandLength() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#getOutputFileSwitch(java.lang.String)
|
||||
*/
|
||||
protected String[] getOutputFileSwitch(String outputFile) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.Linker#isCaseSensitive()
|
||||
*/
|
||||
public boolean isCaseSensitive() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,166 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2003-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.arm;
|
||||
import java.io.File;
|
||||
import java.util.Vector;
|
||||
|
||||
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.LibraryTypeEnum;
|
||||
|
||||
/**
|
||||
* Adapter for the ARM Linker
|
||||
*
|
||||
* @author CurtA
|
||||
*/
|
||||
public class ADSLinker extends CommandLineLinker {
|
||||
private static final ADSLinker dllInstance = new ADSLinker(".o");
|
||||
private static final ADSLinker instance = new ADSLinker(".axf");
|
||||
public static ADSLinker getDllInstance() {
|
||||
return dllInstance;
|
||||
}
|
||||
public static ADSLinker getInstance() {
|
||||
return instance;
|
||||
}
|
||||
private ADSLinker(String outputSuffix) {
|
||||
super("armlink", "-vsn", new String[]{".o", ".lib", ".res"},
|
||||
new String[]{".map", ".pdb", ".lnk"}, outputSuffix, false, null);
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addBase(long,
|
||||
* java.util.Vector)
|
||||
*/
|
||||
protected void addBase(long base, Vector args) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addFixed(java.lang.Boolean,
|
||||
* java.util.Vector)
|
||||
*/
|
||||
protected void addFixed(Boolean fixed, Vector args) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addImpliedArgs(boolean,
|
||||
* net.sf.antcontrib.cpptasks.compiler.LinkType, java.util.Vector)
|
||||
*/
|
||||
protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args, Boolean defaultflag) {
|
||||
if (debug) {
|
||||
args.addElement("-debug");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addIncremental(boolean,
|
||||
* java.util.Vector)
|
||||
*/
|
||||
protected void addIncremental(boolean incremental, Vector args) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addMap(boolean,
|
||||
* java.util.Vector)
|
||||
*/
|
||||
protected void addMap(boolean map, Vector args) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addStack(int,
|
||||
* java.util.Vector)
|
||||
*/
|
||||
protected void addStack(int stack, Vector args) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addEntry(int, java.util.Vector)
|
||||
*/
|
||||
protected void addEntry(String entry, Vector args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* May have to make this String array return
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#getCommandFileSwitch(java.lang.String)
|
||||
*/
|
||||
protected String getCommandFileSwitch(String commandFile) {
|
||||
return "-via" + commandFile;
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.Linker#getLibraryPath()
|
||||
*/
|
||||
public File[] getLibraryPath() {
|
||||
return CUtil.getPathFromEnvironment("ARMLIB", ";");
|
||||
}
|
||||
/*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.Linker#getLibraryPatterns(java.lang.String[])
|
||||
*/
|
||||
public String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {
|
||||
//
|
||||
// TODO: looks like bad extension
|
||||
//
|
||||
return new String[]{".o"};
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.Processor#getLinker(net.sf.antcontrib.cpptasks.compiler.LinkType)
|
||||
*/
|
||||
public Linker getLinker(LinkType linkType) {
|
||||
return this;
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#getMaximumCommandLength()
|
||||
*/
|
||||
protected int getMaximumCommandLength() {
|
||||
return 1024;
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#getOutputFileSwitch(java.lang.String)
|
||||
*/
|
||||
protected String[] getOutputFileSwitch(String outputFile) {
|
||||
return new String[]{"-output", outputFile};
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see net.sf.antcontrib.cpptasks.compiler.Linker#isCaseSensitive()
|
||||
*/
|
||||
public boolean isCaseSensitive() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
/*
|
||||
*
|
||||
* 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.compaq;
|
||||
import java.io.File;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.CUtil;
|
||||
import net.sf.antcontrib.cpptasks.compiler.CommandLineFortranCompiler;
|
||||
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 Compaq(r) Visual Fortran compiler.
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public class CompaqVisualFortranCompiler extends CommandLineFortranCompiler {
|
||||
private static final CompaqVisualFortranCompiler[] instance = new CompaqVisualFortranCompiler[]{new CompaqVisualFortranCompiler(
|
||||
false, null)};
|
||||
public static CompaqVisualFortranCompiler getInstance() {
|
||||
return instance[0];
|
||||
}
|
||||
private CompaqVisualFortranCompiler(boolean newEnvironment, Environment env) {
|
||||
super("DF", null, new String[]{".f90", ".for", ".f"}, new String[]{
|
||||
".i", ".i90", ".fpp", ".inc", ".bak", ".exe"}, ".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("/nologo");
|
||||
args.addElement("/compile_only");
|
||||
if (debug) {
|
||||
args.addElement("/debug:full");
|
||||
args.addElement("/define:_DEBUG");
|
||||
} else {
|
||||
args.addElement("/debug:none");
|
||||
args.addElement("/define:NDEBUG");
|
||||
}
|
||||
if (multithreaded) {
|
||||
args.addElement("/threads");
|
||||
args.addElement("/define:_MT");
|
||||
} else {
|
||||
args.addElement("/nothreads");
|
||||
}
|
||||
boolean staticRuntime = linkType.isStaticRuntime();
|
||||
if (staticRuntime) {
|
||||
args.addElement("/libs:static");
|
||||
} else {
|
||||
args.addElement("/libs:dll");
|
||||
}
|
||||
if (linkType.isSharedLibrary()) {
|
||||
args.addElement("/dll");
|
||||
args.addElement("/define:_DLL");
|
||||
}
|
||||
}
|
||||
public void addWarningSwitch(Vector args, int level) {
|
||||
switch (level) {
|
||||
case 0 :
|
||||
args.addElement("/nowarn");
|
||||
break;
|
||||
case 1 :
|
||||
break;
|
||||
case 2 :
|
||||
break;
|
||||
case 3 :
|
||||
args.addElement("/warn:usage");
|
||||
break;
|
||||
case 4 :
|
||||
args.addElement("/warn:all");
|
||||
break;
|
||||
case 5 :
|
||||
args.addElement("/warn:errors");
|
||||
break;
|
||||
}
|
||||
}
|
||||
public Processor changeEnvironment(boolean newEnvironment, Environment env) {
|
||||
if (newEnvironment || env != null) {
|
||||
return new CompaqVisualFortranCompiler(newEnvironment, env);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
protected void getDefineSwitch(StringBuffer buf, String define, String value) {
|
||||
buf.append("/define:");
|
||||
buf.append(define);
|
||||
if (value != null && value.length() > 0) {
|
||||
buf.append('=');
|
||||
buf.append(value);
|
||||
}
|
||||
}
|
||||
protected File[] getEnvironmentIncludePath() {
|
||||
return CUtil.getPathFromEnvironment("INCLUDE", ";");
|
||||
}
|
||||
protected String getIncludeDirSwitch(String includeDir) {
|
||||
StringBuffer buf = new StringBuffer("/include:");
|
||||
if (includeDir.indexOf(' ') >= 0) {
|
||||
buf.append('"');
|
||||
buf.append(includeDir);
|
||||
buf.append('"');
|
||||
} else {
|
||||
buf.append(includeDir);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
public Linker getLinker(LinkType type) {
|
||||
return CompaqVisualFortranLinker.getInstance().getLinker(type);
|
||||
}
|
||||
public int getMaximumCommandLength() {
|
||||
return 1024;
|
||||
}
|
||||
protected void getUndefineSwitch(StringBuffer buf, String define) {
|
||||
buf.append("/undefine:");
|
||||
buf.append(define);
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
*
|
||||
* 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.compaq;
|
||||
import java.io.File;
|
||||
import java.util.Vector;
|
||||
|
||||
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.devstudio.DevStudioLibrarian;
|
||||
import net.sf.antcontrib.cpptasks.devstudio.DevStudioProcessor;
|
||||
import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;
|
||||
|
||||
/**
|
||||
* Adapter for the Compaq(r) Visual Fortran Librarian
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public class CompaqVisualFortranLibrarian extends CommandLineLinker {
|
||||
private static final CompaqVisualFortranLibrarian instance = new CompaqVisualFortranLibrarian();
|
||||
public static CompaqVisualFortranLibrarian getInstance() {
|
||||
return instance;
|
||||
}
|
||||
private CompaqVisualFortranLibrarian() {
|
||||
super("lib", "/bogus", 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) {
|
||||
args.addElement("/nologo");
|
||||
}
|
||||
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 commandFile) {
|
||||
return DevStudioProcessor.getCommandFileSwitch(commandFile);
|
||||
}
|
||||
public File[] getLibraryPath() {
|
||||
return new File[0];
|
||||
}
|
||||
public String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {
|
||||
return new String[0];
|
||||
}
|
||||
public Linker getLinker(LinkType type) {
|
||||
return CompaqVisualFortranLinker.getInstance().getLinker(type);
|
||||
}
|
||||
protected int getMaximumCommandLength() {
|
||||
return DevStudioLibrarian.getInstance().getMaximumCommandLength();
|
||||
}
|
||||
protected String[] getOutputFileSwitch(String outputFile) {
|
||||
return DevStudioLibrarian.getInstance().getOutputFileSwitch(outputFile);
|
||||
}
|
||||
public boolean isCaseSensitive() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
*
|
||||
* 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.compaq;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.compiler.LinkType;
|
||||
import net.sf.antcontrib.cpptasks.compiler.Linker;
|
||||
import net.sf.antcontrib.cpptasks.devstudio.DevStudioCompatibleLinker;
|
||||
/**
|
||||
* Adapter for the Compaq(r) Visual Fortran linker.
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public final class CompaqVisualFortranLinker extends DevStudioCompatibleLinker {
|
||||
private static final CompaqVisualFortranLinker dllLinker = new CompaqVisualFortranLinker(
|
||||
".dll");
|
||||
private static final CompaqVisualFortranLinker instance = new CompaqVisualFortranLinker(
|
||||
".exe");
|
||||
public static CompaqVisualFortranLinker getInstance() {
|
||||
return instance;
|
||||
}
|
||||
private CompaqVisualFortranLinker(String outputSuffix) {
|
||||
super("DF", "__bogus__.xxx", outputSuffix);
|
||||
}
|
||||
protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args) {
|
||||
args.addElement("/NOLOGO");
|
||||
boolean staticRuntime = linkType.isStaticRuntime();
|
||||
if (staticRuntime) {
|
||||
args.addElement("/libs:static");
|
||||
} else {
|
||||
args.addElement("/libs:dll");
|
||||
}
|
||||
if (debug) {
|
||||
args.addElement("/debug");
|
||||
} else {
|
||||
}
|
||||
if (linkType.isSharedLibrary()) {
|
||||
args.addElement("/dll");
|
||||
} else {
|
||||
args.addElement("/exe");
|
||||
}
|
||||
}
|
||||
public Linker getLinker(LinkType type) {
|
||||
if (type.isStaticLibrary()) {
|
||||
return CompaqVisualFortranLibrarian.getInstance();
|
||||
}
|
||||
if (type.isSharedLibrary()) {
|
||||
return dllLinker;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
public String[] getOutputFileSwitch(String outputFile) {
|
||||
StringBuffer buf = new StringBuffer("/OUT:");
|
||||
if (outputFile.indexOf(' ') >= 0) {
|
||||
buf.append('"');
|
||||
buf.append(outputFile);
|
||||
buf.append('"');
|
||||
} else {
|
||||
buf.append(outputFile);
|
||||
}
|
||||
return new String[]{buf.toString()};
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2001-2005 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.compiler;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.AslcompilerDef;
|
||||
import net.sf.antcontrib.cpptasks.CCTask;
|
||||
import net.sf.antcontrib.cpptasks.ProcessorDef;
|
||||
import net.sf.antcontrib.cpptasks.TargetDef;
|
||||
|
||||
/**
|
||||
* An abstract asl compiler implementation.
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractAslcompiler extends AbstractProcessor
|
||||
implements Aslcompiler {
|
||||
private String outputSuffix;
|
||||
protected AbstractAslcompiler(String[] sourceExtensions,
|
||||
String[] headerExtensions, String outputSuffix) {
|
||||
super(sourceExtensions, headerExtensions);
|
||||
this.outputSuffix = outputSuffix;
|
||||
}
|
||||
abstract protected AslcompilerConfiguration createConfiguration(CCTask task,
|
||||
LinkType linkType, ProcessorDef[] baseConfigs,
|
||||
AslcompilerDef specificConfig, TargetDef targetPlatform);
|
||||
|
||||
public ProcessorConfiguration createConfiguration(CCTask task,
|
||||
LinkType linkType, ProcessorDef[] baseConfigs,
|
||||
ProcessorDef specificConfig, TargetDef targetPlatform) {
|
||||
if (specificConfig == null) {
|
||||
throw new NullPointerException("specificConfig");
|
||||
}
|
||||
return createConfiguration(task, linkType, baseConfigs,
|
||||
(AslcompilerDef) specificConfig, targetPlatform);
|
||||
}
|
||||
|
||||
public String getOutputFileName(String inputFile) {
|
||||
if (bid(inputFile) > 1) {
|
||||
String baseName = getBaseOutputName(inputFile);
|
||||
return baseName + outputSuffix;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
protected String getBaseOutputName(String inputFile) {
|
||||
int lastSlash = inputFile.lastIndexOf('/');
|
||||
int lastReverse = inputFile.lastIndexOf('\\');
|
||||
int lastSep = inputFile.lastIndexOf(File.separatorChar);
|
||||
if (lastReverse > lastSlash) {
|
||||
lastSlash = lastReverse;
|
||||
}
|
||||
if (lastSep > lastSlash) {
|
||||
lastSlash = lastSep;
|
||||
}
|
||||
int lastPeriod = inputFile.lastIndexOf('.');
|
||||
if (lastPeriod < 0) {
|
||||
lastPeriod = inputFile.length();
|
||||
}
|
||||
return inputFile.substring(lastSlash + 1, lastPeriod);
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2001-2005 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.compiler;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.AssemblerDef;
|
||||
import net.sf.antcontrib.cpptasks.CCTask;
|
||||
import net.sf.antcontrib.cpptasks.ProcessorDef;
|
||||
import net.sf.antcontrib.cpptasks.TargetDef;
|
||||
/**
|
||||
* An abstract assembler implementation.
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractAssembler extends AbstractProcessor
|
||||
implements Assembler {
|
||||
private String outputSuffix;
|
||||
protected AbstractAssembler(String[] sourceExtensions,
|
||||
String[] headerExtensions, String outputSuffix) {
|
||||
super(sourceExtensions, headerExtensions);
|
||||
this.outputSuffix = outputSuffix;
|
||||
}
|
||||
abstract protected AssemblerConfiguration createConfiguration(CCTask task,
|
||||
LinkType linkType, ProcessorDef[] baseConfigs,
|
||||
AssemblerDef specificConfig, TargetDef targetPlatform);
|
||||
public ProcessorConfiguration createConfiguration(CCTask task,
|
||||
LinkType linkType, ProcessorDef[] baseConfigs,
|
||||
ProcessorDef specificConfig, TargetDef targetPlatform) {
|
||||
if (specificConfig == null) {
|
||||
throw new NullPointerException("specificConfig");
|
||||
}
|
||||
return createConfiguration(task, linkType, baseConfigs,
|
||||
(AssemblerDef) specificConfig, targetPlatform);
|
||||
}
|
||||
public String getOutputFileName(String inputFile) {
|
||||
if (bid(inputFile) > 1) {
|
||||
String baseName = getBaseOutputName(inputFile);
|
||||
return baseName + outputSuffix;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
protected String getBaseOutputName(String inputFile) {
|
||||
int lastSlash = inputFile.lastIndexOf('/');
|
||||
int lastReverse = inputFile.lastIndexOf('\\');
|
||||
int lastSep = inputFile.lastIndexOf(File.separatorChar);
|
||||
if (lastReverse > lastSlash) {
|
||||
lastSlash = lastReverse;
|
||||
}
|
||||
if (lastSep > lastSlash) {
|
||||
lastSlash = lastSep;
|
||||
}
|
||||
int lastPeriod = inputFile.lastIndexOf('.');
|
||||
if (lastPeriod < 0) {
|
||||
lastPeriod = inputFile.length();
|
||||
}
|
||||
return inputFile.substring(lastSlash + 1, lastPeriod);
|
||||
}
|
||||
}
|
@ -0,0 +1,205 @@
|
||||
/*
|
||||
*
|
||||
* 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.compiler;
|
||||
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 net.sf.antcontrib.cpptasks.CCTask;
|
||||
import net.sf.antcontrib.cpptasks.CUtil;
|
||||
import net.sf.antcontrib.cpptasks.CompilerDef;
|
||||
import net.sf.antcontrib.cpptasks.DependencyInfo;
|
||||
import net.sf.antcontrib.cpptasks.ProcessorDef;
|
||||
import net.sf.antcontrib.cpptasks.parser.Parser;
|
||||
import net.sf.antcontrib.cpptasks.TargetDef;
|
||||
|
||||
/**
|
||||
* An abstract compiler implementation.
|
||||
*
|
||||
* @author Adam Murdoch
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public abstract class AbstractCompiler extends AbstractProcessor
|
||||
implements
|
||||
Compiler {
|
||||
private static final String[] emptyIncludeArray = new String[0];
|
||||
private String outputSuffix;
|
||||
protected AbstractCompiler(String[] sourceExtensions,
|
||||
String[] headerExtensions, String outputSuffix) {
|
||||
super(sourceExtensions, headerExtensions);
|
||||
this.outputSuffix = outputSuffix;
|
||||
}
|
||||
/**
|
||||
* Checks file name to see if parse should be attempted
|
||||
*
|
||||
* Default implementation returns false for files with extensions '.dll',
|
||||
* 'tlb', '.res'
|
||||
*
|
||||
*/
|
||||
protected boolean canParse(File sourceFile) {
|
||||
String sourceName = sourceFile.toString();
|
||||
int lastPeriod = sourceName.lastIndexOf('.');
|
||||
if (lastPeriod >= 0 && lastPeriod == sourceName.length() - 4) {
|
||||
String ext = sourceName.substring(lastPeriod).toUpperCase();
|
||||
if (ext.equals(".DLL") || ext.equals(".TLB") || ext.equals(".RES")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
abstract protected CompilerConfiguration createConfiguration(CCTask task,
|
||||
LinkType linkType, ProcessorDef[] baseConfigs,
|
||||
CompilerDef specificConfig, TargetDef targetPlatform);
|
||||
public ProcessorConfiguration createConfiguration(CCTask task,
|
||||
LinkType linkType, ProcessorDef[] baseConfigs,
|
||||
ProcessorDef specificConfig, TargetDef targetPlatform) {
|
||||
if (specificConfig == null) {
|
||||
throw new NullPointerException("specificConfig");
|
||||
}
|
||||
return createConfiguration(task, linkType, baseConfigs,
|
||||
(CompilerDef) specificConfig, targetPlatform);
|
||||
}
|
||||
abstract protected Parser createParser(File sourceFile);
|
||||
protected String getBaseOutputName(String inputFile) {
|
||||
int lastSlash = inputFile.lastIndexOf('/');
|
||||
int lastReverse = inputFile.lastIndexOf('\\');
|
||||
int lastSep = inputFile.lastIndexOf(File.separatorChar);
|
||||
if (lastReverse > lastSlash) {
|
||||
lastSlash = lastReverse;
|
||||
}
|
||||
if (lastSep > lastSlash) {
|
||||
lastSlash = lastSep;
|
||||
}
|
||||
int lastPeriod = inputFile.lastIndexOf('.');
|
||||
if (lastPeriod < 0) {
|
||||
lastPeriod = inputFile.length();
|
||||
}
|
||||
return inputFile.substring(lastSlash + 1, lastPeriod);
|
||||
}
|
||||
public String getOutputFileName(String inputFile) {
|
||||
//
|
||||
// if a recognized input file
|
||||
//
|
||||
if (bid(inputFile) > 1) {
|
||||
String baseName = getBaseOutputName(inputFile);
|
||||
return baseName + outputSuffix;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Returns dependency info for the specified source file
|
||||
*
|
||||
* @param task
|
||||
* task for any diagnostic output
|
||||
* @param source
|
||||
* file to be parsed
|
||||
* @param includePath
|
||||
* include path to be used to resolve included files
|
||||
*
|
||||
* @param sysIncludePath
|
||||
* sysinclude path from build file, files resolved using
|
||||
* sysInclude path will not participate in dependency analysis
|
||||
*
|
||||
* @param envIncludePath
|
||||
* include path from environment variable, files resolved with
|
||||
* envIncludePath will not participate in dependency analysis
|
||||
*
|
||||
* @param baseDir
|
||||
* used to produce relative paths in DependencyInfo
|
||||
* @param includePathIdentifier
|
||||
* used to distinguish DependencyInfo's from different include
|
||||
* path settings
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public final DependencyInfo parseIncludes(CCTask task, File source,
|
||||
File[] includePath, File[] sysIncludePath, File[] envIncludePath,
|
||||
File baseDir, String includePathIdentifier) {
|
||||
//
|
||||
// if any of the include files can not be identified
|
||||
// change the sourceLastModified to Long.MAX_VALUE to
|
||||
// force recompilation of anything that depends on it
|
||||
long sourceLastModified = source.lastModified();
|
||||
File[] sourcePath = new File[1];
|
||||
sourcePath[0] = new File(source.getParent());
|
||||
Vector onIncludePath = new Vector();
|
||||
Vector onSysIncludePath = new Vector();
|
||||
String baseDirPath;
|
||||
try {
|
||||
baseDirPath = baseDir.getCanonicalPath();
|
||||
} catch (IOException ex) {
|
||||
baseDirPath = baseDir.toString();
|
||||
}
|
||||
String relativeSource = CUtil.getRelativePath(baseDirPath, source);
|
||||
String[] includes = emptyIncludeArray;
|
||||
if (canParse(source)) {
|
||||
Parser parser = createParser(source);
|
||||
try {
|
||||
Reader reader = new BufferedReader(new FileReader(source));
|
||||
parser.parse(reader);
|
||||
includes = parser.getIncludes();
|
||||
} catch (IOException ex) {
|
||||
task.log("Error parsing " + source.toString() + ":"
|
||||
+ ex.toString());
|
||||
includes = new String[0];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < includes.length; i++) {
|
||||
String includeName = includes[i];
|
||||
if (!resolveInclude(includeName, sourcePath, onIncludePath)) {
|
||||
if (!resolveInclude(includeName, includePath, onIncludePath)) {
|
||||
if (!resolveInclude(includeName, sysIncludePath,
|
||||
onSysIncludePath)) {
|
||||
if (!resolveInclude(includeName, envIncludePath,
|
||||
onSysIncludePath)) {
|
||||
//
|
||||
// this should be enough to require us to reparse
|
||||
// the file with the missing include for dependency
|
||||
// information without forcing a rebuild
|
||||
sourceLastModified++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < onIncludePath.size(); i++) {
|
||||
String relativeInclude = CUtil.getRelativePath(baseDirPath,
|
||||
(File) onIncludePath.elementAt(i));
|
||||
onIncludePath.setElementAt(relativeInclude, i);
|
||||
}
|
||||
for (int i = 0; i < onSysIncludePath.size(); i++) {
|
||||
String relativeInclude = CUtil.getRelativePath(baseDirPath,
|
||||
(File) onSysIncludePath.elementAt(i));
|
||||
onSysIncludePath.setElementAt(relativeInclude, i);
|
||||
}
|
||||
return new DependencyInfo(includePathIdentifier, relativeSource,
|
||||
sourceLastModified, onIncludePath, onSysIncludePath);
|
||||
}
|
||||
protected boolean resolveInclude(String includeName, File[] includePath,
|
||||
Vector onThisPath) {
|
||||
for (int i = 0; i < includePath.length; i++) {
|
||||
File includeFile = new File(includePath[i], includeName);
|
||||
if (includeFile.exists()) {
|
||||
onThisPath.addElement(includeFile);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
*
|
||||
* 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.compiler;
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.CCTask;
|
||||
import net.sf.antcontrib.cpptasks.LinkerDef;
|
||||
import net.sf.antcontrib.cpptasks.ProcessorDef;
|
||||
import net.sf.antcontrib.cpptasks.TargetDef;
|
||||
|
||||
|
||||
import org.apache.tools.ant.types.Environment;
|
||||
/**
|
||||
* An abstract Linker implementation.
|
||||
*
|
||||
* @author Adam Murdoch
|
||||
*/
|
||||
public abstract class AbstractLinker extends AbstractProcessor
|
||||
implements
|
||||
Linker {
|
||||
public AbstractLinker(String[] objExtensions, String[] ignoredExtensions) {
|
||||
super(objExtensions, ignoredExtensions);
|
||||
}
|
||||
/**
|
||||
* Returns the bid of the processor for the file.
|
||||
*
|
||||
* A linker will bid 1 on any unrecognized file type.
|
||||
*
|
||||
* @param inputFile
|
||||
* filename of input file
|
||||
* @return bid for the file, 0 indicates no interest, 1 indicates that the
|
||||
* processor recognizes the file but doesn't process it (header
|
||||
* files, for example), 100 indicates strong interest
|
||||
*/
|
||||
public int bid(String inputFile) {
|
||||
int bid = super.bid(inputFile);
|
||||
switch (bid) {
|
||||
//
|
||||
// unrecognized extension, take the file
|
||||
//
|
||||
case 0 :
|
||||
return 1;
|
||||
//
|
||||
// discard the ignored extensions
|
||||
//
|
||||
case 1 :
|
||||
return 0;
|
||||
}
|
||||
return bid;
|
||||
}
|
||||
public Processor changeEnvironment(boolean newEnvironment, Environment env) {
|
||||
return this;
|
||||
}
|
||||
abstract protected LinkerConfiguration createConfiguration(CCTask task,
|
||||
LinkType linkType, ProcessorDef[] baseConfigs,
|
||||
LinkerDef specificConfig, TargetDef targetPlatform);
|
||||
public ProcessorConfiguration createConfiguration(CCTask task,
|
||||
LinkType linkType, ProcessorDef[] baseConfigs,
|
||||
ProcessorDef specificConfig,
|
||||
TargetDef targetPlatform) {
|
||||
if (specificConfig == null) {
|
||||
throw new NullPointerException("specificConfig");
|
||||
}
|
||||
return createConfiguration(task, linkType, baseConfigs,
|
||||
(LinkerDef) specificConfig, targetPlatform);
|
||||
}
|
||||
public String getLibraryKey(File libfile) {
|
||||
return libfile.getName();
|
||||
}
|
||||
public abstract String getOutputFileName(String fileName);
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
/*
|
||||
*
|
||||
* 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.compiler;
|
||||
import org.apache.tools.ant.types.Environment;
|
||||
/**
|
||||
* An abstract processor (compiler/linker) implementation.
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public abstract class AbstractProcessor implements Processor, Cloneable {
|
||||
/**
|
||||
* default bid for a file name that the processor recognizes but does not
|
||||
* process and does not want to fall through to the linker
|
||||
*/
|
||||
public final static int DEFAULT_DISCARD_BID = 1;
|
||||
/**
|
||||
* default bid for a file name that the processor desires to process
|
||||
*/
|
||||
public final static int DEFAULT_PROCESS_BID = 100;
|
||||
/**
|
||||
* Determines the identification of a command line processor by capture the
|
||||
* first line of its output for a specific command.
|
||||
*
|
||||
* @param command
|
||||
* array of command line arguments starting with executable
|
||||
* name. For example, { "cl" }
|
||||
* @param fallback
|
||||
* start of identifier if there is an error in executing the
|
||||
* command
|
||||
* @return identifier for the processor
|
||||
*/
|
||||
protected static String getIdentifier(String[] command, String fallback) {
|
||||
String identifier = fallback;
|
||||
try {
|
||||
String[] cmdout = CaptureStreamHandler.run(command);
|
||||
if (cmdout.length > 0) {
|
||||
identifier = cmdout[0];
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
identifier = fallback + ":" + ex.toString();
|
||||
}
|
||||
return identifier;
|
||||
}
|
||||
private final String[] headerExtensions;
|
||||
private final String[] sourceExtensions;
|
||||
protected AbstractProcessor(String[] sourceExtensions,
|
||||
String[] headerExtensions) {
|
||||
this.sourceExtensions = (String[]) sourceExtensions.clone();
|
||||
this.headerExtensions = (String[]) headerExtensions.clone();
|
||||
}
|
||||
/**
|
||||
* Returns the bid of the processor for the file.
|
||||
*
|
||||
* @param inputFile
|
||||
* filename of input file
|
||||
* @return bid for the file, 0 indicates no interest, 1 indicates that the
|
||||
* processor recognizes the file but doesn't process it (header
|
||||
* files, for example), 100 indicates strong interest
|
||||
*/
|
||||
public int bid(String inputFile) {
|
||||
String lower = inputFile.toLowerCase();
|
||||
for (int i = 0; i < sourceExtensions.length; i++) {
|
||||
if (lower.endsWith(sourceExtensions[i])) {
|
||||
return DEFAULT_PROCESS_BID;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < headerExtensions.length; i++) {
|
||||
if (lower.endsWith(headerExtensions[i])) {
|
||||
return DEFAULT_DISCARD_BID;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public Processor changeEnvironment(boolean newEnvironment, Environment env) {
|
||||
return this;
|
||||
}
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
public String[] getHeaderExtensions() {
|
||||
return (String[]) this.headerExtensions.clone();
|
||||
}
|
||||
abstract public String getIdentifier();
|
||||
/**
|
||||
* Gets the target operating system architecture
|
||||
*
|
||||
* @return String target operating system architecture
|
||||
*/
|
||||
protected String getOSArch() {
|
||||
return System.getProperty("os.arch");
|
||||
}
|
||||
/**
|
||||
* Gets the target operating system name
|
||||
*
|
||||
* @return String target operating system name
|
||||
*/
|
||||
protected String getOSName() {
|
||||
return System.getProperty("os.name");
|
||||
}
|
||||
public String[] getSourceExtensions() {
|
||||
return (String[]) this.sourceExtensions.clone();
|
||||
}
|
||||
/**
|
||||
* Returns true if the target operating system is Mac OS X or Darwin.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected boolean isDarwin() {
|
||||
String osName = getOSName();
|
||||
return "Mac OS X".equals(osName);
|
||||
}
|
||||
public final String toString() {
|
||||
return getIdentifier();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2001-2005 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.compiler;
|
||||
/**
|
||||
* A asl compiler.
|
||||
*
|
||||
*/
|
||||
public interface Aslcompiler extends Processor {
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2001-2005 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.compiler;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.CCTask;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
/**
|
||||
* A configuration for an ASL compiler
|
||||
*
|
||||
*/
|
||||
public interface AslcompilerConfiguration extends ProcessorConfiguration {
|
||||
void aslcompiler(CCTask task, File outputDir, String[] sourceFiles) throws BuildException;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2001-2005 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.compiler;
|
||||
/**
|
||||
* A assembler.
|
||||
*
|
||||
*/
|
||||
public interface Assembler extends Processor {
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2001-2005 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.compiler;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.CCTask;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
/**
|
||||
* A configuration for an assembler
|
||||
*
|
||||
*/
|
||||
public interface AssemblerConfiguration extends ProcessorConfiguration {
|
||||
void assembler(CCTask task, File outputDir, String[] sourceFiles) throws BuildException;
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
/*
|
||||
*
|
||||
* 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.compiler;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.apache.tools.ant.taskdefs.Execute;
|
||||
import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
|
||||
/**
|
||||
* Implements ExecuteStreamHandler to capture the output of a Execute to an
|
||||
* array of strings
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public class CaptureStreamHandler implements ExecuteStreamHandler {
|
||||
/**
|
||||
* Runs an executable and captures the output in a String array
|
||||
*
|
||||
* @param cmdline
|
||||
* command line arguments
|
||||
* @return output of process
|
||||
*/
|
||||
public static String[] run(String[] cmdline) {
|
||||
CaptureStreamHandler handler = new CaptureStreamHandler();
|
||||
Execute exec = new Execute(handler);
|
||||
exec.setCommandline(cmdline);
|
||||
try {
|
||||
int status = exec.execute();
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
return handler.getOutput();
|
||||
}
|
||||
private InputStream errorStream;
|
||||
private InputStream fromProcess;
|
||||
public CaptureStreamHandler() {
|
||||
}
|
||||
public String[] getOutput() {
|
||||
String[] output;
|
||||
if (fromProcess != null) {
|
||||
Vector lines = new Vector(10);
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(errorStream));
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 100; j++) {
|
||||
String line = reader.readLine();
|
||||
if (line == null) {
|
||||
reader = new BufferedReader(new InputStreamReader(
|
||||
fromProcess));
|
||||
break;
|
||||
}
|
||||
lines.addElement(line);
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
output = new String[lines.size()];
|
||||
lines.copyInto(output);
|
||||
return output;
|
||||
}
|
||||
output = new String[0];
|
||||
return output;
|
||||
}
|
||||
/**
|
||||
* Install a handler for the error stream of the subprocess.
|
||||
*
|
||||
* @param is
|
||||
* input stream to read from the error stream from the
|
||||
* subprocess
|
||||
*/
|
||||
public void setProcessErrorStream(InputStream is) throws IOException {
|
||||
errorStream = is;
|
||||
}
|
||||
/**
|
||||
* Install a handler for the input stream of the subprocess.
|
||||
*
|
||||
* @param os
|
||||
* output stream to write to the standard input stream of the
|
||||
* subprocess
|
||||
*/
|
||||
public void setProcessInputStream(OutputStream os) throws IOException {
|
||||
os.close();
|
||||
}
|
||||
/**
|
||||
* Install a handler for the output stream of the subprocess.
|
||||
*
|
||||
* @param is
|
||||
* input stream to read from the error stream from the
|
||||
* subprocess
|
||||
*/
|
||||
public void setProcessOutputStream(InputStream is) throws IOException {
|
||||
fromProcess = is;
|
||||
}
|
||||
/**
|
||||
* Start handling of the streams.
|
||||
*/
|
||||
public void start() throws IOException {
|
||||
}
|
||||
/**
|
||||
* Stop handling of the streams - will not be restarted.
|
||||
*/
|
||||
public void stop() {
|
||||
}
|
||||
}
|
@ -0,0 +1,226 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2001-2005 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.compiler;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.AslcompilerDef;
|
||||
import net.sf.antcontrib.cpptasks.CCTask;
|
||||
import net.sf.antcontrib.cpptasks.CUtil;
|
||||
import net.sf.antcontrib.cpptasks.ProcessorDef;
|
||||
import net.sf.antcontrib.cpptasks.TargetDef;
|
||||
import net.sf.antcontrib.cpptasks.types.CommandLineArgument;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
/**
|
||||
* An abstract ASL Compiler implementation which uses an external program to
|
||||
* perform the ASL compile.
|
||||
*
|
||||
*/
|
||||
public abstract class CommandLineAslcompiler extends AbstractAslcompiler{
|
||||
|
||||
private String command;
|
||||
private String identifier;
|
||||
private String identifierArg;
|
||||
|
||||
protected CommandLineAslcompiler(String command, String identifierArg,
|
||||
String[] sourceExtensions, String[] headerExtensions,
|
||||
String outputSuffix) {
|
||||
super(sourceExtensions, headerExtensions, outputSuffix);
|
||||
this.command = command;
|
||||
this.identifierArg = identifierArg;
|
||||
}
|
||||
|
||||
abstract protected void addImpliedArgs(Vector args, boolean debug,
|
||||
Boolean defaultflag);
|
||||
|
||||
/**
|
||||
* Compile a ACPI source file
|
||||
*
|
||||
*/
|
||||
public void aslcompiler(CCTask task, File outputDir, String[] sourceFiles,
|
||||
String[] args, String[] endArgs) throws BuildException{
|
||||
String command = getCommand();
|
||||
int baseLength = command.length() + args.length + endArgs.length;
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
baseLength += args[i].length();
|
||||
}
|
||||
for (int i = 0; i < endArgs.length; i++) {
|
||||
baseLength += endArgs[i].length();
|
||||
}
|
||||
if (baseLength > getMaximumCommandLength()) {
|
||||
throw new BuildException(
|
||||
"Command line is over maximum length without sepcifying source file");
|
||||
}
|
||||
int maxInputFilesPerCommand = getMaximumInputFilesPerCommand();
|
||||
int argumentCountPerInputFile = getArgumentCountPerInputFIle();
|
||||
for (int sourceIndex = 0; sourceIndex < sourceFiles.length;) {
|
||||
int cmdLength = baseLength;
|
||||
int firstFileNextExec;
|
||||
for (firstFileNextExec = sourceIndex; firstFileNextExec < sourceFiles.length
|
||||
&& (firstFileNextExec - sourceIndex) < maxInputFilesPerCommand; firstFileNextExec++) {
|
||||
cmdLength += getTotalArgumentLengthForInputFile(outputDir,
|
||||
sourceFiles[firstFileNextExec]);
|
||||
if (cmdLength >= getMaximumCommandLength())
|
||||
break;
|
||||
}
|
||||
if (firstFileNextExec == sourceIndex) {
|
||||
throw new BuildException(
|
||||
"Extremely long file name, can't fit on command line");
|
||||
}
|
||||
int argCount = args.length + 1 + endArgs.length
|
||||
+ (firstFileNextExec - sourceIndex)
|
||||
* argumentCountPerInputFile;
|
||||
String[] commandline = new String[argCount];
|
||||
int index = 0;
|
||||
commandline[index++] = command;
|
||||
for (int j = 0; j < args.length; j++) {
|
||||
commandline[index++] = args[j];
|
||||
}
|
||||
for (int j = sourceIndex; j < firstFileNextExec; j++) {
|
||||
for (int k = 0; k < argumentCountPerInputFile; k++) {
|
||||
commandline[index++] = getInputFileArgument(outputDir,
|
||||
sourceFiles[j], k);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < endArgs.length; j++) {
|
||||
commandline[index++] = endArgs[j];
|
||||
}
|
||||
int retval = runCommand(task, outputDir, commandline);
|
||||
// if with monitor, add more code
|
||||
if (retval != 0) {
|
||||
throw new BuildException(this.getCommand()
|
||||
+ " failed with return code " + retval,
|
||||
task.getLocation());
|
||||
}
|
||||
sourceIndex = firstFileNextExec;
|
||||
}
|
||||
}
|
||||
|
||||
protected AslcompilerConfiguration createConfiguration(final CCTask task,
|
||||
final LinkType linkType,
|
||||
final ProcessorDef[] baseDefs,
|
||||
final AslcompilerDef specificDef,
|
||||
final TargetDef targetPlatform) {
|
||||
Vector args = new Vector();
|
||||
AslcompilerDef[] defaultProviders = new AslcompilerDef[baseDefs.length +1];
|
||||
for (int i = 0; i < baseDefs.length; i++) {
|
||||
defaultProviders[i + 1] = (AslcompilerDef) baseDefs[i];
|
||||
}
|
||||
defaultProviders[0] = specificDef;
|
||||
Vector cmdArgs = new Vector();
|
||||
//
|
||||
// add command line arguments inherited from <cc> element
|
||||
// any "extends" and finally and specific AslcompilerDef
|
||||
//
|
||||
CommandLineArgument[] commandArgs;
|
||||
for (int i = defaultProviders.length - 1; i >=0; i--){
|
||||
commandArgs = defaultProviders[i].getActiveProcessorArgs();
|
||||
for (int j = 0; j < commandArgs.length; j++) {
|
||||
if (commandArgs[j].getLocation() == 0) {
|
||||
args.addElement(commandArgs[j].getValue());
|
||||
}
|
||||
else {
|
||||
cmdArgs.addElement(commandArgs[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// omit param
|
||||
boolean debug = specificDef.getDebug(baseDefs, 0);
|
||||
Boolean defaultflag = specificDef.getDefaultflag(defaultProviders, 1);
|
||||
this.addImpliedArgs(args, debug, defaultflag);
|
||||
Enumeration argEnum = cmdArgs.elements();
|
||||
int endCount = 0;
|
||||
while( argEnum.hasMoreElements()) {
|
||||
CommandLineArgument arg = (CommandLineArgument) argEnum.nextElement();
|
||||
switch (arg.getLocation()) {
|
||||
case 1 :
|
||||
args.addElement(arg.getValue());
|
||||
break;
|
||||
case 2 :
|
||||
endCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String[] endArgs = new String[endCount];
|
||||
argEnum = cmdArgs.elements();
|
||||
int index = 0;
|
||||
while (argEnum.hasMoreElements()) {
|
||||
CommandLineArgument arg = (CommandLineArgument) argEnum.nextElement();
|
||||
if (arg.getLocation() == 2) {
|
||||
endArgs[index++] = arg.getValue();
|
||||
}
|
||||
}
|
||||
String[] argArray = new String[args.size()];
|
||||
args.copyInto(argArray);
|
||||
return new CommandLineAslcompilerConfiguration(this, argArray, true, endArgs);
|
||||
}
|
||||
|
||||
protected int getArgumentCountPerInputFile() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
if (identifier == null) {
|
||||
if (identifierArg == null) {
|
||||
identifier = getIdentifier(new String[]{command}, command);
|
||||
}
|
||||
else {
|
||||
identifier = getIdentifier(
|
||||
new String[]{command, identifierArg}, command);
|
||||
}
|
||||
}
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public final String getCommand() {
|
||||
return command;
|
||||
}
|
||||
abstract public int getMaximumCommandLength();
|
||||
public void setCommand(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
protected int getTotalArgumentLengthForInputFile(File outputDir,
|
||||
String inputFile) {
|
||||
return inputFile.length() + 1;
|
||||
}
|
||||
protected int runCommand(CCTask task, File workingDir, String[] cmdline)
|
||||
throws BuildException {
|
||||
return CUtil.runCommand(task, workingDir, cmdline, false, null);
|
||||
|
||||
}
|
||||
protected int getMaximumInputFilesPerCommand(){
|
||||
return 1;
|
||||
}
|
||||
protected int getArgumentCountPerInputFIle(){
|
||||
return 1;
|
||||
}
|
||||
protected String getInputFileArgument(File outputDir, String filename, int index) {
|
||||
//
|
||||
// if there is an embedded space,
|
||||
// must enclose in quotes
|
||||
if (filename.indexOf(' ') >= 0) {
|
||||
StringBuffer buf = new StringBuffer("\"");
|
||||
buf.append(filename);
|
||||
buf.append("\"");
|
||||
return buf.toString();
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2001-2005 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.compiler;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.CCTask;
|
||||
import net.sf.antcontrib.cpptasks.ProcessorParam;
|
||||
|
||||
/**
|
||||
* A configuration for an ASL compiler
|
||||
*
|
||||
*/
|
||||
public final class CommandLineAslcompilerConfiguration implements
|
||||
AslcompilerConfiguration {
|
||||
|
||||
private String[] args;
|
||||
|
||||
private CommandLineAslcompiler acpi;
|
||||
|
||||
private String[] endArgs;
|
||||
|
||||
private boolean rebuild;
|
||||
|
||||
public CommandLineAslcompilerConfiguration (CommandLineAslcompiler acpi,
|
||||
String[] args, boolean rebuild, String[] endArgs) {
|
||||
if (acpi == null) {
|
||||
throw new NullPointerException("acpi");
|
||||
}
|
||||
if (args == null) {
|
||||
this.args = new String[0];
|
||||
} else {
|
||||
this.args = (String[]) args.clone();
|
||||
}
|
||||
this.acpi = acpi;
|
||||
this.rebuild = rebuild;
|
||||
this.endArgs = (String[]) endArgs.clone();
|
||||
}
|
||||
|
||||
public int bid (String inputFile) {
|
||||
int acpiBid = acpi.bid(inputFile);
|
||||
return acpiBid;
|
||||
}
|
||||
|
||||
public void aslcompiler (CCTask task, File outputDir, String[] sourceFiles)
|
||||
throws BuildException {
|
||||
try {
|
||||
acpi.aslcompiler(task, outputDir, sourceFiles, args, endArgs);
|
||||
} catch (BuildException ex) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public String getIdentifier () {
|
||||
return acpi.getCommand();
|
||||
}
|
||||
|
||||
public ProcessorParam[] getParams () {
|
||||
return new ProcessorParam[0];
|
||||
}
|
||||
|
||||
public boolean getRebuild () {
|
||||
return rebuild;
|
||||
}
|
||||
|
||||
public String[] getPreArguments () {
|
||||
return (String[]) args.clone();
|
||||
}
|
||||
|
||||
public String[] getEndArguments () {
|
||||
return (String[]) endArgs.clone();
|
||||
}
|
||||
|
||||
public String getOutputFileName (String inputFile) {
|
||||
return acpi.getOutputFileName(inputFile);
|
||||
}
|
||||
}
|
@ -0,0 +1,326 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2001-2005 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.compiler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.AssemblerDef;
|
||||
import net.sf.antcontrib.cpptasks.CCTask;
|
||||
import net.sf.antcontrib.cpptasks.CUtil;
|
||||
import net.sf.antcontrib.cpptasks.ProcessorDef;
|
||||
import net.sf.antcontrib.cpptasks.TargetDef;
|
||||
import net.sf.antcontrib.cpptasks.types.CommandLineArgument;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
/**
|
||||
* An abstract Assembler implementation which uses an external program to
|
||||
* perform the assemble.
|
||||
*
|
||||
*/
|
||||
public abstract class CommandLineAssembler extends AbstractAssembler {
|
||||
|
||||
private String command;
|
||||
|
||||
private String identifier;
|
||||
|
||||
private String identifierArg;
|
||||
|
||||
protected CommandLineAssembler (String command, String identifierArg,
|
||||
String[] sourceExtensions, String[] headerExtensions,
|
||||
String outputSuffix) {
|
||||
super(sourceExtensions, headerExtensions, outputSuffix);
|
||||
this.command = command;
|
||||
this.identifierArg = identifierArg;
|
||||
}
|
||||
|
||||
abstract protected void addImpliedArgs(Vector args, boolean debug,
|
||||
Boolean defaultflag);
|
||||
|
||||
/**
|
||||
* Adds command-line arguments for include directories.
|
||||
*
|
||||
* If relativeArgs is not null will add corresponding relative paths include
|
||||
* switches to that vector (for use in building a configuration identifier
|
||||
* that is consistent between machines).
|
||||
*
|
||||
* @param baseDirPaths
|
||||
* A vector containing the parts of the working directory,
|
||||
* produced by CUtil.DecomposeFile.
|
||||
* @param includeDirs
|
||||
* Array of include directory paths
|
||||
* @param args
|
||||
* Vector of command line arguments used to execute the task
|
||||
* @param relativeArgs
|
||||
* Vector of command line arguments used to build the
|
||||
* configuration identifier
|
||||
*/
|
||||
protected void addIncludes(String baseDirPath, File[] includeDirs,
|
||||
Vector args, Vector relativeArgs, StringBuffer includePathId) {
|
||||
for (int i = 0; i < includeDirs.length; i++) {
|
||||
args.addElement(getIncludeDirSwitch(includeDirs[i]
|
||||
.getAbsolutePath()));
|
||||
if (relativeArgs != null) {
|
||||
String relative = CUtil.getRelativePath(baseDirPath,
|
||||
includeDirs[i]);
|
||||
relativeArgs.addElement(getIncludeDirSwitch(relative));
|
||||
if (includePathId != null) {
|
||||
if (includePathId.length() == 0) {
|
||||
includePathId.append("/I");
|
||||
} else {
|
||||
includePathId.append(" /I");
|
||||
}
|
||||
includePathId.append(relative);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract protected String getIncludeDirSwitch(String source);
|
||||
|
||||
/**
|
||||
* Assembles a source file
|
||||
*
|
||||
*/
|
||||
public void assembler(CCTask task, File outputDir, String[] sourceFiles,
|
||||
String[] args, String[] endArgs) throws BuildException {
|
||||
String command = getCommand();
|
||||
int baseLength = command.length() + args.length + endArgs.length;
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
baseLength += args[i].length();
|
||||
}
|
||||
for (int i = 0; i < endArgs.length; i++) {
|
||||
baseLength += endArgs[i].length();
|
||||
}
|
||||
if (baseLength > getMaximumCommandLength()) {
|
||||
throw new BuildException(
|
||||
"Command line is over maximum length without sepcifying source file");
|
||||
}
|
||||
int maxInputFilesPerCommand = getMaximumInputFilesPerCommand();
|
||||
int argumentCountPerInputFile = getArgumentCountPerInputFIle();
|
||||
for (int sourceIndex = 0; sourceIndex < sourceFiles.length;) {
|
||||
int cmdLength = baseLength;
|
||||
int firstFileNextExec;
|
||||
for (firstFileNextExec = sourceIndex; firstFileNextExec < sourceFiles.length
|
||||
&& (firstFileNextExec - sourceIndex) < maxInputFilesPerCommand; firstFileNextExec++) {
|
||||
cmdLength += getTotalArgumentLengthForInputFile(outputDir,
|
||||
sourceFiles[firstFileNextExec]);
|
||||
if (cmdLength >= getMaximumCommandLength())
|
||||
break;
|
||||
}
|
||||
if (firstFileNextExec == sourceIndex) {
|
||||
throw new BuildException(
|
||||
"Extremely long file name, can't fit on command line");
|
||||
}
|
||||
int argCount = args.length + 1 + endArgs.length
|
||||
+ (firstFileNextExec - sourceIndex)
|
||||
* argumentCountPerInputFile;
|
||||
String[] commandline = new String[argCount];
|
||||
int index = 0;
|
||||
commandline[index++] = command;
|
||||
for (int j = 0; j < args.length; j++) {
|
||||
commandline[index++] = args[j];
|
||||
}
|
||||
for (int j = sourceIndex; j < firstFileNextExec; j++) {
|
||||
for (int k = 0; k < argumentCountPerInputFile; k++) {
|
||||
commandline[index++] = getInputFileArgument(outputDir,
|
||||
sourceFiles[j], k);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < endArgs.length; j++) {
|
||||
commandline[index++] = endArgs[j];
|
||||
}
|
||||
int retval = runCommand(task, outputDir, commandline);
|
||||
// if with monitor, add more code
|
||||
if (retval != 0) {
|
||||
throw new BuildException(this.getCommand()
|
||||
+ " failed with return code " + retval, task
|
||||
.getLocation());
|
||||
}
|
||||
sourceIndex = firstFileNextExec;
|
||||
}
|
||||
}
|
||||
|
||||
protected AssemblerConfiguration createConfiguration(final CCTask task,
|
||||
final LinkType linkType, final ProcessorDef[] baseDefs,
|
||||
final AssemblerDef specificDef,
|
||||
final TargetDef targetPlatform) {
|
||||
Vector args = new Vector();
|
||||
AssemblerDef[] defaultProviders = new AssemblerDef[baseDefs.length + 1];
|
||||
for (int i = 0; i < baseDefs.length; i++) {
|
||||
defaultProviders[i + 1] = (AssemblerDef) baseDefs[i];
|
||||
}
|
||||
defaultProviders[0] = specificDef;
|
||||
Vector cmdArgs = new Vector();
|
||||
//
|
||||
// add command line arguments inherited from <cc> element
|
||||
// any "extends" and finally and specific AssemblerDef
|
||||
//
|
||||
CommandLineArgument[] commandArgs;
|
||||
for (int i = defaultProviders.length - 1; i >= 0; i--) {
|
||||
commandArgs = defaultProviders[i].getActiveProcessorArgs();
|
||||
for (int j = 0; j < commandArgs.length; j++) {
|
||||
if (commandArgs[j].getLocation() == 0) {
|
||||
args.addElement(commandArgs[j].getValue());
|
||||
} else {
|
||||
cmdArgs.addElement(commandArgs[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// omit param
|
||||
boolean debug = specificDef.getDebug(baseDefs, 0);
|
||||
Boolean defaultflag = specificDef.getDefaultflag(defaultProviders, 1);
|
||||
this.addImpliedArgs(args, debug, defaultflag);
|
||||
//
|
||||
// Want to have distinct set of arguments with relative
|
||||
// path names for includes that are used to build
|
||||
// the configuration identifier
|
||||
//
|
||||
Vector relativeArgs = (Vector) args.clone();
|
||||
//
|
||||
// add all active include an
|
||||
//
|
||||
StringBuffer includePathIdentifier = new StringBuffer();
|
||||
File baseDir = specificDef.getProject().getBaseDir();
|
||||
String baseDirPath;
|
||||
try {
|
||||
baseDirPath = baseDir.getCanonicalPath();
|
||||
} catch (IOException ex) {
|
||||
baseDirPath = baseDir.toString();
|
||||
}
|
||||
Vector includePath = new Vector();
|
||||
Vector sysIncludePath = new Vector();
|
||||
for (int i = defaultProviders.length - 1; i >= 0; i--) {
|
||||
String[] incPath = defaultProviders[i].getActiveIncludePaths();
|
||||
for (int j = 0; j < incPath.length; j++) {
|
||||
includePath.addElement(incPath[j]);
|
||||
}
|
||||
incPath = defaultProviders[i].getActiveSysIncludePaths();
|
||||
for (int j = 0; j < incPath.length; j++) {
|
||||
sysIncludePath.addElement(incPath[j]);
|
||||
}
|
||||
}
|
||||
File[] incPath = new File[includePath.size()];
|
||||
for (int i = 0; i < includePath.size(); i++) {
|
||||
incPath[i] = new File((String) includePath.elementAt(i));
|
||||
}
|
||||
File[] sysIncPath = new File[sysIncludePath.size()];
|
||||
for (int i = 0; i < sysIncludePath.size(); i++) {
|
||||
sysIncPath[i] = new File((String) sysIncludePath.elementAt(i));
|
||||
}
|
||||
addIncludes(baseDirPath, incPath, args, relativeArgs,
|
||||
includePathIdentifier);
|
||||
addIncludes(baseDirPath, sysIncPath, args, null, null);
|
||||
StringBuffer buf = new StringBuffer(getIdentifier());
|
||||
for (int i = 0; i < relativeArgs.size(); i++) {
|
||||
buf.append(relativeArgs.elementAt(i));
|
||||
buf.append(' ');
|
||||
}
|
||||
buf.setLength(buf.length() - 1);
|
||||
Enumeration argEnum = cmdArgs.elements();
|
||||
int endCount = 0;
|
||||
while (argEnum.hasMoreElements()) {
|
||||
CommandLineArgument arg = (CommandLineArgument) argEnum
|
||||
.nextElement();
|
||||
switch (arg.getLocation()) {
|
||||
case 1:
|
||||
args.addElement(arg.getValue());
|
||||
break;
|
||||
case 2:
|
||||
endCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String[] endArgs = new String[endCount];
|
||||
argEnum = cmdArgs.elements();
|
||||
int index = 0;
|
||||
while (argEnum.hasMoreElements()) {
|
||||
CommandLineArgument arg = (CommandLineArgument) argEnum
|
||||
.nextElement();
|
||||
if (arg.getLocation() == 2) {
|
||||
endArgs[index++] = arg.getValue();
|
||||
}
|
||||
}
|
||||
String[] argArray = new String[args.size()];
|
||||
args.copyInto(argArray);
|
||||
return new CommandLineAssemblerConfiguration(this, incPath, sysIncPath,
|
||||
new File[0], argArray, true, endArgs, new String[0]);
|
||||
}
|
||||
|
||||
protected int getArgumentCountPerInputFile() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected abstract File[] getEnvironmentIncludePath();
|
||||
|
||||
public String getIdentifier() {
|
||||
if (identifier == null) {
|
||||
if (identifierArg == null) {
|
||||
identifier = getIdentifier(new String[] { command }, command);
|
||||
} else {
|
||||
identifier = getIdentifier(new String[] { command,
|
||||
identifierArg }, command);
|
||||
}
|
||||
}
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public final String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
abstract public int getMaximumCommandLength();
|
||||
|
||||
public void setCommand(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
protected int getTotalArgumentLengthForInputFile(File outputDir,
|
||||
String inputFile) {
|
||||
return inputFile.length() + 1;
|
||||
}
|
||||
|
||||
protected int runCommand(CCTask task, File workingDir, String[] cmdline)
|
||||
throws BuildException {
|
||||
return CUtil.runCommand(task, workingDir, cmdline, false, null);
|
||||
}
|
||||
|
||||
protected int getMaximumInputFilesPerCommand() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
protected int getArgumentCountPerInputFIle() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected String getInputFileArgument(File outputDir, String filename,
|
||||
int index) {
|
||||
//
|
||||
// if there is an embedded space,
|
||||
// must enclose in quotes
|
||||
if (filename.indexOf(' ') >= 0) {
|
||||
StringBuffer buf = new StringBuffer("\"");
|
||||
buf.append(filename);
|
||||
buf.append("\"");
|
||||
return buf.toString();
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2001-2005 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.compiler;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.CCTask;
|
||||
import net.sf.antcontrib.cpptasks.ProcessorParam;
|
||||
|
||||
/**
|
||||
* A configuration for an assember
|
||||
*
|
||||
*/
|
||||
public final class CommandLineAssemblerConfiguration implements
|
||||
AssemblerConfiguration {
|
||||
|
||||
private String[] args;
|
||||
|
||||
private CommandLineAssembler assembler;
|
||||
|
||||
private String[] endArgs;
|
||||
|
||||
//
|
||||
// include path from environment variable
|
||||
// not explicitly stated in Ant script
|
||||
//
|
||||
private File[] envIncludePath;
|
||||
|
||||
private String[] exceptFiles;
|
||||
|
||||
private File[] includePath;
|
||||
|
||||
private boolean rebuild;
|
||||
|
||||
private File[] sysIncludePath;
|
||||
|
||||
public CommandLineAssemblerConfiguration (CommandLineAssembler assembler,
|
||||
File[] includePath, File[] sysIncludePath,
|
||||
File[] envIncludePath, String[] args, boolean rebuild,
|
||||
String[] endArgs, String[] exceptFiles) {
|
||||
if (assembler == null) {
|
||||
throw new NullPointerException("assembler");
|
||||
}
|
||||
if (args == null) {
|
||||
this.args = new String[0];
|
||||
} else {
|
||||
this.args = (String[]) args.clone();
|
||||
}
|
||||
if (includePath == null) {
|
||||
this.includePath = new File[0];
|
||||
} else {
|
||||
this.includePath = (File[]) includePath.clone();
|
||||
}
|
||||
if (sysIncludePath == null) {
|
||||
this.sysIncludePath = new File[0];
|
||||
} else {
|
||||
this.sysIncludePath = (File[]) sysIncludePath.clone();
|
||||
}
|
||||
if (envIncludePath == null) {
|
||||
this.envIncludePath = new File[0];
|
||||
} else {
|
||||
this.envIncludePath = (File[]) envIncludePath.clone();
|
||||
}
|
||||
this.assembler = assembler;
|
||||
this.rebuild = rebuild;
|
||||
this.endArgs = (String[]) endArgs.clone();
|
||||
this.exceptFiles = (String[]) exceptFiles.clone();
|
||||
}
|
||||
|
||||
public int bid(String inputFile) {
|
||||
int assembleBid = assembler.bid(inputFile);
|
||||
return assembleBid;
|
||||
}
|
||||
|
||||
public void assembler(CCTask task, File outputDir, String[] sourceFiles)
|
||||
throws BuildException {
|
||||
try {
|
||||
assembler.assembler(task, outputDir, sourceFiles, args, endArgs);
|
||||
} catch (BuildException ex) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public String getOutputFileName(String inputFile) {
|
||||
return assembler.getOutputFileName(inputFile);
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return assembler.getCommand();
|
||||
}
|
||||
|
||||
public ProcessorParam[] getParams() {
|
||||
return new ProcessorParam[0];
|
||||
}
|
||||
|
||||
public boolean getRebuild() {
|
||||
return rebuild;
|
||||
}
|
||||
|
||||
public String[] getPreArguments() {
|
||||
return (String[]) args.clone();
|
||||
}
|
||||
|
||||
public String[] getEndArguments() {
|
||||
return (String[]) endArgs.clone();
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
*
|
||||
* 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.compiler;
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.parser.CParser;
|
||||
import net.sf.antcontrib.cpptasks.parser.Parser;
|
||||
|
||||
import org.apache.tools.ant.types.Environment;
|
||||
/**
|
||||
* An abstract Compiler implementation which uses an external program to
|
||||
* perform the compile.
|
||||
*
|
||||
* @author Adam Murdoch
|
||||
*/
|
||||
public abstract class CommandLineCCompiler extends CommandLineCompiler {
|
||||
protected CommandLineCCompiler(String command, String identifierArg,
|
||||
String[] sourceExtensions, String[] headerExtensions,
|
||||
String outputSuffix, boolean libtool,
|
||||
CommandLineCCompiler libtoolCompiler, boolean newEnvironment,
|
||||
Environment env) {
|
||||
super(command, identifierArg, sourceExtensions, headerExtensions,
|
||||
outputSuffix, libtool, libtoolCompiler, newEnvironment, env);
|
||||
}
|
||||
protected Parser createParser(File source) {
|
||||
return new CParser();
|
||||
}
|
||||
}
|
@ -0,0 +1,435 @@
|
||||
/*
|
||||
*
|
||||
* 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.compiler;
|
||||
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.CUtil;
|
||||
import net.sf.antcontrib.cpptasks.CompilerDef;
|
||||
import net.sf.antcontrib.cpptasks.ProcessorDef;
|
||||
import net.sf.antcontrib.cpptasks.ProcessorParam;
|
||||
import net.sf.antcontrib.cpptasks.types.CommandLineArgument;
|
||||
import net.sf.antcontrib.cpptasks.types.UndefineArgument;
|
||||
import net.sf.antcontrib.cpptasks.TargetDef;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.types.Environment;
|
||||
import net.sf.antcontrib.cpptasks.OptimizationEnum;;
|
||||
/**
|
||||
* An abstract Compiler implementation which uses an external program to
|
||||
* perform the compile.
|
||||
*
|
||||
* @author Adam Murdoch
|
||||
*/
|
||||
public abstract class CommandLineCompiler extends AbstractCompiler {
|
||||
private String command;
|
||||
private final Environment env;
|
||||
private String identifier;
|
||||
private String identifierArg;
|
||||
private boolean libtool;
|
||||
private CommandLineCompiler libtoolCompiler;
|
||||
private final boolean newEnvironment;
|
||||
protected CommandLineCompiler(String command, String identifierArg,
|
||||
String[] sourceExtensions, String[] headerExtensions,
|
||||
String outputSuffix, boolean libtool,
|
||||
CommandLineCompiler libtoolCompiler, boolean newEnvironment,
|
||||
Environment env) {
|
||||
super(sourceExtensions, headerExtensions, outputSuffix);
|
||||
this.command = command;
|
||||
if (libtool && libtoolCompiler != null) {
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"libtoolCompiler should be null when libtool is true");
|
||||
}
|
||||
this.libtool = libtool;
|
||||
this.libtoolCompiler = libtoolCompiler;
|
||||
this.identifierArg = identifierArg;
|
||||
this.newEnvironment = newEnvironment;
|
||||
this.env = env;
|
||||
}
|
||||
abstract protected void addImpliedArgs(Vector args, boolean debug,
|
||||
boolean multithreaded, boolean exceptions, LinkType linkType,
|
||||
Boolean rtti, OptimizationEnum optimization, Boolean defaultflag);
|
||||
/**
|
||||
* Adds command-line arguments for include directories.
|
||||
*
|
||||
* If relativeArgs is not null will add corresponding relative paths
|
||||
* include switches to that vector (for use in building a configuration
|
||||
* identifier that is consistent between machines).
|
||||
*
|
||||
* @param baseDirPaths
|
||||
* A vector containing the parts of the working directory,
|
||||
* produced by CUtil.DecomposeFile.
|
||||
* @param includeDirs
|
||||
* Array of include directory paths
|
||||
* @param args
|
||||
* Vector of command line arguments used to execute the task
|
||||
* @param relativeArgs
|
||||
* Vector of command line arguments used to build the
|
||||
* configuration identifier
|
||||
*/
|
||||
protected void addIncludes(String baseDirPath, File[] includeDirs,
|
||||
Vector args, Vector relativeArgs, StringBuffer includePathId) {
|
||||
for (int i = 0; i < includeDirs.length; i++) {
|
||||
args.addElement(getIncludeDirSwitch(includeDirs[i]
|
||||
.getAbsolutePath()));
|
||||
if (relativeArgs != null) {
|
||||
String relative = CUtil.getRelativePath(baseDirPath,
|
||||
includeDirs[i]);
|
||||
relativeArgs.addElement(getIncludeDirSwitch(relative));
|
||||
if (includePathId != null) {
|
||||
if (includePathId.length() == 0) {
|
||||
includePathId.append("/I");
|
||||
} else {
|
||||
includePathId.append(" /I");
|
||||
}
|
||||
includePathId.append(relative);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
abstract protected void addWarningSwitch(Vector args, int warnings);
|
||||
protected void buildDefineArguments(CompilerDef[] defs, Vector args) {
|
||||
//
|
||||
// assume that we aren't inheriting defines from containing <cc>
|
||||
//
|
||||
UndefineArgument[] merged = defs[0].getActiveDefines();
|
||||
for (int i = 1; i < defs.length; i++) {
|
||||
//
|
||||
// if we are inheriting, merge the specific defines with the
|
||||
// containing defines
|
||||
merged = UndefineArgument.merge(defs[i].getActiveDefines(), merged);
|
||||
}
|
||||
StringBuffer buf = new StringBuffer(30);
|
||||
for (int i = 0; i < merged.length; i++) {
|
||||
buf.setLength(0);
|
||||
UndefineArgument current = merged[i];
|
||||
if (current.isDefine()) {
|
||||
getDefineSwitch(buf, current.getName(), current.getValue());
|
||||
} else {
|
||||
getUndefineSwitch(buf, current.getName());
|
||||
}
|
||||
args.addElement(buf.toString());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Compiles a source file.
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public void compile(CCTask task, File outputDir, String[] sourceFiles,
|
||||
String[] args, String[] endArgs, boolean relentless,
|
||||
CommandLineCompilerConfiguration config, ProgressMonitor monitor)
|
||||
throws BuildException {
|
||||
BuildException exc = null;
|
||||
//
|
||||
// determine length of executable name and args
|
||||
//
|
||||
String command = getCommand();
|
||||
int baseLength = command.length() + args.length + endArgs.length;
|
||||
if (libtool) {
|
||||
baseLength += 8;
|
||||
}
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
baseLength += args[i].length();
|
||||
}
|
||||
for (int i = 0; i < endArgs.length; i++) {
|
||||
baseLength += endArgs[i].length();
|
||||
}
|
||||
if (baseLength > getMaximumCommandLength()) {
|
||||
throw new BuildException(
|
||||
"Command line is over maximum length without specifying source file");
|
||||
}
|
||||
//
|
||||
// typically either 1 or Integer.MAX_VALUE
|
||||
//
|
||||
int maxInputFilesPerCommand = getMaximumInputFilesPerCommand();
|
||||
int argumentCountPerInputFile = getArgumentCountPerInputFile();
|
||||
for (int sourceIndex = 0; sourceIndex < sourceFiles.length;) {
|
||||
int cmdLength = baseLength;
|
||||
int firstFileNextExec;
|
||||
for (firstFileNextExec = sourceIndex; firstFileNextExec < sourceFiles.length
|
||||
&& (firstFileNextExec - sourceIndex) < maxInputFilesPerCommand; firstFileNextExec++) {
|
||||
cmdLength += getTotalArgumentLengthForInputFile(outputDir,
|
||||
sourceFiles[firstFileNextExec]);
|
||||
if (cmdLength >= getMaximumCommandLength())
|
||||
break;
|
||||
}
|
||||
if (firstFileNextExec == sourceIndex) {
|
||||
throw new BuildException(
|
||||
"Extremely long file name, can't fit on command line");
|
||||
}
|
||||
int argCount = args.length + 1 + endArgs.length
|
||||
+ (firstFileNextExec - sourceIndex)
|
||||
* argumentCountPerInputFile;
|
||||
if (libtool) {
|
||||
argCount++;
|
||||
}
|
||||
String[] commandline = new String[argCount];
|
||||
int index = 0;
|
||||
if (libtool) {
|
||||
commandline[index++] = "libtool";
|
||||
}
|
||||
commandline[index++] = command;
|
||||
for (int j = 0; j < args.length; j++) {
|
||||
commandline[index++] = args[j];
|
||||
}
|
||||
for (int j = sourceIndex; j < firstFileNextExec; j++) {
|
||||
for (int k = 0; k < argumentCountPerInputFile; k++) {
|
||||
commandline[index++] = getInputFileArgument(outputDir,
|
||||
sourceFiles[j], k);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < endArgs.length; j++) {
|
||||
commandline[index++] = endArgs[j];
|
||||
}
|
||||
int retval = runCommand(task, outputDir, commandline);
|
||||
if (monitor != null) {
|
||||
String[] fileNames = new String[firstFileNextExec - sourceIndex];
|
||||
for (int j = 0; j < fileNames.length; j++) {
|
||||
fileNames[j] = sourceFiles[sourceIndex + j];
|
||||
}
|
||||
monitor.progress(fileNames);
|
||||
}
|
||||
//
|
||||
// if the process returned a failure code and
|
||||
// we aren't holding an exception from an earlier
|
||||
// interation
|
||||
if (retval != 0 && exc == null) {
|
||||
//
|
||||
// construct the exception
|
||||
//
|
||||
exc = new BuildException(this.getCommand()
|
||||
+ " failed with return code " + retval, task
|
||||
.getLocation());
|
||||
//
|
||||
// and throw it now unless we are relentless
|
||||
//
|
||||
if (!relentless) {
|
||||
throw exc;
|
||||
}
|
||||
}
|
||||
sourceIndex = firstFileNextExec;
|
||||
}
|
||||
//
|
||||
// if the compiler returned a failure value earlier
|
||||
// then throw an exception
|
||||
if (exc != null) {
|
||||
throw exc;
|
||||
}
|
||||
}
|
||||
protected CompilerConfiguration createConfiguration(final CCTask task,
|
||||
final LinkType linkType,
|
||||
final ProcessorDef[] baseDefs,
|
||||
final CompilerDef specificDef,
|
||||
final TargetDef targetPlatform) {
|
||||
Vector args = new Vector();
|
||||
CompilerDef[] defaultProviders = new CompilerDef[baseDefs.length + 1];
|
||||
for (int i = 0; i < baseDefs.length; i++) {
|
||||
defaultProviders[i + 1] = (CompilerDef) baseDefs[i];
|
||||
}
|
||||
defaultProviders[0] = specificDef;
|
||||
Vector cmdArgs = new Vector();
|
||||
//
|
||||
// add command line arguments inherited from <cc> element
|
||||
// any "extends" and finally the specific CompilerDef
|
||||
CommandLineArgument[] commandArgs;
|
||||
for (int i = defaultProviders.length - 1; i >= 0; i--) {
|
||||
commandArgs = defaultProviders[i].getActiveProcessorArgs();
|
||||
for (int j = 0; j < commandArgs.length; j++) {
|
||||
if (commandArgs[j].getLocation() == 0) {
|
||||
args.addElement(commandArgs[j].getValue());
|
||||
} else {
|
||||
cmdArgs.addElement(commandArgs[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Vector params = new Vector();
|
||||
//
|
||||
// add command line arguments inherited from <cc> element
|
||||
// any "extends" and finally the specific CompilerDef
|
||||
ProcessorParam[] paramArray;
|
||||
for (int i = defaultProviders.length - 1; i >= 0; i--) {
|
||||
paramArray = defaultProviders[i].getActiveProcessorParams();
|
||||
for (int j = 0; j < paramArray.length; j++) {
|
||||
params.add(paramArray[j]);
|
||||
}
|
||||
}
|
||||
paramArray = (ProcessorParam[]) (params
|
||||
.toArray(new ProcessorParam[params.size()]));
|
||||
boolean multithreaded = specificDef.getMultithreaded(defaultProviders,
|
||||
1);
|
||||
boolean debug = specificDef.getDebug(baseDefs, 0);
|
||||
boolean exceptions = specificDef.getExceptions(defaultProviders, 1);
|
||||
Boolean rtti = specificDef.getRtti(defaultProviders, 1);
|
||||
Boolean defaultflag = specificDef.getDefaultflag(defaultProviders, 1);
|
||||
OptimizationEnum optimization = specificDef.getOptimization(defaultProviders, 1);
|
||||
this.addImpliedArgs(args, debug, multithreaded, exceptions, linkType, rtti, optimization, defaultflag);
|
||||
//
|
||||
// add all appropriate defines and undefines
|
||||
//
|
||||
buildDefineArguments(defaultProviders, args);
|
||||
//
|
||||
// Want to have distinct set of arguments with relative
|
||||
// path names for includes that are used to build
|
||||
// the configuration identifier
|
||||
//
|
||||
Vector relativeArgs = (Vector) args.clone();
|
||||
//
|
||||
// add all active include and sysincludes
|
||||
//
|
||||
StringBuffer includePathIdentifier = new StringBuffer();
|
||||
File baseDir = specificDef.getProject().getBaseDir();
|
||||
String baseDirPath;
|
||||
try {
|
||||
baseDirPath = baseDir.getCanonicalPath();
|
||||
} catch (IOException ex) {
|
||||
baseDirPath = baseDir.toString();
|
||||
}
|
||||
Vector includePath = new Vector();
|
||||
Vector sysIncludePath = new Vector();
|
||||
for (int i = defaultProviders.length - 1; i >= 0; i--) {
|
||||
String[] incPath = defaultProviders[i].getActiveIncludePaths();
|
||||
for (int j = 0; j < incPath.length; j++) {
|
||||
includePath.addElement(incPath[j]);
|
||||
}
|
||||
incPath = defaultProviders[i].getActiveSysIncludePaths();
|
||||
for (int j = 0; j < incPath.length; j++) {
|
||||
sysIncludePath.addElement(incPath[j]);
|
||||
}
|
||||
}
|
||||
File[] incPath = new File[includePath.size()];
|
||||
for (int i = 0; i < includePath.size(); i++) {
|
||||
incPath[i] = new File((String) includePath.elementAt(i));
|
||||
}
|
||||
File[] sysIncPath = new File[sysIncludePath.size()];
|
||||
for (int i = 0; i < sysIncludePath.size(); i++) {
|
||||
sysIncPath[i] = new File((String) sysIncludePath.elementAt(i));
|
||||
}
|
||||
addIncludes(baseDirPath, incPath, args, relativeArgs,
|
||||
includePathIdentifier);
|
||||
addIncludes(baseDirPath, sysIncPath, args, null, null);
|
||||
StringBuffer buf = new StringBuffer(getIdentifier());
|
||||
for (int i = 0; i < relativeArgs.size(); i++) {
|
||||
buf.append(relativeArgs.elementAt(i));
|
||||
buf.append(' ');
|
||||
}
|
||||
buf.setLength(buf.length() - 1);
|
||||
String configId = buf.toString();
|
||||
int warnings = specificDef.getWarnings(defaultProviders, 0);
|
||||
addWarningSwitch(args, warnings);
|
||||
Enumeration argEnum = cmdArgs.elements();
|
||||
int endCount = 0;
|
||||
while (argEnum.hasMoreElements()) {
|
||||
CommandLineArgument arg = (CommandLineArgument) argEnum
|
||||
.nextElement();
|
||||
switch (arg.getLocation()) {
|
||||
case 1 :
|
||||
args.addElement(arg.getValue());
|
||||
break;
|
||||
case 2 :
|
||||
endCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String[] endArgs = new String[endCount];
|
||||
argEnum = cmdArgs.elements();
|
||||
int index = 0;
|
||||
while (argEnum.hasMoreElements()) {
|
||||
CommandLineArgument arg = (CommandLineArgument) argEnum
|
||||
.nextElement();
|
||||
if (arg.getLocation() == 2) {
|
||||
endArgs[index++] = arg.getValue();
|
||||
}
|
||||
}
|
||||
String[] argArray = new String[args.size()];
|
||||
args.copyInto(argArray);
|
||||
boolean rebuild = specificDef.getRebuild(baseDefs, 0);
|
||||
File[] envIncludePath = getEnvironmentIncludePath();
|
||||
return new CommandLineCompilerConfiguration(this, configId, incPath,
|
||||
sysIncPath, envIncludePath, includePathIdentifier.toString(),
|
||||
argArray, paramArray, rebuild, endArgs);
|
||||
}
|
||||
protected int getArgumentCountPerInputFile() {
|
||||
return 1;
|
||||
}
|
||||
protected final String getCommand() {
|
||||
return command;
|
||||
}
|
||||
abstract protected void getDefineSwitch(StringBuffer buffer, String define,
|
||||
String value);
|
||||
protected abstract File[] getEnvironmentIncludePath();
|
||||
public String getIdentifier() {
|
||||
if (identifier == null) {
|
||||
if (identifierArg == null) {
|
||||
identifier = getIdentifier(new String[]{command}, command);
|
||||
} else {
|
||||
identifier = getIdentifier(
|
||||
new String[]{command, identifierArg}, command);
|
||||
}
|
||||
}
|
||||
return identifier;
|
||||
}
|
||||
abstract protected String getIncludeDirSwitch(String source);
|
||||
protected String getInputFileArgument(File outputDir, String filename,
|
||||
int index) {
|
||||
//
|
||||
// if there is an embedded space,
|
||||
// must enclose in quotes
|
||||
if (filename.indexOf(' ') >= 0) {
|
||||
StringBuffer buf = new StringBuffer("\"");
|
||||
buf.append(filename);
|
||||
buf.append("\"");
|
||||
return buf.toString();
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
protected final boolean getLibtool() {
|
||||
return libtool;
|
||||
}
|
||||
/**
|
||||
* Obtains the same compiler, but with libtool set
|
||||
*
|
||||
* Default behavior is to ignore libtool
|
||||
*/
|
||||
public final CommandLineCompiler getLibtoolCompiler() {
|
||||
if (libtoolCompiler != null) {
|
||||
return libtoolCompiler;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
abstract public int getMaximumCommandLength();
|
||||
protected int getMaximumInputFilesPerCommand() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
protected int getTotalArgumentLengthForInputFile(File outputDir,
|
||||
String inputFile) {
|
||||
return inputFile.length() + 1;
|
||||
}
|
||||
abstract protected void getUndefineSwitch(StringBuffer buffer, String define);
|
||||
/**
|
||||
* This method is exposed so test classes can overload and test the
|
||||
* arguments without actually spawning the compiler
|
||||
*/
|
||||
protected int runCommand(CCTask task, File workingDir, String[] cmdline)
|
||||
throws BuildException {
|
||||
return CUtil.runCommand(task, workingDir, cmdline, newEnvironment, env);
|
||||
}
|
||||
protected final void setCommand(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
}
|
@ -0,0 +1,216 @@
|
||||
/*
|
||||
*
|
||||
* 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.compiler;
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.CCTask;
|
||||
import net.sf.antcontrib.cpptasks.CompilerParam;
|
||||
import net.sf.antcontrib.cpptasks.DependencyInfo;
|
||||
import net.sf.antcontrib.cpptasks.ProcessorParam;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
/**
|
||||
* A configuration for a C++ compiler
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public final class CommandLineCompilerConfiguration
|
||||
implements
|
||||
CompilerConfiguration {
|
||||
private/* final */String[] args;
|
||||
private/* final */CommandLineCompiler compiler;
|
||||
private String[] endArgs;
|
||||
//
|
||||
// include path from environment variable not
|
||||
// explicitly stated in Ant script
|
||||
private/* final */File[] envIncludePath;
|
||||
private String[] exceptFiles;
|
||||
private/* final */String identifier;
|
||||
private/* final */File[] includePath;
|
||||
private/* final */String includePathIdentifier;
|
||||
private boolean isPrecompiledHeaderGeneration;
|
||||
private/* final */ProcessorParam[] params;
|
||||
private/* final */boolean rebuild;
|
||||
private/* final */File[] sysIncludePath;
|
||||
public CommandLineCompilerConfiguration(CommandLineCompiler compiler,
|
||||
String identifier, File[] includePath, File[] sysIncludePath,
|
||||
File[] envIncludePath, String includePathIdentifier, String[] args,
|
||||
ProcessorParam[] params, boolean rebuild, String[] endArgs) {
|
||||
if (compiler == null) {
|
||||
throw new NullPointerException("compiler");
|
||||
}
|
||||
if (identifier == null) {
|
||||
throw new NullPointerException("identifier");
|
||||
}
|
||||
if (includePathIdentifier == null) {
|
||||
throw new NullPointerException("includePathIdentifier");
|
||||
}
|
||||
if (args == null) {
|
||||
this.args = new String[0];
|
||||
} else {
|
||||
this.args = (String[]) args.clone();
|
||||
}
|
||||
if (includePath == null) {
|
||||
this.includePath = new File[0];
|
||||
} else {
|
||||
this.includePath = (File[]) includePath.clone();
|
||||
}
|
||||
if (sysIncludePath == null) {
|
||||
this.sysIncludePath = new File[0];
|
||||
} else {
|
||||
this.sysIncludePath = (File[]) sysIncludePath.clone();
|
||||
}
|
||||
if (envIncludePath == null) {
|
||||
this.envIncludePath = new File[0];
|
||||
} else {
|
||||
this.envIncludePath = (File[]) envIncludePath.clone();
|
||||
}
|
||||
this.compiler = compiler;
|
||||
this.params = (ProcessorParam[]) params.clone();
|
||||
this.rebuild = rebuild;
|
||||
this.identifier = identifier;
|
||||
this.includePathIdentifier = includePathIdentifier;
|
||||
this.endArgs = (String[]) endArgs.clone();
|
||||
exceptFiles = null;
|
||||
isPrecompiledHeaderGeneration = false;
|
||||
}
|
||||
public CommandLineCompilerConfiguration(
|
||||
CommandLineCompilerConfiguration base, String[] additionalArgs,
|
||||
String[] exceptFiles, boolean isPrecompileHeaderGeneration) {
|
||||
compiler = base.compiler;
|
||||
identifier = base.identifier;
|
||||
rebuild = base.rebuild;
|
||||
includePath = (File[]) base.includePath.clone();
|
||||
sysIncludePath = (File[]) base.sysIncludePath.clone();
|
||||
endArgs = (String[]) base.endArgs.clone();
|
||||
envIncludePath = (File[]) base.envIncludePath.clone();
|
||||
includePathIdentifier = base.includePathIdentifier;
|
||||
if (exceptFiles != null) {
|
||||
this.exceptFiles = (String[]) exceptFiles.clone();
|
||||
}
|
||||
this.isPrecompiledHeaderGeneration = isPrecompileHeaderGeneration;
|
||||
args = new String[base.args.length + additionalArgs.length];
|
||||
for (int i = 0; i < base.args.length; i++) {
|
||||
args[i] = base.args[i];
|
||||
}
|
||||
int index = base.args.length;
|
||||
for (int i = 0; i < additionalArgs.length; i++) {
|
||||
args[index++] = additionalArgs[i];
|
||||
}
|
||||
}
|
||||
public int bid(String inputFile) {
|
||||
int compilerBid = compiler.bid(inputFile);
|
||||
if (compilerBid > 0 && exceptFiles != null) {
|
||||
for (int i = 0; i < exceptFiles.length; i++) {
|
||||
if (inputFile.equals(exceptFiles[i])) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return compilerBid;
|
||||
}
|
||||
public void compile(CCTask task, File outputDir, String[] sourceFiles,
|
||||
boolean relentless, ProgressMonitor monitor) throws BuildException {
|
||||
if (monitor != null) {
|
||||
monitor.start(this);
|
||||
}
|
||||
try {
|
||||
compiler.compile(task, outputDir, sourceFiles, args, endArgs,
|
||||
relentless, this, monitor);
|
||||
if (monitor != null) {
|
||||
monitor.finish(this, true);
|
||||
}
|
||||
} catch (BuildException ex) {
|
||||
if (monitor != null) {
|
||||
monitor.finish(this, false);
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* This method may be used to get two distinct compiler configurations, one
|
||||
* for compiling the specified file and producing a precompiled header
|
||||
* file, and a second for compiling other files using the precompiled
|
||||
* header file.
|
||||
*
|
||||
* The last (preferrably only) include directive in the prototype file will
|
||||
* be used to mark the boundary between pre-compiled and normally compiled
|
||||
* headers.
|
||||
*
|
||||
* @param prototype
|
||||
* A source file (for example, stdafx.cpp) that is used to build
|
||||
* the precompiled header file. @returns null if precompiled
|
||||
* headers are not supported or a two element array containing
|
||||
* the precompiled header generation configuration and the
|
||||
* consuming configuration
|
||||
*
|
||||
*/
|
||||
public CompilerConfiguration[] createPrecompileConfigurations(
|
||||
File prototype, String[] nonPrecompiledFiles) {
|
||||
if (compiler instanceof PrecompilingCompiler) {
|
||||
return ((PrecompilingCompiler) compiler)
|
||||
.createPrecompileConfigurations(this, prototype,
|
||||
nonPrecompiledFiles);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Returns a string representation of this configuration. Should be
|
||||
* canonical so that equivalent configurations will have equivalent string
|
||||
* representations
|
||||
*/
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
public String getIncludePathIdentifier() {
|
||||
return includePathIdentifier;
|
||||
}
|
||||
public String getOutputFileName(String inputFile) {
|
||||
return compiler.getOutputFileName(inputFile);
|
||||
}
|
||||
public CompilerParam getParam(String name) {
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
if (name.equals(params[i].getName()))
|
||||
return (CompilerParam) params[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ProcessorParam[] getParams() {
|
||||
return params;
|
||||
}
|
||||
public boolean getRebuild() {
|
||||
return rebuild;
|
||||
}
|
||||
public boolean isPrecompileGeneration() {
|
||||
return isPrecompiledHeaderGeneration;
|
||||
}
|
||||
public DependencyInfo parseIncludes(CCTask task, File baseDir, File source) {
|
||||
return compiler.parseIncludes(task, source, includePath,
|
||||
sysIncludePath, envIncludePath, baseDir,
|
||||
getIncludePathIdentifier());
|
||||
}
|
||||
public String toString() {
|
||||
return identifier;
|
||||
}
|
||||
public String[] getPreArguments() {
|
||||
return (String[]) args.clone();
|
||||
}
|
||||
public String[] getEndArguments() {
|
||||
return (String[]) endArgs.clone();
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
*
|
||||
* 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.compiler;
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.parser.FortranParser;
|
||||
import net.sf.antcontrib.cpptasks.parser.Parser;
|
||||
|
||||
import org.apache.tools.ant.types.Environment;
|
||||
/**
|
||||
* An abstract Compiler implementation which uses an external program to
|
||||
* perform the compile.
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public abstract class CommandLineFortranCompiler extends CommandLineCompiler {
|
||||
protected CommandLineFortranCompiler(String command, String identifierArg,
|
||||
String[] sourceExtensions, String[] headerExtensions,
|
||||
String outputSuffix, boolean libtool,
|
||||
CommandLineFortranCompiler libtoolCompiler, boolean newEnvironment,
|
||||
Environment env) {
|
||||
super(command, identifierArg, sourceExtensions, headerExtensions,
|
||||
outputSuffix, libtool, libtoolCompiler, newEnvironment, env);
|
||||
}
|
||||
protected Parser createParser(File source) {
|
||||
return new FortranParser();
|
||||
}
|
||||
}
|
@ -0,0 +1,404 @@
|
||||
/*
|
||||
*
|
||||
* 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.compiler;
|
||||
|
||||
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.CCTask;
|
||||
import net.sf.antcontrib.cpptasks.CUtil;
|
||||
import net.sf.antcontrib.cpptasks.LinkerDef;
|
||||
import net.sf.antcontrib.cpptasks.ProcessorDef;
|
||||
import net.sf.antcontrib.cpptasks.ProcessorParam;
|
||||
import net.sf.antcontrib.cpptasks.types.CommandLineArgument;
|
||||
import net.sf.antcontrib.cpptasks.types.LibrarySet;
|
||||
import net.sf.antcontrib.cpptasks.TargetDef;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.types.Environment;
|
||||
|
||||
|
||||
/**
|
||||
* An abstract Linker implementation that performs the link via an external
|
||||
* command.
|
||||
*
|
||||
* @author Adam Murdoch
|
||||
*/
|
||||
public abstract class CommandLineLinker extends AbstractLinker
|
||||
{
|
||||
private String command;
|
||||
private Environment env = null;
|
||||
private String identifier;
|
||||
private String identifierArg;
|
||||
private boolean isLibtool;
|
||||
private String[] librarySets;
|
||||
private CommandLineLinker libtoolLinker;
|
||||
private boolean newEnvironment = false;
|
||||
private String outputSuffix;
|
||||
|
||||
|
||||
/** Creates a comand line linker invocation */
|
||||
public CommandLineLinker(String command,
|
||||
String identifierArg,
|
||||
String[] extensions,
|
||||
String[] ignoredExtensions, String outputSuffix,
|
||||
boolean isLibtool, CommandLineLinker libtoolLinker)
|
||||
{
|
||||
super(extensions, ignoredExtensions);
|
||||
this.command = command;
|
||||
this.identifierArg = identifierArg;
|
||||
this.outputSuffix = outputSuffix;
|
||||
this.isLibtool = isLibtool;
|
||||
this.libtoolLinker = libtoolLinker;
|
||||
}
|
||||
protected abstract void addBase(long base, Vector args);
|
||||
|
||||
protected abstract void addFixed(Boolean fixed, Vector args);
|
||||
|
||||
abstract protected void addImpliedArgs(boolean debug,
|
||||
LinkType linkType, Vector args, Boolean defaultflag);
|
||||
protected abstract void addIncremental(boolean incremental, Vector args);
|
||||
|
||||
//
|
||||
// Windows processors handle these through file list
|
||||
//
|
||||
protected String[] addLibrarySets(CCTask task, LibrarySet[] libsets, Vector preargs,
|
||||
Vector midargs, Vector endargs) {
|
||||
return null;
|
||||
}
|
||||
protected abstract void addMap(boolean map, Vector args);
|
||||
protected abstract void addStack(int stack, Vector args);
|
||||
protected abstract void addEntry(String entry, Vector args);
|
||||
|
||||
protected LinkerConfiguration createConfiguration(
|
||||
CCTask task,
|
||||
LinkType linkType,
|
||||
ProcessorDef[] baseDefs, LinkerDef specificDef, TargetDef targetPlatform) {
|
||||
|
||||
Vector preargs = new Vector();
|
||||
Vector midargs = new Vector();
|
||||
Vector endargs = new Vector();
|
||||
Vector[] args = new Vector[] { preargs, midargs, endargs };
|
||||
|
||||
LinkerDef[] defaultProviders = new LinkerDef[baseDefs.length+1];
|
||||
defaultProviders[0] = specificDef;
|
||||
for(int i = 0; i < baseDefs.length; i++) {
|
||||
defaultProviders[i+1] = (LinkerDef) baseDefs[i];
|
||||
}
|
||||
//
|
||||
// add command line arguments inherited from <cc> element
|
||||
// any "extends" and finally the specific CompilerDef
|
||||
CommandLineArgument[] commandArgs;
|
||||
for(int i = defaultProviders.length-1; i >= 0; i--) {
|
||||
commandArgs = defaultProviders[i].getActiveProcessorArgs();
|
||||
for(int j = 0; j < commandArgs.length; j++) {
|
||||
args[commandArgs[j].getLocation()].
|
||||
addElement(commandArgs[j].getValue());
|
||||
}
|
||||
}
|
||||
|
||||
Vector params = new Vector();
|
||||
//
|
||||
// add command line arguments inherited from <cc> element
|
||||
// any "extends" and finally the specific CompilerDef
|
||||
ProcessorParam[] paramArray;
|
||||
for (int i = defaultProviders.length - 1; i >= 0; i--) {
|
||||
paramArray = defaultProviders[i].getActiveProcessorParams();
|
||||
for (int j = 0; j < paramArray.length; j++) {
|
||||
params.add(paramArray[j]);
|
||||
}
|
||||
}
|
||||
|
||||
paramArray = (ProcessorParam[])(params.toArray(new ProcessorParam[params.size()]));
|
||||
|
||||
boolean debug = specificDef.getDebug(baseDefs,0);
|
||||
|
||||
|
||||
String startupObject = getStartupObject(linkType);
|
||||
Boolean defaultflag = specificDef.getDefaultflag(defaultProviders, 1);
|
||||
addImpliedArgs(debug, linkType, preargs, defaultflag);
|
||||
addIncremental(specificDef.getIncremental(defaultProviders,1), preargs);
|
||||
addFixed(specificDef.getFixed(defaultProviders,1), preargs);
|
||||
addMap(specificDef.getMap(defaultProviders,1), preargs);
|
||||
addBase(specificDef.getBase(defaultProviders,1), preargs);
|
||||
addStack(specificDef.getStack(defaultProviders,1), preargs);
|
||||
addEntry(specificDef.getEntry(defaultProviders, 1), preargs);
|
||||
|
||||
String[] libnames = null;
|
||||
LibrarySet[] libsets = specificDef.getActiveLibrarySets(defaultProviders,1);
|
||||
if (libsets.length > 0) {
|
||||
libnames = addLibrarySets(task, libsets, preargs, midargs, endargs);
|
||||
}
|
||||
|
||||
StringBuffer buf = new StringBuffer(getIdentifier());
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Enumeration argenum = args[i].elements();
|
||||
while (argenum.hasMoreElements()) {
|
||||
buf.append(' ');
|
||||
buf.append(argenum.nextElement().toString());
|
||||
}
|
||||
}
|
||||
String configId = buf.toString();
|
||||
|
||||
String[][] options = new String[][] {
|
||||
new String[args[0].size() + args[1].size()],
|
||||
new String[args[2].size()] };
|
||||
args[0].copyInto(options[0]);
|
||||
int offset = args[0].size();
|
||||
for (int i = 0; i < args[1].size(); i++) {
|
||||
options[0][i+offset] = (String) args[1].elementAt(i);
|
||||
}
|
||||
args[2].copyInto(options[1]);
|
||||
|
||||
|
||||
boolean rebuild = specificDef.getRebuild(baseDefs,0);
|
||||
boolean map = specificDef.getMap(defaultProviders,1);
|
||||
|
||||
//task.log("libnames:"+libnames.length, Project.MSG_VERBOSE);
|
||||
return new CommandLineLinkerConfiguration(this,configId,options,
|
||||
paramArray,
|
||||
rebuild,map,libnames, startupObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows drived linker to decorate linker option.
|
||||
* Override by GccLinker to prepend a "-Wl," to
|
||||
* pass option to through gcc to linker.
|
||||
*
|
||||
* @param buf buffer that may be used and abused in the decoration process,
|
||||
* must not be null.
|
||||
* @param arg linker argument
|
||||
*/
|
||||
protected String decorateLinkerOption(StringBuffer buf, String arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
protected final String getCommand() {
|
||||
return command;
|
||||
}
|
||||
protected abstract String getCommandFileSwitch(String commandFile);
|
||||
|
||||
|
||||
public String getIdentifier() {
|
||||
if(identifier == null) {
|
||||
if (identifierArg == null) {
|
||||
identifier = getIdentifier(new String[] { command }, command);
|
||||
} else {
|
||||
identifier = getIdentifier(new String[] { command, identifierArg },
|
||||
command);
|
||||
}
|
||||
}
|
||||
return identifier;
|
||||
}
|
||||
public final CommandLineLinker getLibtoolLinker() {
|
||||
if (libtoolLinker != null) {
|
||||
return libtoolLinker;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
protected abstract int getMaximumCommandLength();
|
||||
|
||||
public String getOutputFileName(String baseName) {
|
||||
return baseName + outputSuffix;
|
||||
}
|
||||
|
||||
protected String[] getOutputFileSwitch(CCTask task, String outputFile) {
|
||||
return getOutputFileSwitch(outputFile);
|
||||
}
|
||||
protected abstract String[] getOutputFileSwitch(String outputFile);
|
||||
protected String getStartupObject(LinkType linkType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a link using a command line linker
|
||||
*
|
||||
*/
|
||||
public void link(CCTask task,
|
||||
File outputFile,
|
||||
String[] sourceFiles,
|
||||
CommandLineLinkerConfiguration config)
|
||||
throws BuildException
|
||||
{
|
||||
File parentDir = new File(outputFile.getParent());
|
||||
String parentPath;
|
||||
try {
|
||||
parentPath = parentDir.getCanonicalPath();
|
||||
} catch(IOException ex) {
|
||||
parentPath = parentDir.getAbsolutePath();
|
||||
}
|
||||
String[] execArgs = prepareArguments(task, parentPath,outputFile.getName(),
|
||||
sourceFiles, config);
|
||||
int commandLength = 0;
|
||||
for(int i = 0; i < execArgs.length; i++) {
|
||||
commandLength += execArgs[i].length() + 1;
|
||||
}
|
||||
|
||||
//
|
||||
// if command length exceeds maximum
|
||||
// (1024 for Windows) then create a temporary
|
||||
// file containing everything but the command name
|
||||
if(commandLength >= this.getMaximumCommandLength()) {
|
||||
try {
|
||||
execArgs = prepareResponseFile(outputFile,execArgs);
|
||||
}
|
||||
catch(IOException ex) {
|
||||
throw new BuildException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
int retval = runCommand(task,parentDir,execArgs);
|
||||
//
|
||||
// if the process returned a failure code then
|
||||
// throw an BuildException
|
||||
//
|
||||
if(retval != 0) {
|
||||
//
|
||||
// construct the exception
|
||||
//
|
||||
throw new BuildException(this.getCommand() + " failed with return code " + retval, task.getLocation());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepares argument list for exec command. Will return null
|
||||
* if command line would exceed allowable command line buffer.
|
||||
*
|
||||
* @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 outputFile,
|
||||
String[] sourceFiles,
|
||||
CommandLineLinkerConfiguration config) {
|
||||
|
||||
String[] preargs = config.getPreArguments();
|
||||
String[] endargs = config.getEndArguments();
|
||||
String outputSwitch[] = getOutputFileSwitch(task, outputFile);
|
||||
int allArgsCount = preargs.length + 1 + outputSwitch.length +
|
||||
sourceFiles.length + endargs.length;
|
||||
if (isLibtool) {
|
||||
allArgsCount++;
|
||||
}
|
||||
String[] allArgs = new String[allArgsCount];
|
||||
int index = 0;
|
||||
if (isLibtool) {
|
||||
allArgs[index++] = "libtool";
|
||||
}
|
||||
allArgs[index++] = this.getCommand();
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = 0; i < preargs.length; i++) {
|
||||
allArgs[index++] = decorateLinkerOption(buf, preargs[i]);
|
||||
}
|
||||
for (int i = 0; i < outputSwitch.length; i++) {
|
||||
allArgs[index++] = outputSwitch[i];
|
||||
}
|
||||
for (int i = 0; i < sourceFiles.length; i++) {
|
||||
allArgs[index++] = prepareFilename(buf,outputDir,sourceFiles[i]);
|
||||
}
|
||||
for (int i = 0; i < endargs.length; i++) {
|
||||
allArgs[index++] = decorateLinkerOption(buf, endargs[i]);
|
||||
}
|
||||
return allArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes filename into argument form
|
||||
*
|
||||
*/
|
||||
protected String prepareFilename(StringBuffer buf,
|
||||
String outputDir, String sourceFile) {
|
||||
String relativePath = CUtil.getRelativePath(outputDir,
|
||||
new File(sourceFile));
|
||||
return quoteFilename(buf,relativePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
String baseName = outputFile.getName();
|
||||
File commandFile = new File(outputFile.getParent(),baseName + ".rsp");
|
||||
FileWriter writer = new FileWriter(commandFile);
|
||||
int execArgCount = 1;
|
||||
if (isLibtool) {
|
||||
execArgCount++;
|
||||
}
|
||||
String[] execArgs = new String[execArgCount+1];
|
||||
for (int i = 0; i < execArgCount; i++) {
|
||||
execArgs[i] = args[i];
|
||||
}
|
||||
execArgs[execArgCount] = getCommandFileSwitch(commandFile.toString());
|
||||
for(int i = execArgCount; i < args.length; i++) {
|
||||
//
|
||||
// if embedded space and not quoted then
|
||||
// quote argument
|
||||
if (args[i].indexOf(" ") >= 0 && args[i].charAt(0) != '\"') {
|
||||
writer.write('\"');
|
||||
writer.write(args[i]);
|
||||
writer.write("\"\n");
|
||||
} else {
|
||||
writer.write(args[i]);
|
||||
writer.write('\n');
|
||||
}
|
||||
}
|
||||
writer.close();
|
||||
return execArgs;
|
||||
}
|
||||
|
||||
|
||||
protected String quoteFilename(StringBuffer buf,String filename) {
|
||||
if(filename.indexOf(' ') >= 0) {
|
||||
buf.setLength(0);
|
||||
buf.append('\"');
|
||||
buf.append(filename);
|
||||
buf.append('\"');
|
||||
return buf.toString();
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is exposed so test classes can overload
|
||||
* and test the arguments without actually spawning the
|
||||
* compiler
|
||||
*/
|
||||
protected int runCommand(CCTask task, File workingDir,String[] cmdline)
|
||||
throws BuildException {
|
||||
return CUtil.runCommand(task,workingDir,cmdline, newEnvironment, env);
|
||||
}
|
||||
|
||||
protected final void setCommand(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
/*
|
||||
*
|
||||
* 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.compiler;
|
||||
import net.sf.antcontrib.cpptasks.CCTask;
|
||||
import net.sf.antcontrib.cpptasks.LinkerParam;
|
||||
import net.sf.antcontrib.cpptasks.ProcessorParam;
|
||||
import net.sf.antcontrib.cpptasks.TargetInfo;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
/**
|
||||
* A configuration for a command line linker
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public final class CommandLineLinkerConfiguration
|
||||
implements
|
||||
LinkerConfiguration {
|
||||
private/* final */String[][] args;
|
||||
private/* final */String identifier;
|
||||
private String[] libraryNames;
|
||||
private/* final */CommandLineLinker linker;
|
||||
private/* final */boolean map;
|
||||
private/* final */ProcessorParam[] params;
|
||||
private/* final */boolean rebuild;
|
||||
private String startupObject;
|
||||
public CommandLineLinkerConfiguration(CommandLineLinker linker,
|
||||
String identifier, String[][] args, ProcessorParam[] params,
|
||||
boolean rebuild, boolean map, String[] libraryNames,
|
||||
String startupObject) {
|
||||
if (linker == null) {
|
||||
throw new NullPointerException("linker");
|
||||
}
|
||||
if (args == null) {
|
||||
throw new NullPointerException("args");
|
||||
} else {
|
||||
this.args = (String[][]) args.clone();
|
||||
}
|
||||
this.linker = linker;
|
||||
this.params = (ProcessorParam[]) params.clone();
|
||||
this.rebuild = rebuild;
|
||||
this.identifier = identifier;
|
||||
this.map = map;
|
||||
if (libraryNames == null) {
|
||||
this.libraryNames = new String[0];
|
||||
} else {
|
||||
this.libraryNames = (String[]) libraryNames.clone();
|
||||
}
|
||||
this.startupObject = startupObject;
|
||||
}
|
||||
public int bid(String filename) {
|
||||
return linker.bid(filename);
|
||||
}
|
||||
public String[] getEndArguments() {
|
||||
String[] clone = (String[]) args[1].clone();
|
||||
return clone;
|
||||
}
|
||||
/**
|
||||
* Returns a string representation of this configuration. Should be
|
||||
* canonical so that equivalent configurations will have equivalent string
|
||||
* representations
|
||||
*/
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
public String[] getLibraryNames() {
|
||||
String[] clone = (String[]) libraryNames.clone();
|
||||
return clone;
|
||||
}
|
||||
public boolean getMap() {
|
||||
return map;
|
||||
}
|
||||
public String getOutputFileName(String inputFile) {
|
||||
return linker.getOutputFileName(inputFile);
|
||||
}
|
||||
public LinkerParam getParam(String name) {
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
if (name.equals(params[i].getName()))
|
||||
return (LinkerParam) params[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ProcessorParam[] getParams() {
|
||||
return params;
|
||||
}
|
||||
public String[] getPreArguments() {
|
||||
String[] clone = (String[]) args[0].clone();
|
||||
return clone;
|
||||
}
|
||||
public boolean getRebuild() {
|
||||
return rebuild;
|
||||
}
|
||||
public String getStartupObject() {
|
||||
return startupObject;
|
||||
}
|
||||
public void link(CCTask task, TargetInfo linkTarget) throws BuildException {
|
||||
//
|
||||
// AllSourcePath's include any syslibsets
|
||||
//
|
||||
String[] sourcePaths = linkTarget.getAllSourcePaths();
|
||||
linker.link(task, linkTarget.getOutput(), sourcePaths, this);
|
||||
}
|
||||
public String toString() {
|
||||
return identifier;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
*
|
||||
* 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.compiler;
|
||||
/**
|
||||
* A compiler.
|
||||
*
|
||||
* @author Adam Murdoch
|
||||
*/
|
||||
public interface Compiler extends Processor {
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
*
|
||||
* 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.compiler;
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.antcontrib.cpptasks.CCTask;
|
||||
import net.sf.antcontrib.cpptasks.CompilerParam;
|
||||
import net.sf.antcontrib.cpptasks.DependencyInfo;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
/**
|
||||
* A configuration for a compiler
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public interface CompilerConfiguration extends ProcessorConfiguration {
|
||||
void compile(CCTask task, File outputDir, String[] sourceFiles,
|
||||
boolean relentless, ProgressMonitor monitor) throws BuildException;
|
||||
/**
|
||||
*
|
||||
* This method may be used to get two distinct compiler configurations, one
|
||||
* for compiling the specified file and producing a precompiled header
|
||||
* file, and a second for compiling other files using the precompiled
|
||||
* header file.
|
||||
*
|
||||
* The last (preferrably only) include directive in the prototype file will
|
||||
* be used to mark the boundary between pre-compiled and normally compiled
|
||||
* headers.
|
||||
*
|
||||
* @param prototype
|
||||
* A source file (for example, stdafx.cpp) that is used to build
|
||||
* the precompiled header file. @returns null if precompiled
|
||||
* headers are not supported or a two element array containing
|
||||
* the precompiled header generation configuration and the
|
||||
* consuming configuration
|
||||
*
|
||||
*/
|
||||
CompilerConfiguration[] createPrecompileConfigurations(File prototype,
|
||||
String[] nonPrecompiledFiles);
|
||||
/**
|
||||
* Returns an digest for the include path for the configuration.
|
||||
*
|
||||
* This is used to determine if cached dependency information is invalid
|
||||
* because the include paths have changed
|
||||
*/
|
||||
String getIncludePathIdentifier();
|
||||
public CompilerParam getParam(String name);
|
||||
boolean isPrecompileGeneration();
|
||||
DependencyInfo parseIncludes(CCTask task, File baseDir, File source);
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
/*
|
||||
*
|
||||
* 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.compiler;
|
||||
import net.sf.antcontrib.cpptasks.OutputTypeEnum;
|
||||
import net.sf.antcontrib.cpptasks.SubsystemEnum;
|
||||
/**
|
||||
* This class represents the target platform for the compile and link step. The
|
||||
* name is an anachronism and should be changed.
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public class LinkType {
|
||||
private OutputTypeEnum outputType = new OutputTypeEnum();
|
||||
private boolean staticRuntime = false;
|
||||
private SubsystemEnum subsystem = new SubsystemEnum();
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* By default, an gui executable with a dynamically linked runtime
|
||||
*
|
||||
*/
|
||||
public LinkType() {
|
||||
}
|
||||
/**
|
||||
* Gets whether the link should produce an executable
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isExecutable() {
|
||||
String value = outputType.getValue();
|
||||
return value.equals("executable");
|
||||
}
|
||||
/**
|
||||
* Gets whether the link should produce a plugin module.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isPluginModule() {
|
||||
String value = outputType.getValue();
|
||||
return value.equals("plugin");
|
||||
}
|
||||
/**
|
||||
* Gets whether the link should produce a shared library.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isSharedLibrary() {
|
||||
String value = outputType.getValue();
|
||||
return value.equals("shared") || value.equals("plugin");
|
||||
}
|
||||
/**
|
||||
* Gets whether the link should produce a static library.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isStaticLibrary() {
|
||||
String value = outputType.getValue();
|
||||
return value.equals("static");
|
||||
}
|
||||
/**
|
||||
* Gets whether the module should use a statically linked runtime library.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isStaticRuntime() {
|
||||
return staticRuntime;
|
||||
}
|
||||
/**
|
||||
* Gets whether the link should produce a module for a console subsystem.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isSubsystemConsole() {
|
||||
String value = subsystem.getValue();
|
||||
return value.equals("console");
|
||||
}
|
||||
/**
|
||||
* Gets whether the link should produce a module for a graphical user
|
||||
* interface subsystem.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isSubsystemGUI() {
|
||||
String value = subsystem.getValue();
|
||||
return value.equals("gui");
|
||||
}
|
||||
/**
|
||||
* Sets the output type (execuable, shared, etc).
|
||||
*
|
||||
* @param outputType,
|
||||
* may not be null
|
||||
*/
|
||||
public void setOutputType(OutputTypeEnum outputType) {
|
||||
if (outputType == null) {
|
||||
throw new IllegalArgumentException("outputType");
|
||||
}
|
||||
this.outputType = outputType;
|
||||
}
|
||||
/**
|
||||
* Requests use of a static runtime library.
|
||||
*
|
||||
* @param staticRuntime
|
||||
* if true, use static runtime library if possible.
|
||||
*/
|
||||
public void setStaticRuntime(boolean staticRuntime) {
|
||||
this.staticRuntime = staticRuntime;
|
||||
}
|
||||
/**
|
||||
* Sets the subsystem (gui, console, etc).
|
||||
*
|
||||
* @param subsystem
|
||||
* subsystem, may not be null
|
||||
*/
|
||||
public void setSubsystem(SubsystemEnum subsystem) {
|
||||
if (subsystem == null) {
|
||||
throw new IllegalArgumentException("subsystem");
|
||||
}
|
||||
this.subsystem = subsystem;
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
*
|
||||
* 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.compiler;
|
||||
import java.io.File;
|
||||
import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;
|
||||
/**
|
||||
* A linker for executables, and static and dynamic libraries.
|
||||
*
|
||||
* @author Adam Murdoch
|
||||
*/
|
||||
public interface Linker extends Processor {
|
||||
/**
|
||||
* Extracts the significant part of a library name to ensure there aren't
|
||||
* collisions
|
||||
*/
|
||||
String getLibraryKey(File libname);
|
||||
/**
|
||||
* returns the library path for the linker
|
||||
*/
|
||||
File[] getLibraryPath();
|
||||
/**
|
||||
* Returns a set of filename patterns corresponding to library names.
|
||||
*
|
||||
* For example, "advapi32" would be expanded to "advapi32.dll" by
|
||||
* DevStudioLinker and to "libadvapi32.a" and "libadvapi32.so" by
|
||||
* GccLinker.
|
||||
*
|
||||
* @param libnames
|
||||
* array of library names
|
||||
*/
|
||||
String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libraryType);
|
||||
/**
|
||||
* Gets the linker for the specified link type.
|
||||
*
|
||||
* @return appropriate linker or null, will return this if this linker can
|
||||
* handle the specified link type
|
||||
*/
|
||||
Linker getLinker(LinkType linkType);
|
||||
/**
|
||||
* Returns true if the linker is case-sensitive
|
||||
*/
|
||||
boolean isCaseSensitive();
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
*
|
||||
* 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.compiler;
|
||||
import net.sf.antcontrib.cpptasks.CCTask;
|
||||
import net.sf.antcontrib.cpptasks.LinkerParam;
|
||||
import net.sf.antcontrib.cpptasks.TargetInfo;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
/**
|
||||
* A configuration for a linker
|
||||
*
|
||||
* @author Curt Arnold
|
||||
*/
|
||||
public interface LinkerConfiguration extends ProcessorConfiguration {
|
||||
public LinkerParam getParam(String name);
|
||||
void link(CCTask task, TargetInfo linkTarget) throws BuildException;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user