<?xml version="1.0" ?>

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

<makefile>


    <!--                                               -->
    <!--                    GLOBAL TAGS                -->
    <!--                                               -->

    <!-- A nicer way to set the COMP_NAME special variable used by all wxCode bakefiles -->
    <define-global-tag name="set-comp-name">
        <if cond="isdefined('COMP_NAME')">
            <echo level="warning">The component name has already been defined</echo>
        </if>
        <if cond="not value.islower()">
            <echo level="warning">The component name should be all lowercase</echo>
        </if>

        <set var="COMP_NAME">$(value)</set>
    </define-global-tag>


    <!--                                               -->
    <!--                    TEMPLATES                  -->
    <!--                                               -->

    <template id="wxcode-basic">
        <!-- most if not all templates derived from wxcode-basic needs to have COMP_NAME
             variable correctly set:
        -->
        <if cond="not isdefined('COMP_NAME')">
            <error>Before using this template please set the COMP_NAME variable</error>
        </if>

        <!-- in both debug and release builds, we want maximum warnings to be able
             to spot as many hidden errors as possible!
             NOTE: you can use <warnings>default</warnings> in your own bakefile to
                   restore the default warning level if you don't like this setting
        -->
        <warnings>max</warnings>

        <if cond="FORMAT=='gnu' or FORMAT=='autoconf'">
            <lib-path>$(SRCDIR)/lib</lib-path>
            <include>$(SRCDIR)/include</include>
        </if>
        <if cond="FORMAT!='gnu' and FORMAT!='autoconf'">
            <wxlike-paths>$(SRCDIR)</wxlike-paths>
        </if>
    </template>

    <template id="wxcode-lib" template="wx-lib,wxlike,wxcode-basic">
        <install-to>$(LIBDIR)</install-to>
        <install-headers-to>$(PREFIX)</install-headers-to>

        <wxcode-dirname>$(SRCDIR)/lib</wxcode-dirname>
        <wxlike-libname prefix="wxcode">$(COMP_NAME)</wxlike-libname>

        <sources>$(COMP_SRC)</sources>
        <headers>$(COMP_HDR)</headers>
    </template>

    <template id="wxcode-dll" template="wx,wxlike,wxcode-basic">
        <install-to>$(LIBDIR)</install-to>
        <install-headers-to>$(PREFIX)</install-headers-to>

        <wxlike-dirname>$(SRCDIR)/lib</wxlike-dirname>
        <wxlike-dllname prefix="wxcode">$(COMP_NAME)</wxlike-dllname>

        <version>1.0</version>
        <so_version>0.0.0</so_version>

        <!-- the mac_version tag is used to add the "-compatibility_version -current_version" options.
             For more info about these options, look at Darwin linker man page:
                           http://www.hmug.org/man/1/ld.php

             NOTE: setting it we disable the compatibility checks done on Darwin
        -->
        <!-- <mac_version>1</mac_version> -->

        <define>WXMAKINGDLL_$(COMP_NAME.upper())</define>

        <sources>$(COMP_SRC)</sources>
        <headers>$(COMP_HDR)</headers>
    </template>


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

    <!--
        IMPORTANT: we use new rules instead of simple templates whenever we want to add
                   new tags to them. This makes it clear that e.g. <has-win32-res> is
                   not a tag declared by Bakefile for <exe> tags but rather a
                   wxcode-specific tag for <wxcode-exe> tags.
    -->

    <!-- the rule for components which don't build a library but rather an <exe> -->
    <define-rule name="wxcode-exe" extends="exe">
        <template template="wx,wxlike,wxcode-basic">
            <dirname>$(SRCDIR)</dirname>
            <sources>$(COMP_SRC)</sources>
            <headers>$(COMP_HDR)</headers>
        </template>

        <define-tag name="has-win32-res">
            <win32-res>$(fileList(value + '/*.rc'))</win32-res>
        </define-tag>
    </define-rule>


    <!-- the rule for wxCode components' samples -->
    <define-rule name="wxcode-sample" extends="exe">
        <template template="wx,wxlike,wxcode-basic">
            <!--
                This template needs to be completed by the <library> tag
                which cannot be placed here since we don't know the name of
                the lib target for this component.
                You'll need also some <wx-lib> tags to indicate the required wx libs.
            -->
            <app-type>gui</app-type>

            <!-- the dir where is located the sample -->
            <set var="__dir"/>
        </template>

        <define-tag name="dir">
            <if cond="value.startswith('$(srcdir)')">
                <!-- don't do <dir>$(SRCDIR)/mysample</dir> but rather <dir>mysample</dir>  -->
                <error>Don't prefix the directory name with SRCDIR - it's done automatically</error>
            </if>
            <if cond="value.startswith('/') or value.endswith('/')">
                <error>Don't prefix or postfix the directory name with slashes</error>
            </if>
            <if cond="value.find('\\')!=-1">
                <error>Don't use Windows directory separators - always use forward slashes</error>
            </if>

            <set var="__dir">$(value)</set>

            <!-- __topdir is the root folder of the sample as a relative path -->
            <set var="__topdir">$('../'*(__dir.count('/')+1))</set>

            <dirname>$(SRCDIR)/$(value)</dirname>
            <res-include>$(SRCDIR)/$(value)</res-include>

            <sources>
                $(fileList(value + '/*.c'))
                $(fileList(value + '/*.cc'))
                $(fileList(value + '/*.cpp'))
                $(fileList(value + '/*.cxx'))
            </sources>
            <headers>$(fileList(value + '/*.h*'))</headers>


            <!-- unlike win compilers, Unix's LD linker supports the -rpath option to insert
                in the generated ELF files an hint to the OS about where to search the required
                shared libraries. This means the user under Unix will be able to run samples
                also before installing the component system-wide:
            -->
            <set var="RPATH">
                <if cond="FORMAT=='gnu' and SHARED=='1'">-Wl,-rpath,$(__topdir)lib/gcc_dll</if>
                <if cond="FORMAT=='autoconf' and SHARED=='1'">-Wl,-rpath,$(__topdir)lib</if>
            </set>

            <!-- for autoconf&gnu only (see comments above): -->
            <ldflags>$(RPATH)</ldflags>


            <!-- this is for autoconf format when BUILDDIR!=SRCDIR; without it
                 the Makefile would try to put the generated binaries in folders
                 which do not exist -->
            <if cond="FORMAT_SUPPORTS_ACTIONS=='1'">
                <add-target target="make_sample_dir_$(id)" type="action"/>
                <modify-target target="make_sample_dir_$(id)">
                    <command cond="TOOLSET=='unix'">
                        @mkdir -p $(SRCDIR)/$(value)
                    </command>
                    <command cond="TOOLSET in ['win32','os2','dos']">
                        if not exist $(SRCDIR)\$(nativePaths(value)) mkdir $(SRCDIR)\$(nativePaths(value))
                    </command>
                    <dependency-of>$(id)</dependency-of>
                </modify-target>
            </if>
        </define-tag>

        <define-tag name="has-win32-res">
            <win32-res>$(fileList(__dir + '/*.rc'))</win32-res>
        </define-tag>
    </define-rule>

    <define-rule name="wxcode-console-sample" extends="exe">
        <template template="wxconsole">
        </template>
    </define-rule>

</makefile>
