是否可以在Eclipse中设置条件路径变量?这对于自定义构建器(与Indigo中的项目一起存储 - 我认为在旧的Eclipse版本中不是这种情况)在不同平台下调用不同的程序非常有用。
所以我正在寻找的东西将是:
${if{${system:OS}=='Windows'}compiler.exe${else}compiler.sh
答案 0 :(得分:1)
如果您特别想在不同平台上调用不同的编译器,那么您可以使用Ant或Make来检测您的平台并调用不同的程序。
在项目的属性中,转到“Builders”并创建一个新的构建步骤。如果您使用GNU Make作为构建器,则可以在Makefile中使用如下语法:
# Only MS-DOS/Windows builds of GNU Make check for the MAKESHELL variable
# On those platforms, the default is command.com, which is not what you want
MAKESHELL := cmd.exe
# Ask make what OS it's running on
MAKE_OS := $(shell $(MAKE) -v)
# On Windows, GNU Make is built using either MinGW or Cygwin
ifeq ($(findstring mingw, $(MAKE_OS)), mingw)
BUILD_COMMAND := compiler.exe
else ifeq ($(findstring cygwin, $(MAKE_OS)), cygwin)
BUILD_COMMAND := compiler.exe
else ifeq ($(findstring darwin, $(MAKE_OS)), darwin)
BUILD_COMMAND := compiler-osx.sh
else ifeq ($(findstring linux, $(MAKE_OS)), linux)
BUILD_COMMAND := compiler.sh
endif
在Ant构建脚本中,条件执行由if
,unless
和depends
等属性决定。 <os family=xxx>
标记会告诉您正在运行的操作系统。这是devdaily的一个例子:
<?xml version="1.0"?>
<!--
An Ant build script that demonstrates how to test to see
which operating system (computer platform) the Ant build
script is currently running on. Currently tests for Mac OS X,
Windows, and Unix systems.
Created by Alvin Alexander, DevDaily.com
-->
<project default="OS-TEST" name="Ant Operating System Test" >
<!-- set the operating system test properties -->
<condition property="isMac">
<os family="mac" />
</condition>
<condition property="isWindows">
<os family="windows" />
</condition>
<condition property="isUnix">
<os family="unix" />
</condition>
<!-- define the operating system specific targets -->
<target name="doMac" if="isMac">
<echo message="Came into the Mac target" />
<!-- do whatever you want to do here for Mac systems -->
</target>
<target name="doWindows" if="isWindows">
<echo message="Came into the Windows target" />
</target>
<target name="doUnix" if="isUnix">
<echo message="Came into the Unix target" />
</target>
<!-- define our main/default target -->
<target name="OS-TEST" depends="doMac, doWindows, doUnix">
<echo message="Running OS-TEST target" />
</target>
</project>
答案 1 :(得分:0)
我通过运行Windows .exe
文件作为构建后步骤解决了这个问题。
在Windows下这很好,但在Linux中,我不得不在wine
前面加上命令。
为了解决OS条件问题,我在Eclipse中创建了一个环境变量:
wineLinux=wine
然后像这样构建后构建步骤:
${wine${OsType}} window_file.exe args
系统变量OsType
将扩展为Linux
,并且在上一步骤中创建的环境变量wineLinux
将扩展为wine
。