diff options
Diffstat (limited to 'org.rtems.cdt.toolchain/src/org/rtems/cdt/toolchain/RtemsEnvironmentVariableSupplier.java')
-rw-r--r-- | org.rtems.cdt.toolchain/src/org/rtems/cdt/toolchain/RtemsEnvironmentVariableSupplier.java | 301 |
1 files changed, 301 insertions, 0 deletions
diff --git a/org.rtems.cdt.toolchain/src/org/rtems/cdt/toolchain/RtemsEnvironmentVariableSupplier.java b/org.rtems.cdt.toolchain/src/org/rtems/cdt/toolchain/RtemsEnvironmentVariableSupplier.java new file mode 100644 index 0000000..11865ec --- /dev/null +++ b/org.rtems.cdt.toolchain/src/org/rtems/cdt/toolchain/RtemsEnvironmentVariableSupplier.java @@ -0,0 +1,301 @@ +/********************************************************************** + * Copyright (c) 2008 RobertF. + * All rights reserved. + **********************************************************************/ + +package org.rtems.cdt.toolchain; + +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable; +import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier; +import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider; +import org.eclipse.cdt.utils.WindowsRegistry; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; + +public class RtemsEnvironmentVariableSupplier implements + IConfigurationEnvironmentVariableSupplier { + public static final String ENV_RTEMS_TOOL_DIR = "RTEMS_TOOL_DIR"; + public static final String ENV_RTEMS_TARGET_TOOL_DIR = "RTEMS_TARGET_TOOL_DIR"; + public static final String ENV_RTEMS_TARGET_CPU_GCC_LIB_DIR = "RTEMS_TARGET_CPU_GCC_LIB_DIR"; + public static final String ENV_RTEMS_INSTALL_DIR = "RTEMS_INSTALL_DIR"; + public static final String ENV_RTEMS_INSTALL_BSP_DIR = "RTEMS_INSTALL_BSP_DIR"; + + private static IPath toolPath; // e.g., /opt/rtems-4.9 + private static IPath targetToolPath; // e.g., /opt/rtems-4.9/i386-rtems4.9 + private static IPath targetCpuGccLibPath; // e.g., /opt/rtems-4.9/lib/gcc/i386-rtems4.9/4.3.2/mpentiumpro + private static IPath installPath; // e.g., /opt/rtems_install + private static IPath installBspPath; // e.g., /opt/rtems_install/i386-rtems4.9/pc686/lib + + private static IBuildEnvironmentVariable evBinPath = null; + private static IBuildEnvironmentVariable evCIncludePath = null; + private static IBuildEnvironmentVariable evLibPath = null; + + public static boolean toolChainSupported; + public static boolean isOSWindows; + public static String pathSeparator; // ":" on UNIX + private static String drivePrefix; // disk drive prefix: C: for Windows a + // blank for other OS + + private static class RtemsBuildEnvironmentVariable implements IBuildEnvironmentVariable { + private final String name; + private final String value; + private final int operation; + + public RtemsBuildEnvironmentVariable(String name, String value, int operation) { + this.name = name; + this.value = value; + this.operation = operation; + } + + public String getName() { return name; } + public String getValue() { return value; } + public int getOperation() { return operation; } + public String getDelimiter() { return pathSeparator; } + } + + static { + /* Some useful system properties + + property Description + -------------- --------------------------- + os.name Operating system name + os.arch Operating system architecture + os.version Operating system version + file.separator File separator ("/" on UNIX) + path.separator Path separator (":" on UNIX) + */ + pathSeparator = System.getProperty("path.separator"); + + isOSWindows = false; + String osName = System.getProperty("os.name"); + if (osName != null) { + isOSWindows = osName.indexOf("Windows") >= 0; + } + + drivePrefix = isOSWindows ? "C:" : ""; + + toolPath = getRtemsToolDirectory(); + targetToolPath = getRtemsTargetToolDirectory(); + targetCpuGccLibPath = getRtemsTargetCpuGccLibDirectory(); + installPath = getRtemsInstallDirectory(); + installBspPath = getRtemsInstallBspDirectory(); + + toolChainSupported = toolPath != null && targetToolPath != null + && installPath != null && installBspPath != null + && targetCpuGccLibPath != null; + + StringBuffer binPathBuf = new StringBuffer(); + StringBuffer incPathBuf = new StringBuffer(); + StringBuffer libPathBuf = new StringBuffer(); + + if (toolPath != null) { + binPathBuf = binPathBuf.append(toolPath.append("bin").toOSString()); + } + + if (targetCpuGccLibPath != null) { + if (libPathBuf.length()>0) libPathBuf.append(pathSeparator); + libPathBuf = libPathBuf.append(targetCpuGccLibPath.toOSString()); + + + IPath targetGccVersionPath; + try { + targetGccVersionPath = targetCpuGccLibPath.append(".."); + + IPath gccIncPath = targetGccVersionPath.append("include"); + if (!gccIncPath.toFile().isDirectory()) { + targetGccVersionPath = targetCpuGccLibPath; + } + } catch (Exception e) { + targetGccVersionPath = targetCpuGccLibPath; + } + + if (incPathBuf.length()>0) incPathBuf.append(pathSeparator); + incPathBuf = incPathBuf.append(targetGccVersionPath.append("include").toOSString()); + + incPathBuf.append(pathSeparator); + incPathBuf = incPathBuf.append(targetGccVersionPath.append("include-fixed").toOSString()); + + } + + if (targetToolPath != null) { + if (binPathBuf.length()>0) binPathBuf.append(pathSeparator); + binPathBuf = binPathBuf.append(targetToolPath.append("bin").toOSString()); + + if (incPathBuf.length()>0) incPathBuf.append(pathSeparator); + incPathBuf = incPathBuf.append(targetToolPath.append("include").toOSString()); + + if (libPathBuf.length()>0) libPathBuf.append(pathSeparator); + libPathBuf = libPathBuf.append(targetToolPath.append("lib").toOSString()); + } + + if (installPath != null) { + if (binPathBuf.length()>0) binPathBuf.append(pathSeparator); + binPathBuf = binPathBuf.append(installPath.append("bin").toOSString()); + } + + if (installBspPath != null) { + if (binPathBuf.length()>0) binPathBuf.append(pathSeparator); + binPathBuf = binPathBuf.append(installBspPath.append("build-tools").toOSString()); + + IPath bspLibPath = installBspPath.append("lib"); + if (incPathBuf.length()>0) incPathBuf.append(pathSeparator); + incPathBuf = incPathBuf.append(bspLibPath.append("include").toOSString()); + + if (libPathBuf.length()>0) libPathBuf.append(pathSeparator); + libPathBuf = libPathBuf.append(bspLibPath.toOSString()); + } + + evBinPath = new RtemsBuildEnvironmentVariable("PATH", + binPathBuf.toString(), + IBuildEnvironmentVariable.ENVVAR_PREPEND); + evCIncludePath = new RtemsBuildEnvironmentVariable("C_INCLUDE_PATH", + incPathBuf.toString(), + IBuildEnvironmentVariable.ENVVAR_PREPEND); + //evCppIncludePath = new RtemsBuildEnvironmentVariable("CPLUS_INCLUDE_PATH", + // incPath.toString(), + // IBuildEnvironmentVariable.ENVVAR_PREPEND); + evLibPath = new RtemsBuildEnvironmentVariable("LIBRARY_PATH", + libPathBuf.toString(), + IBuildEnvironmentVariable.ENVVAR_PREPEND); + } + + public RtemsEnvironmentVariableSupplier() { + } + + public IBuildEnvironmentVariable getVariable(String variableName, + IConfiguration configuration, IEnvironmentVariableProvider provider) { + if (evBinPath != null && + variableName.equals(evBinPath.getName())) { + return evBinPath; + + } else if (evLibPath != null && + variableName.equals(evLibPath.getName())) { + return evLibPath; + + } else if (evCIncludePath != null && + variableName.equals(evCIncludePath.getName())) { + return evCIncludePath; + } + + return null; + } + + public IBuildEnvironmentVariable[] getVariables( + IConfiguration configuration, IEnvironmentVariableProvider provider) { + return new IBuildEnvironmentVariable[] { + evBinPath, evCIncludePath, evLibPath }; + } + + public static IPath getRtemsToolDirectory() { + IPath path; + + // Preferred way to get RTEMS Tool directory via environment variable + String dir = System.getenv(ENV_RTEMS_TOOL_DIR); + if (dir != null) { + path = new Path(dir); + if (path.toFile().isDirectory()) return path; + } + + // Try to locate RTEMS Tool directory at /opt/rtems + // User can create such a soft link to point to the latest one + path = new Path(drivePrefix + "/opt/rtems"); + if (path.toFile().isDirectory()) return path; + + // Try RTEMS 4.9 specific tool bin directory + path = new Path(drivePrefix + "/opt/rtems-4.9"); + if (path.toFile().isDirectory()) return path; + + // Still not found + return null; + } + + public static IPath getRtemsTargetToolDirectory() { + IPath path; + + // Preferred way to get RTEMS Target Tool directory via environment variable + String dir = System.getenv(ENV_RTEMS_TARGET_TOOL_DIR); + if (dir != null) { + path = new Path(dir); + if (path.toFile().isDirectory()) return path; + } + + // Try to locate RTEMS Target Tool directory at /opt/rtems/i386-rtems4.9 + // User can create such a soft link to point to the latest one + path = new Path(drivePrefix + "/opt/rtems/i386-rtems4.9"); + if (path.toFile().isDirectory()) return path; + + // Try RTEMS 4.9 specific target tool bin directory + path = new Path(drivePrefix + "/opt/rtems-4.9/i386-rtems4.9"); + if (path.toFile().isDirectory()) return path; + + // Still not found + return null; + } + + public static IPath getRtemsTargetCpuGccLibDirectory() { + IPath path; + + // Preferred way to get RTEMS Target Tool directory via environment variable + String dir = System.getenv(ENV_RTEMS_TARGET_CPU_GCC_LIB_DIR); + if (dir != null) { + path = new Path(dir); + if (path.toFile().isDirectory()) return path; + } + + //Try default RTEMS 4.9 Target Tool bin directory + path = new Path(drivePrefix + "/opt/rtems-4.9/lib/gcc/i386-rtems4.9/4.3.2/mpentiumpro"); + if (path.toFile().isDirectory()) return path; + + // Still not found + return null; + } + + public static IPath getRtemsInstallDirectory() { + IPath path; + + // Preferred way to get RTEMS Install directory via environment variable + String dir = System.getenv(ENV_RTEMS_INSTALL_DIR); + if (dir != null) { + path = new Path(dir); + if (path.toFile().isDirectory()) return path; + } + + // Try /opt/rtems_install + path = new Path(drivePrefix + "/opt/rtems_install"); + if (path.toFile().isDirectory()) return path; + + // Still not found + return null; + } + + public static IPath getRtemsInstallBspDirectory() { + IPath path; + + // Preferred way to get installed target lib directory via environment variable + String dir = System.getenv(ENV_RTEMS_INSTALL_BSP_DIR); + if (dir != null) { + path = new Path(dir); + if (path.toFile().isDirectory()) return path; + } + + // Try /opt/rtems_install/i386-rtems4.9/pc686/lib + path = new Path(drivePrefix + "/opt/rtems_install/i386-rtems4.9/pc686/lib"); + if (path.toFile().isDirectory()) return path; + + // Still not found + return null; + } + + public static IPath getRtemsInstallBspLibDirectory() { + IPath installedBspLibPath = getRtemsInstallBspDirectory(); + + if (installedBspLibPath != null) { + installedBspLibPath = installedBspLibPath.append("lib"); + } + + return installedBspLibPath; + } +} + |