<?xml version="1.0" ?>

<!-- Created by: Francesco Montorsi <frm@users.sourceforge.net>     -->
<!-- Creation date: 9/10/2004                                       -->
<!-- RCS-ID: $Id$      -->

<makefile>

    <using module="datafiles"/>

    <!--                                               -->
    <!--                   NEW TAGS                    -->
    <!--                                               -->

    <!-- A shortcut for the INCLUDE and LIB-PATH tags. -->
    <define-tag name="stdlib" rules="exe,dll,lib">
        <include>$(value)$(DIRSEP)include</include>
        <lib-path>$(value)$(DIRSEP)lib</lib-path>
    </define-tag>

    <!--  Localization stuff -->
    <set var="MSGFMT">msgfmt --statistics</set>
    <set var="MSGMERGE">msgmerge</set>
    <set var="XGETTEXT">xgettext</set>
    <set var="XARGS">xargs</set>
    <set var="XGETTEXT_ARGS">--c++ -k_ -kwxPLURAL:1,2 -kwxTRANSLATE -s -j</set>

    <define-tag name="create-pot" rules="action">
        <command>
            rm -f $(value)
            touch $(value)
            find $(SRCDIR)/include -name "*.h" | $(XARGS) $(XGETTEXT) $(XGETTEXT_ARGS) -o $(value)
            find $(SRCDIR)/src -name "*.cpp" | $(XARGS) $(XGETTEXT) $(XGETTEXT_ARGS) -o $(value)
            find $(SRCDIR)/src -name "*.xrc.extracted" | $(XARGS) $(XGETTEXT) $(XGETTEXT_ARGS) -o $(value)
        </command>
    </define-tag>
    <define-tag name="update-po" rules="action">
        <command>
            $(MSGMERGE) $(value) $(POTFILE) > $(value).new &amp;&amp; mv $(value).new $(value)
        </command>
    </define-tag>
    <define-tag name="compile-po" rules="action">
        <command>
            $(MSGFMT) -o $(value.replace('po', 'mo')) $(value)
        </command>
    </define-tag>

    <define-tag name="update-and-compile-po" rules="action">
        <update-po>$(value)</update-po>
        <compile-po>$(value)</compile-po>
    </define-tag>
    <define-tag name="scanxrc" rules="action">
        <!-- Extract translatable strings from XRC and put them in a fake file which will be scanned later -->
        <command>wxrc $(value) -g -c -o $(value).extracted</command>
    </define-tag>

    <!-- E.g.:

        <set var="POTFILE">locale/webupdater.pot</set>
        <set var="XRCFILE">$(SRCDIR)/src/webupdatedlg.xrc</set>

        <gettext-catalogs id="locale">
            <srcdir>$(SRCDIR)/locale</srcdir>
            <catalog-name>webupdater</catalog-name>
            <linguas>it de</linguas>
            <install-to>$(LOCALEDIR)</install-to>
        </gettext-catalogs>
        <action id="i18n" cond="TARGETING_WIN32=='0'">
            <scanxrc>$(XRCFILE)</scanxrc>
            <create-pot>$(POTFILE)</create-pot>
            <update-and-compile-po>locale/it.po</update-and-compile-po>
            <update-and-compile-po>locale/de.po</update-and-compile-po>
        </action>
    -->


    <!--                                               -->
    <!--                   NEW RULES                   -->
    <!--                                               -->

    <!-- Changes the current directory to the folder given to the CD    -->
    <!-- tag and then executes the command given to the RUN tag.        -->
    <!-- Usage sample:                                                  -->
    <!--          <cd-and-run id="tarball">                             -->
    <!--              <cd>..</cd>                                       -->
    <!--              <run>tar -cvzf tarball.tar.gz myproj/*</run>      -->
    <!--          </cd-and-run>                                         -->
    <define-rule name="cd-and-run" extends="action">
        <template>
            <set var="__cmddir"/>
            <set var="__cmdstr"/>
        </template>
        <define-tag name="cd">
            <set var="__cmddir">$(nativePaths(value))</set>
        </define-tag>
        <define-tag name="run">
            <set var="__cmdstr">$(value)</set>
            <if cond="FORMAT=='msvc' or FORMAT=='mingw' or FORMAT=='gnu' or FORMAT=='autoconf'">
                <command>( cd $(__cmddir) &amp;&amp; $(__cmdstr) )</command>
            </if>
            <if cond="FORMAT=='borland' or FORMAT=='watcom'">
                <command>-cd $(__cmddir)</command>
                <command>-$(__cmdstr)</command>
            </if>
        </define-tag>
    </define-rule>

    <!-- NOTE: the following tags do:
               - create a .tar.gz in the parent's folder of the component
               - assume that the folder containing the component is named $(COMP_NAME)
               - need to be run from $(SRCDIR)/..
    -->
    <define-tag name="run-tarball" rules="action">
        <!-- NOTE: the double quotes are to avoid shell expansion (and 'tar' will accept
                   wildcards inside options as well) -->
        <run>tar -cvzf $(value) --exclude="*~" --exclude="*.log" --exclude="*.o*" --exclude="*.a" --exclude=".svn" --exclude="autom4te.cache" $(COMP_NAME)$(DIRSEP)*</run>
    </define-tag>
    <define-tag name="run-zip" rules="action">
        <run>zip -r9 $(value) $(COMP_NAME) -x "*.pdb" -x "*.log" -x "*.o*"</run>
    </define-tag>


    <!-- Helps you to set the MAKEARGS variable manually.               -->
    <!-- he MAKEARGS variable is usually automatically generated by     -->
    <!-- Bakefile using all the options available; the problem is that  -->
    <!-- maybe you have to translate from an option name to another...  -->
    <!-- For example, I often found that I need to translate the:       -->
    <!--   WX_UNICODE=1/0,                                              -->
    <!--   WX_SHARED=1/0,                                               -->
    <!--   WX_DEBUG=1/0,                                                -->
    <!-- options of the build system of my wxWidgets-based projects, to -->
    <!-- some other option name, when building the non wx-based part of -->
    <!-- those projects, like:                                          -->
    <!--   UNICODE=1/0,                                                 -->
    <!--   SHARED=1/0,                                                  -->
    <!--   BUILD=debug/release                                          -->
    <!-- To do such kind of substitution in the arguments passed to the -->
    <!-- other MAKEs by the <subproject> targets, you need to write the -->
    <!-- MAKEARGS variable by hand... and this tag helps you a lot !    -->
    <!-- Usage sample:                                                  -->
    <!--      <set var="BUILD_EQUIVALENT">                              -->
    <!--           <if cond="WX_DEBUG=='1'">debug</if>                  -->
    <!--           <if cond="WX_DEBUG=='0'">release</if>                -->
    <!--      </set>                                                    -->
    <!--      <smart-subproject id="nonwxbased">                        -->
    <!--           <set-makeargs>                                       -->
    <!--                    UNICODE=$(WX_UNICODE)                       -->
    <!--                    SHARED=$(WX_SHARED)                         -->
    <!--                    BUILD=$(BUILD_EQUIVALENT)                   -->
    <!--           </set-makeargs>                                      -->
    <!--      </smart-subproject>                                       -->
    <define-rule name="smart-subproject" extends="subproject">
        <template>
        </template>
        <define-tag name="set-makeargs">
            <set var="_MAKEARGS">
                CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" 
                CPPFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS)" $(value)
            </set>

            <!-- now adjust the real MAKEARGS -->
            <if cond="FORMAT=='borland'">
                <set var="MAKEARGS" make_var="1">$(''.join(['-D%s ' % (x) for x in _MAKEARGS.split()]))</set>
            </if>
            <if cond="FORMAT!='borland'">
                <set var="MAKEARGS" make_var="1">$(_MAKEARGS)</set>
            </if>
        </define-tag>
    </define-rule>

    <!-- Forces the presence of the $(id) option into the final makefile; -->
    <!-- this rule (which is really used more like a tag) is a tweaky way -->
    <!-- to tell Bakefile not to remove from the final makefile an option -->
    <!-- which has been qualified as 'useless'.                           -->
    <!-- See bakefile docs for the VARS_DONT_ELIMINATE global switch.     -->
    <!-- Usage sample:                                                    -->
    <!--    <force-opt-presence id="MY_USELESS_OPTION"/>                  -->    
    <define-rule name="force-opt-presence" extends="phony">
        <template id="dummytemplate_for_$(id)">
            <set var="dummy_for_$(id)"><if cond="$(id)=='dummy'">AAA</if></set>
        </template>
    </define-rule>

    <!-- exactly like <copy-files> but this target just does not contain the "if not exist"
            check and thus always performs the copy of the files (maybe overwriting old 
            versions of them). -->
    <define-rule name="force-copy-files" extends="action">
        <template>
            <is-phony/>
            <set var="__srcdir"/>

            <!--
                DigitalMars' smake has problems with long command lines, so we
                have to work around it. More details here:
                http://sourceforge.net/mailarchive/message.php?msg_id=9595825
                -->
            <if cond="TOOLSET=='win32' and FORMAT=='dmars_smake'">
                <set var="__copy_depends" eval="0">
                    $(''.join(['$(__srcdir)%s ' % (x) for x in __files.split()]))
                </set>
                <set var="__deps" append="1">$(__copy_depends)</set>
                <set var="__copy_script_name">$(FORMAT)_copy_$(id).bat</set>
            </if>

            <set var="__copy_cmd" eval="0">

                <if cond="TOOLSET=='unix'">
                    @mkdir -p $(__dstdir)
                    @for f in $(__files); do \
                            cp -pRf $(__srcdir)$(DOLLAR)$(DOLLAR)f $(__dstdir) ; \
                    done
                </if>

                <if cond="TOOLSET in ['win32','os2'] and FORMAT!='mingw' and FORMAT!='dmars_smake'">
                    if not exist $(__dstdir) mkdir $(__dstdir)
                    for %f in ($(__files)) do copy $(__srcdir)%f $(__dstdir)
                </if>
                <if cond="TOOLSET=='win32' and FORMAT=='dmars_smake'">
                    if not exist $(__dstdir) mkdir $(__dstdir)
                    echo copy $(__srcdir)%%1 $(__dstdir)\%%1 &gt; $(__copy_script_name)
                    !$(__copy_script_name) $**
                    del $(__copy_script_name)
                </if>
                <if cond="TOOLSET=='win32' and FORMAT=='mingw'">
                    if not exist $(__dstdir) mkdir $(__dstdir)
                    for %%f in ($(__files)) do copy $(__srcdir)%%f $(__dstdir)
                </if>

            </set>
            <command>$(__copy_cmd)</command>
        </template>
        <define-tag name="dstdir">
            <set var="__dstdir">$(nativePaths(value))</set>
        </define-tag>
        <define-tag name="srcdir">
            <set var="__srcdir">$(nativePaths(value))$(DIRSEP)</set>
        </define-tag>
        <define-tag name="files">
            <set var="__files">$(' '.join(value.split()))</set>
        </define-tag>
    </define-rule>

</makefile>
