# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 68513 2010-06-05 09:36:17Z dports@macports.org $

PortSystem 1.0

name                macfuse
version             2.0.3
revision            1
categories          fuse devel
platforms           macosx
maintainers         dports
description         A FUSE-Compliant File System Implementation Mechanism for \
                    Mac OS X

long_description    MacFUSE implements a mechanism that makes it possible to  \
                    implement a fully functional file system in a user-space  \
                    program on Mac OS X (10.4 and above). It aims to be       \
                    API-compliant with the FUSE (File-system in USErspace)    \
                    mechanism that originated on Linux.  Therefore, many      \
                    existing FUSE file systems become readily usable on       \
                    Mac OS X. The core of MacFUSE is in a dynamically         \
                    loadable kernel extension.

homepage            http://code.google.com/p/macfuse/
master_sites        macports
use_bzip2           yes
worksrcdir          core
checksums           md5     97ab76bbade128828596aca878c6c475 \
                    sha1    60ea1536091740e2faeb9ebf72d8696ccd11ce2f \
                    rmd160  e9a79de37d84ee5e21f63f02b924d04a5df94636

depends_build       port:pkgconfig

patchfiles          patch-10.5-to-10.6.diff \
                    patch-macfuse_buildtool.sh.diff \
                    patch-sdk-objc_GMUserFileSystem.m.diff \
                    patch-sdk-objc_MacFuse.xcodeproj.diff \
                    patch-10.5_fusefs_fusefs.xcodeproj_project.pbxproj.diff \
                    patch-10.5_libfuse_fuse-2.7.3-macosx.patch.diff \
                    patch-10.6_libfuse_fuse-2.7.3-macosx.patch.diff

livecheck.type      googlecode
livecheck.distname  MacFUSE-(.*)%2C.*.dmg

use_configure       no

variant universal {
    # provide a dummy variant since the script will actually build universal
    # and we don't want to error out if someone says +universal
}

# ensure that user is running OS X 10.5 or higher: MacFUSE requires XCode 3
pre-fetch {
    if {${os.platform} != "darwin" || [rpm-vercomp ${os.version} 9.0.0] < 0} {
        return -code error "MacFUSE requires at least Mac OS X 10.5 to build"
    }
}

# copy 10.5 source directory to 10.6 to prepare for the 10.5-to-10.6 patch
# (this patch really should be applied upstream)
#
# use cp -R instead of cp -r or copy to preserve symlinks
pre-patch {
    system "cp -R ${worksrcpath}/10.5 ${worksrcpath}/10.6"
}

post-patch {
    reinplace s,/usr/local,${prefix},g ${worksrcpath}/macfuse_buildtool.sh
    reinplace s,/usr/local,${prefix},g ${worksrcpath}/sdk-objc/MacFUSE.xcodeproj/project.pbxproj
    reinplace s,@@PREFIX@@,${prefix},g ${worksrcpath}/10.5/libfuse/fuse-2.7.3-macosx.patch
    reinplace s,@@PREFIX@@,${prefix},g ${worksrcpath}/10.6/libfuse/fuse-2.7.3-macosx.patch
    reinplace s,@@WORKPATH@@,${workpath},g ${worksrcpath}/macfuse_buildtool.sh
    reinplace s,@@DESTPATH@@,${destpath},g ${worksrcpath}/macfuse_buildtool.sh
}

# macfuse_buildtool has been patched to install directly into ${destpath},
# so destroot phase is unnecessary
build {
     system "cd ${worksrcpath} && ./macfuse_buildtool.sh -t smalldist"
}

destroot.violate_mtree yes

destroot {
}

post-activate {
    if {[string length [exec kextstat -lb com.google.filesystems.fusefs]] > 0} {
        ui_msg "********************************************************"
        ui_msg "*  fusefs is already loaded. You may need to restart.  *"
        ui_msg "*  Alternatively, if feeling adventurous, you can run  *"
        ui_msg "*  `sudo kextunload -b com.google.filesystems.fusefs`  *"
        ui_msg "********************************************************"
    }
}
