src/mulle-bootstrap-mingw.sh
c81c8721
 #! /usr/bin/env bash
a3018cdd
 #
 #   Copyright (c) 2015 Nat! - Mulle kybernetiK
 #   All rights reserved.
 #
 #   Redistribution and use in source and binary forms, with or without
 #   modification, are permitted provided that the following conditions are met:
 #
 #   Redistributions of source code must retain the above copyright notice, this
 #   list of conditions and the following disclaimer.
 #
 #   Redistributions in binary form must reproduce the above copyright notice,
 #   this list of conditions and the following disclaimer in the documentation
 #   and/or other materials provided with the distribution.
 #
 #   Neither the name of Mulle kybernetiK nor the names of its contributors
 #   may be used to endorse or promote products derived from this software
 #   without specific prior written permission.
 #
 #   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 #   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 #   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 #   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 #   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 #   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 #   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 #   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 #   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 #   POSSIBILITY OF SUCH DAMAGE.
3c4acfba
 #
a3018cdd
 MULLE_BOOTSTRAP_MINGW_SH="included"
 
 
3c4acfba
 find_msvc_executable()
a3018cdd
 {
15a06d2e
    local exe="${1:-cl.exe}"
    local name="${2:-compiler}"
    local searchpath="${3:-$PATH}"
a3018cdd
 
    local path
3c4acfba
    local compiler
a3018cdd
 
    IFS=":"
15a06d2e
    for path in ${searchpath}
a3018cdd
    do
5c06c0e8
       IFS="${DEFAULT_IFS}"
 
a3018cdd
       case "${path}" in
          /usr/*|/bin)
             continue;
          ;;
 
          *)
3c4acfba
             executable="${path}/${exe}"
             if [ -x "${executable}" ]
a3018cdd
             then
3c4acfba
                log_fluff "MSVC ${name} found as ${C_RESET}${executable}"
                echo "${executable}"
a3018cdd
                break
             fi
          ;;
       esac
    done
 
5c06c0e8
    IFS="${DEFAULT_IFS}"
a3018cdd
 }
 
 
96a9f077
 # used by tests
 mingw_demangle_path()
 {
    echo "$1" | sed 's|^/\(.\)|\1:|' | sed s'|/|\\|g'
 }
 
 
 
 mingw_eval_demangle_path()
 {
    echo "$1" | sed 's|^/\(.\)|\1:|' | sed s'|/|\\\\|g'
 }
 
 
 #
 # mingw wille demangle first -I/c/users but not the next one
 # but when one -I looks demangled, it doesn't demangle the first
 # one. It's so complicated
 #
 mingw_eval_demangle_paths()
 {
 #   if [ $# -eq 0 ]
 #   then
 #      return
 #   fi
 #
 #   echo "$1"
 #   shift
 
    while [ $# -ne 0 ]
    do
       mingw_eval_demangle_path "$1"
       shift
    done
 }
 
 
 # used by anyone ?
8b9f64f2
 mingw_mangle_compiler()
 {
    local compiler
 
    compiler="$1"
    case "${compiler}" in
550b5448
       *clang) # mulle-clang|clang
8b9f64f2
          compiler="${compiler}-cl"
       ;;
 
       *)
          compiler="cl"
          log_fluff "Using default compiler cl"
       ;;
    esac
    echo "${compiler}"
 }
 
 
96a9f077
 
 # used by tests, probably old and wrong
 mingw_mangle_compiler_exe()
 {
    local compiler
 
    compiler="$1"
    case "${compiler}" in
       mulle-clang|clang)
          compiler="${compiler}-cl"
          echo "Using ${compiler} on mingw for $2" >&2
       ;;
 
       mulle-clang-*|clang-*)
       ;;
 
       *)
          compiler="cl.exe"
          echo "Using default compiler cl for $2" >&2
       ;;
    esac
    echo "${compiler}"
 }
 
 
 
a3018cdd
 #
 # fix path fckup
 #
8f77be37
 setup_mingw_buildenvironment()
a3018cdd
 {
9c3cca2d
    log_debug "setup_mingw_buildenvironment"
    
75913c0b
    local linker
a3018cdd
 
    if [ -z "${LIBPATH}" -o  -z "${INCLUDE}" ] && [ -z "${DONT_USE_VS}" ]
    then
       fail "environment variables INCLUDE and LIBPATH not set, start MINGW inside IDE environment"
    fi
 
75913c0b
    linker="`find_msvc_executable "link.exe" "linker"`"
    if [ ! -z "${linker}" ]
    then
       LD="${linker}"
       export LD
2f8d42a5
       log_verbose "Environment variable ${C_INFO}LD${C_VERBOSE} set to ${C_RESET}\"${LD}\""
3c4acfba
    else
       log_fluff "MSVC link.exe not found"
    fi
 
    local preprocessor
15a06d2e
    local searchpath
  
    searchpath="`dirname -- "${MULLE_EXECUTABLE_PATH}"`:$PATH"
    preprocessor="`find_msvc_executable "mulle-mingw-cpp.sh" "preprocessor" "${searchpath}"`"
75913c0b
    if [ ! -z "${preprocessor}" ]
    then
       CPP="${preprocessor}"
       export CPP
2f8d42a5
       log_verbose "Environment variable ${C_INFO}CPP${C_VERBOSE} set to ${C_RESET}\"${CPP}\""
75913c0b
    else
9514a7cb
       log_fluff "mulle-mingw-cpp.sh not found"
3c4acfba
    fi
a3018cdd
 }
 
d2100287
 
96a9f077
 
d2100287
 #
96a9f077
 # mingw32-make can't have sh.exe in its path, so remove it
d2100287
 #
 mingw_buildpath()
 {
    local i
96a9f077
    local buildpath
    local vspath
d2100287
 
75913c0b
    IFS=":"
d2100287
    for i in $PATH
    do
5c06c0e8
       IFS="${DEFAULT_IFS}"
 
d2100287
       if [ -x "${i}/sh.exe" ]
       then
57935531
          log_fluff "Removed \"$i\" from build PATH because it contains sh"
d2100287
          continue
       fi
 
96a9f077
       if [ -z "${buildpath}" ]
d2100287
       then
96a9f077
          buildpath="${i}"
d2100287
       else
96a9f077
          buildpath="${buildpath}:${i}"
d2100287
       fi
    done
 
96a9f077
    echo "${buildpath}"
 }
 
 
 #
 # mingw likes to put it's stuff in front, obscuring Visual Studio
 # executables this function resorts this (used in mulle-tests)
 #
 mingw_visualstudio_buildpath()
 {
    local i
    local buildpath
    local vspath
 
    IFS=":"
    for i in $PATH
    do
       IFS="${DEFAULT_IFS}"
 
       case "$i" in
          *"/Microsoft Visual Studio"*)
             if [ -z "${vspath}" ]
             then
                vspath="${i}"
             else
                vspath="${vspath}:${i}"
             fi
          ;;
       
          *)         
             if [ -z "${buildpath}" ]
             then
                buildpath="${i}"
             else
                buildpath="${buildpath}:${i}"
             fi
          ;;
       esac
    done
5c06c0e8
    IFS="${DEFAULT_IFS}"
d2100287
 
96a9f077
    if [ ! -z "${vspath}" ]
    then
       if [ -z "${buildpath}" ]
       then
          buildpath="${vspath}"
       else
          buildpath="${vspath}:${buildpath}"
       fi
    fi
 
    echo "${buildpath}"
 }
 
 
 mingw32_make_buildpath()
 {
    mingw_buildpath
d2100287
 }
8f77be37
 
 
 mingw_initialize()
 {
ec2b9bc2
    [ -z "${MULLE_BOOTSTRAP_LOGGING_SH}" ] && . mulle-bootstrap-logging.sh
9339a58a
    log_debug ":mingw_initialize:"
8f77be37
 }
ec2b9bc2
 
 mingw_initialize