<?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_defs_msvc.bkl 1315 2009-07-12 15:06:29Z vadz $

-->
<makefile>

    <!--

      MSVC compilers can be used in VC/eVC/VCIDE developments and
      Symbian development (which holds more compilers) therefore some shared
      flags are exposed with __FLAG_MSVC_* prefix to not conflict with flags
      imported from makefile_defs_cw.bkl and makefile_defs_gnu.bkl

      -->

    <set var="__FLAG_MSVC_OPTIMIZE_OFF">/Od</set>
    <set var="__FLAG_MSVC_OPTIMIZE_SIZE">/O1</set>
    <set var="__FLAG_MSVC_OPTIMIZE_SPEED">/O2</set>
    <set var="__FLAG_MSVC_WARNINGS_NO">/w</set>
    <set var="__FLAG_MSVC_WARNINGS_DEFAULT"></set>
    <set var="__FLAG_MSVC_WARNINGS_MAX">/W4</set>

    <if cond="FORMAT!='symbian'">

        <include file="win32.bkl"/>

        <set var="__DEFINE_ARG">/D</set>
        <set var="__INCLUDE_ARG">/I</set>
        <set var="__LIB_ARG">%s.lib</set>
        <set var="__LIBDIR_ARG">/LIBPATH:</set>

        <set var="__LIB_TOOL">
            <if cond="FORMAT=='msvc'">link /LIB</if>
            <if cond="FORMAT!='msvc'">lib</if>
        </set>

        <set var="__DEFAULT_CC">cl</set>
        <set var="__DEFAULT_CXX">cl</set>
        <set var="__DEFAULT_CFLAGS"></set>
        <set var="__DEFAULT_CPPFLAGS"></set>
        <set var="__DEFAULT_CXXFLAGS"></set>
        <set var="__DEFAULT_LDFLAGS"></set>

        <set var="__LINKER_CC">link</set>
        <set var="__LINKER_CXX">link</set>
        <set var="__DLL_LINKER_CC">link /DLL</set>
        <set var="__DLL_LINKER_CXX">link /DLL</set>
        <set var="__MODULE_LINKER_CC">$(__DLL_LINKER_CC)</set>
        <set var="__MODULE_LINKER_CXX">$(__DLL_LINKER_CXX)</set>

        <!-- basic compiler/linker flags: -->
        <set var="__FLAG_EXE_CONSOLE" eval="0">/SUBSYSTEM:CONSOLE</set>
        <set var="__FLAG_EXE_GUI" eval="0">/SUBSYSTEM:WINDOWS</set>
        <set var="__FLAG_DEBUG_ON">/Zi</set>
        <set var="__FLAG_DEBUG_ON_LINKER">/DEBUG</set>
        <set var="__FLAG_DEBUG_OFF"></set>
        <set var="__FLAG_DEBUG_OFF_LINKER"></set>
        <set var="__FLAG_OPTIMIZE_OFF">$(__FLAG_MSVC_OPTIMIZE_OFF)</set>
        <set var="__FLAG_OPTIMIZE_SIZE">$(__FLAG_MSVC_OPTIMIZE_SIZE)</set>
        <set var="__FLAG_OPTIMIZE_SPEED">$(__FLAG_MSVC_OPTIMIZE_SPEED)</set>
        <set var="__FLAG_ARCH_I386">/G3</set>
        <set var="__FLAG_ARCH_I486">/G4</set>
        <set var="__FLAG_ARCH_I586">/G5</set>
        <set var="__FLAG_ARCH_I686">/G6</set>
        <set var="__FLAG_SINGLE_THREADING_LD"></set>
        <set var="__FLAG_MULTI_THREADING_LD"></set>
        <set var="__FLAG_SINGLE_THREADING_CPP"/>
        <set var="__FLAG_MULTI_THREADING_CPP"/>
        <set var="__FLAG_WARNINGS_NO">$(__FLAG_MSVC_WARNINGS_NO)</set>
        <set var="__FLAG_WARNINGS_DEFAULT">$(__FLAG_MSVC_WARNINGS_DEFAULT)</set>
        <set var="__FLAG_WARNINGS_MAX">$(__FLAG_MSVC_WARNINGS_MAX)</set>
        <set var="__FLAG_RTTI_ON">/GR</set>
        <set var="__FLAG_RTTI_OFF"></set>
        <set var="__FLAG_EXCEPTIONS_ON">/EHsc</set>
        <set var="__FLAG_EXCEPTIONS_OFF"></set>

        <!-- rules building blocks: -->

        <template id="__commands_templ_C">
            <set var="__COMPILE_C_CMD" eval="0">
                $(CC) /c /nologo /TC /Fo$@ $(__cflags) $(src)
            </set>
            <!-- FIXME: temporary hack, $(src) should be used only if there are
                        object-dependencies, otherwise $** should be used -->
        </template>

        <template id="__commands_templ_CXX">
            <set var="__COMPILE_CXX_CMD" eval="0">
                $(CXX) /c /nologo /TP /Fo$@ $(__cxxflags) $(src)
            </set>
            <!-- FIXME: temporary hack, $(src) should be used only if there are
                        object-dependencies, otherwise $** should be used -->
        </template>

        <set var="__exe_baser">__msvc_comp</set>
        <set var="__dll_baser">__msvc_comp</set>
        <set var="__lib_baser">__msvc_comp</set>

        <!--
        cl's runtime library flags:
            /MD      multithreaded DLL            <- bakefile debug
            /MDd     ditto debug
            /ML      static singlethreaded
            /MLd     ditto debug
            /MT      static multithreaded
            /MTd     ditto debug
        -->

        <define-rule name="__msvc_comp">
            <template>
                <set var="__win32rc_flags"/>
                <set var="__pch_header"/>
                <set var="__pch_flags">/YX</set>
                <set var="__rtl_dbg"/>
                <set var="__rtl_static">L</set>
                <set var="__rtl_type">D</set>
                <set var="__rtl" eval="0">/M$(__rtl_type)$(__rtl_dbg)</set>
                <cppflags>$(__rtl)</cppflags>
                <define>WIN32</define>

                <!-- enable C++ exception handling and rtti
                     (FIXME: make it configurable) -->
                <cxx-rtti>on</cxx-rtti>
                <cxx-exceptions>on</cxx-exceptions>

                <set var="__win32_resources"/>
                <set var="__win32_resources_var">
                    $(createMakeVar(id, '__win32_resources', 'RESOURCES', hints='files'))
                </set>
            </template>

            <define-tag name="precomp-headers-gen">
                <set var="__pch_object">$(getObjectName(value, id, OBJEXT))</set>
                <set var="__deps">$(__pch_object) $(__deps)</set>
                <modify-target target="$(__pch_object)">
                    <set var="__cflags" append="1">
                        /Yc$(ref('__pch_header',id))
                    </set>
                    <set var="__cxxflags" append="1">
                        /Yc$(ref('__pch_header',id))
                    </set>
                </modify-target>
            </define-tag>

        </define-rule>

        <template id="__commands_templ">
            <set var="__LINK_EXE_CMD" eval="0">
                $(__linker) /NOLOGO /OUT:$@ $(__ldflags_all) @&lt;&lt;
                $(__objects_var) $(__win32_resources_var) $(__ldlibs)
                &lt;&lt;NOKEEP
            </set>
            <set var="__LINK_LIB_CMD" eval="0">
                if exist $@ del $@
                $(__LIB_TOOL) /NOLOGO /OUT:$@ @&lt;&lt;
                $(__objects_var) $(__win32_resources_var)
                &lt;&lt;NOKEEP
            </set>
            <set var="__LINK_DLL_CMD" eval="0">
                $(__dll_linker) /NOLOGO /OUT:$@ $(__ldflags_all) @&lt;&lt;
                $(__objects_var) $(__win32_resources_var) $(__ldlibs) /IMPLIB:$(__targetdir)$(__libname).lib
                &lt;&lt;NOKEEP
            </set>
            <set var="__LINK_MODULE_CMD" eval="0">
                $(__dll_linker) /NOLOGO /OUT:$@ $(__ldflags_all) @&lt;&lt;
                $(__objects_var) $(__win32_resources_var) $(__ldlibs)
                &lt;&lt;NOKEEP
            </set>
        </template>

        <template id="__subproject_templ">
            <set var="__targetname">sub_$(id)</set>
            <set var="__MAKE_SUBPROJECT_CMD" eval="0">
                cd $(__subdir)
                $(DOLLAR)(MAKE) -f $(os.path.basename(OUTPUT_FILE)) $(MAKEARGS) $(__subtarget)
                cd "$(DOLLAR)(MAKEDIR)"
            </set>
            <set var="__INSTALL_SUBPROJECT_CMD" eval="0">
                cd $(__subdir)
                $(DOLLAR)(MAKE) -f $(os.path.basename(OUTPUT_FILE)) $(MAKEARGS) install
                cd "$(DOLLAR)(MAKEDIR)"
            </set>
            <set var="__UNINSTALL_SUBPROJECT_CMD" eval="0">
                cd $(__subdir)
                $(DOLLAR)(MAKE) -f $(os.path.basename(OUTPUT_FILE)) $(MAKEARGS) uninstall
                cd "$(DOLLAR)(MAKEDIR)"
            </set>
            <set var="__CLEAN_SUBPROJECT_CMD" eval="0">
                cd $(__subdir)
                $(DOLLAR)(MAKE) -f $(os.path.basename(OUTPUT_FILE)) $(MAKEARGS) clean
                cd "$(DOLLAR)(MAKEDIR)"
            </set>
        </template>

    </if>

</makefile>
