mulle-bootstrap-build.sh
5de2fbd6
 #! /bin/sh
 #
 #   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.
 
d7f96955
 . mulle-bootstrap-local-environment.sh
 . mulle-bootstrap-gcc.sh
 . mulle-bootstrap-scripts.sh
5de2fbd6
 
 
61fc7238
 
 CLEAN_BEFORE_BUILD=`read_config_setting "clean_before_build" "YES"`
 CONFIGURATIONS="`read_build_root_setting "configurations" "Debug
 Release"`"
 
 # get number of cores, use 50% more for make -j
 CORES="`get_core_count`"
 CORES="`expr $CORES + $CORES / 2`"
 
3be635de
 check_and_usage_and_help()
 {
61fc7238
    local defk
    local defc
    local defkk
 
    defc="`printf "$CONFIGURATIONS" | tr '\012' ','`"
    if [ "${CLEAN_BEFORE_BUILD}" = "YES" ]
    then
       defk=""
       defkk="(default)"
    else
       defk="(default)"
       defkk=""
    fi
 
40fe269d
    cat <<EOF
61fc7238
 usage: build [-ck] [repos]*
 
    -k         :  don't clean before building $defk
    -K         :  always clean before building $defkk
    -c <name>  :  configurations to build ($defc)
    -j         :  number of cores parameter for make (${CORES})
28ed6b30
 
    You can optionally specify the names of the repositories to build.
40fe269d
    Currently available names are:
 EOF
290ab3f7
    (cd "${CLONES_SUBDIR}" ; ls -1 ) 2> /dev/null
3be635de
 }
 
 
61fc7238
 while :
 do
94c78e4d
    if [ "$1" = "-h" -o "$1" = "--help" ]
    then
       check_and_usage_and_help >&2
       exit 1
    fi
 
61fc7238
    if [ "$1" = "-K" ]
    then
       CLEAN_BEFORE_BUILD="YES"
       [ $# -eq 0 ] || shift
       continue
    fi
 
    if [ "$1" = "-k" ]
    then
       CLEAN_BEFORE_BUILD=
       [ $# -eq 0 ] || shift
       continue
    fi
 
    if [ "$1" = "-j" ]
    then
       if [ $# -eq 0 ]
       then
          fail "core count missing"
       fi
       shift
 
       CORES="$1"
       [ $# -eq 0 ] || shift
       continue
    fi
 
    #
    # specify configuration to build
    #
    if [ "$1" = "-c"  ]
    then
       if [ $# -eq 0 ]
       then
          fail "configuration name missing"
       fi
       shift
 
       CONFIGURATIONS="`printf "%s" "$1" | tr ',' '\012'`"
       [ $# -eq 0 ] || shift
       continue
    fi
 
    break
 done
5de2fbd6
 
94c78e4d
 
5de2fbd6
 #
 # move stuff produced my cmake and configure to places
 # where we expect them. Expect  others to build to
 # <prefix>/include  and <prefix>/lib or <prefix>/Frameworks
 #
3be635de
 dispense_headers()
5de2fbd6
 {
28ed6b30
    local name
    local src
5de2fbd6
 
28ed6b30
    name="${1}"
    src="$2"
3be635de
 
    local dst
28ed6b30
    local headers
    local suffix
3be635de
 
7fdfcd11
    log_fluff "Consider copying headers from \"${src}\""
5de2fbd6
 
    if [ -d "${src}" ]
    then
       if dir_has_files "${src}"
       then
28ed6b30
          headers="`read_build_setting "${name}" "dispense_headers_path" "/usr/local/${HEADER_DIR_NAME}"`"
3be635de
 
28ed6b30
          dst="${REFERENCE_DEPENDENCY_SUBDIR}${headers}"
          mkdir_if_missing "${dst}"
3be635de
 
57730883
          # this fails with more nested header set ups, need to fix!
 
7fdfcd11
          log_fluff "Copying \"${src}\" to \"${dst}\""
57730883
          exekutor cp -Ra ${COPYMOVEFLAGS} "${src}"/* "${dst}" || exit 1
a7b563e1
 
3be635de
          rmdir_safer "${src}"
d7f96955
       else
a7b563e1
          log_fluff "But there are none"
5de2fbd6
       fi
d7f96955
    else
       log_fluff "But it doesn't exist"
5de2fbd6
    fi
3be635de
 }
 
 
 dispense_binaries()
 {
    local src
28ed6b30
    local findtype
    local subpath
    local name
3be635de
 
28ed6b30
    name="$1"
    src="$2"
    findtype="$3"
    subpath="$4"
3be635de
 
    local dst
    local usrlocal
28ed6b30
    local findtype2
38373663
    local copyflag
28ed6b30
 
422c21da
    findtype2="l"
38373663
    copyflag="-f"
    if [ "${findtype}" = "-d"  ]
    then
       copyflag="-n"
    fi
7fdfcd11
    log_fluff "Consider copying binaries from \"${src}\" for type \"${findtype}/${findtype2}\""
3be635de
 
    if [ -d "${src}" ]
5de2fbd6
    then
       if dir_has_files "${src}"
       then
3be635de
          dst="${REFERENCE_DEPENDENCY_SUBDIR}${subpath}${subdir}"
 
7fdfcd11
          log_fluff "Copying \"${src}\" to \"${dst}\""
3be635de
          mkdir_if_missing "${dst}"
151d8edd
          exekutor find "${src}" -xdev -mindepth 1 -maxdepth 1 \( -type "${findtype}" -o -type "${findtype2}" \) -print0 | \
38373663
             exekutor xargs -0 -I % mv ${COPYMOVEFLAGS} "${copyflag}" % "${dst}"
3be635de
          [ $? -eq 0 ]  || exit 1
d7f96955
       else
          log_fluff "But threre are none"
5de2fbd6
       fi
3be635de
       rmdir_safer "${src}"
d7f96955
    else
       log_fluff "But it doesn't exist"
5de2fbd6
    fi
3be635de
 }
5de2fbd6
 
3be635de
 
 collect_and_dispense_product()
 {
28ed6b30
    local  name
3be635de
    local  subdir
28ed6b30
    local  name
 
    name="${1}"
    subdir="${2}"
    wasxcode="${3}"
 
3be635de
    local  dst
    local  src
 
422c21da
    if read_yes_no_config_setting "skip_collect_and_dispense" "NO"
    then
       log_info "Skipped collection and dispensal on request"
       return 0
    fi
 
a203984b
    log_fluff "Collecting and dispensing \"${name}\" \"`basename -- "${subdir}"`\" products "
3be635de
    #
    # probably should use install_name_tool to hack all dylib paths that contain .ref
    # (will this work with signing stuff ?)
    #
    if [ "${wasxcode}" = "YES" ]
5de2fbd6
    then
3be635de
       log_fluff "Choosing xcode dispense path"
 
       src="${BUILD_DEPENDENCY_SUBDIR}/usr/local/include"
28ed6b30
       dispense_headers "${name}" "${src}"
3be635de
 
       src="${BUILD_DEPENDENCY_SUBDIR}/usr/include"
28ed6b30
       dispense_headers "${name}" "${src}"
3be635de
 
       src="${BUILD_DEPENDENCY_SUBDIR}/include"
28ed6b30
       dispense_headers "${name}" "${src}"
3be635de
 
       src="${BUILD_DEPENDENCY_SUBDIR}/lib${subdir}"
28ed6b30
       dispense_binaries "${name}" "${src}" "f" "/${LIBRARY_DIR_NAME}"
3be635de
 
422c21da
       src="${BUILD_DEPENDENCY_SUBDIR}/Library/Frameworks${subdir}"
       dispense_binaries "${name}" "${src}" "d" "/${FRAMEWORK_DIR_NAME}"
 
3be635de
       src="${BUILD_DEPENDENCY_SUBDIR}/Frameworks${subdir}"
422c21da
       dispense_binaries "${name}" "${src}" "d" "/${FRAMEWORK_DIR_NAME}"
3be635de
 
61fc7238
       src="${BUILD_DEPENDENCY_SUBDIR}${subdir}/Library/Frameworks"
       dispense_binaries "${name}" "${src}" "d" "/${FRAMEWORK_DIR_NAME}"
3be635de
 
61fc7238
       src="${BUILD_DEPENDENCY_SUBDIR}${subdir}/Frameworks"
422c21da
       dispense_binaries "${name}" "${src}" "d" "/${FRAMEWORK_DIR_NAME}"
 
61fc7238
 
422c21da
       src="${BUILD_DEPENDENCY_SUBDIR}/Library/Frameworks"
       dispense_binaries "${name}" "${src}" "d" "/${FRAMEWORK_DIR_NAME}"
 
       src="${BUILD_DEPENDENCY_SUBDIR}/Frameworks"
       dispense_binaries "${name}" "${src}" "d" "/${FRAMEWORK_DIR_NAME}"
61fc7238
    else
       log_fluff "Choosing cmake/configure dispense path"
 
       src="${BUILD_DEPENDENCY_SUBDIR}/usr/local/include"
       dispense_headers "${name}" "${src}"
 
       src="${BUILD_DEPENDENCY_SUBDIR}/usr/local/lib"
       dispense_binaries "${name}" "${src}" "f" "/${LIBRARY_DIR_NAME}"
3be635de
    fi
 
    #
    # Delete empty dirs if so
    #
    src="${BUILD_DEPENDENCY_SUBDIR}/usr/local"
    dir_has_files "${src}"
    if [ $? -ne 0 ]
    then
       rmdir_safer "${src}"
    fi
 
    src="${BUILD_DEPENDENCY_SUBDIR}/usr"
    dir_has_files "${src}"
    if [ $? -ne 0 ]
    then
       rmdir_safer "${src}"
5de2fbd6
    fi
 
3be635de
    #
    # probably should hack all executables with install_name_tool that contain .ref
    #
5de2fbd6
    # now copy over the rest of the output
ae0af5cf
    if read_yes_no_build_setting "${name}" "dispense_other_product" "NO"
    then
       local usrlocal
3be635de
 
ae0af5cf
       usrlocal="`read_build_setting "${name}" "dispense_other_path" "/usr/local"`"
3be635de
 
ae0af5cf
       log_fluff "Considering copying ${BUILD_DEPENDENCY_SUBDIR}/*"
3be635de
 
ae0af5cf
       src="${BUILD_DEPENDENCY_SUBDIR}"
       if [ "${wasxcode}" = "YES" ]
       then
          src="${src}${subdir}"
       fi
3be635de
 
ae0af5cf
       if dir_has_files "${src}"
       then
          dst="${REFERENCE_DEPENDENCY_SUBDIR}${usrlocal}"
3be635de
 
7fdfcd11
          log_fluff "Copying everything from \"${src}\" to \"${dst}\""
151d8edd
          exekutor find "${src}" -xdev -mindepth 1 -maxdepth 1 -print0 | \
6d782b8f
                exekutor xargs -0 -I % mv ${COPYMOVEFLAGS} -f % "${dst}"
ae0af5cf
          [ $? -eq 0 ]  || fail "moving files from ${src} to ${dst} failed"
       fi
 
       if [ "$MULLE_BOOTSTRAP_VERBOSE" = "YES"  ]
3be635de
       then
ae0af5cf
          if dir_has_files "${BUILD_DEPENDENCY_SUBDIR}"
          then
7fdfcd11
             log_fluff "Directory \"${dst}\" contained files after collect and dispense"
ae0af5cf
             log_fluff "--------------------"
             ( cd "${BUILD_DEPENDENCY_SUBDIR}" ; ls -lR >&2 )
             log_fluff "--------------------"
          fi
3be635de
       fi
    fi
5de2fbd6
 
3be635de
    rmdir_safer "${BUILD_DEPENDENCY_SUBDIR}"
5de2fbd6
 
3be635de
    log_fluff "Done collecting and dispensing product"
    log_fluff
5de2fbd6
 }
 
 
 enforce_build_sanity()
 {
3be635de
    local builddir
 
    builddir="$1"
 
5de2fbd6
    # these must not exist
3be635de
    if [ -d "${BUILD_DEPENDENCY_SUBDIR}" ]
5de2fbd6
    then
7fdfcd11
       fail "A previous build left \"${BUILD_DEPENDENCY_SUBDIR}\", can't continue"
5de2fbd6
    fi
 }
 
 
 determine_suffix()
 {
e3e80f18
    local configuration
5de2fbd6
    local sdk
    local suffix
    local hackish
 
e3e80f18
    configuration="$1"
5de2fbd6
    sdk="$2"
 
8e817cc1
    [ ! -z "$configuration" ] || fail "configuration must not be empty"
    [ ! -z "$sdk" ] || fail "sdk must not be empty"
3ed530a3
 
e3e80f18
    suffix="/${configuration}"
5de2fbd6
    if [ "${sdk}" != "Default" ]
    then
       hackish=`echo "${sdk}" | sed 's/^\([a-zA-Z]*\).*$/\1/g'`
       suffix="${suffix}-${hackish}"
    fi
    echo "${suffix}"
 }
 
 
b06853c1
 cmake_sdk_parameter()
5de2fbd6
 {
ece6382e
    local sdk
 
    sdk="$1"
 
5de2fbd6
    local sdkpath
 
ece6382e
    sdkpath=`gcc_sdk_parameter "${sdk}"`
b06853c1
    if [ "${sdkpath}" != "" ]
5de2fbd6
    then
7fdfcd11
       log_fluff "Set cmake -DCMAKE_OSX_SYSROOT to \"${sdkpath}\""
b06853c1
       echo '-DCMAKE_OSX_SYSROOT='"${sdkpath}"
5de2fbd6
    fi
 }
 
28ed6b30
 
 create_dummy_dirs_against_warnings()
 {
ece6382e
    local builddir
    local configuration
28ed6b30
    local suffix
 
    builddir="$1"
    configuration="$2"
    suffix="$3"
 
    local owd
 
    owd="${PWD}"
 
    # to avoid warnings make sure directories are all there
7fdfcd11
    mkdir_if_missing "${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${HEADER_DIR_NAME}"
    if [ ! -z "${configuration}" ]
    then
       mkdir_if_missing "${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME}/${configuration}"
28ed6b30
       mkdir_if_missing "${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}/${configuration}"
7fdfcd11
    fi
    if [ ! -z "${suffix}" ]
    then
        mkdir_if_missing "${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME}${suffix}"
        mkdir_if_missing "${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}${suffix}"
    fi
28ed6b30
 }
 
 
a7b563e1
 build_fail()
 {
422c21da
    if [ -f "${1}" ]
    then
       printf "${C_RED}"
23cfa536
       egrep -B1 -A5 -w "[Ee]rror" "${1}" >&2
422c21da
       printf "${C_RESET}"
    fi
a7b563e1
 
602ae7d9
    if [ -z "$MULLE_BOOTSTRAP_TRACE" ]
    then
       log_info "Check the build log: ${C_RESET_BOLD}${1}${C_INFO}"
    fi
a7b563e1
    fail "$2 failed"
 }
 
 
b6db9b87
 build_log_name()
 {
    local tool
    local name
 
    tool="$1"
2d8f68ea
    [ $# -eq 0 ] || shift
b6db9b87
    name="$1"
2d8f68ea
    [ $# -eq 0 ] || shift
b6db9b87
 
    local logfile
    logfile="${BUILDLOG_SUBDIR}/${name}"
 
    while [ $# -gt 0 ]
    do
       if [ ! -z "${1}" ]
       then
          logfile="${logfile}-${1}"
       fi
2d8f68ea
       [ $# -eq 0 ] || shift
b6db9b87
    done
 
    echo "${logfile}.${tool}.log"
 }
 
5de2fbd6
 #
 # remove old builddir, create a new one
e3e80f18
 # depending on configuration cmake with flags
5de2fbd6
 # build stuff into dependencies
 #
 #
 build_cmake()
 {
e3e80f18
    local configuration
5de2fbd6
    local srcdir
    local builddir
    local name
    local sdk
 
e3e80f18
    configuration="$1"
5de2fbd6
    srcdir="$2"
    builddir="$3"
bf4c7902
    name="$4"
    sdk="$5"
5de2fbd6
 
3be635de
    enforce_build_sanity "${builddir}"
5de2fbd6
 
3bbc5caf
    log_info "Let ${C_RESET_BOLD}cmake${C_INFO} do a \
 ${C_MAGENTA}${C_BOLD}${configuration}${C_INFO} build of \
 ${C_MAGENTA}${C_BOLD}${name}${C_INFO} for SDK \
 ${C_MAGENTA}${C_BOLD}${sdk}${C_INFO} in \"${builddir}\" ..."
7fdfcd11
 
    local sdkparameter
    local suffix
    local mapped
61fc7238
    local fallback
bf4c7902
    local localcmakeflags
c6e7156e
 
61fc7238
    fallback="`echo "${CONFIGURATIONS}" | tail -1`"
bf4c7902
    fallback="`read_build_setting "${name}" "fallback-configuration" "${fallback}"`"
    mapped="`read_build_setting "${name}" "cmake-${configuration}.map" "${configuration}"`"
    localcmakeflags="`read_build_root_setting "cmakeflags"`"
3c8ec4d2
    suffix="`determine_suffix "${configuration}" "${sdk}"`"
7fdfcd11
    sdkparameter="`cmake_sdk_parameter "${sdk}"`"
b06853c1
 
    local other_cflags
    local other_cppflags
    local other_ldflags
 
3c8ec4d2
    other_cflags="`gcc_cflags_value "${name}"`"
    other_cppflags="`gcc_cppflags_value "${name}"`"
    other_ldflags="`gcc_ldflags_value "${name}"`"
5de2fbd6
 
7fdfcd11
    create_dummy_dirs_against_warnings "${builddir}" "${configuration}" "${suffix}"
5de2fbd6
 
422c21da
    local logfile1
    local logfile2
a7b563e1
 
    mkdir_if_missing "${BUILDLOG_SUBDIR}"
b6db9b87
 
151d8edd
    logfile1="`build_log_name "cmake" "${name}" "${configuration}" "${sdk}"`"
    logfile2="`build_log_name "make" "${name}" "${configuration}" "${sdk}"`"
a7b563e1
 
23cfa536
    log_fluff "Build logs will be in \"${logfile1}\" and \"${logfile2}\""
a7b563e1
 
61fc7238
    local   local_make_flags
 
    local_make_flags="${MAKE_FLAGS} -j ${CORES}"
 
28ed6b30
    owd="${PWD}"
602ae7d9
 
bf4c7902
 #   cmake_keep_builddir="`read_build_setting "${name}" "cmake_keep_builddir" "YES"`"
602ae7d9
 #   if [ "${cmake_keep_builddir}" != "YES" ]
 #   then
 #      rmdir_safer "${builddir}"
 #   fi
 
28ed6b30
    mkdir_if_missing "${builddir}"
    exekutor cd "${builddir}" || fail "failed to enter ${builddir}"
5de2fbd6
 
       #
       # cmake doesn't seem to "get" CMAKE_CXX_FLAGS or -INCLUDE
       #
       set -f
8e817cc1
 
93bd7113
       logfile1="${owd}/${logfile1}"
       logfile2="${owd}/${logfile2}"
1b26e970
 
       if [ "$MULLE_BOOTSTRAP_VERBOSE" != "" ]
       then
          logfile1="`tty`"
          logfile2="$logfile1"
       fi
422c21da
       if [ "$MULLE_BOOTSTRAP_DRY_RUN" = "YES" ]
       then
          logfile1="/dev/null"
          logfile2="/dev/null"
       fi
a7b563e1
 
bf4c7902
       local relative_srcdir
 
       relative_srcdir="`relative_path_between "${owd}/${srcdir}" "${PWD}"`"
 
422c21da
       logging_exekutor cmake "-DCMAKE_BUILD_TYPE=${mapped}" \
7fdfcd11
 "${sdkparameter}" \
7a4ae0c8
 "-DDEPENDENCIES_DIR=${owd}/${REFERENCE_DEPENDENCY_SUBDIR}" \
3be635de
 "-DCMAKE_INSTALL_PREFIX:PATH=${owd}/${BUILD_DEPENDENCY_SUBDIR}/usr/local"  \
5de2fbd6
 "-DCMAKE_C_FLAGS=\
602ae7d9
 -I${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${HEADER_DIR_NAME} \
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}${suffix} \
61fc7238
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}/${mapped} \
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}/${fallback} \
602ae7d9
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME} \
7fdfcd11
 ${other_cflags}" \
5de2fbd6
 "-DCMAKE_CXX_FLAGS=\
602ae7d9
 -I${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${HEADER_DIR_NAME} \
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}${suffix} \
61fc7238
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}/${mapped} \
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}/${fallback} \
602ae7d9
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME} \
7fdfcd11
 ${other_cppflags}" \
602ae7d9
 "-DCMAKE_EXE_LINKER_FLAGS=\
 -L${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME}${suffix} \
61fc7238
 -L${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME}/${mapped} \
 -L${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME}/${fallback} \
602ae7d9
 -L${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME} \
7fdfcd11
 ${other_ldflags}" \
602ae7d9
 "-DCMAKE_SHARED_LINKER_FLAGS=\
 -L${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME}${suffix} \
61fc7238
 -L${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME}/${mapped} \
 -L${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME}/${fallback} \
602ae7d9
 -L${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME} \
 ${other_ldflags}" \
bf4c7902
 "-DCMAKE_MODULE_PATH=${CMAKE_MODULE_PATH};\${CMAKE_MODULE_PATH}" \
602ae7d9
 ${CMAKE_FLAGS} \
bf4c7902
 ${localcmakeflags} \
 "${relative_srcdir}" > "${logfile1}" || build_fail "${logfile1}" "cmake"
5de2fbd6
 
61fc7238
       logging_exekutor make ${local_make_flags} VERBOSE=1 install > "${logfile2}" || build_fail "${logfile2}" "make"
8e817cc1
 
5de2fbd6
       set +f
 
8e817cc1
    exekutor cd "${owd}"
5de2fbd6
 
28ed6b30
    collect_and_dispense_product "${name}" "${suffix}" || internal_fail "collect failed silently"
5de2fbd6
 }
 
 
 #
 # remove old builddir, create a new one
e3e80f18
 # depending on configuration cmake with flags
5de2fbd6
 # build stuff into dependencies
 #
 #
 build_configure()
 {
e3e80f18
    local configuration
5de2fbd6
    local srcdir
    local builddir
    local name
    local sdk
 
e3e80f18
    configuration="$1"
5de2fbd6
    srcdir="$2"
    builddir="$3"
bf4c7902
    name="$4"
    sdk="$5"
5de2fbd6
 
3be635de
    enforce_build_sanity "${builddir}"
5de2fbd6
 
3bbc5caf
    log_info "Let ${C_RESET_BOLD}configure${C_INFO} do a \
 ${C_MAGENTA}${C_BOLD}${configuration}${C_INFO} build of \
 ${C_MAGENTA}${C_BOLD}${name}${C_INFO} for SDK \
 ${C_MAGENTA}${C_BOLD}${sdk}${C_INFO} in \"${builddir}\" ..."
c6e7156e
 
ece6382e
    local sdkpath
61fc7238
    local fallback
    local mapped
    local suffix
    local fallback
bf4c7902
    local configureflags
61fc7238
 
    fallback="`echo "${CONFIGURATIONS}" | tail -1`"
bf4c7902
    fallback="`read_build_setting "${name}" "fallback-configuration" "${fallback}"`"
 
    configureflags="`read_build_setting "${name}" "configure_flags"`"
c6e7156e
 
bf4c7902
    mapped="`read_build_setting "${name}" "configure-${configuration}.map" "${configuration}"`"
28ed6b30
    suffix="`determine_suffix "${configuration}" "${sdk}"`"
ece6382e
    sdkpath="`gcc_sdk_parameter "${sdk}"`"
    sdkpath="`echo "${sdkpath}" | sed -e 's/ /\\ /g'`"
5de2fbd6
 
b06853c1
    local other_cflags
    local other_cppflags
    local other_ldflags
 
28ed6b30
    other_cflags="`gcc_cflags_value "${name}"`"
    other_cppflags="`gcc_cppflags_value "${name}"`"
    other_ldflags="`gcc_ldflags_value "${name}"`"
3be635de
 
7fdfcd11
    create_dummy_dirs_against_warnings "${builddir}" "${configuration}" "${suffix}"
5de2fbd6
 
422c21da
    local logfile1
    local logfile2
a7b563e1
 
    mkdir_if_missing "${BUILDLOG_SUBDIR}"
b6db9b87
 
151d8edd
    logfile1="`build_log_name "configure" "${name}" "${configuration}" "${sdk}"`"
    logfile2="`build_log_name "make" "${name}" "${configuration}" "${sdk}"`"
a7b563e1
 
23cfa536
    log_fluff "Build logs will be in \"${logfile1}\" and \"${logfile2}\""
a7b563e1
 
28ed6b30
    owd="${PWD}"
    mkdir_if_missing "${builddir}"
    exekutor cd "${builddir}" || fail "failed to enter ${builddir}"
5de2fbd6
 
28ed6b30
        set -f
5de2fbd6
 
93bd7113
       logfile1="${owd}/${logfile1}"
       logfile2="${owd}/${logfile2}"
1b26e970
 
       if [ "$MULLE_BOOTSTRAP_TRACE" != "" ]
       then
          logfile1="`tty`"
          logfile2="$logfile1"
       fi
422c21da
       if [ "$MULLE_BOOTSTRAP_DRY_RUN" = "YES" ]
       then
          logfile1="/dev/null"
          logfile2="/dev/null"
       fi
a7b563e1
 
5de2fbd6
       # use absolute paths for configure, safer (and easier to read IMO)
7a4ae0c8
        DEPENDENCIES_DIR="'${owd}/${REFERENCE_DEPENDENCY_SUBDIR}'" \
eaa65bf9
        CFLAGS="\
3c8ec4d2
 -I${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${HEADER_DIR_NAME} \
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}${suffix} \
61fc7238
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}/${mapped} \
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}/${fallback} \
3c8ec4d2
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME} \
b06853c1
 ${other_cflags} \
ece6382e
 -isysroot ${sdkpath}" \
5de2fbd6
       CPPFLAGS="\
3c8ec4d2
 -I${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${HEADER_DIR_NAME} \
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}${suffix} \
61fc7238
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}/${mapped} \
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}/${fallback} \
3c8ec4d2
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME} \
b06853c1
 ${other_cppflags} \
ece6382e
 -isysroot ${sdkpath}" \
5de2fbd6
       LDFLAGS="\
3c8ec4d2
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}${suffix} \
61fc7238
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}/${mapped} \
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}/${fallback} \
3c8ec4d2
 -F${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME} \
 -L${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME}${suffix} \
61fc7238
 -L${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME}/${mapped} \
 -L${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME}/${fallback} \
3c8ec4d2
 -L${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME} \
b06853c1
 ${other_ldflags} \
ece6382e
 -isysroot ${sdkpath}" \
bf4c7902
        logging_exekutor "${owd}/${srcdir}/configure" ${configureflags} \
422c21da
           --prefix "${owd}/${BUILD_DEPENDENCY_SUBDIR}/usr/local" >> "${logfile1}" \
       || build_fail "${logfile1}" "configure"
5de2fbd6
 
f146fd2e
       logging_exekutor make install > "${logfile2}" \
422c21da
       || build_fail "${logfile2}" "make"
5de2fbd6
 
       set +f
 
8e817cc1
    exekutor cd "${owd}"
5de2fbd6
 
28ed6b30
    collect_and_dispense_product "${name}" "${suffix}" || exit 1
5de2fbd6
 }
 
 
b6db9b87
 _xcode_get_setting()
 {
    eval_exekutor "xcodebuild -showBuildSettings $*" || fail "failed to read xcode settings"
 }
 
 
5de2fbd6
 xcode_get_setting()
 {
    local key
 
    key="$1"
    shift
 
b6db9b87
    _xcode_get_setting "$@" | egrep "^[ ]*${key}" | sed 's/^[^=]*=[ ]*\(.*\)/\1/'
5de2fbd6
 }
 
 
c6e7156e
 #
3be635de
 # Code I didn't want to throw away really
 # In general just uss "public_headers" or
 # "private_headers" and set them to a /usr/local/include/whatever
c6e7156e
 #
3be635de
 create_mangled_header_path()
8e817cc1
 {
3be635de
    local name
8e817cc1
    local key
    local default
 
    key="$1"
3be635de
    name="$2"
    default="$3"
8e817cc1
 
c6e7156e
    local headers
3be635de
    local prefix
8e817cc1
 
b6db9b87
    headers=`xcode_get_setting "${key}" $*` || exit 1
c6e7156e
    log_fluff "${key} read as \"${headers}\""
8e817cc1
 
c6e7156e
    case "${headers}" in
       /*)
       ;;
8e817cc1
 
c6e7156e
       ./*|../*)
          log_warning "relative path \"${headers}\" as header path ???"
       ;;
8e817cc1
 
c6e7156e
       "")
          headers="${default}"
       ;;
8e817cc1
 
c6e7156e
       *)
          headers="/${headers}"
       ;;
    esac
8e817cc1
 
c6e7156e
    prefix=""
    read_yes_no_build_setting "${name}" "xcode_mangle_include_prefix"
    if [ $? -ne 0 ]
    then
       headers="`remove_absolute_path_prefix_up_to "${headers}" "include"`"
3c8ec4d2
       prefix="${HEADER_DIR_NAME}"
c6e7156e
    fi
8e817cc1
 
c6e7156e
    if read_yes_no_build_setting "${name}" "xcode_mangle_header_dash"
    then
       headers="`echo "${headers}" | tr '-' '_'`"
8e817cc1
    fi
 
3be635de
    echo "${headers}"
 }
 
 
 fixup_header_path()
 {
    local key
    local setting_key
    local default
    local name
 
    key="$1"
    shift
    setting_key="$1"
    shift
    name="$1"
    shift
    default="$1"
    shift
 
    headers="`read_repo_setting "${name}" "${setting_key}"`"
    if [ "$headers" = "" ]
    then
28ed6b30
       read_yes_no_build_setting "${name}" "xcode_mangle_header_paths"
3be635de
       if [ $? -ne 0 ]
       then
          return 1
       fi
 
40fe269d
       headers="`create_mangled_header_path "${key}" "${name}" "${default}"`"
3be635de
    fi
c6e7156e
 
    log_fluff "${key} set to \"${headers}\""
 
8e817cc1
    echo "${headers}"
 }
 
 
5de2fbd6
 build_xcodebuild()
 {
e3e80f18
    local configuration
5de2fbd6
    local srcdir
    local builddir
    local name
    local sdk
    local project
e3e80f18
    local schemename
    local targetname
5de2fbd6
 
e3e80f18
    configuration="$1"
5de2fbd6
    srcdir="$2"
    builddir="$3"
fdd375ea
    name="$4"
bf4c7902
    sdk="$5"
    project="$6"
    schemename="$7"
    targetname="$8"
5de2fbd6
 
151d8edd
    [ ! -z "${configuration}" ] || internal_fail "configuration is empty"
    [ ! -z "${srcdir}" ]        || internal_fail "srcdir is empty"
    [ ! -z "${builddir}" ]      || internal_fail "builddir is empty"
    [ ! -z "${name}" ]          || internal_fail "name is empty"
    [ ! -z "${sdk}" ]           || internal_fail "sdk is empty"
    [ ! -z "${project}" ]       || internal_fail "project is empty"
5de2fbd6
 
3be635de
    enforce_build_sanity "${builddir}"
 
c6e7156e
    local info
 
    info=""
    if [ ! -z "${targetname}" ]
    then
23cfa536
       info=" Target ${C_MAGENTA}${C_BOLD}${targetname}${C_INFO}"
c6e7156e
    fi
 
    if [ ! -z "${schemename}" ]
    then
23cfa536
       info=" Scheme ${C_MAGENTA}${C_BOLD}${schemename}${C_INFO}"
c6e7156e
    fi
 
3bbc5caf
    log_info "Let ${C_RESET_BOLD}xcodebuild${C_INFO} do a \
 ${C_MAGENTA}${C_BOLD}${configuration}${C_INFO} build of \
 ${C_MAGENTA}${C_BOLD}${name}${C_INFO} for SDK \
 ${C_MAGENTA}${C_BOLD}${sdk}${C_INFO}${info} in \
1b26e970
 \"${builddir}\" ..."
3ed530a3
 
5de2fbd6
    local projectname
 
e3e80f18
     # always pass project directly
    projectname=`read_repo_setting "${name}" "project" "${project}"`
5de2fbd6
 
    local mapped
61fc7238
    local fallback
 
    fallback="`echo "${CONFIGURATIONS}" | tail -1`"
bf4c7902
    fallback="`read_build_setting "${name}" "fallback-configuration" "${fallback}"`"
5de2fbd6
 
e3e80f18
    mapped=`read_build_setting "${name}" "${configuration}.map" "${configuration}"`
    [ -z "${mapped}" ] && internal_fail "mapped configuration is empty"
5de2fbd6
 
    local hackish
    local targetname
    local suffix
 
e3e80f18
    suffix="/${configuration}"
5de2fbd6
    if [ "${sdk}" != "Default" ]
    then
3c8ec4d2
       hackish="`echo "${sdk}" | sed 's/^\([a-zA-Z]*\).*$/\1/g'`"
5de2fbd6
       suffix="${suffix}-${hackish}"
    else
       sdk=
    fi
 
3c8ec4d2
    local xcode_proper_skip_install
5de2fbd6
    local skip_install
 
    skip_install=
3c8ec4d2
    xcode_proper_skip_install=`read_build_setting "${name}" "xcode_proper_skip_install" "NO"`
    if [ "$xcode_proper_skip_install" != "YES" ]
5de2fbd6
    then
       skip_install="SKIP_INSTALL=NO"
    fi
 
    local xcodebuild
    local binary
 
e3e80f18
    xcodebuild=`read_config_setting "xcodebuild" "xcodebuild"`
5de2fbd6
    binary=`which "${xcodebuild}"`
    if [ "${binary}"  = "" ]
    then
       echo "${xcodebuild} is an unknown build tool" >& 2
       exit 1
    fi
 
e3e80f18
 
5de2fbd6
    #
    # xctool needs schemes, these are often autocreated, which xctool cant do
    # xcodebuild can just use a target
    # xctool is by and large useless fluff IMO
    #
    if [ "$xcodebuild" = "xctool"  -a "${schemename}" = ""  ]
    then
       if [ "$targetname" != "" ]
       then
8e817cc1
          schemename="${targetname}"
          targetname=
5de2fbd6
       else
          echo "Please specify a scheme to compile in ${BOOTSTRAP_SUBDIR}/${name}/SCHEME for xctool" >& 2
          echo "and be sure that this scheme exists and is shared." >& 2
          echo "Or just delete ${HOME}/.mulle-bootstrap/xcodebuild and use xcodebuild (preferred)" >& 2
          exit 1
       fi
8e817cc1
    fi
5de2fbd6
 
    local key
    local aux
    local value
    local keys
 
    aux=
    keys=`all_build_flag_keys "${name}"`
    for key in ${keys}
    do
       value=`read_build_setting "${name}" "${key}"`
       aux="${aux} ${key}=${value}"
    done
 
    # now don't load any settings anymoe
    local owd
    local command
 
    if [ "$MULLE_BOOTSTRAP_DRY" != "" ]
    then
       command=-showBuildSettings
    else
       command=install
    fi
 
3be635de
       #
       # headers are complicated, the preference is to get it uniform into
       # dependencies/include/libraryname/..
       #
 
    local public_headers
    local private_headers
    local default
 
    default="/include/${name}"
28ed6b30
    public_headers="`fixup_header_path "PUBLIC_HEADERS_FOLDER_PATH" "xcode_public_headers" "${name}" "${default}" ${arguments}`"
3be635de
    default="/include/${name}/private"
28ed6b30
    private_headers="`fixup_header_path "PRIVATE_HEADERS_FOLDER_PATH" "xcode_private_headers" "${name}" "${default}" ${arguments}`"
3be635de
 
a7b563e1
 
    local logfile
 
    mkdir_if_missing "${BUILDLOG_SUBDIR}"
 
151d8edd
    logfile="`build_log_name "xcodebuild" "${name}" "${configuration}" "${targetname}" "${schemename}" "${sdk}"`"
23cfa536
    log_fluff "Build log will be in: ${C_RESET_BOLD}${logfile}${C_INFO}"
a7b563e1
 
    set -f
 
    arguments=""
    if [ ! -z "${projectname}" ]
    then
       arguments="${arguments} -project \"${projectname}\""
    fi
    if [ ! -z "${sdk}" ]
    then
       arguments="${arguments} -sdk \"${sdk}\""
    fi
    if [ ! -z "${schemename}" ]
    then
       arguments="${arguments} -scheme \"${schemename}\""
    fi
    if [ ! -z "${targetname}" ]
    then
       arguments="${arguments} -target \"${targetname}\""
    fi
    if [ ! -z "${mapped}" ]
    then
       arguments="${arguments} -configuration \"${mapped}\""
    fi
 
a203984b
 # an empty xcconfig is nice, because it acts as a reset for
    local xcconfig
 
    xcconfig=`read_repo_setting "${name}" "xcconfig"`
    if [ ! -z "${xcconfig}" ]
    then
       arguments="${arguments} -xcconfig \"${xcconfig}\""
    fi
 
    local other_cflags
    local other_cppflags
    local other_ldflags
 
    other_cflags="`gcc_cflags_value "${name}"`"
    other_cppflags="`gcc_cppflags_value "${name}"`"
    other_ldflags="`gcc_ldflags_value "${name}"`"
 
    if [ ! -z "${other_cflags}" ]
    then
       other_cflags="OTHER_CFLAGS=${other_cflags}"
    fi
    if [ ! -z "${other_cppflags}" ]
    then
       other_cppflags="OTHER_CPPFLAGS=${other_cppflags}"
    fi
    if [ ! -z "${other_ldflags}" ]
    then
       other_ldflags="OTHER_LDFLAGS=${other_ldflags}"
    fi
 
 
7fdfcd11
    create_dummy_dirs_against_warnings "${builddir}" "${configuration}" "${suffix}"
 
5de2fbd6
    owd=`pwd`
422c21da
    exekutor cd "${srcdir}" || exit 1
5de2fbd6
 
8e817cc1
 
a7b563e1
       logfile="${owd}/${logfile}"
1b26e970
 
       if [ "${MULLE_BOOTSTRAP_TRACE}" != "" ]
       then
          logfile="`tty`"
       fi
b6db9b87
       if [ "$MULLE_BOOTSTRAP_DRY_RUN" = "YES" ]
       then
          logfile="/dev/null"
       fi
8e817cc1
 
5de2fbd6
       # manually point xcode to our headers and libs
       # this is like manually doing xcode-setup
       local dependencies_framework_search_path
       local dependencies_header_search_path
       local dependencies_lib_search_path
       local inherited
8e817cc1
       local path
       local escaped
5de2fbd6
 
       #
       # TODO: need to figure out the correct mapping here
       #
b6db9b87
       inherited="`xcode_get_setting HEADER_SEARCH_PATHS ${arguments}`" || exit 1
8e817cc1
       path=`combined_escaped_search_path \
3c8ec4d2
 "${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${HEADER_DIR_NAME}" \
8e817cc1
 "/usr/local/include"`
       if [ -z "${inherited}" ]
3ed530a3
       then
8e817cc1
          dependencies_header_search_path="${path}"
       else
          dependencies_header_search_path="${path} ${inherited}"
3ed530a3
       fi
8e817cc1
 
b6db9b87
       inherited="`xcode_get_setting LIBRARY_SEARCH_PATHS ${arguments}`" || exit 1
8e817cc1
       path=`combined_escaped_search_path \
3c8ec4d2
 "${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME}/${mapped}" \
61fc7238
 "${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME}/${fallback}" \
3c8ec4d2
 "${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME}" \
8e817cc1
 "/usr/local/lib"`
       if [ ! -z "$sdk" ]
3ed530a3
       then
3c8ec4d2
          escaped="`escaped_spaces "${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${LIBRARY_DIR_NAME}/${mapped}"'-$(EFFECTIVE_PLATFORM_NAME)'`"
8e817cc1
          path="${escaped} ${path}" # prepend
       fi
       if [ -z "${inherited}" ]
       then
          dependencies_lib_search_path="${path}"
       else
          dependencies_lib_search_path="${path} ${inherited}"
3ed530a3
       fi
5de2fbd6
 
b6db9b87
       inherited="`xcode_get_setting FRAMEWORK_SEARCH_PATHS ${arguments}`" || exit 1
8e817cc1
       path=`combined_escaped_search_path \
3c8ec4d2
 "${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}/${mapped}" \
61fc7238
 "${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}/${fallback}" \
3c8ec4d2
 "${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}"`
8e817cc1
       if [ ! -z "$sdk" ]
       then
3c8ec4d2
          escaped="`escaped_spaces "${owd}/${REFERENCE_DEPENDENCY_SUBDIR}/${FRAMEWORK_DIR_NAME}/${mapped}"'-$(EFFECTIVE_PLATFORM_NAME)'`"
8e817cc1
          path="${escaped} ${path}" # prepend
       fi
       if [ -z "${inherited}" ]
       then
          dependencies_framework_search_path="${path}"
       else
          dependencies_framework_search_path="${path} ${inherited}"
       fi
c6e7156e
 
       if [ ! -z "${public_headers}" ]
       then
          arguments="${arguments} PUBLIC_HEADERS_FOLDER_PATH='${public_headers}'"
       fi
       if [ ! -z "${private_headers}" ]
       then
          arguments="${arguments} PRIVATE_HEADERS_FOLDER_PATH='${private_headers}'"
       fi
 
5de2fbd6
       # if it doesn't install, probably SKIP_INSTALL is set
8e817cc1
       cmdline="\"${xcodebuild}\" \"${command}\" ${arguments} \
61fc7238
 ARCHS='${ARCHS:-\${ARCHS_STANDARD_32_64_BIT\}}' \
3be635de
 DSTROOT='${owd}/${BUILD_DEPENDENCY_SUBDIR}' \
8e817cc1
 SYMROOT='${owd}/${builddir}/' \
 OBJROOT='${owd}/${builddir}/obj' \
7a4ae0c8
 DEPENDENCIES_DIR='${owd}/${REFERENCE_DEPENDENCY_SUBDIR}' \
61fc7238
 ONLY_ACTIVE_ARCH=${ONLY_ACTIVE_ARCH:-NO} \
8e817cc1
 ${skip_install} \
a203984b
 ${other_cflags} \
 ${other_cppflags} \
 ${other_ldflags} \
8e817cc1
 HEADER_SEARCH_PATHS='${dependencies_header_search_path}' \
 LIBRARY_SEARCH_PATHS='${dependencies_lib_search_path}' \
 FRAMEWORK_SEARCH_PATHS='${dependencies_framework_search_path}'"
 
f146fd2e
       logging_eval_exekutor "${cmdline}" > "${logfile}" \
eaa65bf9
       || build_fail "${logfile}" "xcodebuild"
8e817cc1
 
5de2fbd6
       set +f
 
422c21da
    exekutor cd "${owd}"
3be635de
 
28ed6b30
    collect_and_dispense_product "${name}" "${suffix}" "YES" || exit 1
5de2fbd6
 }
 
 
e3e80f18
 build_xcodebuild_schemes_or_target()
 {
    local builddir
    local name
3be635de
    local project
e3e80f18
 
    builddir="$3"
bf4c7902
    name="$4"
    project="$6"
e3e80f18
 
    local scheme
    local schemes
 
    schemes=`read_repo_setting "${name}" "schemes"`
8e817cc1
 
    local old
 
    old="${IFS:-" "}"
    IFS="
 "
e3e80f18
    for scheme in $schemes
    do
8e817cc1
       IFS="$old"
3be635de
       log_fluff "Building scheme \"${scheme}\" of \"${project}\" ..."
e3e80f18
       build_xcodebuild "$@" "${scheme}" ""
    done
8e817cc1
    IFS="${old}"
e3e80f18
 
    local target
    local targets
 
    targets=`read_repo_setting "${name}" "targets"`
8e817cc1
 
    old="$IFS"
    IFS="
 "
e3e80f18
    for target in $targets
    do
8e817cc1
       IFS="${old}"
3be635de
       log_fluff "Building target \"${target}\" of \"${project}\" ..."
e3e80f18
       build_xcodebuild "$@" "" "${target}"
    done
8e817cc1
    IFS="${old}"
e3e80f18
 
    if [ "${targets}" = "" -a "${schemes}" = "" ]
    then
3be635de
       log_fluff "Building project \"${project}\"..."
e3e80f18
       build_xcodebuild "$@"
    fi
 }
 
 
f146fd2e
 run_build_script()
 {
    local script
 
    script="$1"
    shift
 
    [ ! -z "$script" ] || internal_fail "script is empty"
 
    if [ -x "${script}" ]
    then
       log_fluff "Executing script \"${script}\" $1"
       exekutor "${script}" "$@"
    else
       if [ ! -e "${script}" ]
       then
          fail "script \"${script}\" not found ($PWD)"
       else
          fail "script \"${script}\" not executable"
       fi
    fi
 }
 
 
 run_log_build_script()
 {
    echo "$@"
    run_build_script "$@"
 }
 
 
422c21da
 build_script()
 {
    local script
 
    script="$1"
    shift
 
    local configuration
    local srcdir
    local builddir
    local name
    local sdk
    local project
    local schemename
    local targetname
 
    configuration="$1"
    srcdir="$2"
    builddir="$3"
bf4c7902
    name="$4"
    sdk="$5"
422c21da
 
    local logfile
 
    mkdir_if_missing "${BUILDLOG_SUBDIR}"
 
1b26e970
    logfile="${BUILDLOG_SUBDIR}/${name}-${configuration}-${sdk}.script.log"
23cfa536
    log_fluff "Build log will be in: ${C_RESET_BOLD}${logfile}${C_INFO}"
422c21da
 
602ae7d9
    mkdir_if_missing "${builddir}"
 
422c21da
    local owd
 
    owd=`pwd`
    exekutor cd "${srcdir}" || exit 1
 
       logfile="${owd}/${logfile}"
1b26e970
 
       if [ "$MULLE_BOOTSTRAP_TRACE" != "" ]
       then
          logfile="`tty`"
       fi
422c21da
       if [ "$MULLE_BOOTSTRAP_DRY_RUN" = "YES" ]
       then
          logfile="/dev/null"
       fi
 
23cfa536
       log_info "Let ${C_RESET_BOLD}script${C_INFO} do a \
 ${C_MAGENTA}${C_BOLD}${configuration}${C_INFO} build of \
 ${C_MAGENTA}${C_BOLD}${name}${C_INFO} for SDK \
 ${C_MAGENTA}${C_BOLD}${sdk}${C_INFO}${info} in \
 \"${builddir}\" ..."
 
f146fd2e
       run_log_build_script "${owd}/${script}" \
422c21da
          "${configuration}" \
          "${owd}/${srcdir}" \
          "${owd}/${builddir}" \
          "${owd}/${BUILD_DEPENDENCY_SUBDIR}" \
          "${name}" \
f146fd2e
          "${sdk}" > "${logfile}" \
422c21da
       || build_fail "${logfile}" "build.sh"
 
    exekutor cd "${owd}"
 
    local suffix
 
    suffix="`determine_suffix "${configuration}" "${sdk}"`"
    collect_and_dispense_product "${name}" "${suffix}" || internal_fail "collect failed silently"
 }
 
 
 
5de2fbd6
 build()
 {
151d8edd
    local name
5de2fbd6
    local srcdir
 
151d8edd
    name="$1"
    srcdir="$2"
8e817cc1
 
    [ "${name}" != "${CLONES_SUBDIR}" ] || internal_fail "missing repo argument (${srcdir})"
5de2fbd6
 
    local preferences
 
b9894c39
    #
    # repo may override how it wants to be build
    #
    preferences="`read_build_setting "${name}" "build_preferences"`"
    if [ -z "${preferences}" ]
    then
2d8f68ea
       if [ "`uname`" = 'Darwin' ]
       then
          preferences="`read_config_setting "build_preferences" "script
5de2fbd6
 cmake
602ae7d9
 configure
 xcodebuild"`"
2d8f68ea
       else
          preferences="`read_config_setting "build_preferences" "script
 cmake
 configure"`"
       fi
b9894c39
    fi
5de2fbd6
 
8e817cc1
    local xcodebuild
    local cmake
 
5de2fbd6
    xcodebuild=`which "xcodebuild"`
    cmake=`which "cmake"`
 
8e817cc1
    local sdk
    local sdks
 
5de2fbd6
    # need uniform SDK for our builds
    sdks=`read_build_root_setting "sdks" "Default"`
40fe269d
    [ ! -z "${sdks}" ] || fail "setting \"sdks\" must at least contain \"Default\" to build anything"
5de2fbd6
 
8e817cc1
    local builddir
d7f96955
    local hasbuilt
8e817cc1
    local configuration
    local preference
61fc7238
    local configurations
 
    # settings can override the commandline default
    configurations="`read_build_setting "${name}" "configurations" "${CONFIGURATIONS}"`"
3ed530a3
 
5de2fbd6
    for sdk in ${sdks}
    do
ac6ff55d
       # remap macosx to Default, as EFFECTIVE_PLATFORM_NAME will not be appeneded by Xcode
       if [ "$sdk" = "macosx" ]
       then
          sdk="Default"
       fi
 
5de2fbd6
       for configuration in ${configurations}
       do
ece6382e
          if [ "/${configuration}" = "/${LIBRARY_DIR_NAME}" -o "/${configuration}" = "${HEADER_DIR_NAME}" -o "/${configuration}" = "${FRAMEWORK_DIR_NAME}" ]
5de2fbd6
          then
ece6382e
             fail "You are just asking for trouble naming your configuration \"${configuration}\"."
5de2fbd6
          fi
 
          if [ "${configuration}" = "lib" -o "${configuration}" = "include" -o "${configuration}" = "Frameworks" ]
          then
ece6382e
             fail "You are just asking for major trouble naming your configuration \"${configuration}\"."
5de2fbd6
          fi
 
          builddir="${CLONESBUILD_SUBDIR}/${configuration}/${name}"
 
602ae7d9
          if [ -d "${builddir}" -a "${CLEAN_BEFORE_BUILD}" = "YES" ]
          then
             log_fluff "Cleaning build directory \"${builddir}\""
             rmdir_safer "${builddir}"
          fi
 
d7f96955
          hasbuilt=no
5de2fbd6
          for preference in ${preferences}
          do
d7f96955
             if [ "${preference}" = "script" ]
5de2fbd6
             then
d7f96955
                local script
 
                script="`find_build_setting_file "${name}" "bin/build.sh"`"
                if [ -x "${script}" ]
                then
bf4c7902
                   build_script "${script}" "${configuration}" "${srcdir}" "${builddir}" "${name}" "${sdk}" || exit 1
d7f96955
                   hasbuilt=yes
                   break
422c21da
                else
                   [ ! -e "${script}" ] || fail "script ${script} is not executable"
d7f96955
                fi
5de2fbd6
             fi
 
             if [ "${preference}" = "xcodebuild" -a -x "${xcodebuild}" ]
             then
                project=`(cd "${srcdir}" ; find_xcodeproj "${name}")`
 
                if [ "$project" != "" ]
                then
bf4c7902
                   build_xcodebuild_schemes_or_target "${configuration}" "${srcdir}" "${builddir}" "${name}" "${sdk}" "${project}"  || exit 1
d7f96955
                   hasbuilt=yes
5de2fbd6
                   break
                fi
             fi
 
             if [ "${preference}" = "configure"  ]
             then
                if [ ! -f "${srcdir}/configure"  ]
                then
                   # try for autogen if installed (not coded yet)
                   :
                fi
                if [ -x "${srcdir}/configure" ]
                then
bf4c7902
                   build_configure "${configuration}" "${srcdir}" "${builddir}" "${name}" "${sdk}"  || exit 1
d7f96955
                   hasbuilt=yes
5de2fbd6
                   break
                fi
             fi
 
290ab3f7
             if [ "${preference}" = "cmake" ]
5de2fbd6
             then
                if [ -f "${srcdir}/CMakeLists.txt" ]
                then
290ab3f7
                   if [ ! -x "${cmake}" ]
                   then
                      log_warning "Found a CMakeLists.txt, but cmake is not installed"
                   else
bf4c7902
                      build_cmake "${configuration}" "${srcdir}" "${builddir}" "${name}" "${sdk}"  || exit 1
290ab3f7
                      hasbuilt=yes
                      break
                   fi
5de2fbd6
                fi
             fi
          done
 
d7f96955
          if [ "$hasbuilt" != "yes" ]
5de2fbd6
          then
             fail "Don't know how to build ${name}"
          fi
       done
    done
 }
 
 
3be635de
 #
 # ${DEPENDENCY_SUBDIR} is split into
 #
 #  REFERENCE_DEPENDENCY_SUBDIR and
 #  BUILD_DEPENDENCY_SUBDIR
 #
 # above this function, noone should access ${DEPENDENCY_SUBDIR}
 #
 build_wrapper()
 {
151d8edd
    local srcdir
d7f96955
    local name
 
151d8edd
    name="$1"
    srcdir="$2"
3be635de
 
    REFERENCE_DEPENDENCY_SUBDIR="${DEPENDENCY_SUBDIR}"
    BUILD_DEPENDENCY_SUBDIR="${DEPENDENCY_SUBDIR}/tmp"
 
    DEPENDENCY_SUBDIR="WRONG_DONT_USE_DEPENDENCY_SUBDIR_DURING_BUILD"
 
d7f96955
    log_fluff "Setting up BUILD_DEPENDENCY_SUBDIR as \"${BUILD_DEPENDENCY_SUBDIR}\""
 
1b26e970
    if [ "${COMMAND}" != "ibuild" -a -d "${BUILD_DEPENDENCY_SUBDIR}" ]
3be635de
    then
40fe269d
       log_info "Cleaning up orphaned \"${BUILD_DEPENDENCY_SUBDIR}\""
3be635de
       rmdir_safer "${BUILD_DEPENDENCY_SUBDIR}"
    fi
 
422c21da
    export BUILD_DEPENDENCY_SUBDIR
    export REFERENCE_DEPENDENCY_SUBDIR
bf4c7902
 
3be635de
    #
    # move dependencies we have so far away into safety,
    # need that path for includes though
    #
 
151d8edd
    run_repo_settings_script "${name}" "${srcdir}" "pre-build" "$@" || exit 1
d7f96955
 
151d8edd
    build "${name}" "${srcdir}" || exit 1
d7f96955
 
151d8edd
    run_repo_settings_script "${name}" "${srcdir}" "post-build" "$@" || exit 1
3be635de
 
1b26e970
    if [ "${COMMAND}" != "ibuild"  ]
    then
       log_fluff "Remove \"${BUILD_DEPENDENCY_SUBDIR}\""
    fi
3be635de
 
    rmdir_safer "${BUILD_DEPENDENCY_SUBDIR}"
 
    DEPENDENCY_SUBDIR="${REFERENCE_DEPENDENCY_SUBDIR}"
 
1b26e970
    # for mulle-bootstrap developers
3be635de
    REFERENCE_DEPENDENCY_SUBDIR="WRONG_DONT_USE_REFERENCE_DEPENDENCY_SUBDIR_AFTER_BUILD"
    BUILD_DEPENDENCY_SUBDIR="WRONG_DONT_USE_BUILD_DEPENDENCY_SUBDIR_AFTER_BUILD"
 }
 
 
151d8edd
 build_if_alive()
3ed530a3
 {
    local name
151d8edd
    local srcdir
3ed530a3
 
151d8edd
    name="$1"
    srcdir="$2"
3ed530a3
 
d7f96955
    local xdone
151d8edd
    local zombie
 
a203984b
    zombie="`dirname -- "${srcdir}"`/.zombies/${name}"
151d8edd
    if [ -e "${zombie}" ]
3ed530a3
    then
7fdfcd11
       log_warning "Ignoring zombie repo ${name} as \"${zombie}${C_WARNING} exists"
3ed530a3
    else
d7f96955
       xdone="`/bin/echo "${BUILT}" | grep -x "${name}"`"
3ed530a3
       if [ "$xdone" = "" ]
       then
7fdfcd11
          build_wrapper "${name}" "${srcdir}"
d7f96955
          BUILT="${name}
 ${BUILT}"
       else
          log_fluff "Ignoring \"${name}\". (Either in \"build_ignore\" or already built)"
3ed530a3
       fi
    fi
 }
 
 
bf4c7902
 get_source_dir()
 {
    local name
 
    name="${1}"
 
    local srcdir
    local srcsubdir
 
    srcdir="${CLONES_SUBDIR}/${name}"
    srcsubdir="`read_build_setting "${name}" "source_dir"`"
    if [ ! -z "${srcsubdir}" ]
    then
       srcdir="${srcdir}/${srcsubdir}"
    fi
    echo "${srcdir}"
 }
 
 
5de2fbd6
 build_clones()
 {
    local clone
    local xdone
    local name
151d8edd
    local srcdir
bf4c7902
    local srcsubdir
7fdfcd11
    local old
 
    old="${IFS:-" "}"
5de2fbd6
 
    for clone in ${CLONES_SUBDIR}/*.failed
    do
       if [ -d "${clone}" ]
       then
          fail "failed checkout $clone detected, can't continue"
       fi
    done
 
d7f96955
    run_build_root_settings_script "pre-build" "$@"
 
5de2fbd6
    #
    # build order is there, because we want to have gits
    # and maybe later hgs
    #
d7f96955
    BUILT=
    export BUILT
 
5de2fbd6
    if [ "$#" -eq 0 ]
    then
d7f96955
       BUILT="`read_build_root_setting "build_ignore"`"
3ed530a3
 
7fdfcd11
       clones="`read_build_root_setting "build_order"`"
       IFS="
 "
       for clone in ${clones}
5de2fbd6
       do
7fdfcd11
          IFS="$old"
cbead75b
          name="`canonical_clone_name "${clone}"`"
bf4c7902
          srcdir="`get_source_dir "${name}"`"
151d8edd
          if [ -d "${srcdir}" ]
5de2fbd6
          then
151d8edd
             build_if_alive  "${name}" "${srcdir}" || exit 1
5de2fbd6
          else
151d8edd
             fail "build_order contains unknown repo \"${clone}\" (\"${srcdir}\")"
5de2fbd6
          fi
       done
7fdfcd11
       IFS="$old"
5de2fbd6
 
b9894c39
       #
7fdfcd11
       # otherwise compile in repositories order
b9894c39
       #
7fdfcd11
       clones="`read_fetch_setting "repositories"`"
b9894c39
       if [ "${clones}" != "" ]
       then
7fdfcd11
          IFS="
 "
b9894c39
          for clone in ${clones}
          do
7fdfcd11
             IFS="$old"
 
             name="`canonical_name_from_clone "${clone}"`"
bf4c7902
             srcdir="`get_source_dir "${name}"`"
5de2fbd6
 
151d8edd
             if [ -d "${srcdir}" ]
b9894c39
             then
151d8edd
                build_if_alive "${name}" "${srcdir}" || exit  1
cbead75b
             else
151d8edd
                fail "repo for \"${clone}\" not found (\"${srcdir}\") ($PWD)"
b9894c39
             fi
          done
       fi
5de2fbd6
    else
8e817cc1
       for name in "$@"
5de2fbd6
       do
bf4c7902
          srcdir="`get_source_dir "${name}"`"
5de2fbd6
 
151d8edd
          if [ -d "${srcdir}" ]
8e817cc1
          then
151d8edd
             build_if_alive "${name}" "${srcdir}"|| exit 1
8e817cc1
          else
             fail "unknown repo ${name}"
          fi
5de2fbd6
       done
    fi
d7f96955
 
7fdfcd11
    IFS="$old"
 
d7f96955
    run_build_root_settings_script "post-build" "$@"
5de2fbd6
 }
 
 
a203984b
 have_tars()
 {
    tarballs=`read_fetch_setting "tarballs"`
    [ "${tarballs}" != "" ]
 }
 
 
3be635de
 install_tars()
 {
    local tarballs
    local tar
40fe269d
 
3be635de
    tarballs=`read_fetch_setting "tarballs" | sort | sort -u`
7fdfcd11
    if [ "${tarballs}" = "" ]
3be635de
    then
7fdfcd11
       return 0
    fi
3be635de
 
7fdfcd11
    local old
 
    old="${IFS:-" "}"
    IFS="
3be635de
 "
7fdfcd11
    for tar in ${tarballs}
    do
       if [ ! -f "$tar" ]
       then
          fail "tarball \"$tar\" not found"
       else
          log_info "Installing tarball \"${tar}\""
          exekutor tar -xz -C "${DEPENDENCY_SUBDIR}" -f "${tar}" || fail "failed to extract ${tar}"
       fi
    done
    IFS="${old}"
3be635de
 }
 
 
5de2fbd6
 main()
 {
28ed6b30
    local  clean
3be635de
 
3c8ec4d2
    log_fluff "::: build :::"
40fe269d
 
    #
    # START
    #
    if [ ! -d "${CLONES_SUBDIR}" ]
    then
7fdfcd11
       log_info "No repositories in \"${CLONES_SUBDIR}\", so nothing to build."
40fe269d
       return 0
    fi
 
602ae7d9
    ensure_consistency
 
28ed6b30
    if [ $# -eq 0 ]
    then
d7f96955
       log_fluff "Setting up dependencies directory as \"${DEPENDENCY_SUBDIR}\""
28ed6b30
       clean="`read_config_setting "clean_dependencies_before_build" "YES"`"
       if [ "${clean}" = "YES" ]
       then
          rmdir_safer "${DEPENDENCY_SUBDIR}"
       fi
    else
7fdfcd11
       log_fluff "Unprotecting \"${DEPENDENCY_SUBDIR}\" (as this is a partial build)."
       exekutor chmod -R u+w "${DEPENDENCY_SUBDIR}"
28ed6b30
    fi
 
3be635de
    # if present then we didnt't want to clean and we do nothing special
    if [ ! -d "${DEPENDENCY_SUBDIR}" ]
    then
       mkdir_if_missing "${DEPENDENCY_SUBDIR}/usr/local/include"
       exekutor ln -s "usr/local/include" "${DEPENDENCY_SUBDIR}/include" || fail "failed to symlink future usr/local/include"
       install_tars "$@"
422c21da
    else
a203984b
       if have_tars
       then
          log_warning "Tars have not been installed, as \"${DEPENDENCY_SUBDIR}\" already exists."
       fi
3be635de
    fi
 
5de2fbd6
    build_clones "$@"
a7b563e1
 
23cfa536
    log_info "Write-protecting ${C_RESET_BOLD}${DEPENDENCY_SUBDIR}${C_INFO} to avoid spurious header edits"
    exekutor chmod -R a-w "${DEPENDENCY_SUBDIR}"
5de2fbd6
 }
 
 main "$@"