--- /opt/local/var/macports/sources/git.macports.org/dports/lang/fpc/Portfile	2016-10-31 09:43:40.000000000 +0100
+++ lang/fpc/Portfile	2016-12-18 16:00:12.000000000 +0100
@@ -1,17 +1,19 @@
 # -*- 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$
 
 PortSystem          1.0
 
 name                fpc
-version             2.6.4
-revision            1
+version             3.0.0
 categories          lang
 platforms           darwin
 license             GPL-2 LGPL-2
 maintainers         takeshi openmaintainer
-description         free pascal
-long_description    Open source compiler for Pascal and Object Pascal
+description         Free Pascal, an open source Pascal and Object Pascal compiler.
+long_description    Free Pascal is a 32, 64 and 16 bit professional Pascal compiler. \
+                    It can target many processor architectures: Intel x86 (including 8086), \
+                    AMD64/x86-64, PowerPC, PowerPC64, SPARC, ARM, AArch64, MIPS and the JVM. \
+                    Supported operating systems include Linux, FreeBSD, Mac OS X/iOS/iPhoneSimulator/Darwin, \
+                    Win32, Win64, WinCE and Android.
 homepage            http://www.freepascal.org
 master_sites        sourceforge:freepascal
 
@@ -19,79 +21,129 @@
 set pp              universal-macosx-10.5-ppcuniversal.tar.bz2
 distfiles           ${src} ${pp}
 checksums           ${src} \
-                    rmd160  339b71d3c9983a720eed7c6bda1cfd330d89966f \
-                    sha256  8d9c3bcfa469d9b37c05663e2775d179809e4b3443604fac7d21aa64c9a56daa \
+                    rmd160  e921a79d1898b959ee71909d6cd2f036b00477bd \
+                    sha256  d5913b1d5d3d13190ae7ee72c305d5da49ac2ddc1b375b814751ef09ae5c80ec \
                     ${pp} \
                     rmd160  0124c2f4447ba7f96e3db0a27e6bff459c5749f4 \
                     sha256  e7243e83e6a04de147ebab7530754ec92cd1fbabbc9b6b00a3f90a796312f3e9
 
 extract.only        ${src}
-                    
+
 use_configure       no
 universal_variant   no
 
-post-extract {
-    system -W ${workpath} "bzip2 -dc ${distpath}/${pp} | tar xf -"
-}
+set fpcbasepath     ${prefix}/libexec/${name}
 
-worksrcdir          ${name}build-${version}/fpcsrc
-set fpcbasepath     ${prefix}/lib/${name}
-build.env           PP=${workpath}/ppcuniversal \
-                    PREFIX=${destroot}${fpcbasepath}
-build.target        all
-
-destroot.env        ${build.env}
-
-# Yosemite fix: fpc's build system checkes MACOSX_DEPLOYMENT_TARGET and halts if > 10.9
-platform darwin {
-    if {${os.major} > 13} {
-        macosx_deployment_target    10.9
+subport "chmcmd-${name}" {
+    description     The FPC Pascal htmlhelp (CHM) compiler
+    long_description \
+                    chmcmd is an cross-platform utility to generate compressed HTML (.chm)\
+                    documentation, written in Free Pascal
+    installs_libs   no
+
+    depends_build-append \
+                    port:${name}
+    extract.post_args-append \
+                    ${name}build-${version}/fpcsrc/packages/chm \
+                    ${name}build-${version}/fpcsrc/packages/fcl-xml \
+                    ${name}build-${version}/fpcsrc/packages/fcl-base \
+                    ${name}build-${version}/fpcsrc/packages/fcl-process \
+                    ${name}build-${version}/fpcsrc/packages/fpmkunit \
+                    ${name}build-${version}/fpcsrc/packages/hash \
+                    ${name}build-${version}/fpcsrc/packages/iconvenc \
+                    ${name}build-${version}/fpcsrc/packages/libtar \
+                    ${name}build-${version}/fpcsrc/packages/paszlib \
+                    ${name}build-${version}/fpcsrc/packages/univint \
+                    ${name}build-${version}/fpcsrc/rtl
+    worksrcdir      ${name}build-${version}/fpcsrc/packages/chm
+    use_configure   yes
+    configure.cmd   ${fpcbasepath}/bin/fpcmake
+    configure.pre_args
+    configure.args  -r -v Makefile.fpc.fpcmake
+    configure.post_args
+    build.env       PREFIX=${prefix}
+    build.target
+    build.post_args-append \
+                    V=1 VERBOSE=1
+    destroot {
+        xinstall -m 755 ${build.dir}/chmcmd ${destroot}${prefix}/bin
     }
 }
 
-post-destroot {
-# create a symlink to the architecture dependent executable
-    switch ${build_arch} {
-        "x86_64" {
-            set b "ppcx64"
-        } 
-        "i386" {
-            set b "ppc386"
-        }
-        default {
-            set b "ppcppc"
+if {${subport} eq "${name}"} {
+    installs_libs       yes
+
+    post-extract {
+        system -W ${workpath} "bzip2 -dc ${distpath}/${pp} | tar xf -"
+    }
+
+    worksrcdir          ${name}build-${version}/fpcsrc
+    build.env           PP=${workpath}/ppcuniversal \
+                        PREFIX=${destroot}${fpcbasepath}
+    build.target        all
+
+    destroot.env        ${build.env}
+
+    # Yosemite fix: fpc's build system checkes MACOSX_DEPLOYMENT_TARGET and halts if > 10.9
+    platform darwin {
+        if {${os.major} > 13} {
+            macosx_deployment_target    10.9
         }
     }
-    ln -s ${fpcbasepath}/lib/${name}/${version}/${b} ${destroot}${fpcbasepath}/bin
-# generate a configuration file
-    xinstall -d ${destroot}${fpcbasepath}/etc
-    system "
-        ${destroot}${fpcbasepath}/bin/fpcmkcfg \
-            -d basepath=${fpcbasepath}/lib/${name}/${version} \
-            -o ${destroot}${fpcbasepath}/etc/fpc.cfg
-    "
-# install man
-    xinstall -d ${destroot}${fpcbasepath}/man
-    foreach d {1 5} {
-        file copy ${workpath}/${name}build-${version}/install/man/man${d} ${destroot}${fpcbasepath}/man
-        foreach f [glob ${destroot}${fpcbasepath}/man/man${d}/*.${d}] {
-            system "/usr/bin/gzip ${f}"
+
+    post-destroot {
+    # create a symlink to the architecture dependent executable
+        switch ${build_arch} {
+            "x86_64" {
+                set b "ppcx64"
+            } 
+            "i386" {
+                set b "ppc386"
+            }
+            default {
+                set b "ppcppc"
+            }
+        }
+        ln -s ${fpcbasepath}/lib/${name}/${version}/${b} ${destroot}${fpcbasepath}/bin
+        # generate a configuration file
+        xinstall -d ${destroot}${fpcbasepath}/etc
+        system "
+            ${destroot}${fpcbasepath}/bin/fpcmkcfg \
+                -d basepath=${fpcbasepath}/lib/${name}/${version} \
+                -o ${destroot}${fpcbasepath}/etc/fpc.cfg
+        "
+        ln -s ${fpcbasepath}/etc/fpc.cfg ${destroot}${prefix}/etc
+
+        # install man
+        xinstall -d ${destroot}${fpcbasepath}/man
+        foreach d {1 5} {
+            file copy ${workpath}/${name}build-${version}/install/man/man${d} ${destroot}${fpcbasepath}/man
+            foreach f [glob ${destroot}${fpcbasepath}/man/man${d}/*.${d}] {
+                system "/usr/bin/gzip ${f}"
+            }
+        }
+        ln -s ${fpcbasepath}/man/man1/fpc.1.gz ${destroot}${prefix}/share/man/man1
+        ln -s ${fpcbasepath}/man/man5/fpc.cfg.5.gz ${destroot}${prefix}/share/man/man5
+
+        # chmcmd will be installed by the chmcmd-fpc subport
+        file delete -force ${destroot}${fpcbasepath}/bin/chmcmd
+        foreach b [glob -nocomplain ${destroot}${fpcbasepath}/bin/*] {
+            set n [file tail ${b}]
+            ln -s ${fpcbasepath}/bin/${n} ${destroot}${prefix}/bin
         }
     }
-    ln -s ${fpcbasepath}/man/man1/fpc.1.gz ${destroot}${prefix}/share/man/man1
-    ln -s ${fpcbasepath}/man/man5/fpc.cfg.5.gz ${destroot}${prefix}/share/man/man5
-}
 
-notes "
-    The compiler fpc looks for the fpc.cfg file in the following places: \n\
-    - The current directory. \n\
-    - Home directory, looks for .fpc.cfg \n\
-    - The directory specified in the environment variable PPC_CONFIG_PATH, \n\
-      and if it's not set under compilerdir/../etc. \n\
-    - If it is not yet found: in /etc. \n\
-    \n\
-    All the files of fpc are installed in ${fpcbasepath} and \n\
-    the executables are installed in ${fpcbasepath}/bin. \n\
-    The fpc.cfg is installed in ${fpcbasepath}/etc to make fpc find fpc.cfg. \n\
-    To customize, use ~/.fpc.cfg or /etc/fpc.cfg and call ${fpcbasepath}/bin/fpc directly.
-" 
+    notes "
+        The compiler fpc looks for the fpc.cfg file in the following places: \n\
+        - The current directory. \n\
+        - Home directory, looks for .fpc.cfg \n\
+        - The directory specified in the environment variable PPC_CONFIG_PATH, \n\
+          and if it's not set under compilerdir/../etc. \n\
+        - If it is not yet found: in /etc. \n\
+        \n\
+        All the files of fpc are installed in ${fpcbasepath} and \n\
+        the executables are installed in ${fpcbasepath}/bin. \n\
+        The fpc.cfg is installed in ${fpcbasepath}/etc to make fpc find fpc.cfg. \n\
+        To customize, use ~/.fpc.cfg or /etc/fpc.cfg and call ${fpcbasepath}/bin/fpc directly.
+    " 
+}
