2014-04-06 61 views
0
<?xml version="1.0" encoding="UTF-8" ?> 

<project name="winplay" default="build"> 

    <target name="build"> 
    <echo message="${bitoption}" /> 
    <mkdir dir="build" /> 
    <mkdir dir="build/obj" /> 
    <cc name="g++" objdir="build/obj" debug="${debug}"> 
     <fileset dir="src" includes="*.cpp" /> 
     <compiler name="g++"> 
     <compilerarg value="-std=c++11" /> 
     <compilerarg value="-m32" /> 
     </compiler> 
    </cc> 

    <condition property="debugoption" value="-g -O0" else="-O2"> 
     <isset property="debug" /> 
    </condition> 
    <fileset dir="build/obj" id="objects"> 
     <include name="*.o" /> 
    </fileset> 
    <pathconvert pathsep=" " property="objectslinker" refid="objects" /> 

    <!-- Due to a bug in GppLinker.java in cpptasks.jar, we must exec g++ because GppLinker erroneously uses gcc, which breaks exception handling. --> 
    <exec command="g++ -std=c++11 -m32 -mwindows ${debugoption} -o build/winplay ${objectslinker}" failonerror="true" /> 
    </target> 

    <target name="build-32" depends="build"> 
    <property name="bitoption" value="-m32" /> 
    </target> 

    <target name="build-64" depends="build"> 
    <property name="bitoption" value="-m64" /> 
    </target> 


    <target name="clean"> 
    <delete dir="build" /> 
    </target> 
</project> 

我試圖讓$ {bitoption}爲-m32或-m64,這取決於我們是調用目標build-32還是build-64。然後,我將$ {bitoption}傳遞給編譯器和鏈接器參數,以便可以生成相應的exe。我做了一個簡單的回聲測試,看看$ {bitoption}是否設置正確,並且看起來不起作用。我得到的是:爲什麼這個ant腳本不能工作?

Buildfile: E:\_dev\windows\MinGW\msys\home\windoze\projects\Winplay\build.xml 
build: 
    [echo] ${bitoption} 
     [cc] 1 total files to be compiled. 
    [exec] The command attribute is deprecated. 
    [exec] Please use the executable attribute and nested arg elements. 
build-64: 
BUILD SUCCESSFUL 
Total time: 1 second 

回答

2

構建目標總是先運行,因爲它是一個依賴,所以$ {} bitoption有沒有價值呢。

你可以這樣做,而不是:

<target name="build-32" depends="setup-32, build" /> 
<target name="build-64" depends="setup-64, build" /> 

<target name="setup-32"> 
    <property name="bitoption" value="-m32" /> 
</target> 

<target name="setup-64"> 
    <property name="bitoption" value="-m64" /> 
</target> 
相關問題