<?xml version="1.0" ?>
<!--

  This file is part of Bakefile (http://www.bakefile.org)

  Copyright (C) 2003-2008 Vaclav Slavik

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to
  deal in the Software without restriction, including without limitation the
  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  sell copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  IN THE SOFTWARE.

  $Id: makefile.bkl 1247 2008-08-28 14:59:28Z vaclavslavik $

  This file is common to all formats that share Unix way of writing
  makefiles (most notably GNU Make and Autoconf formats).

-->
<makefile>

    <!-- see format_features.bkl for explanation: -->
    <set var="FORMAT_HAS_VARIABLES">1</set>

    <!--
    how to pass options to subproject's make - may be overriden by
    makefile_defs_*.bkl: -->
    <set var="__MAKEARGS" eval="0">
        $(' '.join(['%s="$(DOLLAR)(%s)"' % (x,x) for x in OPTIONS.split()]))
    </set>
    <set var="MAKEARGS" make_var="1">$(__MAKEARGS)</set>


    <include file="makefile_defs_$(MAKEFILE_SYNTAX).bkl"/>

    <!-- =============================================================== -->
    <!--                       Compiler options:                         -->
    <!-- =============================================================== -->

    <set var="DEFAULT_CC">$(__DEFAULT_CC)</set>
    <set var="DEFAULT_CXX">$(__DEFAULT_CXX)</set>
    <set var="DEFAULT_CFLAGS">$(__DEFAULT_CFLAGS)</set>
    <set var="DEFAULT_CXXFLAGS">$(__DEFAULT_CXXFLAGS)</set>
    <set var="DEFAULT_CPPFLAGS">$(__DEFAULT_CPPFLAGS)</set>
    <set var="DEFAULT_LDFLAGS">$(__DEFAULT_LDFLAGS)</set>

    <option name="CC">
        <default-value>$(DEFAULT_CC)</default-value>
        <description>
            C compiler
        </description>
    </option>
    <option name="CXX">
        <default-value>$(DEFAULT_CXX)</default-value>
        <description>
            C++ compiler
        </description>
    </option>
    <option name="CFLAGS">
        <default-value>$(DEFAULT_CFLAGS)</default-value>
        <description>
            Standard flags for CC
        </description>
    </option>
    <option name="CXXFLAGS">
        <default-value>$(DEFAULT_CXXFLAGS)</default-value>
        <description>
            Standard flags for C++
        </description>
    </option>
    
    <if cond="MAKEFILE_SYNTAX=='unix'">
        <option name="OBJCFLAGS">
            <default-value>$(__DEFAULT_OBJCFLAGS)</default-value>
            <description>
                Standard flags for Objective-C
            </description>
        </option>
        <option name="OBJCXXFLAGS">
            <default-value>$(__DEFAULT_OBJCXXFLAGS)</default-value>
            <description>
                Standard flags for Objective-C++
            </description>
        </option>
    </if>

    <option name="CPPFLAGS">
        <default-value>$(DEFAULT_CPPFLAGS)</default-value>
        <description>
            Standard preprocessor flags (common for CC and CXX)
        </description>
    </option>
    <option name="LDFLAGS">
        <default-value>$(DEFAULT_LDFLAGS)</default-value>
        <description>
            Standard linker flags
        </description>
    </option>


    <!-- =============================================================== -->
    <!--                     Rules & tags definitions:                   -->
    <!-- =============================================================== -->

    <!-- in case specialized makefile wants to insert something: -->
    <set var="__exe_baset" overwrite="0"/>
    <set var="__dll_baset" overwrite="0"/>
    <set var="__lib_baset" overwrite="0"/>
    <set var="__exe_baser" overwrite="0"/>
    <set var="__dll_baser" overwrite="0"/>
    <set var="__lib_baser" overwrite="0"/>

    <define-rule name="__any">
        <template>
            <set var="__targetdir"></set>
            <set var="__targetdir_dironly">.</set>
            <set var="__is_phony">0</set>
            <set var="__deps"/>
            <set var="__command"/>
            <set var="__targetname">$(id)</set>
            <set var="__libname"/>
            <set var="__depname">
                <if cond="target">
                    $(ref('__targetdir',id))$(ref('__targetname',id))
                </if>
            </set>
        </template>
        <define-tag name="depends">
            <set var="__deps" append="1">
                $(substitute(value, lambda x: ref('__depname', x), 'DEP'))
            </set>
        </define-tag>
        <define-tag name="depends-on-file">
            <set var="__deps" append="1">$(nativePaths(value))</set>
        </define-tag>
        <define-tag name="dependency-of">
            <modify-target target="$(value)">
                <depends>$(id)</depends>
            </modify-target>
        </define-tag>
        <define-tag name="clean-files">
            <modify-target target="clean">
                <command cond="TOOLSET!='win32'">$(RM) $(value)</command>
                <command cond="TOOLSET=='win32'">
                    <!-- in case $(value) is a list of files, we split all the tokens of the
                         list and create single clean commands -->
                    $('\n'.join([('-if exist %s del %s' % (x, x)) for x in safeSplit(value)]))
                </command>
            </modify-target>
        </define-tag>

        <define-tag name="__command">
            <set var="__command" append="1">$(value)$(LF)</set>
        </define-tag>
    </define-rule>

    <define-rule name="__compiled" extends="__any">

        <template template="__commands_templ">
            <set var="__post_command"/>
            <set var="__install_if_cond"/>
            <set var="__targetdir">$(mkPathPrefix(BUILDDIR))</set>
            <set var="__targetdir_dironly">$(BUILDDIR)</set>
            <set var="__uses_c">0</set>
            <set var="__uses_objc">0</set>
            <set var="__uses_cxx">0</set>
            <set var="__uses_objcxx">0</set>
            <set var="__ldflags"/>
            <set var="__ldlibs"/>
            <set var="__cppflags"/>
            <set var="__cflags"/>
            <set var="__cxxflags"/>
            <set var="__objcflags"/>
            <set var="__objcxxflags"/>
            <set var="__win32rc_flags"/>

            <!-- this should be used when __ldflags is referenced, so that
                 user-provided additional flags always come last (see
                 http://www.bakefile.org/attachment/ticket/182) -->
            <set var="__ldflags_all" eval="0">$(__ldflags) $(LDFLAGS)</set>

            <!-- cflags, cxxflags make variables (CFLAGS etc. options must
                 be last, so that e.g. headers from -I passed by configure
                 don't override headers from build tree): -->
            <set var="__cflags_mv" eval="0">
                $(__cppflags) $(__cflags) $(CPPFLAGS) $(CFLAGS)
            </set>
            <set var="__cxxflags_mv" eval="0">
                $(__cppflags) $(__cxxflags) $(CPPFLAGS) $(CXXFLAGS)
            </set>
            
            <set var="__cflags_var">
                $(createMakeVar(id, '__cflags_mv', 'CFLAGS'))
            </set>
            <set var="__cxxflags_var">
                $(createMakeVar(id, '__cxxflags_mv', 'CXXFLAGS'))
            </set>
            
            <if cond="MAKEFILE_SYNTAX=='unix'">
                <set var="__objcflags_mv" eval="0">
                    $(__cppflags) $(__objcflags) $(CPPFLAGS) $(OBJCFLAGS)
                </set>
                <set var="__objcxxflags_mv" eval="0">
                    $(__cppflags) $(__objcxxflags) $(CPPFLAGS) $(OBJCXXFLAGS)
                </set>
                <set var="__objcflags_var">
                    $(createMakeVar(id, '__objcflags_mv', 'OBJCFLAGS'))
                </set>
                <set var="__objcxxflags_var">
                    $(createMakeVar(id, '__objcxxflags_mv', 'OBJCXXFLAGS'))
                </set>
            </if>

            <set var="__objects"/>
            <!-- access __objects as global make variable: -->
            <set var="__objects_var">
                $(createMakeVar(id, '__objects', 'OBJECTS', hints='files'))
            </set>
            <set var="__deps" append="1">$(__objects_var)</set>

            <set var="__headers"/>
            <!-- access __headers as global make variable: -->
            <set var="__headers_var">
                $(createMakeVar(id, '__headers', 'HEADERS', hints='files'))
            </set>

            <!-- it makes sense to make <objects-depend> use make var, too: -->
            <set var="__objects_deps"/>
            <set var="__objects_deps_var">
                $(createMakeVar(id, '__objects_deps', 'ODEP'))
            </set>

            <set var="__linker" eval="0">
                $(ifthenelse(__uses_cxx, __LINKER_CXX, __LINKER_CC))
            </set>
            <set var="__dll_linker" eval="0">
                $(ifthenelse(__uses_cxx, __DLL_LINKER_CXX, __DLL_LINKER_CC))
            </set>
            <set var="__module_linker" eval="0">
                $(ifthenelse(__uses_cxx, __MODULE_LINKER_CXX, __MODULE_LINKER_CC))
            </set>

            <__clean-target-files/>
        </template>

        <define-tag name="res-define"/>
        <define-tag name="res-include"/>

        <define-tag name="define">
            <if cond="FORMAT=='watcom'">
                <set var="__cppflags" append="1">
                    $(addPrefixIfNotEmpty(__DEFINE_ARG,value))
                </set>
            </if>
            <if cond="FORMAT!='watcom'">
                <set var="__cppflags" append="1">
                    $(addPrefixIfNotEmpty(__DEFINE_ARG,value.replace('"', '\\"')))
                </set>
            </if>
            <res-define>$(value)</res-define>
        </define-tag>
        <define-tag name="include">
            <set var="__cppflags" append="1">
                $(addPrefixIfNotEmpty(__INCLUDE_ARG,nativePaths(value)))</set>
            <res-include>$(value)</res-include>
        </define-tag>

        <define-tag name="sys-lib">
            <set var="__ldlibs" append="1">
                $(formatIfNotEmpty(__LIB_ARG,value))
            </set>
        </define-tag>
        <define-tag name="lib-path">
            <if cond="FORMAT!='dmars' and FORMAT!='dmars_smake'">
                <set var="__ldflags" append="1">
                    $(addPrefixIfNotEmpty(__LIBDIR_ARG,nativePaths(value)))
                </set>
            </if>
        </define-tag>

        <!-- FIXME: This can just go away once compiler-flags is done right -->
        <define-tag name="FIXME-cxx-type-compiler-flags">
            <cxxflags>$(value)</cxxflags>
            <objcxxflags>$(value)</objcxxflags>
        </define-tag>
        <!-- FIXME: This needs to parse its languages attribute but I can't figure out how to do it -->
        <define-tag name="FIXME-compiler-flags">
            <cflags>$(value)</cflags>
            <cxxflags>$(value)</cxxflags>
            <objcflags>$(value)</objcflags>
            <objcxxflags>$(value)</objcxxflags>
        </define-tag>

        <define-tag name="cflags">
            <set var="__cflags" append="1">$(value)</set>
        </define-tag>
        <define-tag name="cxxflags">
            <set var="__cxxflags" append="1">$(value)</set>
        </define-tag>
        <define-tag name="objcflags">
            <set var="__objcflags" append="1">$(value)</set>
        </define-tag>
        <define-tag name="objcxxflags">
            <set var="__objcxxflags" append="1">$(value)</set>
        </define-tag>
        <define-tag name="cppflags">
            <set var="__cppflags" append="1">$(value)</set>
        </define-tag>
        <define-tag name="ldflags">
            <set var="__ldflags" append="1">$(value)</set>
        </define-tag>
        <define-tag name="ldlibs">
            <set var="__ldlibs" append="1">$(value)</set>
        </define-tag>

        <define-tag name="objects-depend">
            <set var="__objects_deps" append="1">
                $(substitute(value, lambda x: ref('__depname', x), 'DEP'))
            </set>
        </define-tag>

        <define-tag name="sources">
            <set var="__objtmp">
                $(sources2objects(value, id, OBJEXT))
            </set>
            <set var="__objects" append="1">$(__objtmp)</set>
        </define-tag>

        <define-tag name="headers">
            <set var="__headers" append="1">$(nativePaths(value))</set>
        </define-tag>

        <define-tag name="library">
            <depends>$(value)</depends>
            <!--
             This doesn't work on BSD Unix where the linker doesn't like
             being given shared library as e.g. lib/foo.so - it's then recorded
             as lib/foo.so instead of foo.so in ELF binary. We implement a
             solution that works on BSD in autoconf.bkl.
             -->
            <if cond="FORMAT!='autoconf'">
                <ldlibs>
                    $(substitute(value,
                                 lambda x: ref('__targetdir',x)+ref('__linkname', x),
                                 'LIBR'))
                </ldlibs>
            </if>
        </define-tag>

        <define-tag name="dirname">
            <set var="__targetdir_dironly">$(nativePaths(value))</set>
            <set var="__targetdir">$(__targetdir_dironly)$(DIRSEP)</set>
        </define-tag>

        <define-tag name="optimize">
            <cppflags>
                $(substituteFromDict(value,
                      {'off':__FLAG_OPTIMIZE_OFF,
                       'speed':__FLAG_OPTIMIZE_SPEED,
                       'size':__FLAG_OPTIMIZE_SIZE}))
            </cppflags>
        </define-tag>

        <define-tag name="arch">
            <cppflags>
                $(substituteFromDict(value,
                      {'i386':__FLAG_ARCH_I386,
                       'i486':__FLAG_ARCH_I486,
                       'i586':__FLAG_ARCH_I586,
                       'i686':__FLAG_ARCH_I686,
                       }))
            </cppflags>
        </define-tag>

        <define-tag name="pic">
            <set var="__picflag">
                $(substituteFromDict(value,
                      {'on':PIC_CFLAGS,
                       'off':''}))
            </set>
            <FIXME-compiler-flags>$(__picflag)</FIXME-compiler-flags>
        </define-tag>

        <define-tag name="debug-info">
            <cppflags>
                $(substituteFromDict(value,
                      {'on':__FLAG_DEBUG_ON,
                       'off':__FLAG_DEBUG_OFF}))
            </cppflags>
            <ldflags>
                $(substituteFromDict(value,
                      {'on':__FLAG_DEBUG_ON_LINKER,
                       'off':__FLAG_DEBUG_OFF_LINKER}))
            </ldflags>
        </define-tag>

        <define-tag name="threading">
            <ldflags>
                $(substituteFromDict(value,
                      {'multi':__FLAG_MULTI_THREADING_LD,
                       'single':__FLAG_SINGLE_THREADING_LD}))
            </ldflags>
            <cppflags>
                $(substituteFromDict(value,
                      {'multi':__FLAG_MULTI_THREADING_CPP,
                       'single':__FLAG_SINGLE_THREADING_CPP}))
            </cppflags>
        </define-tag>

        <define-tag name="warnings">
            <cppflags>
                $(substituteFromDict(value,
                      {'no':__FLAG_WARNINGS_NO,
                       'default':__FLAG_WARNINGS_DEFAULT,
                       'max':__FLAG_WARNINGS_MAX}))
            </cppflags>
        </define-tag>

        <define-tag name="cxx-rtti">
            <FIXME-cxx-type-compiler-flags>
                $(substituteFromDict(value,
                        {'on':__FLAG_RTTI_ON,
                         'off':__FLAG_RTTI_OFF}))
            </FIXME-cxx-type-compiler-flags>
        </define-tag>

        <define-tag name="cxx-exceptions">
            <FIXME-cxx-type-compiler-flags languages="c++,objc++">
                $(substituteFromDict(value,
                        {'on':__FLAG_EXCEPTIONS_ON,
                         'off':__FLAG_EXCEPTIONS_OFF}))
            </FIXME-cxx-type-compiler-flags>
        </define-tag>

        <define-tag name="runtime-libs"/>

        <define-tag name="debug-runtime-libs"/>

        <define-tag name="precomp-headers"/>
        <define-tag name="precomp-headers-file"/>
        <define-tag name="precomp-headers-header"/>
        <define-tag name="precomp-headers-location"/>
        <define-tag name="precomp-headers-gen"/>
        <define-tag name="precomp-headers-exclude"/>

        <define-tag name="msvc-project-files"/>
        <define-tag name="msvc-file-group"/>

        <define-tag name="__clean-target-files">
            <clean-files>
                $(ref('__targetdir',id))$(ref('__targetname',id))
            </clean-files>
        </define-tag>

        <define-tag name="postlink-command">
            <set var="__post_command" append="1">$(value)$(LF)</set>
        </define-tag>

    </define-rule>

    <define-rule name="exe" extends="__compiled,$(__exe_baser)">
        <template template="$(__exe_baset)">
            <set var="__name">$(id)</set>
            <set var="__targetname" eval="0">$(__name)$(EXEEXT)</set>
            <set var="__command" eval="0">
                $(__LINK_EXE_CMD)
                $(__post_command)
            </set>
            <dependency-of>all</dependency-of>
        </template>

        <define-tag name="app-type">
            <ldflags>
                $(substituteFromDict(value,
                      {'console':__FLAG_EXE_CONSOLE,
                       'gui':__FLAG_EXE_GUI}))
            </ldflags>
        </define-tag>

        <define-tag name="exename">
            <set var="__name">$(value)</set>
        </define-tag>

    </define-rule>

    <define-rule name="lib" extends="__compiled,$(__lib_baser)">
        <template template="$(__lib_baset)">
            <set var="__name" eval="0">$(__libname)</set>
            <set var="__command" eval="0">
                $(__LINK_LIB_CMD)
                $(__post_command)
            </set>
            <set var="__libname">$(id)</set>
            <set var="__targetname" eval="0">$(LIBPREFIX)$(__libname)$(LIBEXT)</set>
            <set var="__linkname" eval="0">$(LIBPREFIX)$(__libname)$(LIBEXT)</set>
            <dependency-of>all</dependency-of>
        </template>
        <define-tag name="libname">
            <set var="__libname">$(value)</set>
        </define-tag>
    </define-rule>

    <define-rule name="_dll" extends="__compiled,$(__dll_baser)">
        <template template="$(__dll_baset)">
            <set var="__name" eval="0">$(__dllname)</set>
            <pic>on</pic>
            <set var="__targetname" eval="0">
                $(DLLPREFIX)$(__dllname)$(DLLEXT)
            </set>
            <dllname>$(id)</dllname>
            <dependency-of>all</dependency-of>
        </template>
        <define-tag name="dllname">
            <set var="__dllname">$(value)</set>
        </define-tag>
    </define-rule>

    <define-rule name="dll" extends="_dll">
        <template>
            <set var="__linkname" eval="0">
                $(LIBPREFIX)$(__libname)$(DLLIMPEXT)
            </set>
            <set var="__command" eval="0">
                $(__LINK_DLL_CMD)
                $(__post_command)
            </set>
            <libname>$(id)</libname>
            <clean-files>
                $(ref('__targetdir',id))$(ref('__linkname',id))
            </clean-files>
        </template>
        <define-tag name="version"/>
        <define-tag name="so_version"/>
        <define-tag name="mac_version"/>
        <define-tag name="libname">
            <set var="__libname">$(value)</set>
        </define-tag>
    </define-rule>

    <define-rule name="module" extends="_dll">
        <template>
            <set var="DLLEXT">$(DLLEXT_MODULE)</set>
            <set var="DLLPREFIX">$(DLLPREFIX_MODULE)</set>
            <set var="__command" eval="0">
                $(__LINK_MODULE_CMD)
                $(__post_command)
            </set>
        </template>
    </define-rule>


    <define-rule name="action" extends="__any">
        <template>
            <set var="__command"/>
            <targetname>$(id)</targetname>
        </template>
        <define-tag name="targetname">
            <set var="__targetname">$(value)</set>
        </define-tag>
        <define-tag name="command">
            <__command>$(value)</__command>
        </define-tag>
        <define-tag name="is-phony">
            <set var="__is_phony">1</set>
        </define-tag>
    </define-rule>

    <template id="__phony">
        <set var="__is_phony">1</set>
    </template>

    <define-rule name="phony" extends="__any">
        <template template="__phony"/>
    </define-rule>


    <define-rule name="subproject" extends="action">
        <template template="__subproject_templ">
            <set var="__is_phony">1</set>
            <set var="__subtarget">all</set>
            <set var="__install_if_cond"></set>
            <command>$(__MAKE_SUBPROJECT_CMD)</command>
            <modify-target target="clean">
                <command>$(ref('__CLEAN_SUBPROJECT_CMD',id))</command>
            </modify-target>

            <!-- by default, subprojects are not installable, user can safely
                 override this setting in his bakefiles -->
            <installable>no</installable>
        </template>
        <define-tag name="dir">
            <set var="__subdir">$(nativePaths(value))</set>
        </define-tag>
        <define-tag name="target">
            <set var="__subtarget">$(value)</set>
        </define-tag>

        <define-tag name="installable">
            <if cond="value=='yes' and FORMAT_HAS_MAKE_INSTALL=='1'">

                <!-- create the (conditional) install_$(id) target and add it, as a dependency,
                     to the global INSTALL target of the makefile -->
                <add-target target="install_$(id)"
                            type="inst-action"
                        cond="target$(addPrefixIfNotEmpty(' and ',__install_if_cond))"/>
                <modify-target target="install_$(id)">
                    <command>$(ref('__INSTALL_SUBPROJECT_CMD',id))</command>
                    <dependency-of>install</dependency-of>
                </modify-target>

                <!-- do the same for uninstall_$(id) target -->
                <add-target target="uninstall_$(id)"
                            type="inst-action"
                        cond="target$(addPrefixIfNotEmpty(' and ',__install_if_cond))"/>
                <modify-target target="uninstall_$(id)">
                    <command>$(ref('__UNINSTALL_SUBPROJECT_CMD',id))</command>
                    <dependency-of>uninstall</dependency-of>
                </modify-target>
            </if>
        </define-tag>
    </define-rule>


    <!-- =============================================================== -->
    <!--                  Sources compilation rules:                     -->
    <!-- =============================================================== -->

    <define-tag name="src" rules="compilation_rule">
        <set var="__deps" append="1">
            $(targets[__parent].__objects_deps_var)
        </set>
    </define-tag>

    <define-rule name="__c-to-$(OBJEXT[1:])" extends="__any,compilation_rule">
        <template template="__commands_templ_C">
            <set var="__command">$(__COMPILE_C_CMD)</set>
        </template>
        <define-tag name="parent-target">
            <set var="__uses_c" scope="$(__parent)">1</set>
            <set var="__cflags">$(targets[__parent].__cflags_var)</set>
        </define-tag>
    </define-rule>

    <define-rule name="__cpp-to-$(OBJEXT[1:])" extends="__any,compilation_rule">
        <template template="__commands_templ_CXX">
            <set var="__command">$(__COMPILE_CXX_CMD)</set>
        </template>
        <define-tag name="parent-target">
            <set var="__uses_cxx" scope="$(__parent)">1</set>
            <set var="__cxxflags">$(targets[__parent].__cxxflags_var)</set>
        </define-tag>
    </define-rule>
    <!-- more C++ extensions: -->
    <define-rule name="__cxx-to-$(OBJEXT[1:])" extends="__cpp-to-$(OBJEXT[1:])"/>
    <define-rule name="__cc-to-$(OBJEXT[1:])" extends="__cpp-to-$(OBJEXT[1:])"/>
    <define-rule name="__C-to-$(OBJEXT[1:])" extends="__cpp-to-$(OBJEXT[1:])"/>

    <!-- non-Unix formats don't have native ObjC/C++ compilers -->
    <if cond="MAKEFILE_SYNTAX=='unix'">
        <!-- Objective-C -->
        <define-rule name="__m-to-$(OBJEXT[1:])" extends="__any,compilation_rule">
            <template template="__commands_templ_OBJC">
                <set var="__command">$(__COMPILE_OBJC_CMD)</set>
            </template>
            <define-tag name="parent-target">
                <set var="__uses_objc" scope="$(__parent)">1</set>
                <set var="__objcflags">$(targets[__parent].__objcflags_var)</set>
            </define-tag>
        </define-rule>

        <!-- Objective-C++ -->
        <define-rule name="__mm-to-$(OBJEXT[1:])" extends="__any,compilation_rule">
            <template template="__commands_templ_OBJCXX">
                <set var="__command">$(__COMPILE_OBJCXX_CMD)</set>
            </template>
            <define-tag name="parent-target">
                <set var="__uses_objcxx" scope="$(__parent)">1</set>
                <set var="__objcxxflags">$(targets[__parent].__objcxxflags_var)</set>
            </define-tag>
        </define-rule>
        <!-- more Objective-C++ extensions: -->
        <define-rule name="__M-to-$(OBJEXT[1:])" extends="__mm-to-$(OBJEXT[1:])"/>
    </if>


    <!-- =============================================================== -->
    <!--                      resources:                                 -->
    <!-- =============================================================== -->

    <define-tag name="win32-res" rules="exe,dll,module">
        <!-- do nothing by default -->
    </define-tag>
    <define-tag name="mac-res" rules="exe,dll,module">
        <!-- do nothing by default -->
    </define-tag>
    <define-tag name="symbian-res" rules="exe,dll,module">
        <!-- do nothing by default -->
    </define-tag>



    <if cond="FORMAT_HAS_MAKE_INSTALL=='1'">

        <define-rule name="inst-action" extends="action">
            <template template="__phony,_installcmd"/>
        </define-rule>

        <tag-info name="install-if" position="before:install-to"/>

        <define-tag name="install-if" rules="exe,dll,lib,module">
            <set var="__install_if_cond">$(value)</set>
        </define-tag>

        <define-tag name="install-to" rules="exe,dll,lib,module">
            <add-target target="install_$(id)"
                        type="inst-action"
               cond="target$(addPrefixIfNotEmpty(' and ',__install_if_cond))"/>
            <add-target target="uninstall_$(id)"
                        type="inst-action"
               cond="target$(addPrefixIfNotEmpty(' and ',__install_if_cond))"/>

            <modify-target target="install_$(id)">
                <command>$(INSTALL_DIR) $(DESTDIR)$(nativePaths(value))</command>
                <dependency-of>install</dependency-of>
                <depends>$(id)</depends>
            </modify-target>
            <modify-target target="uninstall_$(id)">
                <!-- we won't uninstall the $(DESTDIR)$(value) folder that we
                     installed in the 'install_$(id)' target since it could
                     really be dangerous: that folder could contain also other
                     user-installed programs (think to /usr/local/bin !) -->
                <dependency-of>uninstall</dependency-of>
            </modify-target>
        </define-tag>


        <define-tag name="install-to" rules="exe">
            <modify-target target="install_$(id)">
                <command>
                    $(INSTALL_PROGRAM) $(ref('__targetdir',id))$(ref('__targetname',id)) $(DESTDIR)$(nativePaths(value))
                </command>
            </modify-target>
            <modify-target target="uninstall_$(id)">
                <command>
                    $(UNINSTALL_PROGRAM) $(DESTDIR)$(nativePaths(value))$(DIRSEP)$(ref('__targetname',id))
                </command>
            </modify-target>
        </define-tag>

        <define-tag name="install-to" rules="dll">
            <modify-target target="install_$(id)">
                <command>
                    $(INSTALL_DATA) $(ref('__targetdir',id))$(ref('__linkname',id)) $(DESTDIR)$(nativePaths(value))
                    $(INSTALL_PROGRAM) $(ref('__targetdir',id))$(ref('__targetname',id)) $(DESTDIR)$(nativePaths(value))
                </command>
            </modify-target>
            <modify-target target="uninstall_$(id)">
                <command>
                    $(UNINSTALL_DATA) $(DESTDIR)$(nativePaths(value))$(DIRSEP)$(ref('__linkname',id))
                    $(UNINSTALL_PROGRAM) $(DESTDIR)$(nativePaths(value))$(DIRSEP)$(ref('__targetname',id))
                </command>
            </modify-target>
        </define-tag>

        <define-tag name="install-to" rules="module">
            <modify-target target="install_$(id)">
                <command>
                    $(INSTALL_PROGRAM) $(ref('__targetdir',id))$(ref('__targetname',id)) $(DESTDIR)$(nativePaths(value))
                </command>
            </modify-target>
            <modify-target target="uninstall_$(id)">
                <command>
                    $(UNINSTALL_PROGRAM) $(DESTDIR)$(nativePaths(value))$(DIRSEP)$(ref('__targetname',id))
                </command>
            </modify-target>
        </define-tag>

        <define-tag name="install-to" rules="lib">
            <modify-target target="install_$(id)">
                <command>
                    $(INSTALL_DATA) $(ref('__targetdir',id))$(ref('__targetname',id)) $(DESTDIR)$(nativePaths(value))
                </command>
            </modify-target>
            <modify-target target="uninstall_$(id)">
                <command>
                    $(UNINSTALL_DATA) $(DESTDIR)$(nativePaths(value))$(DIRSEP)$(ref('__targetname',id))
                </command>
            </modify-target>
        </define-tag>
        
        <tag-info name="install-headers-to" position="after:headers"/>

        <define-tag name="install-headers-to" rules="dll,lib">
            <!-- proceed only if the <headers/> tag was used somewhere in this target -->
            <if cond="__headers!=''">
                <add-target target="install_$(id)_headers"
                            type="inst-action"
                   cond="target$(addPrefixIfNotEmpty(' and ',__install_if_cond))"/>
                <add-target target="uninstall_$(id)_headers"
                            type="inst-action"
                   cond="target$(addPrefixIfNotEmpty(' and ',__install_if_cond))"/>

                <modify-target target="install_$(id)_headers">
                    <set var="__iprg">$(INSTALL_DATA)</set>

                    <!-- both __dstdir and __files must be using native path separators -->
                    <set var="__dstdir">$(DESTDIR)$(nativePaths(value))</set>
                    <set var="__files">
                        <if cond="TOOLSET=='unix'">$(__headers_var)</if>
                        <if cond="TOOLSET!='unix'">$(__headers)</if>
                    </set>
                    
                    <command>$(__install_cmd_preservetree)</command>
                    <dependency-of>install</dependency-of>
                </modify-target>
                <modify-target target="uninstall_$(id)_headers">
                    <set var="__uprg">$(UNINSTALL_DATA)</set>

                    <!-- both __dstdir and __files must be using native path separators -->
                    <set var="__dstdir">$(DESTDIR)$(nativePaths(value))</set>
                    <set var="__files">
                        <if cond="TOOLSET=='unix'">$(__headers_var)</if>
                        <if cond="TOOLSET!='unix'">$(__headers)</if>
                    </set>

                    <command>$(__uninstall_cmd_preservetree)</command>
                    <dependency-of>uninstall</dependency-of>
                </modify-target>
            </if>
        </define-tag>

    </if>



    <!-- =============================================================== -->
    <!--                 Standard makefile targets:                      -->
    <!-- =============================================================== -->

    <phony id="all" category="all"/>

    <if cond="FORMAT_HAS_MAKE_INSTALL=='1'">
        <action id="install" template="__phony"/>

        <action id="uninstall" template="__phony"/>
    </if>

    <include file="makefile_$(MAKEFILE_SYNTAX).bkl" ignore_missing="1"/>

</makefile>
