--- /opt/local/var/macports/sources/git.macports.org/dports/x11/kchmviewer/Portfile	2016-10-31 09:43:45.000000000 +0100
+++ devel/kchmviewer/Portfile	2016-12-18 16:50:23.000000000 +0100
@@ -1,33 +1,94 @@
-# $Id$
+# -*- 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
 
-PortSystem	1.0
+PortSystem          1.0
+# kchmviewer's KDE variant still requires KDE4 and will thus not be shipped for now.
+# The pure Qt variant is obtained by using QMake instead of CMake.
+PortGroup           qmake5 1.0
+
+name                kchmviewer
+version             7.7
+
+categories          devel
+description         A CHM (Winhelp) files viewer written for Qt.
+long_description    kchmviewer is a reader for CHM (Winhelp) and EPUB \
+                    files using the Qt toolkit. \
+                    The main point of kchmviewer is compatibility with \
+                    non-English chm files, including most international charsets.
+
+maintainers         gmail.com:rjvbertin mk openmaintainer
+platforms           darwin linux
+license             GPL-3
+
+homepage            https://sourceforge.net/projects/kchmviewer
+distname            ${name}-${version}
+master_sites        sourceforge:project/${name}/${name}/${version}
+
+checksums           rmd160  3b072a3225c5a4c796a9406232c3f696285d9aa4 \
+                    sha256  27cbac45c786b1718550a87e6f86010e161302b426c6396ff2a3091b913b17dd
+
+depends_build-append \
+                    port:dos2unix
+
+depends_lib-append  port:libzip \
+                    port:chmlib
+
+# kchmviewer is transitioning to QtWebEngine, but that adaptation is not yet functional.
+if {[info exists qt5.using_kde] && ${qt5.using_kde}} {
+    qt5.depends_component \
+                    qtwebkit
+} else {
+    # qt5.depends_component is not yet available
+    if {${os.major} == 11} {
+        depends_lib-append \
+                    port:qt55-qtwebkit
+    } else {
+        depends_lib-append \
+                    port:qt5-qtwebkit
+    }
+}
+
+post-extract {
+    # force consistent line-endings
+    system -W ${worksrcpath} "find . \\\( -name \"*.cpp\" -o -name \"*.h\" -o -name \"*.pro\" \\\) -exec dos2unix '{}' \";\""
+}
+
+patch.pre_args      -Np1
+# make it build and work as intended.
+# Some of these patches have been submitted upstream:
+# https://sourceforge.net/p/kchmviewer/patches/9/
+patchfiles-append   patch-release-build.diff \
+                    patch-libzip-incpath.diff \
+                    patch-use-webkit-and-dbus.diff \
+                    patch-avoid-private-member.diff \
+                    patch-main-mac.diff \
+                    patch-encoding-no-abort.diff
+
+post-patch {
+    reinplace "s|@PREFIX@|${prefix}|g" \
+                    ${worksrcpath}/lib/libebook/libebook.pro \
+                    ${worksrcpath}/src/src.pro
+}
+
+configure.cppflags-append   -I${prefix}/lib/libzip/include
+default configure.dir       {${workpath}/build}
+configure.pre_args-append   ../${worksrcdir}/${name}.pro
+configure.args-append       -nocache -recursive
+default build.dir           {${workpath}/build}
+
+platform darwin {
+    destroot {
+        xinstall -m 755 -d ${destroot}${qt_apps_dir}
+        file copy ${build.dir}/bin/kchmviewer.app ${destroot}${qt_apps_dir}
+        if {[info procs qt5.add_app_wrapper] ne ""} {
+            qt5.add_app_wrapper kchmviewer
+        }
+    }
+}
+
+platform linux {
+    destroot {
+        xinstall -m 755 ${build.dir}/bin/kchmviewer ${destroot}${prefix}/bin
+    }
+}
 
-name			kchmviewer
-version			3.1-2
-revision		1
-categories		x11
-maintainers		nomaintainer
-platforms		darwin
-
-description		A CHM (Winhelp) files viewer written on Qt/KDE.
-long_description	A CHM (Winhelp) files viewer written on Qt/KDE. It \
-			can be build as a standalone Qt-based application, \
-			or a KDE application. The main point of kchmviewer \
-			is compatibility with non-English chm files, including \
-			most international charsets.
-
-homepage		http://www.kchmviewer.net/
-master_sites		sourceforge
-checksums		md5 bc376ce29784f33bf0b5f8d1ae5141bf
-# for version 3.1-2 ...
-worksrcdir		kchmviewer-3.1
-
-depends_lib		port:qt3 port:chmlib
-
-configure.args		--with-qt-dir=${prefix} \
-			--with-qt-includes=${prefix}/include/qt3 \
-			--with-extra-includes=${prefix}/include \
-			--with-extra-libs=${prefix}/lib
-
-#Variant made stub on 2014/09/28
-variant kde description "Stub variant" {}
+livecheck.regex /${name}-(\[0-9.\]+)${extract.suffix}
