# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 90799 2012-03-14 20:01:06Z snc@macports.org $

PortSystem      1.0

name            fontforge
version         20110222
set docversion  20110221
set ftversion   2.4.4
revision        1
categories      graphics fonts
platforms       darwin
maintainers     nomaintainer
license         BSD
description     Outline and bitmap font editor/converter for many formats

long_description \
    FontForge allows you to edit outline and bitmap fonts.  You may create \
    new ones or modify old ones.  It is also a format converter and can \
    interconvert between PostScript (ascii & binary Type1, some Type3, \
    some Type0), TrueType, OpenType (Type2), CID, SVG.  Previously known as \
    pfaedit.

homepage        http://fontforge.sourceforge.net/
master_sites    sourceforge \
                ${homepage}:cidmaps \
                http://download.savannah.gnu.org/releases/freetype/:freetype \
                sourceforge:freetype:freetype
distname        ${name}_full-${version}
dist_subdir     ${name}/${version}
use_bzip2       yes

set docdistname ${name}_htdocs-${docversion}

distfiles-append \
    cidmaps.tgz:cidmaps \
    [suffix ${docdistname}]

patchfiles      patch-Makefile.dynamic.in.diff \
                patch-fontforge_start.c.diff \
                patch-gutils_dynamic.c.diff \
                patch-xcode-43.diff \
                patch-configure.in.diff
post-patch {
    reinplace s|@@DEVDIR@@|${developer_dir}| ${worksrcpath}/fontforge/macbinary.c \
                                               ${worksrcpath}/fontforge/startui.c \
                                               ${worksrcpath}/gutils/giomime.c
}

checksums       [suffix ${distname}] \
                sha1    8fada07647f102351bb1d7d1c4da487356e7142f \
                rmd160  7f276e9e3ef673b78355bb7be50f6b2587aee633 \
                cidmaps.tgz \
                sha1    efbc7c9d3e95159f5600dc71f9cccb370e46bb94 \
                rmd160  d194355e61813d31fe4813bdf10a62d66a9f6d04 \
                [suffix ${docdistname}] \
                sha1    e966fea60a2f7f022af71669f67e15e258948e0e \
                rmd160  ac92a01aafbb39ccbecff2953f3b6f49c3721f71 \
                [suffix freetype-${ftversion}] \
                sha1    1d136cbc51c67b212c91ba04dc5db797f35e64e6 \
                rmd160  6b9b37ccdc8d1bfe0883f0e25df6de49ab30379e

worksrcdir      ${name}-${version}

extract.only    [suffix ${distname}]

post-extract {
    xinstall -d \
        ${worksrcpath}/cidmap \
        ${worksrcpath}/htdocs

    system "tar xzf ${distpath}/cidmaps.tgz -C ${worksrcpath}/cidmap"
    system "tar xjf ${distpath}/[suffix ${docdistname}] -C ${worksrcpath}/htdocs"
}

post-patch {
    reinplace "s|@PREFIX@|${prefix}|g" \
        ${worksrcpath}/gutils/dynamic.c
    reinplace "/^applicationsdir/s|/Applications|${applications_dir}|" \
        ${worksrcpath}/Makefile.dynamic.in
}

depends_lib \
                port:xorg-libXi \
                port:xorg-libxkbui \
                port:xorg-libXt \
                port:freetype \
                port:gettext \
                port:giflib \
                port:jpeg \
                port:libiconv \
                port:libpng \
                port:libuninameslist \
                port:libxml2 \
                port:tiff \
                port:zlib

use_autoconf    yes

configure.args  --mandir=${prefix}/share/man \
                --enable-type3 \
                --enable-devicetables \
                --enable-gb12345 \
                --without-python \
                --without-freetype-bytecode \
                --without-pango \
                --without-cairo \
                --x-includes=${prefix}/include \
                --x-libraries=${prefix}/lib

configure.ldflags-append -lintl

# http://trac.macports.org/ticket/29840
if {${configure.compiler} == "llvm-gcc-4.2"} {
    configure.compiler clang
}

use_parallel_build  yes

set docdir      ${prefix}/share/doc/${name}

destroot.args   docdir=${docdir}

post-destroot {
    xinstall -d ${destroot}${docdir}
    xinstall -m 644 -W ${worksrcpath} \
        AUTHORS INSTALL LICENSE README-Mac.html README-Unix.html README-unix \
        ${destroot}${docdir}
}

variant with_freetype_bytecode requires freetype_bytecode description {Legacy compatibility variant} {}

variant freetype_bytecode description {Enable support for bytecode interpreter} {
    distfiles-append        freetype-${ftversion}${extract.suffix}:freetype
    extract.only-append     freetype-${ftversion}${extract.suffix}
    configure.args-delete   --without-freetype-bytecode
    configure.args-append   --with-freetype-src=${workpath}/freetype-${ftversion}
}

livecheck.regex     ${name}_full-(\\d+)\.
