# -*- 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 106892 2013-06-10 11:40:32Z cal@macports.org $

PortSystem      1.0

name            fontforge
version         20120731
revision        1
set docversion  ${version}
set ftversion   2.4.10
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.org/
master_sites    sourceforge:project/fontforge/fontforge-source \
                sourceforge:project/fontforge/fontforge-docs:docs \
                ${homepage}:cidmaps \
                http://download.savannah.gnu.org/releases/freetype/:freetype \
                sourceforge:project/freetype/freetype2/${ftversion}:freetype
distname        ${name}_full-${version}
dist_subdir     ${name}/${version}
use_bzip2       yes

set docdistfile ${name}_htdocs-${docversion}${extract.suffix}

distfiles-append \
                cidmaps.tgz:cidmaps \
                ${docdistfile}:docs
checksums       ${distname}${extract.suffix} \
                rmd160  351af6022d1c1c80e61788b699ff882bcde1b55f \
                sha256  e5cb9e9e64a99d1dfc549950741eb9b44c3162a4c62f71053905c1f2d024295f \
                cidmaps.tgz \
                rmd160  d194355e61813d31fe4813bdf10a62d66a9f6d04 \
                sha256  1bf9c7eb8835e6ed94e62cb49f1141bc046c562849e52e6c3c7f1d7cfc95c7b3 \
                ${docdistfile} \
                rmd160  8afd7d4eb9d590c989f16047e3ff4c926d1eab31 \
                sha256  a938c08e66c1ff1e853e0833fbde6cb5d92d900f66b1958b6769f5b7d32ad1e7 \
                freetype-${ftversion}${extract.suffix} \
                rmd160  9da7fcde9c42f81c399201d055d85109b2ae7814 \
                sha256  0c8e242c33c45928de560d7d595db06feb41d1b22167e37260ceabe72f9e992f

worksrcdir      ${name}-${version}
extract.only    ${distname}${extract.suffix}

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

    system "tar xzf ${distpath}/cidmaps.tgz -C ${worksrcpath}/cidmap"
    system "tar xjf ${distpath}/${docdistfile} -C ${worksrcpath}/htdocs"
}

patchfiles      patch-Makefile.dynamic.in.diff \
                patch-configure.in.diff \
                patch-fontforge__libffstamp.h-integer-versiondate.diff \
                patch-fontforge_start.c.diff \
                patch-gutils_dynamic.c.diff \
                patch-xcode-43.diff

post-patch {
    if {${os.major} > 11 && ${os.platform} == "darwin"} {
        eval reinplace -W {${worksrcpath}/fontforge} "s|AnchorPoint|FFAnchorPoint|g" \
            [glob -tails -directory ${worksrcpath}/fontforge *.c] \
            splinefont.h baseviews.h views.h
    }
    reinplace "s|@PREFIX@|${prefix}|g" \
        ${worksrcpath}/gutils/dynamic.c
    reinplace "/^applicationsdir/s|/Applications|${applications_dir}|" \
        ${worksrcpath}/Makefile.dynamic.in
}

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

use_autoconf    yes

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

configure.ldflags-append \
                -lintl

# https://trac.macports.org/ticket/29840
compiler.blacklist \
                llvm-gcc-4.2

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}
    # Fix permissions problem on this file
    xinstall -m 0644 -W ${destroot}${applications_dir}/FontForge.app/Contents/Resources FontForge.icns \
        ${destroot}${applications_dir}/FontForge.app/Contents/Resources
}

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}
}

variant python26 conflicts python27 description {Enable Python support (Python 2.6)} {
    configure.args-delete   --without-python
    configure.args-append   --enable-pyextension \
                            --with-python=${prefix}/bin/python2.6 \
                            --with-python-headers=${frameworks_dir}/Python.framework/Versions/2.6/include/python2.6
    destroot.args-append    PYTHON=${prefix}/bin/python2.6 PYTHONPREFIX=${frameworks_dir}/Python.framework/Versions/2.6
    depends_lib-append      port:python26
}

variant python27 conflicts python26 description {Enable Python support (Python 2.7)} {
    configure.args-delete   --without-python
    configure.args-append   --enable-pyextension \
                            --with-python=${prefix}/bin/python2.7 \
                            --with-python-headers=${frameworks_dir}/Python.framework/Versions/2.7/include/python2.7
    destroot.args-append    PYTHON=${prefix}/bin/python2.7 PYTHONPREFIX=${frameworks_dir}/Python.framework/Versions/2.7
    depends_lib-append      port:python27
}

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