문제

Is it possible to set conditional path variables in Eclipse? This would be useful for instance for a custom builder (which is stored with the project in Indigo - I think this wasn't the case in old Eclipse versions) to call a different program under a different platform.

So what I'm looking for would be a something along the lines of:

${if{${system:OS}=='Windows'}compiler.exe${else}compiler.sh
도움이 되었습니까?

해결책

If you would specifically like to invoke different compilers on different platforms, then you can use Ant or Make to detect your platform and call different programs.

In your project's properties, go to "Builders" and create a new build step. If you're using GNU Make as a builder, you can use syntax like the following in your 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

In Ant build scripts, conditional execution is determined by attributes like if, unless, and depends. The <os family=xxx> tag tells you what OS you're running on. Here's an example from 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>

다른 팁

I solved it by running a windows .exe file as a post-build step.

This is fine under Windows, but in Linux, I had to preface the command with wine.

To solve the OS conditional problem, I made an environment variable in Eclipse:

wineLinux=wine

And then constructed the post build-step like this:

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

The system variable OsType will expand to Linux and the environment variable wineLinux that was created in the previous step will expand to wine.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top