$OpenBSD: patch-qmake_generators_unix_unixmake2_cpp,v 1.6 2021/01/19 06:16:29 rsadowski Exp $

Index: qmake/generators/unix/unixmake2.cpp
--- qmake/generators/unix/unixmake2.cpp.orig
+++ qmake/generators/unix/unixmake2.cpp
@@ -63,6 +63,10 @@ UnixMakefileGenerator::writeMakefile(QTextStream &t)
     if (writeDummyMakefile(t))
         return true;
 
+    t << "LOCALBASE     ?=" << var("LOCALBASE") << Qt::endl
+      << "X11BASE       ?=" << var("X11BASE")   << Qt::endl
+      << Qt::endl;
+
     if (project->first("TEMPLATE") == "app" ||
         project->first("TEMPLATE") == "lib" ||
         project->first("TEMPLATE") == "aux") {
@@ -189,16 +193,17 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
     writeExportedVariables(t);
 
     t << "####### Compiler, tools and options\n\n";
-    t << "CC            = " << var("QMAKE_CC") << Qt::endl;
-    t << "CXX           = " << var("QMAKE_CXX") << Qt::endl;
-    t << "DEFINES       = "
+    t << "CC            ?= " << var("QMAKE_CC") << Qt::endl;
+    t << "CXX           ?= " << var("QMAKE_CXX") << Qt::endl;
+    t << "DEFINES       += "
       << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ")
       << varGlue("DEFINES","-D"," -D","") << Qt::endl;
-    t << "CFLAGS        = " << var("QMAKE_CFLAGS") << " $(DEFINES)\n";
-    t << "CXXFLAGS      = " << var("QMAKE_CXXFLAGS") << " $(DEFINES)\n";
-    t << "INCPATH       =";
+    t << "CFLAGS        = " << var("QMAKE_CFLAGS") << " $(DEFINES) $(COPTS)\n";
+    t << "CXXFLAGS      = " << var("QMAKE_CXXFLAGS") << " $(DEFINES) $(CXXOPTS)\n";
+    t << "INCPATH       +=";
     {
-        const ProStringList &incs = project->values("INCLUDEPATH");
+        // Extend INCPATH with -isystem /usr/include/c++/v1 ...
+        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())
@@ -214,9 +219,9 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
     writeDefaultVariables(t);
 
     if(!project->isActiveConfig("staticlib")) {
-        t << "LINK          = " << var("QMAKE_LINK") << Qt::endl;
+        t << "LINK          ?= " << var("QMAKE_LINK") << Qt::endl;
         t << "LFLAGS        = " << var("QMAKE_LFLAGS") << Qt::endl;
-        t << "LIBS          = $(SUBLIBS) " << fixLibFlags("LIBS").join(' ') << ' '
+        t << "LIBS          += $(SUBLIBS) " << fixLibFlags("LIBS").join(' ') << ' '
                                            << fixLibFlags("LIBS_PRIVATE").join(' ') << ' '
                                            << fixLibFlags("QMAKE_LIBS").join(' ') << ' '
                                            << fixLibFlags("QMAKE_LIBS_PRIVATE").join(' ') << Qt::endl;
@@ -224,8 +229,8 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
 
     t << "AR            = " << var("QMAKE_AR") << Qt::endl;
     t << "RANLIB        = " << var("QMAKE_RANLIB") << Qt::endl;
-    t << "SED           = " << var("QMAKE_STREAM_EDITOR") << Qt::endl;
-    t << "STRIP         = " << var("QMAKE_STRIP") << Qt::endl;
+    t << "SED           ?= " << var("QMAKE_STREAM_EDITOR") << Qt::endl;
+    t << "STRIP         ?= " << var("QMAKE_STRIP") << Qt::endl;
 
     t << Qt::endl;
 
@@ -259,12 +264,19 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
             t << "TARGET0       = " << fileVar("TARGET_") << Qt::endl;
         } else if (!project->isActiveConfig("unversioned_libname")) {
             t << "TARGET0       = " << fileVar("TARGET_") << Qt::endl;
-            if (project->isEmpty("QMAKE_HPUX_SHLIB")) {
-                t << "TARGETD       = " << fileVar("TARGET_x.y.z") << Qt::endl;
-                t << "TARGET1       = " << fileVar("TARGET_x") << Qt::endl;
-                t << "TARGET2       = " << fileVar("TARGET_x.y") << Qt::endl;
+            if (!project->isEmpty("QMAKE_OPENBSD_SHLIB")) {
+                t << "LIB" << fileVar("QMAKE_ORIG_TARGET") << "_VERSION   ?= "
+                  << project->first("VER_MAJ") << "." << project->first("VER_MIN")
+                  <<Qt::endl;
+                t << "TARGETD       = " << fileVar("TARGET_x.y") <<Qt::endl;
             } else {
-                t << "TARGETD       = " << fileVar("TARGET_x") << Qt::endl;
+                if (project->isEmpty("QMAKE_HPUX_SHLIB")) {
+                    t << "TARGETD       = " << fileVar("TARGET_x.y.z") <<Qt::endl;
+                    t << "TARGET1       = " << fileVar("TARGET_x") <<Qt::endl;
+                    t << "TARGET2       = " << fileVar("TARGET_x.y") <<Qt::endl;
+                } else {
+                    t << "TARGETD       = " << fileVar("TARGET_x,y") <<Qt::endl;
+                }
             }
         }
     }
@@ -589,7 +601,8 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
             if(!project->isEmpty("QMAKE_POST_LINK"))
                 t << "\n\t" << var("QMAKE_POST_LINK");
             t << Qt::endl << Qt::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"))
@@ -623,7 +636,22 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
             if(!project->isEmpty("QMAKE_POST_LINK"))
                 t << "\n\t" << var("QMAKE_POST_LINK");
             t << Qt::endl << Qt::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 <<Qt::endl <<Qt::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";
@@ -1245,6 +1273,12 @@ 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("PRL_TARGET").prepend("lib" + project->first("TARGET"));
+            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("PRL_TARGET").prepend("lib" + project->first("TARGET"));
             project->values("TARGET_").append(project->first("QMAKE_PREFIX_STATICLIB") + project->first("TARGET")
@@ -1465,18 +1499,33 @@ UnixMakefileGenerator::writeLibtoolFile()
       << QT_VERSION_STR << ")";
     t << "\n";
 
+    if (!project->isEmpty("QMAKE_OPENBSD_SHLIB"))
+      t << "LIB" << fileVar("QMAKE_ORIG_TARGET") << "_VERSION="
+        << project->first("VER_MAJ") << "." << project->first("VER_MIN")
+        <<Qt::endl;
+
     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";
 
