--- macports-current/Portfile	2014-04-08 05:00:05.000000000 +0200
+++ Portfile	2015-01-23 17:41:09.000000000 +0100
@@ -2,97 +2,196 @@
 # $Id: Portfile 118682 2014-04-08 02:56:30Z ryandesign@macports.org $
 
 PortSystem                  1.0
-PortGroup                   muniversal 1.0
 
 name                        fontconfig
-version                     2.11.1
+
+subport "${name}-ultimate" {
+    # sadly we need to provide a senseless univ. variant because
+    # freetype +infinality+universal would require it.
+    #variant universal description {this is a stub variant for dependency reasons only} {
+    #}
+    supported_archs         noarch
+}
+
 categories                  graphics
-maintainers                 ryandesign
-license                     fontconfig
-homepage                    http://fontconfig.org/
 platforms                   darwin
-use_parallel_build          yes
 
-description                 An XML-based font configuration API for X Windows
+set INFRELEASE              2015-01-01
+
+if {${subport} eq "${name}-ultimate"} {
+    name                        fontconfig-ultimate
+    version                     2015.01.01
+    license                     MIT
+    homepage                    http://bohoomil.com
+    platforms                   darwin
+
+    description                 fontconfig-infinality-ultimate & fonts
+
+    long_description            Fontconfig is a library for configuring and \
+                                customising font access. Fontconfig-ultimate is a collection \
+                                of configuration files that leverage the power of the Infinality \
+                                patches to FreeType to provide the ultimate experience in \
+                                customisable font rendering quality. \
+                                This port provides the configuration files\; it requires fontconfig \
+                                to be installed with the +infinality variant.
+    master_sites                https://github.com/bohoomil/fontconfig-ultimate/archive
+    distname                    ${INFRELEASE}
+
+    checksums                   ${distname}${extract.suffix} \
+                                    rmd160  907feca10f32cc777193cc686536a244416a763e \
+                                    sha256  7227af7909c0c72b5014d605ff5acd9db063c056889f22b3e7fa1960b5ad55cb
+
+    depends_lib                 port:freetype-infinality
+    depends_run                 port:bash
+
+    use_configure               no
+    # this appears to be required despite an empty build block!
+    build.cmd                   echo
+    configure {}
+    build {}
+    worksrcdir                  ${name}-${distname}
+    patchfiles                  patch-presets-nocolours.diff
+
+    post-destroot {
+        xinstall -m 0755 -d ${destroot}${prefix}/share/fonts/fontconfig-ultimate/${INFRELEASE}
+        copy ${worksrcpath}/conf.d.infinality ${destroot}${prefix}/share/fonts/fontconfig-ultimate/${INFRELEASE}
+        reinplace "s|\"/etc|\"${prefix}/etc|g" ${worksrcpath}/fontconfig_patches/fc-presets
+        reinplace "s|/bin/bash|${prefix}/bin/bash|g" ${worksrcpath}/fontconfig_patches/fc-presets
+        foreach f {CHANGELOG fc-presets fonts-settings free ms} {
+            copy ${worksrcpath}/fontconfig_patches/${f} ${destroot}${prefix}/share/fonts/fontconfig-ultimate/${INFRELEASE}
+        }
+        copy ${worksrcpath}/fontconfig_patches/combi ${destroot}${prefix}/share/fonts/fontconfig-ultimate/${INFRELEASE}/combi-complete
+        copy ${worksrcpath}/doc/fontconfig-infinality-ultimate/fontconfig-global/combi-minimal ${destroot}${prefix}/share/fonts/fontconfig-ultimate/${INFRELEASE}/combi
+    }
+    notes-append "fontconfig must be now be (re)build and (re)installed with the +infinality variant."
+} else {
 
-long_description            Fontconfig is a library for configuring and \
-                            customizing font access.
+    PortGroup                   muniversal 1.0
 
-master_sites                http://www.freedesktop.org/software/fontconfig/release/
-use_bzip2                   yes
+    version                     2.11.1
+    maintainers                 ryandesign
+    license                     fontconfig
+    homepage                    http://fontconfig.org/
+    use_parallel_build          yes
 
-checksums                   rmd160  9d0a242ec05737f5dba3949ffe095f3c100217c7 \
-                            sha256  dc62447533bca844463a3c3fd4083b57c90f18a70506e7a9f4936b5a1e516a99
+    description                 An XML-based font configuration API for X Windows
 
-depends_build               port:pkgconfig
+    long_description            Fontconfig is a library for configuring and \
+                                customising font access.
 
-depends_lib                 port:libiconv \
-                            port:expat \
-                            port:freetype
+    master_sites                http://www.freedesktop.org/software/fontconfig/release/
+    use_bzip2                   yes
 
-if {${os.platform} eq "darwin" && ${os.major} < 9} {
-    set add_fonts           /usr/X11R6/lib/X11/fonts
-} else {
-    set add_fonts           /usr/X11/lib/X11/fonts
-}
-lappend add_fonts           ${prefix}/share/fonts
-set docdir                  ${prefix}/share/doc/${name}
+    checksums                   ${distname}${extract.suffix} \
+                                    rmd160  9d0a242ec05737f5dba3949ffe095f3c100217c7 \
+                                    sha256  dc62447533bca844463a3c3fd4083b57c90f18a70506e7a9f4936b5a1e516a99
 
-patchfiles                  patch-docbook-4.2.diff
+    depends_build               port:pkgconfig
+
+    depends_lib                 port:libiconv \
+                                port:expat \
+                                port:freetype
+
+    if {${os.platform} eq "darwin" && ${os.major} < 9} {
+        set add_fonts           /usr/X11R6/lib/X11/fonts
+    } else {
+        set add_fonts           /usr/X11/lib/X11/fonts
+    }
+    lappend add_fonts           ${prefix}/share/fonts
+    set docdir                  ${prefix}/share/doc/${name}
+
+    patchfiles                  patch-docbook-4.2.diff
 
 # *** No scandir function available.
 # https://bugs.freedesktop.org/show_bug.cgi?id=77034
 # Can be removed when ccache 3.2 is released with proper clang compatibility
-if {[string match *clang* ${configure.compiler}]} {
-    configure.ccache        no
-}
+    if {[string match *clang* ${configure.compiler}]} {
+        configure.ccache        no
+    }
 
-configure.args              --disable-silent-rules HASDOCBOOK=no
+    configure.args              --disable-silent-rules HASDOCBOOK=no
 
 # We put this into a pre-configure block so it can be evaluated _after_ platform selection.
-pre-configure {
-    configure.args-append   --with-add-fonts=[join ${add_fonts} ,]
-}
+    pre-configure {
+        configure.args-append   --with-add-fonts=[join ${add_fonts} ,]
+    }
 
-post-destroot {
-    xinstall -d ${destroot}${docdir}
-    xinstall -m 0644 -W ${worksrcpath} \
-        AUTHORS \
-        COPYING \
-        ChangeLog \
-        NEWS \
-        README \
-        ${destroot}${docdir}
-}
 
-post-activate {
-    # fc-cache can fail due to /Network/Library/Fonts being unavailable, so force success.
-    system "${prefix}/bin/fc-cache -sv || true"
-    system "${prefix}/bin/fc-cache -v || true"
-}
+    post-destroot {
+        xinstall -d ${destroot}${docdir}
+        xinstall -m 0644 -W ${worksrcpath} \
+            AUTHORS \
+            COPYING \
+            ChangeLog \
+            NEWS \
+            README \
+            ${destroot}${docdir}
+
+        if {[variant_isset infinality]} {
+            catch {eval exec sh ${filespath}/install-conf-files.sh ${prefix} ${workpath} ${destroot} ${INFRELEASE}} result
+            ui_debug "install-conf-files.sh : $result"
+        }
+    }
 
-platform macosx {
-    lappend add_fonts       /Library/Fonts \
-                            /Network/Library/Fonts \
-                            /System/Library/Fonts
-}
+    post-activate {
+        # fc-cache can fail due to /Network/Library/Fonts being unavailable, so force success.
+        system "${prefix}/bin/fc-cache -sv || true"
+        system "${prefix}/bin/fc-cache -v || true"
+    }
 
-merger_arch_flag            no
-merger_arch_compiler        yes
-if {${os.arch} eq "i386"} {
-    if { ${os.major} >= 10 } {
-        set merger_configure_args(ppc) --with-arch=ppc
-        set merger_configure_env(ppc)  CC_FOR_BUILD=${configure.cc}
+    platform macosx {
+        lappend add_fonts       /Library/Fonts \
+                                /Network/Library/Fonts \
+                                /System/Library/Fonts
     }
-    set merger_configure_args(ppc64)   --with-arch=ppc64
-    set merger_configure_env(ppc64)    CC_FOR_BUILD=${configure.cc}
-} else {
-    set merger_configure_args(i386)    --with-arch=i386
-    set merger_configure_args(x86_64)  --with-arch=x86_64
-    set merger_configure_env(i386)     CC_FOR_BUILD=${configure.cc}
-    set merger_configure_env(x86_64)   CC_FOR_BUILD=${configure.cc}
-}
 
-livecheck.type              regex
-livecheck.url               [lindex ${master_sites} 0]
-livecheck.regex             ${name}-(\\d+(?:\\.\\d+)*\\.(?:\\d|\[0-8\]\\d))\\.tar
+    merger_arch_flag            no
+    merger_arch_compiler        yes
+    if {${os.arch} eq "i386"} {
+        if { ${os.major} >= 10 } {
+            set merger_configure_args(ppc) --with-arch=ppc
+            set merger_configure_env(ppc)  CC_FOR_BUILD=${configure.cc}
+        }
+        set merger_configure_args(ppc64)   --with-arch=ppc64
+        set merger_configure_env(ppc64)    CC_FOR_BUILD=${configure.cc}
+    } else {
+        set merger_configure_args(i386)    --with-arch=i386
+        set merger_configure_args(x86_64)  --with-arch=x86_64
+        set merger_configure_env(i386)     CC_FOR_BUILD=${configure.cc}
+        set merger_configure_env(x86_64)   CC_FOR_BUILD=${configure.cc}
+    }
+
+    if {[file exists ${prefix}/share/fonts/fontconfig-ultimate/${INFRELEASE}]} {
+        default_variants    +infinality
+    }
+
+    set TEMPLINFDIR ${prefix}/etc/fonts/conf.avail.infinality
+    variant infinality description {patched for improved font rendering, bohoomil ultimate style} {
+        depends_lib-append port:fontconfig-ultimate
+
+        patchfiles-append  00-fonts.conf.in.patch \
+                           01-configure.patch \
+                           02-configure.ac.patch \
+                           03-Makefile.in.patch \
+                           04-Makefile.conf.d.patch \
+                           05-Makefile.am.in.patch \
+                           fc-cache.c.patch
+        pre-configure {
+            configure.args-append   --with-templatedir=${prefix}/etc/fonts/conf.avail --with-templateinfdir=${TEMPLINFDIR}
+            delete ${worksrcpath}/conf.d.infinality
+            copy ${prefix}/share/fonts/fontconfig-ultimate/${INFRELEASE}/conf.d.infinality ${worksrcpath}
+            catch {eval exec sh -c "\"cd ${worksrcpath} ; aclocal\""} result
+            ui_debug "aclocal: $result"
+            catch {eval exec sh -c "\"cd ${worksrcpath} ; glibtoolize -f\""} result
+            ui_debug "glibtoolize: $result"
+            catch {eval exec sh -c "\"cd ${worksrcpath} ; automake --add-missing -fi\""} result
+            ui_debug "automake: $result"
+        }
+
+        notes-append "Be sure to call fc-presets as root to select one of the provided font configuration presets!"
+    }
+
+    livecheck.type              regex
+    livecheck.url               [lindex ${master_sites} 0]
+    livecheck.regex             ${name}-(\\d+(?:\\.\\d+)*\\.(?:\\d|\[0-8\]\\d))\\.tar
+}
