PageRenderTime 97ms CodeModel.GetById 17ms app.highlight 70ms RepoModel.GetById 1ms app.codeStats 0ms

/core/macfuse_buildtool.sh

http://macfuse.googlecode.com/
Shell | 1706 lines | 1307 code | 276 blank | 123 comment | 167 complexity | e7f38310d7d964670562fb52cc388149 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1#! /bin/bash
   2# Copyright (C) 2008-2009 Google. All Rights Reserved.
   3#
   4# Amit Singh <singh@>
   5# Repurposes code from several earlier scripts by Ted Bonkenburg.
   6#
   7
   8PATH=/Developer/usr/sbin:/Developer/usr/bin:/Developer/Tools:/Developer/Applications:/sbin:/usr/sbin:/bin:/usr/bin
   9
  10export PATH
  11
  12# Configurables
  13#
  14# Beware: GNU libtool cannot handle directory names containing whitespace.
  15#         Therefore, do not set M_CONF_TMPDIR to such a directory.
  16#
  17readonly M_CONF_TMPDIR=/tmp
  18readonly M_CONF_PRIVKEY=/etc/macfuse/private.der
  19
  20# Other constants
  21#
  22readonly M_PROGDESC="MacFUSE build tool"
  23readonly M_PROGNAME=macfuse_buildtool
  24readonly M_PROGVERS=1.0
  25
  26readonly M_DEFAULT_VALUE=__default__
  27
  28readonly M_CONFIGURATIONS="Debug Release" # default is Release
  29readonly M_PLATFORMS="10.4 10.5 10.6"     # default is native
  30readonly M_PLATFORMS_REALISTIC="10.4 10.5"
  31readonly M_TARGETS="clean dist examples lib libsrc reload smalldist swconfigure"
  32readonly M_TARGETS_WITH_PLATFORM="examples lib libsrc smalldist swconfigure"
  33
  34readonly M_DEFAULT_PLATFORM="$M_DEFAULT_VALUE"
  35readonly M_DEFAULT_TARGET="$M_DEFAULT_VALUE"
  36
  37readonly M_XCODE_VERSION_REQUIRED=3.1.1
  38
  39# Globals
  40#
  41declare m_args=
  42declare m_active_target=""
  43declare m_configuration=Release
  44declare m_developer=0
  45declare m_osname=""
  46declare m_platform="$M_DEFAULT_PLATFORM"
  47declare m_release=""
  48declare m_shortcircuit=0
  49declare m_srcroot=""
  50declare m_srcroot_platformdir=""
  51declare m_stderr=/dev/stderr
  52declare m_stdout=/dev/stdout
  53declare m_suprompt=" invalid "
  54declare m_target="$M_DEFAULT_TARGET"
  55declare m_usdk_dir=""
  56declare m_version_tiger=""
  57declare m_version_leopard=""
  58declare m_version_snowleopard=""
  59declare m_xcode_version=
  60
  61# Other implementation details
  62#
  63readonly M_FSBUNDLE_NAME=fusefs.fs
  64readonly M_INSTALL_RESOURCES_DIR=Install_resources
  65readonly M_KEXT_ID=com.google.filesystems.fusefs
  66readonly M_KEXT_NAME=fusefs.kext
  67readonly M_KEXT_SYMBOLS=fusefs-symbols
  68readonly M_LIBFUSE_SRC=fuse-current.tar.gz
  69readonly M_LIBFUSE_PATCH=fuse-current-macosx.patch
  70readonly M_LOGPREFIX=MacFUSEBuildTool
  71readonly M_MACFUSE_PRODUCT_ID=com.google.filesystems.fusefs
  72readonly M_PKGNAME_CORE="MacFUSE Core.pkg"
  73readonly M_PKGNAME=MacFUSE.pkg
  74readonly M_WANTSU="needs the Administrator password"
  75readonly M_WARNING="*** Warning"
  76
  77function m_help()
  78{
  79    cat <<__END_HELP_CONTENT
  80$M_PROGDESC version $M_PROGVERS
  81Copyright (C) 2008 Google. All Rights Reserved.
  82Usage:
  83  $M_PROGNAME [-dhqsv] [-c configuration] [-p platform] -t target
  84
  85  * configuration is one of: $M_CONFIGURATIONS (default is $m_configuration)
  86  * platform is one of: $M_PLATFORMS (default is the host's platform)
  87  * target is one of: $M_TARGETS
  88  * platforms can only be specified for: $M_TARGETS_WITH_PLATFORM
  89
  90The target keywords mean the following:
  91    clean       clean all targets
  92    dist        create a multiplatform distribution package
  93    examples    build example file systems (e.g. fusexmp_fh and hello)
  94    lib         build the user-space library (e.g. to run fusexmp_fh)
  95    libsrc      unpack and patch the user-space library source
  96    reload      rebuild and reload the kernel extension
  97    smalldist   create a platform-specific distribution package
  98    swconfigure configure software (e.g. sshfs) for compilation
  99
 100Other options are:
 101    -d  create a developer prerelease package instead of a regular release
 102    -q  enable quiet mode (suppresses verbose build output)
 103    -s  enable shortcircuit mode (useful for testing the build mechanism itself)
 104    -v  report version numbers and quit
 105__END_HELP_CONTENT
 106
 107    return 0
 108}
 109
 110# m_version()
 111#
 112function m_version
 113{
 114    echo "$M_PROGDESC version $M_PROGVERS"
 115
 116    m_set_platform
 117    m_set_srcroot "$m_platform"
 118
 119    local mv_platform_dirs=`ls -d "$m_srcroot"/core/10.*`
 120    for i in $mv_platform_dirs
 121    do
 122        local mv_release=`awk '/#define[ \t]*MACFUSE_VERSION_LITERAL/ {print $NF}' "$i/fusefs/common/fuse_version.h"`
 123        if [ ! -z "$mv_release" ]
 124        then
 125            echo "Platform source '$i': MacFUSE version $mv_release"
 126        fi
 127    done
 128
 129    return 0
 130}
 131
 132# m_log(msg)
 133#
 134function m_log()
 135{
 136    printf "%-30s: %s\n" "$M_LOGPREFIX($m_active_target)" "$*"
 137}
 138
 139# m_warn(msg)
 140#
 141function m_warn()
 142{
 143    echo "$M_WARNING: $*"
 144}
 145
 146# m_exit_on_error(errmsg)
 147#
 148function m_exit_on_error()
 149{
 150    if [ "$?" != 0 ]
 151    then
 152        local retval=$?
 153        echo "$M_LOGPREFIX($m_active_target) failed: $1" 1>&2
 154        exit $retval
 155    fi
 156
 157    # NOTREACHED
 158}
 159
 160# m_set_suprompt(msg)
 161#
 162function m_set_suprompt()
 163{
 164    m_suprompt="$M_LOGPREFIX($m_active_target) $M_WANTSU $*: "
 165}
 166
 167# m_set_srcroot([platform])
 168#
 169function m_set_srcroot()
 170{
 171    local macfuse_dir=""
 172    local is_absolute_path=`echo "$0" | cut -c1`
 173    if [ "$is_absolute_path" == "/" ]
 174    then
 175        macfuse_dir="`dirname $0`/.."
 176    else
 177        macfuse_dir="`pwd`/`dirname $0`/.."
 178    fi
 179    pushd . > /dev/null
 180    cd "$macfuse_dir" || exit 1
 181    macfuse_dir=`pwd`
 182    popd > /dev/null
 183
 184    m_srcroot="$macfuse_dir"
 185
 186    if [ "x$1" != "x" ] && [ "$1" != "$M_DEFAULT_PLATFORM" ]
 187    then
 188        m_srcroot_platformdir="$m_srcroot/core/$1"
 189        if [ ! -d "$m_srcroot_platformdir" ]
 190        then
 191            m_srcroot_platformdir="$M_DEFAULT_VALUE"
 192            m_warn "directory '$m_srcroot/$1' does not exist."
 193        fi
 194    fi
 195
 196    return 0
 197}
 198
 199# m_set_platform()
 200#
 201function m_set_platform()
 202{
 203    local retval=0
 204
 205    if [ "$m_platform" == "$M_DEFAULT_PLATFORM" ]
 206    then
 207       m_platform=`sw_vers -productVersion | cut -d . -f 1,2`
 208    fi
 209
 210    # XXX For now
 211    if [ "$m_platform" == "10.6" ]
 212    then
 213        m_platform="10.5"
 214    fi
 215
 216    case "$m_platform" in
 217    10.4*)
 218        m_osname="Tiger"
 219        m_usdk_dir="/Developer/SDKs/MacOSX10.4u.sdk"
 220    ;;
 221    10.5*)
 222        m_osname="Leopard"
 223        m_usdk_dir="/Developer/SDKs/MacOSX10.5.sdk"
 224    ;;
 225    10.6*)
 226        m_osname="Snow Leopard"
 227        m_usdk_dir="/Developer/SDKs/MacOSX10.6.sdk"
 228    ;;
 229    *)
 230        m_osname="Unknown"
 231        m_usdk_dir=""
 232        retval=1
 233    ;;
 234    esac
 235
 236    return $retval
 237}
 238
 239# m_build_pkg(pkgversion, install_srcroot, install_payload, pkgname, output_dir)
 240#
 241function m_build_pkg()
 242{
 243    local bp_pkgversion=$1
 244    local bp_install_srcroot=$2
 245    local bp_install_payload=$3
 246    local bp_pkgname=$4
 247    local bp_output_dir=$5
 248
 249    local bp_infoplist_in="$bp_install_srcroot/Info.plist.in"
 250    local bp_infoplist_out="$bp_output_dir/Info.plist"
 251    local bp_descriptionplist="$bp_install_srcroot/Description.plist"
 252
 253    # Fix up the Info.plist
 254    #
 255    sed -e "s/MACFUSE_VERSION_LITERAL/$bp_pkgversion/g" \
 256        < "$bp_infoplist_in" > "$bp_infoplist_out"
 257    m_exit_on_error "cannot finalize Info.plist for package '$bp_pkgname'."
 258
 259    # Get rid of .svn files from M_INSTALL_RESOURCES_DIR
 260    #
 261    (tar -C "$bp_install_srcroot" --exclude '.svn' -cpvf - \
 262        "$M_INSTALL_RESOURCES_DIR" | tar -C "$bp_output_dir/" \
 263            -xpvf - >$m_stdout 2>$m_stderr)>$m_stdout 2>$m_stderr
 264    m_exit_on_error "cannot migrate resources from '$M_INSTALL_RESOURCES_DIR'."
 265
 266    # Make the package
 267    m_set_suprompt "to run packagemaker"
 268    sudo -p "$m_suprompt" \
 269        packagemaker -build -p "$bp_output_dir/$bp_pkgname"    \
 270          -f "$bp_install_payload" -b "$M_CONF_TMPDIR" -ds -v  \
 271          -r "$bp_output_dir/$M_INSTALL_RESOURCES_DIR" -i "$bp_infoplist_out" \
 272          -d "$bp_descriptionplist" >$m_stdout 2>$m_stderr
 273    m_exit_on_error "cannot create package '$bp_pkgname'."
 274
 275    return 0
 276}
 277
 278# Prepare the user-space library source
 279#
 280function m_handler_libsrc()
 281{
 282    m_active_target="libsrc"
 283
 284    m_set_platform
 285
 286    m_set_srcroot "$m_platform"
 287
 288    local lib_dir="$m_srcroot"/core/"$m_platform"/libfuse
 289    if [ ! -d "$lib_dir" ]
 290    then
 291        false
 292        m_exit_on_error "cannot access directory '$lib_dir'."
 293    fi
 294
 295    local kernel_dir="$m_srcroot"/core/"$m_platform"/fusefs
 296    if [ ! -d "$kernel_dir" ]
 297    then
 298        false
 299        m_exit_on_error "cannot access directory '$kernel_dir'."
 300    fi
 301
 302    local package_dir=`tar -tzvf "$lib_dir/$M_LIBFUSE_SRC" | head -1 | awk '{print $NF}'`
 303    if [ "x$package_dir" == "x" ]
 304    then
 305        false
 306        m_exit_on_error "cannot determine MacFUSE library version."
 307    fi
 308
 309    local package_name=`basename "$package_dir"`
 310
 311    if [ "x$package_name" == "x" ]
 312    then
 313        false
 314        m_exit_on_error "cannot determine MacFUSE library version."
 315    fi
 316
 317    rm -rf "$M_CONF_TMPDIR/$package_name"
 318
 319    if [ "$1" == "clean" ]
 320    then
 321        local retval=$?
 322        m_log "cleaned (platform $m_platform)"
 323        return $retval
 324    fi
 325
 326    m_log "initiating Universal build for $m_platform"
 327
 328    tar -C "$M_CONF_TMPDIR" -xzvf "$lib_dir/$M_LIBFUSE_SRC" \
 329        >$m_stdout 2>$m_stderr
 330    m_exit_on_error "cannot untar MacFUSE library source from '$M_LIBFUSE_SRC'."
 331
 332    cd "$M_CONF_TMPDIR/$package_name"
 333    m_exit_on_error "cannot access MacFUSE library source in '$M_CONF_TMPDIR/$package_name'."
 334
 335    m_log "preparing library source"
 336    patch -p1 < "$lib_dir/$M_LIBFUSE_PATCH" >$m_stdout 2>$m_stderr
 337    m_exit_on_error "cannot patch MacFUSE library source."
 338
 339    echo >$m_stdout
 340    m_log "succeeded, results in '$M_CONF_TMPDIR/$package_name'."
 341    echo >$m_stdout
 342
 343    return 0
 344}
 345
 346# Build the user-space library
 347#
 348function m_handler_lib()
 349{
 350    m_active_target="lib"
 351
 352    m_set_platform
 353
 354    m_set_srcroot "$m_platform"
 355
 356    local lib_dir="$m_srcroot"/core/"$m_platform"/libfuse
 357    if [ ! -d "$lib_dir" ]
 358    then
 359        false
 360        m_exit_on_error "cannot access directory '$lib_dir'."
 361    fi
 362
 363    local kernel_dir="$m_srcroot"/core/"$m_platform"/fusefs
 364    if [ ! -d "$kernel_dir" ]
 365    then
 366        false
 367        m_exit_on_error "cannot access directory '$kernel_dir'."
 368    fi
 369
 370    local package_dir=`tar -tzvf "$lib_dir/$M_LIBFUSE_SRC" | head -1 | awk '{print $NF}'`
 371    if [ "x$package_dir" == "x" ]
 372    then
 373        false
 374        m_exit_on_error "cannot determine MacFUSE library version."
 375    fi
 376
 377    local package_name=`basename "$package_dir"`
 378
 379    if [ "x$package_name" == "x" ]
 380    then
 381        false
 382        m_exit_on_error "cannot determine MacFUSE library version."
 383    fi
 384
 385    rm -rf "$M_CONF_TMPDIR/$package_name"
 386
 387    if [ "$1" == "clean" ]
 388    then
 389        local retval=$?
 390        m_log "cleaned (platform $m_platform)"
 391        return $retval
 392    fi
 393
 394    m_log "initiating Universal build for $m_platform"
 395
 396    tar -C "$M_CONF_TMPDIR" -xzvf "$lib_dir/$M_LIBFUSE_SRC" \
 397        >$m_stdout 2>$m_stderr
 398    m_exit_on_error "cannot untar MacFUSE library source from '$M_LIBFUSE_SRC'."
 399
 400    cd "$M_CONF_TMPDIR/$package_name"
 401    m_exit_on_error "cannot access MacFUSE library source in '$M_CONF_TMPDIR/$package_name'."
 402
 403    m_log "preparing library source"
 404    patch -p1 < "$lib_dir/$M_LIBFUSE_PATCH" >$m_stdout 2>$m_stderr
 405    m_exit_on_error "cannot patch MacFUSE library source."
 406
 407    m_log "configuring library source"
 408    /bin/sh ./darwin_configure.sh "$kernel_dir" >$m_stdout 2>$m_stderr
 409    m_exit_on_error "cannot configure MacFUSE library source for compilation."
 410
 411    m_log "running make"
 412    make -j2 >$m_stdout 2>$m_stderr
 413    m_exit_on_error "make failed while compiling the MacFUSE library."
 414
 415    echo >$m_stdout
 416    m_log "succeeded, results in '$M_CONF_TMPDIR/$package_name'."
 417    echo >$m_stdout
 418
 419    return 0
 420}
 421
 422# Rebuild and reload the kernel extension
 423#
 424function m_handler_reload()
 425{
 426    m_active_target="reload"
 427
 428    # Argument validation would have ensured that we use native platform
 429    # for this target.
 430
 431    m_set_platform
 432
 433    m_set_srcroot "$m_platform"
 434
 435    local kernel_dir="$m_srcroot/core/$m_platform/fusefs"
 436    if [ ! -d "$kernel_dir" ]
 437    then
 438        false
 439        m_exit_on_error "cannot access directory '$kernel_dir'."
 440    fi
 441
 442    if [ -e "$M_CONF_TMPDIR/$M_KEXT_NAME" ]
 443    then
 444        m_set_suprompt "to remove old MacFUSE kext"
 445        sudo -p "$m_suprompt" rm -rf "$M_CONF_TMPDIR/$M_KEXT_NAME"
 446        m_exit_on_error "cannot remove old copy of MacFUSE kext."
 447    fi
 448
 449    if [ -e "$M_CONF_TMPDIR/$M_KEXT_SYMBOLS" ]
 450    then
 451        m_set_suprompt "to remove old copy of MacFUSE kext symbols"
 452        sudo -p "$m_suprompt" rm -rf "$M_CONF_TMPDIR/$M_KEXT_SYMBOLS"
 453        m_exit_on_error "cannot remove old copy of MacFUSE kext symbols."
 454    fi
 455
 456    if [ "$1" == "clean" ]
 457    then
 458        rm -rf "$kernel_dir/build/"
 459        local retval=$? 
 460        m_log "cleaned (platform $m_platform)"
 461        return $retval
 462    fi
 463
 464    m_log "initiating kernel extension rebuild/reload for $m_platform"
 465
 466    kextstat -l -b "$M_KEXT_ID" | grep "$M_KEXT_ID" >/dev/null 2>/dev/null
 467    if [ "$?" == "0" ]
 468    then
 469        m_log "unloading kernel extension"
 470        m_set_suprompt "to unload MacFUSE kext"
 471        sudo -p "$m_suprompt" \
 472            kextunload -v -b "$M_KEXT_ID" >$m_stdout 2>$m_stderr
 473        m_exit_on_error "cannot unload kext '$M_KEXT_ID'."
 474    fi
 475
 476    cd "$kernel_dir"
 477    m_exit_on_error "failed to access the kext source directory '$kernel_dir'."
 478
 479    m_log "rebuilding kext"
 480
 481    xcodebuild -configuration Debug -target fusefs >$m_stdout 2>$m_stderr
 482    m_exit_on_error "xcodebuild cannot build configuration Debug for target fusefs."
 483 
 484    mkdir "$M_CONF_TMPDIR/$M_KEXT_SYMBOLS"
 485    m_exit_on_error "cannot create directory for MacFUSE kext symbols."
 486
 487    cp -R "$kernel_dir/build/Debug/$M_KEXT_NAME" "$M_CONF_TMPDIR/$M_KEXT_NAME"
 488    m_exit_on_error "cannot copy newly built MacFUSE kext."
 489
 490    m_set_suprompt "to set permissions on newly built MacFUSE kext"
 491    sudo -p "$m_suprompt" chown -R root:wheel "$M_CONF_TMPDIR/$M_KEXT_NAME"
 492    m_exit_on_error "cannot set permissions on newly built MacFUSE kext."
 493
 494    m_log "reloading kext"
 495
 496    m_set_suprompt "to load newly built MacFUSE kext"
 497    sudo -p "$m_suprompt" \
 498        kextload -s "$M_CONF_TMPDIR/$M_KEXT_SYMBOLS" \
 499            -v "$M_CONF_TMPDIR/$M_KEXT_NAME" >$m_stdout 2>$m_stderr
 500    m_exit_on_error "cannot load newly built MacFUSE kext."
 501
 502    echo >$m_stdout
 503    m_log "checking status of kernel extension"
 504    kextstat -l -b "$M_KEXT_ID"
 505    echo >$m_stdout
 506
 507    echo >$m_stdout
 508    m_log "succeeded, results in '$M_CONF_TMPDIR'."
 509    echo >$m_stdout
 510
 511    return 0
 512}
 513
 514# Build examples from the user-space MacFUSE library
 515#
 516function m_handler_examples()
 517{
 518    m_active_target="examples"
 519
 520    m_set_platform
 521
 522    m_set_srcroot "$m_platform"
 523
 524    local lib_dir="$m_srcroot"/core/"$m_platform"/libfuse
 525    if [ ! -d "$lib_dir" ]
 526    then
 527        false
 528        m_exit_on_error "cannot access directory '$lib_dir'."
 529    fi
 530
 531    local kernel_dir="$m_srcroot"/core/"$m_platform"/fusefs
 532    if [ ! -d "$kernel_dir" ]
 533    then
 534        false
 535        m_exit_on_error "cannot access directory '$kernel_dir'."
 536    fi
 537
 538    local package_dir=`tar -tzvf "$lib_dir/$M_LIBFUSE_SRC" | head -1 | awk '{print $NF}'`
 539    if [ "x$package_dir" == "x" ]
 540    then
 541        false
 542        m_exit_on_error "cannot determine MacFUSE library version."
 543    fi
 544
 545    local package_name=`basename "$package_dir"`
 546
 547    if [ "x$package_name" == "x" ]
 548    then
 549        false
 550        m_exit_on_error "cannot determine MacFUSE library version."
 551    fi
 552
 553    rm -rf "$M_CONF_TMPDIR/$package_name"
 554
 555    if [ "$1" == "clean" ]
 556    then
 557        local retval=$?
 558        m_log "cleaned (platform $m_platform)"
 559        return $retval
 560    fi
 561
 562    m_log "initiating Universal build for $m_platform"
 563
 564    tar -C "$M_CONF_TMPDIR" -xzvf "$lib_dir/$M_LIBFUSE_SRC" \
 565        >$m_stdout 2>$m_stderr
 566    m_exit_on_error "cannot untar MacFUSE library source from '$M_LIBFUSE_SRC'."
 567
 568    cd "$M_CONF_TMPDIR/$package_name"
 569    m_exit_on_error "cannot access MacFUSE library source in '$M_CONF_TMPDIR/$package_name'."
 570
 571    m_log "preparing library source"
 572    patch -p1 < "$lib_dir/$M_LIBFUSE_PATCH" >$m_stdout 2>$m_stderr
 573    m_exit_on_error "cannot patch MacFUSE library source."
 574
 575    m_log "configuring library source"
 576    /bin/sh ./darwin_configure_ino64.sh "$kernel_dir" >$m_stdout 2>$m_stderr
 577    m_exit_on_error "cannot configure MacFUSE library source for compilation."
 578
 579    cd example
 580    m_exit_on_error "cannot access examples source."
 581
 582    local me_installed_lib="/usr/local/lib/libfuse_ino64.la"
 583    if [ "$m_platform" == "10.4" ]
 584    then
 585        me_installed_lib="/usr/local/lib/libfuse.la"
 586    fi
 587
 588    perl -pi -e "s#../lib/libfuse.la#$me_installed_lib#g" Makefile
 589    m_exit_on_error "failed to prepare example source for build."
 590
 591    m_log "running make"
 592    make -j2 >$m_stdout 2>$m_stderr
 593    m_exit_on_error "make failed while compiling the MacFUSE examples."
 594
 595    echo >$m_stdout
 596    m_log "succeeded, results in '$M_CONF_TMPDIR/$package_name/example'."
 597    echo >$m_stdout
 598
 599    return 0
 600}
 601
 602# Build a multiplatform distribution package
 603#
 604function m_handler_dist()
 605{
 606    m_active_target="dist"
 607
 608    if [ "$1" == "clean" ]
 609    then
 610        for m_p in $M_PLATFORMS_REALISTIC
 611        do
 612            m_platform="$m_p"
 613            m_handler_smalldist clean
 614        done
 615
 616        m_active_target="dist"
 617
 618        m_set_platform
 619
 620        m_set_srcroot "$m_platform"
 621
 622        rm -rf "$m_srcroot/core/autoinstaller/build"
 623        m_log "cleaned internal subtarget autoinstaller"
 624
 625        rm -rf "$m_srcroot/core/prefpane/build"
 626        m_log "cleaned internal subtarget prefpane"
 627
 628        m_release=`awk '/#define[ \t]*MACFUSE_VERSION_LITERAL/ {print $NF}' "$m_srcroot/core/$m_platform/fusefs/common/fuse_version.h" | cut -d . -f 1,2`
 629        if [ ! -z "$m_release" ]
 630        then
 631            if [ -e "$M_CONF_TMPDIR/macfuse-$m_release" ]
 632            then
 633                m_set_suprompt "to remove previous output packages"
 634                sudo -p "$m_suprompt" rm -rf "$M_CONF_TMPDIR/macfuse-$m_release"
 635                m_log "cleaned any previous output packages in '$M_CONF_TMPDIR'"
 636            fi
 637        fi
 638
 639        return 0
 640    fi
 641
 642    m_log "initiating Universal build of MacFUSE"
 643
 644    m_set_platform
 645    m_set_srcroot "$m_platform"
 646
 647    m_log "configuration is '$m_configuration'"
 648    if [ "$m_developer" == "0" ]
 649    then
 650        m_log "packaging flavor is 'Mainstream'"
 651    else
 652        m_log "packaging flavor is 'Developer Prerelease'"
 653    fi
 654
 655    m_log "locating MacFUSE private key"
 656    if [ ! -f "$M_CONF_PRIVKEY" ]
 657    then
 658        false
 659        m_exit_on_error "cannot find MacFUSE private key in '$M_CONF_PRIVKEY'."
 660    fi
 661
 662    # Autoinstaller
 663    #
 664
 665    local md_ai_builddir="$m_srcroot/core/autoinstaller/build"
 666
 667    if [ "$m_shortcircuit" != "1" ]
 668    then
 669        rm -rf "$md_ai_builddir"
 670        # ignore any errors
 671    fi
 672
 673    m_log "building the MacFUSE autoinstaller"
 674
 675    pushd "$m_srcroot/core/autoinstaller" >/dev/null 2>/dev/null
 676    m_exit_on_error "cannot access the autoinstaller source."
 677    xcodebuild -configuration "$m_configuration" -target "Build All" \
 678        >$m_stdout 2>$m_stderr
 679    m_exit_on_error "xcodebuild cannot build configuration $m_configuration for subtarget autoinstaller."
 680    popd >/dev/null 2>/dev/null
 681
 682    local md_ai="$md_ai_builddir/$m_configuration/autoinstall-macfuse-core"
 683    if [ ! -x "$md_ai" ]
 684    then
 685        false
 686        m_exit_on_error "cannot find autoinstaller '$md_ai'."
 687    fi
 688    local md_plistsigner="$md_ai_builddir/$m_configuration/plist_signer"
 689    if [ ! -x "$md_plistsigner" ]
 690    then
 691        false
 692        m_exit_on_error "cannot find plist signer '$md_plistsigner'."
 693    fi
 694
 695    # Create platform-Specific MacFUSE subpackages
 696    #
 697    for m_p in $M_PLATFORMS_REALISTIC
 698    do
 699        pushd . >/dev/null 2>/dev/null
 700        m_active_target="dist"
 701        m_platform="$m_p"
 702        m_log "building platform $m_platform"
 703        m_handler_smalldist
 704        popd >/dev/null 2>/dev/null
 705    done
 706
 707    # Build the preference pane
 708    #
 709    local md_pp_builddir="$m_srcroot/core/prefpane/build"
 710
 711    if [ "$m_shortcircuit" != "1" ]
 712    then
 713        rm -rf "$md_pp_builddir"
 714        # ignore any errors
 715    fi
 716
 717    m_log "building the MacFUSE prefpane"
 718
 719    pushd "$m_srcroot/core/prefpane" >/dev/null 2>/dev/null
 720    m_exit_on_error "cannot access the prefpane source."
 721    xcodebuild -configuration "$m_configuration" -target "MacFUSE" \
 722        >$m_stdout 2>$m_stderr
 723    m_exit_on_error "xcodebuild cannot build configuration $m_configuration for subtarget prefpane."
 724    popd >/dev/null 2>/dev/null
 725
 726    local md_pp="$md_pp_builddir/$m_configuration/MacFUSE.prefPane"
 727    if [ ! -d "$md_pp" ]
 728    then
 729        false
 730        m_exit_on_error "cannot find preference pane."
 731    fi
 732
 733    cp "$md_ai" "$md_pp/Contents/MacOS"
 734    m_exit_on_error "cannot copy the autoinstaller to the prefpane bundle."
 735
 736    # Build the container
 737    #
 738
 739    m_active_target="dist"
 740
 741    m_release=`awk '/#define[ \t]*MACFUSE_VERSION_LITERAL/ {print $NF}' "$m_srcroot/core/$m_platform/fusefs/common/fuse_version.h" | cut -d . -f 1,2`
 742    m_exit_on_error "cannot get MacFUSE release version."
 743
 744    local md_macfuse_out="$M_CONF_TMPDIR/macfuse-$m_release"
 745    local md_macfuse_root="$md_macfuse_out/pkgroot/"
 746
 747    if [ -e "$md_macfuse_out" ]
 748    then
 749        m_set_suprompt "to remove a previously built container package"
 750        sudo -p "$m_suprompt" rm -rf "$md_macfuse_out"
 751        # ignore any errors
 752    fi
 753
 754    m_log "initiating distribution build"
 755
 756    local md_platforms=""
 757    local md_platform_dirs=`ls -d "$M_CONF_TMPDIR"/macfuse-core-*${m_release}.* | paste -s -`
 758    m_log "found payloads $md_platform_dirs"
 759    for i in $md_platform_dirs
 760    do
 761        local md_tmp_versions=${i#*core-}
 762        local md_tmp_release_version=${md_tmp_versions#*-}
 763        local md_tmp_os_version=${md_tmp_versions%-*}
 764
 765        md_platforms="${md_platforms},${md_tmp_os_version}=${i}/$M_PKGNAME_CORE"
 766
 767        case "$md_tmp_os_version" in
 768        10.4)
 769            m_version_tiger=$md_tmp_release_version
 770        ;;
 771        10.5)
 772            m_version_leopard=$md_tmp_release_version
 773        ;;
 774        10.6)
 775            m_version_snowleopard=$md_tmp_release_version
 776        ;;
 777        esac
 778
 779        m_log "adding [ '$md_tmp_os_version', '$md_tmp_release_version' ]"
 780    done
 781
 782    m_log "building '$M_PKGNAME'"
 783
 784    mkdir "$md_macfuse_out"
 785    m_exit_on_error "cannot create directory '$md_macfuse_out'."
 786
 787    mkdir "$md_macfuse_root"
 788    m_exit_on_error "cannot create directory '$md_macfuse_root'."
 789
 790    m_log "copying generic container package payload"
 791    mkdir -p "$md_macfuse_root/Library/PreferencePanes"
 792    m_exit_on_error "cannot make directory '$md_macfuse_root/Library/PreferencePanes'."
 793    cp -R "$md_pp" "$md_macfuse_root/Library/PreferencePanes/"
 794    m_exit_on_error "cannot copy the prefpane to '$md_macfuse_root/Library/PreferencePanes/'."
 795    m_set_suprompt "to chown '$md_macfuse_root/'."
 796    sudo -p "$m_suprompt" chown -R root:wheel "$md_macfuse_root/"
 797
 798    local md_srcroot="$m_srcroot/core/packaging/macfuse"
 799    local md_infoplist_in="$md_srcroot/Info.plist.in"
 800    local md_infoplist_out="$md_macfuse_out/Info.plist"
 801    local md_descriptionplist="$md_srcroot/Description.plist"
 802    local md_install_resources="$md_macfuse_out/$M_INSTALL_RESOURCES_DIR"
 803
 804    # Get rid of .svn files from M_INSTALL_RESOURCES_DIR
 805    #
 806    (tar -C "$md_srcroot" --exclude '.svn' -cpvf - \
 807        "$M_INSTALL_RESOURCES_DIR" | tar -C "$md_macfuse_out" -xpvf - \
 808            >$m_stdout 2>$m_stderr)>$m_stdout 2>$m_stderr
 809
 810    # Copy subpackage platform directories under Resources
 811    #
 812
 813    local md_pkg_size=0
 814    local md_saved_ifs="$IFS"
 815    IFS=","
 816    for i in $md_platforms
 817    do
 818        if [ x"$i" == x"" ]
 819        then
 820            continue;  # Skip empty/bogus comma-item
 821        fi
 822
 823        local md_tmp_os_version=${i%%=*}
 824        local md_tmp_core_pkg=${i##*=}
 825        local md_tmp_core_pkg_dir=$(dirname "$md_tmp_core_pkg")
 826        local md_tmp_core_pkg_name=$(basename "$md_tmp_core_pkg")
 827        local md_tmp_pkg_dst="$md_install_resources/$md_tmp_os_version"
 828
 829        local md_tmp_new_size=$(defaults read "$md_tmp_core_pkg/Contents/Info" IFPkgFlagInstalledSize)
 830        if [ -z "$md_tmp_new_size" ]
 831        then
 832            m_warn "unable to read package size from '$md_tmp_core_pkg'."
 833        fi
 834        if [ $md_tmp_new_size -gt $md_pkg_size ]
 835        then
 836            md_pkg_size=$md_tmp_new_size
 837        fi
 838
 839        mkdir "$md_tmp_pkg_dst"
 840        m_exit_on_error "cannot make package subdirectory '$md_tmp_pkg_dst'."
 841
 842        m_set_suprompt "to add platform-specific package to container"
 843        (sudo -p "$m_suprompt" tar -C "$md_tmp_core_pkg_dir" -cpvf - "$md_tmp_core_pkg_name" | sudo -p "$m_suprompt" tar -C "$md_tmp_pkg_dst" -xpvf - >$m_stdout 2>$m_stderr)>$m_stdout 2>$m_stderr
 844        m_exit_on_error "cannot add package."
 845    done
 846    IFS="$md_saved_ifs"
 847
 848    # XXX For now, make 10.5 also valid for 10.6
 849    #
 850    if [ -d "$md_install_resources/10.5" ]
 851    then
 852        ln -s "10.5" "$md_install_resources/10.6"
 853    fi
 854
 855    # Throw in the autoinstaller
 856    #
 857    cp "$md_ai" "$md_install_resources"
 858    m_exit_on_error "cannot copy '$md_ai' to '$md_install_resources'."
 859
 860    # Fix up the container's Info.plist
 861    #
 862    sed -e "s/MACFUSE_PKG_VERSION_LITERAL/$m_release/g"  \
 863        -e "s/MACFUSE_PKG_INSTALLED_SIZE/$md_pkg_size/g" \
 864            < "$md_infoplist_in" > "$md_infoplist_out"
 865    m_exit_on_error "cannot fix the Info.plist of the container package."
 866
 867    # Create the big package
 868    #
 869    m_set_suprompt "to run packagemaker for the container package"
 870    sudo -p "$m_suprompt" \
 871        packagemaker -build -p "$md_macfuse_out/$M_PKGNAME" \
 872          -f "$md_macfuse_root" -b "$M_CONF_TMPDIR" -ds -v  \
 873          -r "$md_install_resources" -i "$md_infoplist_out" \
 874          -d "$md_descriptionplist" >$m_stdout 2>$m_stderr
 875    m_exit_on_error "cannot create container package '$M_PKGNAME'."
 876
 877    # Create the distribution volume
 878    #
 879    local md_volume_name="MacFUSE $m_release"
 880    local md_scratch_dmg="$md_macfuse_out/macfuse-scratch.dmg"
 881    hdiutil create -layout NONE -megabytes 10 -fs HFS+ \
 882        -volname "$md_volume_name" "$md_scratch_dmg" >$m_stdout 2>$m_stderr
 883    m_exit_on_error "cannot create scratch MacFUSE disk image."
 884
 885    # Attach/mount the volume
 886    #
 887    hdiutil attach -private -nobrowse "$md_scratch_dmg" >$m_stdout 2>$m_stderr
 888    m_exit_on_error "cannot attach scratch MacFUSE disk image."
 889
 890    # Create the .engine_install file
 891    #
 892    local md_volume_path="/Volumes/$md_volume_name"
 893    local md_engine_install="$md_volume_path/.engine_install"
 894cat > "$md_engine_install" <<__END_ENGINE_INSTALL
 895#!/bin/sh -p
 896/usr/sbin/installer -pkg "\$1/$M_PKGNAME" -target /
 897__END_ENGINE_INSTALL
 898
 899    chmod +x "$md_engine_install"
 900    m_exit_on_error "cannot set permissions on autoinstaller engine file."
 901
 902    # For backward compatibility, we need a .keystone_install too
 903    #
 904    ln -s ".engine_install" "$md_volume_path/.keystone_install"
 905    # ignore any errors
 906
 907    # Copy over the package
 908    #
 909    cp -pRX "$md_macfuse_out/$M_PKGNAME" "$md_volume_path"
 910    if [ $? -ne 0 ]
 911    then
 912        hdiutil detach "$md_volume_path" >$m_stdout 2>$m_stderr
 913        false
 914        m_exit_on_error "cannot copy '$M_PKGNAME' to scratch disk image."
 915    fi
 916
 917    # Set the custom icon
 918    #
 919    cp -pRX "$md_install_resources/.VolumeIcon.icns" \
 920        "$md_volume_path/.VolumeIcon.icns"
 921    m_exit_on_error "cannot copy custom volume icon to scratch disk image."
 922
 923    /Developer/Tools/SetFile -a C "$md_volume_path"
 924    m_exit_on_error "cannot set custom volume icon on scratch disk image."
 925
 926    # Copy over the license file
 927    #
 928    cp "$md_install_resources/License.rtf" "$md_volume_path/License.rtf"
 929    m_exit_on_error "cannot copy MacFUSE license to scratch disk image."
 930
 931    # Copy over the CHANGELOG.txt file
 932    #
 933    cp "$m_srcroot/CHANGELOG.txt" "$md_volume_path/CHANGELOG.txt"
 934    m_exit_on_error "cannot copy MacFUSE CHANGELOG to scratch disk image."
 935
 936    # Detach the volume.
 937    hdiutil detach "$md_volume_path" >$m_stdout 2>$m_stderr
 938    if [ $? -ne 0 ]
 939    then
 940        false
 941        m_exit_on_error "cannot detach volume '$md_volume_path'."
 942    fi
 943
 944    # Convert to a read-only compressed dmg
 945    #
 946    local md_dmg_name="MacFUSE-$m_release.dmg"
 947    local md_dmg_path="$md_macfuse_out/$md_dmg_name"
 948    hdiutil convert -imagekey zlib-level=9 -format UDZO "$md_scratch_dmg" \
 949        -o "$md_dmg_path" >$m_stdout 2>$m_stderr
 950    m_exit_on_error "cannot finalize MacFUSE distribution disk image."
 951
 952    rm -f "$md_scratch_dmg"
 953    # ignore any errors
 954
 955    m_log "creating autoinstaller rules"
 956
 957    # Make autoinstaller rules file
 958    #
 959    local md_dmg_hash=$(openssl sha1 -binary "$md_dmg_path" | openssl base64)
 960    local md_dmg_size=$(stat -f%z "$md_dmg_path")
 961
 962    local md_rules_plist="$md_macfuse_out/DeveloperRelease.plist"
 963    local md_download_url="http://macfuse.googlecode.com/svn/releases/developer/$md_dmg_name"
 964    if [ "$m_developer" == "0" ]
 965    then
 966        md_rules_plist="$md_macfuse_out/CurrentRelease.plist"
 967        md_download_url="http://macfuse.googlecode.com/svn/releases/$md_dmg_name"
 968    fi
 969
 970cat > "$md_rules_plist" <<__END_RULES_PLIST
 971<?xml version="1.0" encoding="UTF-8"?>
 972<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
 973<plist version="1.0">
 974<dict>
 975  <key>Rules</key>
 976  <array>
 977    <dict>
 978      <key>ProductID</key>
 979      <string>$M_MACFUSE_PRODUCT_ID</string>
 980      <key>Predicate</key>
 981      <string>SystemVersion.ProductVersion beginswith "10.6" AND Ticket.version != "$m_version_leopard"</string>
 982      <key>Version</key>
 983      <string>$m_version_leopard</string>
 984      <key>Codebase</key>
 985      <string>$md_download_url</string>
 986      <key>Hash</key>
 987      <string>$md_dmg_hash</string>
 988      <key>Size</key>
 989      <string>$md_dmg_size</string>
 990    </dict>
 991    <dict>
 992      <key>ProductID</key>
 993      <string>$M_MACFUSE_PRODUCT_ID</string>
 994      <key>Predicate</key>
 995      <string>SystemVersion.ProductVersion beginswith "10.5" AND Ticket.version != "$m_version_leopard"</string>
 996      <key>Version</key>
 997      <string>$m_version_leopard</string>
 998      <key>Codebase</key>
 999      <string>$md_download_url</string>
1000      <key>Hash</key>
1001      <string>$md_dmg_hash</string>
1002      <key>Size</key>
1003      <string>$md_dmg_size</string>
1004    </dict>
1005    <dict>
1006      <key>ProductID</key>
1007      <string>$M_MACFUSE_PRODUCT_ID</string>
1008      <key>Predicate</key>
1009      <string>SystemVersion.ProductVersion beginswith "10.4" AND Ticket.version != "$m_version_tiger"</string>
1010      <key>Version</key>
1011      <string>$m_version_tiger</string>
1012      <key>Codebase</key>
1013      <string>$md_download_url</string>
1014      <key>Hash</key>
1015      <string>$md_dmg_hash</string>
1016      <key>Size</key>
1017      <string>$md_dmg_size</string>
1018    </dict>
1019  </array>
1020</dict>
1021</plist>
1022__END_RULES_PLIST
1023
1024    # Sign the output rules
1025    #
1026  
1027    m_log "signing autoinstaller rules"
1028
1029    m_set_suprompt "to sign the rules file"
1030    sudo -p "$m_suprompt" \
1031        "$md_plistsigner" --sign --key "$M_CONF_PRIVKEY" \
1032            "$md_rules_plist" >$m_stdout 2>$m_stderr
1033    m_exit_on_error "cannot sign the rules file '$md_rules_plist' with key '$M_CONF_PRIVKEY'."
1034
1035    echo >$m_stdout
1036    m_log "succeeded, results in '$md_macfuse_out'."
1037    echo >$m_stdout
1038
1039    return 0
1040}
1041
1042
1043# Build a platform-specific distribution package
1044#
1045function m_handler_smalldist()
1046{
1047    m_active_target="smalldist"
1048
1049    m_set_platform
1050
1051    m_set_srcroot "$m_platform"
1052
1053    local lib_dir="$m_srcroot"/core/"$m_platform"/libfuse
1054    if [ ! -d "$lib_dir" ]
1055    then
1056        false
1057        m_exit_on_error "cannot access directory '$lib_dir'."
1058    fi
1059
1060    local kernel_dir="$m_srcroot"/core/"$m_platform"/fusefs
1061    if [ ! -d "$kernel_dir" ]
1062    then
1063        false
1064        m_exit_on_error "cannot access directory '$kernel_dir'."
1065    fi
1066
1067    if [ "$m_shortcircuit" != "1" ]
1068    then
1069        rm -rf "$kernel_dir/build/"
1070        rm -rf "$m_srcroot/core/sdk-objc/build/"
1071    fi
1072
1073    local ms_os_version="$m_platform"
1074    local ms_macfuse_version=`awk '/#define[ \t]*MACFUSE_VERSION_LITERAL/ {print $NF}' "$kernel_dir"/common/fuse_version.h`
1075    m_exit_on_error "cannot get platform-specific MacFUSE version."
1076
1077    local ms_macfuse_out="$M_CONF_TMPDIR/macfuse-core-$ms_os_version-$ms_macfuse_version"
1078    local ms_macfuse_build="$ms_macfuse_out/build/"
1079    local ms_macfuse_root="$ms_macfuse_out/pkgroot/"
1080
1081    if [ "$m_shortcircuit" != "1" ]
1082    then
1083        if [ -e "$ms_macfuse_out" ]
1084        then
1085            m_set_suprompt "to remove a previously built platform-specific package"
1086            sudo -p "$m_suprompt" rm -rf "$ms_macfuse_out"
1087            m_exit_on_error "failed to clean up previous platform-specific MacFUSE build."
1088        fi
1089        if [ -e "$M_CONF_TMPDIR/macfuse-core-$ms_os_version-"* ]
1090        then
1091            m_warn "removing unrecognized version of platform-specific package"
1092            m_set_suprompt "to remove unrecognized version of platform-specific package"
1093            sudo -p "$m_suprompt" rm -rf "$M_CONF_TMPDIR/macfuse-core-$ms_os_version-"*
1094            m_exit_on_error "failed to clean up unrecognized version of platform-specific package."
1095        fi
1096    else
1097        if [ -e "$ms_macfuse_out/$M_PKGNAME_CORE" ]
1098        then
1099            echo >$m_stdout
1100            m_log "succeeded (shortcircuited), results in '$ms_macfuse_out'."
1101            echo >$m_stdout
1102            return 0
1103        fi
1104    fi
1105
1106    if [ "$1" == "clean" ]
1107    then
1108        local retval=$?
1109        m_log "cleaned (platform $m_platform)"
1110        return $retval
1111    fi
1112
1113    m_log "initiating Universal build for $m_platform"
1114
1115    cd "$kernel_dir"
1116    m_exit_on_error "failed to access the kext source directory '$kernel_dir'."
1117
1118    m_log "building MacFUSE kernel extension and tools"
1119
1120    if [ "$m_developer" == "0" ]
1121    then
1122        xcodebuild -configuration "$m_configuration" -target All >$m_stdout 2>$m_stderr
1123    else
1124        xcodebuild MACFUSE_BUILD_FLAVOR=Beta -configuration "$m_configuration" -target All >$m_stdout 2>$m_stderr
1125    fi
1126
1127    m_exit_on_error "xcodebuild cannot build configuration $m_configuration."
1128
1129    # Go for it
1130
1131    local ms_project_dir="$kernel_dir"
1132
1133    local ms_built_products_dir="$kernel_dir/build/$m_configuration/"
1134    if [ ! -d "$ms_built_products_dir" ]
1135    then
1136        m_exit_on_error "cannot find built products directory."
1137    fi
1138
1139    if [ "$m_platform" == "10.4" ]
1140    then
1141        ms_macfuse_system_dir="/System"
1142    else
1143        ms_macfuse_system_dir=""
1144    fi
1145
1146    mkdir -p "$ms_macfuse_build"
1147    m_exit_on_error "cannot make new build directory '$ms_macfuse_build'."
1148
1149    mkdir -p "$ms_macfuse_root"
1150    m_exit_on_error "cannot make directory '$ms_macfuse_root'."
1151
1152    mkdir -p "$ms_macfuse_root$ms_macfuse_system_dir/Library/Filesystems/"
1153    m_exit_on_error "cannot make directory '$ms_macfuse_root$ms_macfuse_system_dir/Library/Filesystems/'."
1154
1155    mkdir -p "$ms_macfuse_root/Library/Frameworks/"
1156    m_exit_on_error "cannot make directory '$ms_macfuse_root/Library/Frameworks/'."
1157
1158    mkdir -p "$ms_macfuse_root/usr/local/lib/"
1159    m_exit_on_error "cannot make directory '$ms_macfuse_root/usr/local/lib/'."
1160
1161    mkdir -p "$ms_macfuse_root/usr/local/include/"
1162    m_exit_on_error "cannot make directory '$ms_macfuse_root/usr/local/include/'."
1163
1164    mkdir -p "$ms_macfuse_root/usr/local/lib/pkgconfig/"
1165    m_exit_on_error "cannot make directory '$ms_macfuse_root/usr/local/lib/pkgconfig/'."
1166
1167    local ms_bundle_dir_generic="/Library/Filesystems/$M_FSBUNDLE_NAME"
1168    local ms_bundle_dir="$ms_macfuse_root$ms_macfuse_system_dir/$ms_bundle_dir_generic"
1169    local ms_bundle_support_dir="$ms_bundle_dir/Support"
1170
1171    cp -pRX "$ms_built_products_dir/$M_FSBUNDLE_NAME" "$ms_bundle_dir"
1172    m_exit_on_error "cannot copy '$M_FSBUNDLE_NAME' to destination."
1173
1174    mkdir -p "$ms_bundle_support_dir"
1175    m_exit_on_error "cannot make directory '$ms_bundle_support_dir'."
1176
1177    cp -pRX "$ms_built_products_dir/$M_KEXT_NAME" "$ms_bundle_support_dir/$M_KEXT_NAME"
1178    m_exit_on_error "cannot copy '$M_KEXT_NAME' to destination."
1179
1180    cp -pRX "$ms_built_products_dir/load_fusefs" "$ms_bundle_support_dir/load_fusefs"
1181    m_exit_on_error "cannot copy 'load_fusefs' to destination."
1182
1183    cp -pRX "$ms_built_products_dir/mount_fusefs" "$ms_bundle_support_dir/mount_fusefs"
1184    m_exit_on_error "cannot copy 'mount_fusefs' to destination."
1185
1186    cp -pRX "$m_srcroot/core/$m_platform/packaging/macfuse-core/uninstall-macfuse-core.sh" "$ms_bundle_support_dir/uninstall-macfuse-core.sh"
1187    m_exit_on_error "cannot copy 'uninstall-macfuse-core.sh' to destination."
1188
1189    ln -s "/Library/PreferencePanes/MacFUSE.prefPane/Contents/MacOS/autoinstall-macfuse-core" "$ms_bundle_support_dir/autoinstall-macfuse-core"
1190    m_exit_on_error "cannot create legacy symlink '$ms_bundle_support_dir/autoinstall-macfuse-core'".
1191
1192    if [ "$m_platform" == "10.4" ]
1193    then
1194        mkdir -p "$ms_macfuse_root/Library/Filesystems"
1195        ln -s "$ms_macfuse_system_dir/$ms_bundle_dir_generic" "$ms_macfuse_root/$ms_bundle_dir_generic"
1196    fi
1197
1198    # Build the user-space MacFUSE library
1199    #
1200
1201    m_log "building user-space MacFUSE library"
1202
1203    tar -C "$ms_macfuse_build" -xzf "$lib_dir/$M_LIBFUSE_SRC" \
1204        >$m_stdout 2>$m_stderr
1205    m_exit_on_error "cannot untar MacFUSE library source from '$M_LIBFUSE_SRC'."
1206
1207    cd "$ms_macfuse_build"/fuse*
1208    m_exit_on_error "cannot access MacFUSE library source in '$ms_macfuse_build/fuse*'."
1209
1210    patch -p1 < "$lib_dir/$M_LIBFUSE_PATCH" >$m_stdout 2>$m_stderr
1211    m_exit_on_error "cannot patch MacFUSE library source."
1212
1213    /bin/sh ./darwin_configure.sh "$kernel_dir" >$m_stdout 2>$m_stderr
1214    m_exit_on_error "cannot configure MacFUSE library source for compilation."
1215
1216    make -j2 >$m_stdout 2>$m_stderr
1217    m_exit_on_error "make failed while compiling the MacFUSE library."
1218
1219    make install DESTDIR="$ms_macfuse_root" >$m_stdout 2>$m_stderr
1220    m_exit_on_error "cannot prepare library build for installation."
1221
1222    ln -s libfuse.dylib "$ms_macfuse_root/usr/local/lib/libfuse.0.dylib"
1223    m_exit_on_error "cannot create compatibility symlink."
1224
1225    rm -f "ms_macfuse_root"/usr/local/lib/*ulockmgr*
1226    # ignore any errors
1227
1228    rm -f "ms_macfuse_root"/usr/local/include/*ulockmgr*
1229    # ignore any errors
1230
1231    # Now build again, if necessary, with 64-bit inode support
1232    #
1233
1234    # ino64 is not supported on Tiger
1235
1236    if [ "$m_platform" != "10.4" ]
1237    then
1238
1239        m_log "building user-space MacFUSE library (ino64)"
1240
1241        cd "$ms_macfuse_build"/fuse*/lib
1242        m_exit_on_error "cannot access MacFUSE library (ino64) source in '$ms_macfuse_build/fuse*/lib'."
1243
1244        make clean >$m_stdout 2>$m_stderr
1245        m_exit_on_error "make failed while compiling the MacFUSE library (ino64)."
1246
1247        perl -pi -e 's#libfuse#libfuse_ino64#g' Makefile
1248        m_exit_on_error "failed to prepare MacFUSE library (ino64) for compilation."
1249
1250        perl -pi -e 's#-D__FreeBSD__=10#-D__DARWIN_64_BIT_INO_T=1 -D__FreeBSD__=10#g' Makefile
1251        m_exit_on_error "failed to prepare MacFUSE library (ino64) for compilation."
1252
1253        make -j2 >$m_stdout 2>$m_stderr
1254        m_exit_on_error "make failed while compiling the MacFUSE library (ino64)."
1255
1256        make install DESTDIR="$ms_macfuse_root" >$m_stdout 2>$m_stderr
1257        m_exit_on_error "cannot prepare MacFUSE library (ino64) build for installation."
1258
1259        rm -f "$ms_macfuse_root"/usr/local/lib/*ulockmgr*
1260        # ignore any errors
1261
1262        rm -f "$ms_macfuse_root"/usr/local/include/*ulockmgr*
1263        # ignore any errors
1264
1265        # generate dsym
1266        dsymutil "$ms_macfuse_root"/usr/local/lib/libfuse.dylib
1267        m_exit_on_error "cannot generate debugging information for libfuse."
1268        dsymutil "$ms_macfuse_root"/usr/local/lib/libfuse_ino64.dylib
1269        m_exit_on_error "cannot generate debugging information for libfuse_ino64."
1270
1271    fi # ino64 on > Tiger
1272
1273    # Build MacFUSE.framework
1274    #
1275
1276    m_log "building MacFUSE Objective-C SDK"
1277
1278    cd "$ms_project_dir/../../sdk-objc"
1279    m_exit_on_error "cannot access Objective-C SDK directory."
1280
1281    rm -rf build/
1282    m_exit_on_error "cannot remove previous build of MacFUSE.framework."
1283
1284    if [ "$m_platform" == "10.4" ]
1285    then
1286        xcodebuild -configuration "$m_configuration" -target "MacFUSE-$ms_os_version" "MACFUSE_BUILD_ROOT=$ms_macfuse_root" "MACFUSE_BUNDLE_VERSION_LITERAL=$ms_macfuse_version" "CUSTOM_CFLAGS=-DMACFUSE_TARGET_OS=MAC_OS_X_VERSION_10_4" >$m_stdout 2>$m_stderr
1287    else
1288        xcodebuild -configuration "$m_configuration" -target "MacFUSE-$ms_os_version" "MACFUSE_BUILD_ROOT=$ms_macfuse_root" "MACFUSE_BUNDLE_VERSION_LITERAL=$ms_macfuse_version" >$m_stdout 2>$m_stderr
1289    fi
1290    m_exit_on_error "xcodebuild cannot build configuration '$m_configuration'."
1291
1292    cp -pRX build/"$m_configuration"/*.framework "$ms_macfuse_root/Library/Frameworks/"
1293    m_exit_on_error "cannot copy 'MacFUSE.framework' to destination."
1294
1295    if [ "$m_platform" != "10.4" ]
1296    then
1297        mv "$ms_macfuse_root"/usr/local/lib/*.dSYM "$ms_macfuse_root"/Library/Frameworks/MacFUSE.framework/Resources/Debug/
1298        mkdir -p "$ms_macfuse_root/Library/Application Support/Developer/Shared/Xcode/Project Templates"
1299        m_exit_on_error "cannot create directory for Xcode templates."
1300        ln -s "/Library/Frameworks/MacFUSE.framework/Resources/ProjectTemplates/" "$ms_macfuse_root/Library/Application Support/Developer/Shared/Xcode/Project Templates/MacFUSE"
1301        m_exit_on_error "cannot create symlink for Xcode templates."
1302    fi
1303
1304    m_set_suprompt "to chown '$ms_macfuse_root/*'"
1305    sudo -p "$m_suprompt" chown -R root:wheel "$ms_macfuse_root"/*
1306    m_exit_on_error "cannot chown '$ms_macfuse_root/*'."
1307
1308    m_set_suprompt "to setuid 'load_fusefs'"
1309    sudo -p "$m_suprompt" chmod u+s "$ms_bundle_support_dir/load_fusefs"
1310    m_exit_on_error "cannot setuid 'load_fusefs'."
1311
1312    m_set_suprompt "to chown '$ms_macfuse_root/Library/'"
1313    sudo -p "$m_suprompt" chown root:admin "$ms_macfuse_root/Library/"
1314    m_exit_on_error "cannot chown '$ms_macfuse_root/Library/'."
1315
1316    m_set_suprompt "to chown '$ms_macfuse_root/Library/Frameworks/"
1317    sudo -p "$m_suprompt" \
1318        chown -R root:admin "$ms_macfuse_root/Library/Frameworks/"
1319    m_exit_on_error "cannot chown '$ms_macfuse_root/Library/Frameworks/'."
1320
1321    m_set_suprompt "to chmod '$ms_macfuse_root/Library/Frameworks/'"
1322    sudo -p "$m_suprompt" chmod 0775 "$ms_macfuse_root/Library/Frameworks/"
1323    m_exit_on_error "cannot chmod '$ms_macfuse_root/Library/Frameworks/'."
1324
1325    m_set_suprompt "to chmod '$ms_macfuse_root/Library/'"
1326    sudo -p "$m_suprompt" chmod 1775 "$ms_macfuse_root/Library/"
1327    m_exit_on_error "cannot chmod '$ms_macfuse_root/Library/'."
1328
1329    m_set_suprompt "to chmod files in '$ms_macfuse_root/usr/local/lib/'"
1330    sudo -p "$m_suprompt" \
1331        chmod -h 755 `find "$ms_macfuse_root/usr/local/lib" -type l`
1332    m_exit_on_error "cannot chmod files in '$ms_macfuse_root/usr/local/lib/'."
1333
1334    m_set_suprompt "to chmod files in '$ms_macfuse_root/Library/Frameworks/'"
1335    sudo -p "$m_suprompt" \
1336        chmod -h 755 `find "$ms_macfuse_root/Library/Frameworks/" -type l`
1337    # no exit upon error
1338
1339    cd "$ms_macfuse_root"
1340    m_exit_on_error "cannot access directory '$ms_macfuse_root'."
1341
1342    # Create the MacFUSE Installer Package
1343    #
1344
1345    m_log "building installer package for $m_platform"
1346
1347    m_build_pkg "$ms_macfuse_version" "$m_srcroot/core/$m_platform/packaging/macfuse-core" "$ms_macfuse_root" "$M_PKGNAME_CORE" "$ms_macfuse_out"
1348    m_exit_on_error "cannot create '$M_PKGNAME_CORE'."
1349
1350    echo >$m_stdout
1351    m_log "succeeded, results in '$ms_macfuse_out'."
1352    echo >$m_stdout
1353
1354    return 0
1355}
1356
1357function m_handler_swconfigure()
1358{
1359    m_active_target="swconfigure"
1360
1361    m_set_platform
1362
1363    m_set_srcroot "$m_platform"
1364
1365    local lib_dir="$m_srcroot"/core/"$m_platform"/libfuse
1366    if [ ! -d "$lib_dir" ]
1367    then
1368        false
1369        m_exit_on_error "cannot access directory '$lib_dir'."
1370    fi
1371
1372    local kernel_dir="$m_srcroot"/core/"$m_platform"/fusefs
1373    if [ ! -d "$kernel_dir" ]
1374    then
1375        false
1376        m_exit_on_error "cannot access directory '$kernel_dir'."
1377    fi
1378
1379    local current_dir=`pwd`
1380    local current_product=`basename "$current_dir"`
1381
1382    local extra_cflags=""
1383    local architectures=""
1384
1385    if [ "$m_platform" == "10.4" ]
1386    then
1387        extra_cflags="-mmacosx-version-min=10.4"
1388        architectures="-arch i386 -arch ppc"
1389    else
1390        architectures="-arch i386 -arch ppc"
1391    fi
1392
1393    local common_cflags="-O0 -g $architectures -isysroot $m_usdk_dir -I/usr/local/include"
1394    local common_ldflags="-Wl,-syslibroot,$m_usdk_dir $architectures -L/usr/local/lib"
1395
1396    local final_cflags="$common_cflags $extra_cflags"
1397    local final_ldflags="$common_ldflags"
1398
1399    local retval=1
1400
1401    # For pkg-config and such
1402    PATH=$PATH:/usr/local/sbin:/usr/local/bin
1403    export PATH
1404
1405    # We have some special cases for current_product
1406
1407    case "$current_product" in
1408
1409    gettext*)
1410        m_log "Configuring Universal build of gettext for Mac OS X \"$m_osname\""
1411        CFLAGS="$final_cflags -D_POSIX_C_SOURCE=200112L" LDFLAGS="$final_ldflags -fno-common" ./configure --prefix=/usr/local --disable-dependency-tracking --with-libiconv-prefix="$m_usdk_dir"/usr
1412        retval=$?
1413        ;; 
1414
1415    glib*)
1416        m_log "Configuring Universal build of glib for Mac OS X \"$m_osname\""
1417        CFLAGS="$final_cflags" LDFLAGS="$final_ldflags" ./configure --prefix=/usr/local --disable-dependency-tracking --enable-static
1418        retval=$?
1419        ;;
1420
1421    pkg-config*)
1422        m_log "Configuring Universal build of pkg-config for Mac OS X \"$m_osname\""
1423        CFLAGS="$final_cflags" LDFLAGS="$final_ldflags" ./configure --prefix=/usr/local --disable-dependency-tracking
1424        ;;
1425
1426    *sshfs*)
1427        m_log "Configuring Universal build of sshfs for Mac OS X \"$m_osname\""
1428        CFLAGS="$final_cflags -D__FreeBSD__=10 -DDARWIN_SEMAPHORE_COMPAT -DSSH_NODELAY_WORKAROUND" LDFLAGS="$final_ldflags" ./configure --prefix=/usr/local --disable-dependency-tracking
1429        ;;
1430
1431    *)
1432        m_log "Configuring Universal build of generic software for Mac OS X \"$m_osname\""
1433        CFLAGS="$final_cflags" LDFLAGS="$final_ldflags" ./configure --prefix=/usr/local --disable-dependency-tracking
1434        ;;
1435
1436    esac
1437
1438    return $retval
1439}
1440
1441# --
1442
1443function m_validate_xcode()
1444{
1445    m_xcode_version=`xcodebuild -version | head -1 | grep Xcode | awk '{print $NF}'`
1446    if [ $? != 0 ] || [ -z "$m_xcode_version" ]
1447    then
1448        echo "failed to determine Xcode version."
1449        exit 2
1450    fi
1451
1452    local mvs_xcode_major=`echo $m_xcode_version | cut -d . -f 1`
1453    local mvs_xcode_minor=`echo $m_xcode_version | cut -d . -f 2`
1454    if [ -z $mvs_xcode_minor ]
1455    then
1456        mvs_xcode_minor=0
1457    fi
1458    local mvs_xcode_rev=`echo $m_xcode_version | cut -d . -f 3`
1459    if [ -z $mvs_xcode_rev ]
1460    then
1461        mvs_xcode_rev=0
1462    fi
1463    local mvs_have=$(( $mvs_xcode_major * 100 + $mvs_xcode_minor * 10 + $mvs_xcode_rev ))
1464
1465    mvs_xcode_major=`echo $M_XCODE_VERSION_REQUIRED | cut -d . -f 1`
1466    mvs_xcode_minor=`echo $M_XCODE_VERSION_REQUIRED | cut -d . -f 2`
1467    if [ -z $mvs_xcode_minor ]
1468    then
1469        mvs_xcode_minor=0
1470    fi
1471    mvs_xcode_rev=`echo $M_XCODE_VERSION_REQUIRED | cut -d . -f 3`
1472    if [ -z $mvs_xcode_rev ]
1473    then
1474        mvs_xcode_rev=0
1475    fi
1476    local mvs_want=$(( $mvs_xcode_major * 100 + $mvs_xcode_minor * 10 + $mvs_xcode_rev ))
1477
1478    if [ $mvs_have -lt $mvs_want ]
1479    then
1480        echo "Xcode version $M_XCODE_VERSION_REQUIRED or higher is required to build MacFUSE."
1481        exit 2
1482    fi 
1483
1484    m_active_target="preflight"
1485    m_log "Xcode version $m_xcode_version found (minimum requirement is $M_XCODE_VERSION_REQUIRED)"
1486
1487    return 0
1488}
1489
1490function m_validate_input()
1491{
1492    local mvi_found=
1493    local mvi_good=
1494
1495    # Validate scratch directory
1496    if [ ! -d "$M_CONF_TMPDIR" ] || [ ! -w "$M_CONF_TMPDIR" ]
1497    then
1498        echo "M_CONF_TMPDIR (currently '$M_CONF_TMPDIR') must be set to a writeable directory."
1499        exit 2
1500    fi
1501
1502    # Validate if platform was specified when it shouldn't have been
1503    #
1504    if [ "$m_platform" != "$M_DEFAULT_PLATFORM" ]
1505    then
1506        mvi_found="0"
1507        for m_p in $M_TARGETS_WITH_PLATFORM
1508        do
1509            if [ "$m_target" == "$m_p" ]
1510            then
1511                mvi_found="1"
1512                break
1513            fi
1514        done
1515        if [ "$mvi_found" == "0" ]
1516        then
1517            echo "Unknown argument or invalid combination of arguments."
1518            echo  "Try $0 -h for help."
1519            exit 2
1520        fi
1521    fi
1522
1523    # Validate platform
1524    if [ "$m_platform" != "$M_DEFAULT_PLATFORM" ]
1525    then
1526        mvi_good="0"
1527        for m_p in $M_PLATFORMS
1528        do
1529            if [ "$m_platform" == "$m_p" ]
1530            then
1531                mvi_good="1"
1532                break
1533            fi
1534        done
1535        if [ "$mvi_good" == "0" ]
1536        then
1537            echo "Unknown platform '$m_platform'."
1538            echo "Valid platforms are: $M_PLATFORMS."
1539            exit 2
1540        fi
1541    fi
1542
1543    # Validate target
1544    #
1545    if [ "$m_target" != "$M_DEFAULT_TARGET" ]
1546    then
1547        mvi_good="0"
1548        for m_t in $M_TARGETS
1549        do
1550            if [ "$m_target" == "$m_t" ]
1551            then
1552                mvi_good="1"
1553                break
1554            fi
1555        done
1556        if [ "$mvi_good" == "0" ]
1557        then
1558            echo "Unknown target '$m_target'."
1559            echo "Valid targets are: $M_TARGETS."
1560            exit 2
1561        fi
1562    fi
1563
1564    # Validate configuration
1565    #
1566    mvi_good="0"
1567    for m_c in $M_CONFIGURATIONS
1568    do
1569        if [ "$m_configuration" == "$m_c" ]
1570        then
1571            mvi_good="1"
1572            break
1573        fi
1574    done
1575    if [ "$mvi_good" == "0" ]
1576    then
1577        echo "Unknown configuration '$m_configuration'."
1578        echo "Valid configurations are: $M_CONFIGURATIONS."
1579        exit 2
1580    fi
1581
1582    if [ "$m_shortcircuit" == "1" ] && [ "$m_target" == "clean" ]
1583    then
1584       echo "Cleaning cannot be shortcircuited!"
1585       exit 2
1586    fi
1587
1588    return 0
1589}
1590
1591function m_read_input()
1592{
1593    m_args=`getopt c:dhp:qst:v $*`
1594
1595    if [ $? != 0 ]
1596    then
1597

Large files files are truncated, but you can click here to view the full file