Attached to this email you'll find a diff that modifies the wkhtmltopdf port so that it is statically built against their patched qt. This will will enable the following extra features:

 * Printing more then one HTML document into a PDF file.
 * Running without an X11 server.
 * Adding a document outline to the PDF file.
 * Adding headers and footers to the PDF file.
 * Generating a table of contents.
 * Adding links in the generated PDF file.
 * Printing using the screen media-type.
 * Disabling the smart shrink feature of webkit.

Note that the patches I needed in this diff are copied from the phantomjs port and the qt4 port.

As far as I can see, the current diff has only one problem left: it can only be built when qt4 is not already installed on the system, because the linking phase will fail otherwise. How would I be able to solve this problem?

Thanks,
Frank
Index: Makefile
===================================================================
RCS file: /cvs/ports/textproc/wkhtmltopdf/Makefile,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 Makefile
--- Makefile    4 Nov 2015 21:11:16 -0000       1.1.1.1
+++ Makefile    16 Dec 2015 20:46:42 -0000
@@ -5,8 +5,13 @@ COMMENT =              convert HTML to PDF using Web
 GH_ACCOUNT =           wkhtmltopdf
 GH_PROJECT =           wkhtmltopdf
 GH_TAGNAME =           0.12.2.4
+REVISION =             0
 
+QT_COMMIT =            7e48a1fac7e0f9aefccd01e9871f987da3a62fda
+
+MASTER_SITES0 =                https://github.com/wkhtmltopdf/qt/archive/
 DISTNAME =             wkhtmltopdf-${GH_TAGNAME}
+DISTFILES +=           ${DISTNAME}.tar.gz ${QT_COMMIT}.tar.gz:0
 
 SHARED_LIBS =          wkhtmltox 0.0 # 0.12
 
@@ -20,10 +25,7 @@ MAINTAINER =         Frank Groeneveld <frank@fr
 PERMIT_PACKAGE_CDROM = Yes
 
 WANTLIB +=             ICE SM X11 Xext Xi Xinerama Xrender c fontconfig
-WANTLIB +=             freetype m pthread stdc++ QtCore QtGui QtNetwork
-WANTLIB +=             QtSvg QtWebKit QtXmlPatterns
-
-MODULES =              x11/qt4
+WANTLIB +=             freetype m pthread stdc++
 
 MAKE_FLAGS =           LIBwkhtmltox_VERSION=${LIBwkhtmltox_VERSION}
 FAKE_FLAGS =           INSTALL_ROOT=${WRKINST}${TRUEPREFIX}
@@ -32,7 +34,93 @@ SEPARATE_BUILD =     Yes
 
 NO_TEST =              Yes
 
+pre-patch:
+       cd ${WRKDIR}/${DISTNAME} && rmdir qt
+       cd ${WRKDIR}/${DISTNAME} && mv ../qt-${QT_COMMIT} qt
+
 do-configure:
-       cd ${WRKBUILD} && env -i ${CONFIGURE_ENV} qmake4 
${WRKSRC}/wkhtmltopdf.pro
+       mkdir ${WRKBUILD}/qt
+       # qt config options taken from scripts/build.py
+       cd ${WRKBUILD}/qt && \
+               env -i ${CONFIGURE_ENV} ${WRKSRC}/qt/configure \
+               --prefix=${WRKBUILD}/qt \
+               -opensource \
+               -confirm-license \
+               -fast \
+               -release \
+               -static \
+               -graphicssystem raster \
+               -webkit \
+               -exceptions \
+               -xmlpatterns \
+               -system-zlib \
+               -system-libpng \
+               -system-libjpeg \
+               -no-libmng \
+               -no-libtiff \
+               -no-accessibility \
+               -no-stl \
+               -no-qt3support \
+               -no-phonon \
+               -no-phonon-backend \
+               -no-opengl \
+               -no-declarative \
+               -no-script \
+               -no-scripttools \
+               -no-sql-ibase \
+               -no-sql-mysql \
+               -no-sql-odbc \
+               -no-sql-psql \
+               -no-sql-sqlite \
+               -no-sql-sqlite2 \
+               -no-mmx \
+               -no-3dnow \
+               -no-sse \
+               -no-sse2 \
+               -no-multimedia \
+               -nomake demos \
+               -nomake docs \
+               -nomake examples \
+               -nomake tools \
+               -nomake tests \
+               -nomake translations \
+               -silent \
+               -xrender \
+               -largefile \
+               -iconv \
+               -openssl \
+               -no-rpath \
+               -no-dbus \
+               -no-nis \
+               -no-cups \
+               -no-pch \
+               -no-gtkstyle \
+               -no-nas-sound \
+               -no-sm \
+               -no-xshape \
+               -no-xinerama \
+               -no-xcursor \
+               -no-xfixes \
+               -no-xrandr \
+               -no-mitshm \
+               -no-xinput \
+               -no-xkb \
+               -no-glib \
+               -no-gstreamer \
+               -D ENABLE_VIDEO=0 \
+               -no-openvg \
+               -no-xsync \
+               -no-audio-backend \
+               -no-sse3 \
+               -no-ssse3 \
+               -no-sse4.1 \
+               -no-sse4.2 \
+               -no-avx \
+               -no-neon
+       cd ${WRKBUILD} && env -i ${CONFIGURE_ENV} qt/bin/qmake \
+               ${WRKSRC}/wkhtmltopdf.pro
+
+pre-build:
+       cd ${WRKBUILD}/qt && env -i ${MAKE_FLAGS} gmake -j${MAKE_JOBS}
 
 .include <bsd.port.mk>
Index: distinfo
===================================================================
RCS file: /cvs/ports/textproc/wkhtmltopdf/distinfo,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 distinfo
--- distinfo    4 Nov 2015 21:11:16 -0000       1.1.1.1
+++ distinfo    16 Dec 2015 20:46:42 -0000
@@ -1,2 +1,4 @@
+SHA256 (7e48a1fac7e0f9aefccd01e9871f987da3a62fda.tar.gz) = 
0uxGcEwKVGE7Wlhv/0bSRZLFCiYYJJTxqkmKy0aLwlQ=
 SHA256 (wkhtmltopdf-0.12.2.4.tar.gz) = 
27AWbpzhkeeH6QlgHkzbrnEGnylpM2Lt9c19TUREcog=
+SIZE (7e48a1fac7e0f9aefccd01e9871f987da3a62fda.tar.gz) = 173043701
 SIZE (wkhtmltopdf-0.12.2.4.tar.gz) = 127595
Index: patches/patch-qt_config_tests_unix_gnu-libiconv_gnu-libiconv_cpp
===================================================================
RCS file: patches/patch-qt_config_tests_unix_gnu-libiconv_gnu-libiconv_cpp
diff -N patches/patch-qt_config_tests_unix_gnu-libiconv_gnu-libiconv_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-qt_config_tests_unix_gnu-libiconv_gnu-libiconv_cpp    16 Dec 
2015 20:46:42 -0000
@@ -0,0 +1,12 @@
+$OpenBSD$
+--- qt/config.tests/unix/gnu-libiconv/gnu-libiconv.cpp.orig    Wed Dec  9 
20:22:20 2015
++++ qt/config.tests/unix/gnu-libiconv/gnu-libiconv.cpp Wed Dec  9 20:22:28 2015
+@@ -48,7 +48,7 @@ int main(int, char **)
+ {
+     iconv_t x = iconv_open("", "");
+ 
+-    const char *inp;
++    char *inp;
+     char *outp;
+     size_t inbytes, outbytes;
+     iconv(x, &inp, &inbytes, &outp, &outbytes);
Index: patches/patch-qt_qmake_generators_unix_unixmake2_cpp
===================================================================
RCS file: patches/patch-qt_qmake_generators_unix_unixmake2_cpp
diff -N patches/patch-qt_qmake_generators_unix_unixmake2_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-qt_qmake_generators_unix_unixmake2_cpp        16 Dec 2015 
20:46:42 -0000
@@ -0,0 +1,121 @@
+$OpenBSD$
+--- qt/qmake/generators/unix/unixmake2.cpp.orig        Thu Jul  2 13:46:37 2015
++++ qt/qmake/generators/unix/unixmake2.cpp     Sun Dec 13 11:47:43 2015
+@@ -247,10 +247,8 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
+         } else if(!project->isEmpty("QMAKE_SYMBIAN_SHLIB")) {
+             t << "TARGETD       = " << escapeFilePath(var("TARGET")) << endl;
+         } else if(project->isEmpty("QMAKE_HPUX_SHLIB")) {
+-            t << "TARGETD       = " << escapeFilePath(var("TARGET_x.y.z")) << 
endl;
+-            t << "TARGET0       = " << escapeFilePath(var("TARGET_")) << endl;
+-            t << "TARGET1       = " << escapeFilePath(var("TARGET_x")) << 
endl;
+-            t << "TARGET2       = " << escapeFilePath(var("TARGET_x.y")) << 
endl;
++          t << "LIB" << var("OBSD_TARGET_NAME") << "_VERSION = " << 
var("OBSD_TARGET_VERSION") << endl;
++            t << "TARGETD       = " << var("OBSD_TARGET_x.y") << endl;
+         } else {
+             t << "TARGETD       = " << escapeFilePath(var("TARGET_x")) << 
endl;
+             t << "TARGET0       = " << escapeFilePath(var("TARGET_")) << endl;
+@@ -572,31 +570,22 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
+             t << endl << endl;
+         } else if(project->isEmpty("QMAKE_HPUX_SHLIB")) {
+             t << "\n\t"
+-              << "-$(DEL_FILE) $(TARGET) $(TARGET0) $(TARGET1) $(TARGET2)" << 
"\n\t"
+               << var("QMAKE_LINK_SHLIB_CMD") << "\n\t";
+-            t << varGlue("QMAKE_LN_SHLIB","-"," "," $(TARGET) $(TARGET0)")  
<< "\n\t"
+-              << varGlue("QMAKE_LN_SHLIB","-"," "," $(TARGET) $(TARGET1)") << 
"\n\t"
+-              << varGlue("QMAKE_LN_SHLIB","-"," "," $(TARGET) $(TARGET2)");
+             if(!destdir.isEmpty())
+                 t << "\n\t"
+                   << "-$(DEL_FILE) " << destdir << "$(TARGET)\n\t"
+-                  << "-$(DEL_FILE) " << destdir << "$(TARGET0)\n\t"
+-                  << "-$(DEL_FILE) " << destdir << "$(TARGET1)\n\t"
+-                  << "-$(DEL_FILE) " << destdir << "$(TARGET2)\n\t"
+-                  << "-$(MOVE) $(TARGET) $(TARGET0) $(TARGET1) $(TARGET2) " 
<< destdir;
++                  << "-$(MOVE) $(TARGET) " << destdir;
+             if(!project->isEmpty("QMAKE_POST_LINK"))
+                 t << "\n\t" << var("QMAKE_POST_LINK");
+             t << endl << endl;
+         } else {
+             t << "\n\t"
+-              << "-$(DEL_FILE) $(TARGET) $(TARGET0)" << "\n\t"
++              << "-$(DEL_FILE) $(TARGET)" << "\n\t"
+               << var("QMAKE_LINK_SHLIB_CMD") << "\n\t";
+-            t << varGlue("QMAKE_LN_SHLIB",""," "," $(TARGET) $(TARGET0)");
+             if(!destdir.isEmpty())
+                 t  << "\n\t"
+                    << "-$(DEL_FILE) " << destdir << "$(TARGET)\n\t"
+-                   << "-$(DEL_FILE) " << destdir << "$(TARGET0)\n\t"
+-                   << "-$(MOVE) $(TARGET) $(TARGET0) " << destdir;
++                   << "-$(MOVE) $(TARGET) " << destdir;
+             if(!project->isEmpty("QMAKE_POST_LINK"))
+                 t << "\n\t" << var("QMAKE_POST_LINK");
+             t << endl << endl;
+@@ -1019,6 +1008,13 @@ void UnixMakefileGenerator::init2()
+     project->values("VER_MAJ").append(l[0]);
+     project->values("VER_MIN").append(l[1]);
+     project->values("VER_PAT").append(l[2]);
++    project->values("OBSD_TARGET_NAME").append(project->first("TARGET"));
++    project->values("OBSD_TARGET_VERSION").append(project->first("VER_MAJ") + 
 "."  + project->first("VER_MIN"));
++    // for (portable) Makefiles
++    project->values("OBSD_TARGET_x.y").append("lib" + 
project->first("TARGET") + "." + project->first("QMAKE_EXTENSION_SHLIB") + 
".$(LIB" + project->first("TARGET") + "_VERSION)");
++    // for libtool files, to be updated by SUBST_CMD in OpenBSD ports
++    project->values("OBSD_SUBST_x.y").append("lib" + project->first("TARGET") 
+ "." + project->first("QMAKE_EXTENSION_SHLIB") + ".${LIB" + 
project->first("TARGET") + "_VERSION}");
++
+     if(project->isEmpty("QMAKE_FRAMEWORK_VERSION"))
+         
project->values("QMAKE_FRAMEWORK_VERSION").append(project->values("VER_MAJ").first());
+ 
+@@ -1159,7 +1155,7 @@ void UnixMakefileGenerator::init2()
+                                                             
project->first("VER_MIN") +  "." +
+                                                             
project->first("VER_PAT"));
+             }
+-            project->values("TARGET") = project->values("TARGET_x.y.z");
++            project->values("TARGET") = project->values("OBSD_TARGET_x.y");
+         }
+         if(project->isEmpty("QMAKE_LN_SHLIB"))
+             project->values("QMAKE_LN_SHLIB").append("ln -s");
+@@ -1304,18 +1300,31 @@ UnixMakefileGenerator::writeLibtoolFile()
+       << QT_VERSION_STR << ") on: " << 
QDateTime::currentDateTime().toString();
+       t << "\n";
+ 
+-    t << "# The name that we can dlopen(3).\n"
+-      << "dlname='" << var(project->isActiveConfig("plugin") ? "TARGET" : 
"TARGET_x")
+-      << "'\n\n";
++    t << "# The name that we can dlopen(3).\ndlname='";
++    if(project->isActiveConfig("plugin")) {
++        t << var("TARGET");
++    } else {
++#ifdef __OpenBSD__
++        t << var("OBSD_SUBST_x.y");
++#else
++        t << var("TARGET_x");
++#endif
++    }
++    t << "'\n\n";
+ 
+     t << "# Names of this library.\n";
+     t << "library_names='";
+     if(project->isActiveConfig("plugin")) {
+         t << var("TARGET");
+     } else {
+-        if (project->isEmpty("QMAKE_HPUX_SHLIB"))
+-            t << var("TARGET_x.y.z") << " ";
+-        t << var("TARGET_x") << " " << var("TARGET_");
++        if (project->isEmpty("QMAKE_HPUX_SHLIB")) {
++#ifdef __OpenBSD__
++            t << var("OBSD_SUBST_x.y") << " ";
++#else
++            t << var("TARGET_x.y.z") << " " << var("TARGET_x") << " ";
++#endif
++        }
++        t << var("TARGET_");
+     }
+     t << "'\n\n";
+ 
+@@ -1330,7 +1339,7 @@ UnixMakefileGenerator::writeLibtoolFile()
+         libs << "QMAKE_LIBS"; //obvious one
+     t << "dependency_libs='";
+     for(QStringList::ConstIterator it = libs.begin(); it != libs.end(); ++it)
+-        t << project->values((*it)).join(" ") << " ";
++        t << project->values((*it)).join(" ").replace('(', '{').replace(')', 
'}') << " ";
+     t << "'\n\n";
+ 
+     t << "# Version information for " << lname << "\n";
Index: patches/patch-qt_qmake_generators_unix_unixmake_cpp
===================================================================
RCS file: patches/patch-qt_qmake_generators_unix_unixmake_cpp
diff -N patches/patch-qt_qmake_generators_unix_unixmake_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-qt_qmake_generators_unix_unixmake_cpp 16 Dec 2015 20:46:42 
-0000
@@ -0,0 +1,12 @@
+$OpenBSD$
+--- qt/qmake/generators/unix/unixmake.cpp.orig Mon Dec 14 19:17:46 2015
++++ qt/qmake/generators/unix/unixmake.cpp      Mon Dec 14 19:17:54 2015
+@@ -757,7 +757,7 @@ UnixMakefileGenerator::defaultInstall(const QString &t
+         if(project->isEmpty("QMAKE_CYGWIN_SHLIB")) {
+             if(!project->isActiveConfig("staticlib") && 
!project->isActiveConfig("plugin")) {
+                 if(project->isEmpty("QMAKE_HPUX_SHLIB")) {
+-                    links << "$(TARGET0)" << "$(TARGET1)" << "$(TARGET2)";
++                    //links << "$(TARGET0)" << "$(TARGET1)" << "$(TARGET2)";
+                 } else {
+                     links << "$(TARGET0)";
+                 }
Index: 
patches/patch-qt_src_3rdparty_webkit_Source_JavaScriptCore_heap_MachineStackMarker_cpp
===================================================================
RCS file: 
patches/patch-qt_src_3rdparty_webkit_Source_JavaScriptCore_heap_MachineStackMarker_cpp
diff -N 
patches/patch-qt_src_3rdparty_webkit_Source_JavaScriptCore_heap_MachineStackMarker_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ 
patches/patch-qt_src_3rdparty_webkit_Source_JavaScriptCore_heap_MachineStackMarker_cpp
      16 Dec 2015 20:46:42 -0000
@@ -0,0 +1,29 @@
+$OpenBSD$
+--- 
qt/src/3rdparty/webkit/Source/JavaScriptCore/heap/MachineStackMarker.cpp.orig   
   Wed Dec  9 20:20:38 2015
++++ qt/src/3rdparty/webkit/Source/JavaScriptCore/heap/MachineStackMarker.cpp   
Wed Dec  9 20:21:52 2015
+@@ -380,8 +380,10 @@ static size_t getPlatformThreadRegisters(const Platfor
+ #elif USE(PTHREADS)
+     pthread_attr_init(&regs);
+ #if HAVE(PTHREAD_NP_H) || OS(NETBSD)
++#ifndef __OpenBSD__
+     // e.g. on FreeBSD 5.4, neund...@kde.org
+     pthread_attr_get_np(platformThread, &regs);
++#endif
+ #else
+     // FIXME: this function is non-portable; other POSIX systems may have 
different np alternatives
+     pthread_getattr_np(platformThread, &regs);
+@@ -432,7 +434,14 @@ static inline void* otherThreadStackPointer(const Plat
+ #elif USE(PTHREADS)
+     void* stackBase = 0;
+     size_t stackSize = 0;
++#if defined(__OpenBSD__)
++    stack_t ss;
++    int rc = pthread_stackseg_np(pthread_self(), &ss);
++    stackBase = (void*)((size_t) ss.ss_sp - ss.ss_size);
++    stackSize = ss.ss_size;
++#else
+     int rc = pthread_attr_getstack(&regs, &stackBase, &stackSize);
++#endif
+     (void)rc; // FIXME: Deal with error code somehow? Seems fatal.
+     ASSERT(stackBase);
+     return static_cast<char*>(stackBase) + stackSize;
Index: 
patches/patch-qt_src_3rdparty_webkit_Source_JavaScriptCore_jit_JITStubs_cpp
===================================================================
RCS file: 
patches/patch-qt_src_3rdparty_webkit_Source_JavaScriptCore_jit_JITStubs_cpp
diff -N 
patches/patch-qt_src_3rdparty_webkit_Source_JavaScriptCore_jit_JITStubs_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-qt_src_3rdparty_webkit_Source_JavaScriptCore_jit_JITStubs_cpp 
16 Dec 2015 20:46:42 -0000
@@ -0,0 +1,12 @@
+$OpenBSD$
+--- qt/src/3rdparty/webkit/Source/JavaScriptCore/jit/JITStubs.cpp.orig Wed Dec 
 9 21:34:01 2015
++++ qt/src/3rdparty/webkit/Source/JavaScriptCore/jit/JITStubs.cpp      Wed Dec 
 9 21:34:22 2015
+@@ -79,7 +79,7 @@ namespace JSC {
+ #define THUMB_FUNC_PARAM(name)
+ #endif
+ 
+-#if (OS(LINUX) || OS(FREEBSD)) && CPU(X86_64)
++#if (OS(LINUX) || OS(FREEBSD) || OS(OPENBSD)) && CPU(X86_64)
+ #define SYMBOL_STRING_RELOCATION(name) #name "@plt"
+ #elif OS(DARWIN) || (CPU(X86_64) && COMPILER(MINGW) && 
!GCC_VERSION_AT_LEAST(4, 5, 0))
+ #define SYMBOL_STRING_RELOCATION(name) "_" #name
Index: patches/patch-qt_src_corelib_codecs_qiconvcodec_cpp
===================================================================
RCS file: patches/patch-qt_src_corelib_codecs_qiconvcodec_cpp
diff -N patches/patch-qt_src_corelib_codecs_qiconvcodec_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-qt_src_corelib_codecs_qiconvcodec_cpp 16 Dec 2015 20:46:42 
-0000
@@ -0,0 +1,40 @@
+$OpenBSD$
+--- qt/src/corelib/codecs/qiconvcodec.cpp.orig Wed Dec  9 20:22:51 2015
++++ qt/src/corelib/codecs/qiconvcodec.cpp      Wed Dec  9 20:23:50 2015
+@@ -219,12 +219,7 @@ QString QIconvCodec::convertToUnicode(const char* char
+     IconvState *state = *pstate;
+     size_t inBytesLeft = len;
+     // best case assumption, each byte is converted into one UTF-16 
character, plus 2 bytes for the BOM
+-#ifdef GNU_LIBICONV
+-    // GNU doesn't disagree with POSIX :/
+-    const char *inBytes = chars;
+-#else
+     char *inBytes = const_cast<char *>(chars);
+-#endif
+ 
+     QByteArray in;
+     if (remainingCount) {
+@@ -318,11 +313,7 @@ static bool setByteOrder(iconv_t cd)
+     size_t outBytesLeft = sizeof buf;
+     size_t inBytesLeft = sizeof bom;
+ 
+-#if defined(GNU_LIBICONV)
+-    const char **inBytesPtr = const_cast<const char **>(&inBytes);
+-#else
+     char **inBytesPtr = &inBytes;
+-#endif
+ 
+     if (iconv(cd, inBytesPtr, &inBytesLeft, &outBytes, &outBytesLeft) == 
(size_t) -1) {
+         return false;
+@@ -338,11 +329,7 @@ QByteArray QIconvCodec::convertFromUnicode(const QChar
+     char *outBytes;
+     size_t inBytesLeft;
+ 
+-#if defined(GNU_LIBICONV)
+-    const char **inBytesPtr = const_cast<const char **>(&inBytes);
+-#else
+     char **inBytesPtr = &inBytes;
+-#endif
+ 
+     IconvState *temporaryState = 0;
+     QThreadStorage<QIconvCodec::IconvState *> *ts = fromUnicodeState();

Reply via email to