2012-01-29 112 views
1

是否可以在Eclipse中設置條件路徑變量?這對於自定義構建器(與Indigo中的項目存儲 - 我認爲舊版Eclipse中不是這種情況)在另一個平臺下調用不同的程序非常有用。Eclipse條件路徑變量

所以,我正在尋找將沿着線的一個東西:

${if{${system:OS}=='Windows'}compiler.exe${else}compiler.sh 

回答

1

如果你會特別喜歡在不同的平臺上調用不同的編譯器,那麼你可以使用Ant或對檢測到您的平臺並調用不同的程序。

在您的項目屬性中,轉到「構建器」並創建一個新的構建步驟。如果您使用GNU使作爲一個建設者,你可以使用類似語法在你的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構建腳本,條件執行由屬性像ifunlessdepends確定。 <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> 
+0

感謝您的回答。我意識到使用ant(或者其他任何構建工具)的可能性,但是我認爲Eclipse可以直接支持基於平臺的分支。顯然沒有。因此,您的答案是解決問題的最佳方案。 – 2012-03-14 20:37:09

0

我解決它通過運行Windows .exe文件作爲生成後步驟。

這在Windows下很好,但在Linux中,我必須在wine前面加上命令。

爲了解決操作系統有條件的問題,我做在Eclipse環境變量:

wineLinux=wine 

然後構建後生成步驟是這樣的:

${wine${OsType}} window_file.exe args 

系統變量OsType將擴大到Linux,並且在上一步中創建的環境變量wineLinux將擴展到wine