$OpenBSD: patch-qtbase_qmake_generators_unix_unixmake2_cpp,v 1.5 2016/03/06 11:56:41 zhuk Exp $
1. Un-hardcode system paths and compiler flags.
2. Make sure some paths are listed before others, needed to
   make sure egcc won't pick up /usr/include before its own
   directories.
3. Respect OpenBSD shared library naming rules.
--- qtbase/qmake/generators/unix/unixmake2.cpp.ports.orig	Tue Oct 13 07:35:09 2015
+++ qtbase/qmake/generators/unix/unixmake2.cpp	Thu Dec 10 09:22:47 2015
@@ -74,6 +74,10 @@ UnixMakefileGenerator::writeMakefile(QTextStream &t)
     if (writeDummyMakefile(t))
         return true;
 
+    t << "LOCALBASE=" << LOCALBASE << endl
+      << "X11BASE="   << X11BASE   << endl
+      << endl;
+
     if (project->first("TEMPLATE") == "app" ||
         project->first("TEMPLATE") == "lib" ||
         project->first("TEMPLATE") == "aux") {
@@ -181,12 +185,12 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
     t << "DEFINES       = "
       << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ")
       << varGlue("DEFINES","-D"," -D","") << endl;
-    t << "CFLAGS        = " << var("QMAKE_CFLAGS") << " $(DEFINES)\n";
-    t << "CXXFLAGS      = " << var("QMAKE_CXXFLAGS") << " $(DEFINES)\n";
+    t << "CFLAGS        = " << var("QMAKE_CFLAGS") << " $(DEFINES) $(COPTS)\n";
+    t << "CXXFLAGS      = " << var("QMAKE_CXXFLAGS") << " $(DEFINES) $(CXXOPTS)\n";
     t << "INCPATH       =";
     {
         QString isystem = var("QMAKE_CFLAGS_ISYSTEM");
-        const ProStringList &incs = project->values("INCLUDEPATH");
+        ProStringList incs = project->values("QMAKE_INCDIR_PREPEND") + project->values("INCLUDEPATH");
         for(int i = 0; i < incs.size(); ++i) {
             const ProString &inc = incs.at(i);
             if (inc.isEmpty())
@@ -286,12 +290,19 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
             t << "TARGET0       = " << fileVar("TARGET_") << endl;
         } else if (!project->isActiveConfig("unversioned_libname")) {
             t << "TARGET0       = " << fileVar("TARGET_") << endl;
-            if (project->isEmpty("QMAKE_HPUX_SHLIB")) {
-                t << "TARGETD       = " << fileVar("TARGET_x.y.z") << endl;
-                t << "TARGET1       = " << fileVar("TARGET_x") << endl;
-                t << "TARGET2       = " << fileVar("TARGET_x.y") << endl;
+            if (!project->isEmpty("QMAKE_OPENBSD_SHLIB")) {
+                t << "LIB" << fileVar("QMAKE_ORIG_TARGET") << "_VERSION   = "
+                  << project->first("VER_MAJ") << "." << project->first("VER_MIN")
+                  << endl;
+                t << "TARGETD       = " << fileVar("TARGET_x.y") << endl;
             } else {
-                t << "TARGETD       = " << fileVar("TARGET_x") << endl;
+                if (project->isEmpty("QMAKE_HPUX_SHLIB")) {
+                    t << "TARGETD       = " << fileVar("TARGET_x.y.z") << endl;
+                    t << "TARGET1       = " << fileVar("TARGET_x") << endl;
+                    t << "TARGET2       = " << fileVar("TARGET_x.y") << endl;
+                } else {
+                    t << "TARGETD       = " << fileVar("TARGET_x") << endl;
+                }
             }
         }
     }
@@ -626,7 +637,8 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
             if(!project->isEmpty("QMAKE_POST_LINK"))
                 t << "\n\t" << var("QMAKE_POST_LINK");
             t << endl << endl;
-        } else if(project->isEmpty("QMAKE_HPUX_SHLIB")) {
+        } else if(project->isEmpty("QMAKE_HPUX_SHLIB")
+                      && project->isEmpty("QMAKE_OPENBSD_SHLIB")) {
             t << "\n\t";
 
             if (!project->isActiveConfig("unversioned_libname"))
@@ -660,7 +672,22 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
             if(!project->isEmpty("QMAKE_POST_LINK"))
                 t << "\n\t" << var("QMAKE_POST_LINK");
             t << endl << endl;
+        } else if (!project->isEmpty("QMAKE_OPENBSD_SHLIB")) {
+            // OpenBSD-specific shared libraries handling:
+            // libfoo.so.X.Y, without any symlinks.
+            // 
+            t << "\n\t"
+              << "-$(DEL_FILE) $(TARGET)\n\t"
+              << var("QMAKE_LINK_SHLIB_CMD");
+            if(!destdir.isEmpty())
+                t  << "\n\t-$(DEL_FILE) " << destdir << "$(TARGET)"
+                   << "\n\t-$(MOVE) $(TARGET)  " << destdir;
+            if(!project->isEmpty("QMAKE_POST_LINK"))
+                t << "\n\t" << var("QMAKE_POST_LINK");
+            t << endl << endl;
         } else {
+            // HP-UX-specific shared libraries handling:
+            // libfoo.sl.X, with symlink to libfoo.sl.
             t << "\n\t"
               << "-$(DEL_FILE) $(TARGET) $(TARGET0)\n\t"
               << var("QMAKE_LINK_SHLIB_CMD") << "\n\t";
@@ -1239,6 +1266,11 @@ void UnixMakefileGenerator::init2()
                 project->values("TARGET_x").append("lib" + project->first("TARGET") + "." +
                                                         project->first("VER_MAJ"));
             project->values("TARGET") = project->values("TARGET_x");
+        } else if (!project->isEmpty("QMAKE_OPENBSD_SHLIB")) {
+            project->values("TARGET_x.y").append("lib" + project->first("TARGET") +
+                                                      "." + project->first("QMAKE_EXTENSION_SHLIB") + 
+                                                      ".$(LIB" + project->first("TARGET") + "_VERSION)");
+            project->values("TARGET") = project->values("TARGET_x.y");
         } else if (!project->isEmpty("QMAKE_AIX_SHLIB")) {
             project->values("TARGET_").append(project->first("QMAKE_PREFIX_STATICLIB") + project->first("TARGET")
                     + "." + project->first("QMAKE_EXTENSION_STATICLIB"));
@@ -1431,17 +1463,27 @@ UnixMakefileGenerator::writeLibtoolFile()
     t << "\n";
 
     t << "# The name that we can dlopen(3).\n"
-      << "dlname='" << fileVar(project->isActiveConfig("plugin") ? "TARGET" : "TARGET_x")
-      << "'\n\n";
+      << "dlname='";
+    if (project->isActiveConfig("plugin"))
+        t << fileVar("TARGET");
+    else if (!project->isEmpty("QMAKE_OPENBSD_SHLIB"))
+        t << fileVar("TARGET_x.y");
+    else
+        t << fileVar("TARGET_x");
+    t << "'\n\n";
 
     t << "# Names of this library.\n";
     t << "library_names='";
     if(project->isActiveConfig("plugin")) {
         t << fileVar("TARGET");
     } else {
-        if (project->isEmpty("QMAKE_HPUX_SHLIB"))
-            t << fileVar("TARGET_x.y.z") << ' ';
-        t << fileVar("TARGET_x") << ' ' << fileVar("TARGET_");
+        if (!project->isEmpty("QMAKE_OPENBSD_SHLIB")) {
+            t << fileVar("TARGET_x.y") << " ";
+        } else {
+            if (!project->isEmpty("QMAKE_HPUX_SHLIB"))
+                t << fileVar("TARGET_x.y.z") << " ";
+            t << fileVar("TARGET_x") << " " << fileVar("TARGET_");
+        }
     }
     t << "'\n\n";
 
