$NetBSD: patch-SConstruct,v 1.8 2019/03/05 19:35:58 adam Exp $

Add support for NetBSD and Dragonfly.
Fix locations.
Don't compile with debug info.
Don't mess with the linker.
Respect LDFLAGS and CXXFLAGS.

--- SConstruct.orig	2019-01-30 14:26:33.000000000 +0000
+++ SConstruct
@@ -974,6 +974,7 @@ envDict = dict(BUILD_ROOT=buildDir,
                INSTALL_DIR=installDir,
                CONFIG_HEADER_DEFINES={},
                LIBDEPS_TAG_EXPANSIONS=[],
+               ENV = os.environ,
                )
 
 env = Environment(variables=env_vars, **envDict)
@@ -1110,7 +1111,9 @@ def CheckForProcessor(context, which_arc
 os_macros = {
     "windows": "defined(_WIN32)",
     "solaris": "defined(__sun)",
+    "dragonfly": "defined(__DragonFly__)",
     "freebsd": "defined(__FreeBSD__)",
+    "netbsd": "defined(__NetBSD__)",
     "openbsd": "defined(__OpenBSD__)",
     "iOS": "defined(__APPLE__) && TARGET_OS_IOS && !TARGET_OS_SIMULATOR",
     "iOS-sim": "defined(__APPLE__) && TARGET_OS_IOS && TARGET_OS_SIMULATOR",
@@ -1514,7 +1517,7 @@ if env['_LIBDEPS'] == '$_LIBDEPS_LIBS':
     if not env.TargetOSIs('solaris', 'darwin', 'windows', 'openbsd'):
         env.Tool('thin_archive')
 
-if env.TargetOSIs('linux', 'freebsd', 'openbsd'):
+if env.TargetOSIs('linux', 'dragonfly', 'freebsd', 'netbsd', 'openbsd'):
     env['LINK_LIBGROUP_START'] = '-Wl,--start-group'
     env['LINK_LIBGROUP_END'] = '-Wl,--end-group'
     # NOTE: The leading and trailing spaces here are important. Do not remove them.
@@ -1554,9 +1557,15 @@ elif env.TargetOSIs('freebsd'):
     env.Append( LIBS=[ "kvm" ] )
     env.Append( CCFLAGS=[ "-fno-omit-frame-pointer" ] )
 
+elif env.TargetOSIs('dragonfly'):
+    env.Append( LIBS=["m", "kvm"] )
+
 elif env.TargetOSIs('darwin'):
      env.Append( LIBS=["resolv"] )
 
+elif env.TargetOSIs('netbsd'):
+    env.Append( LIBS=["m", "kvm"] )
+
 elif env.TargetOSIs('openbsd'):
     env.Append( LIBS=[ "kvm" ] )
 
@@ -1777,7 +1786,6 @@ if env.TargetOSIs('posix'):
     # -Winvalid-pch Warn if a precompiled header (see Precompiled Headers) is found in the search path but can't be used.
     env.Append( CCFLAGS=["-fno-omit-frame-pointer",
                          "-fno-strict-aliasing",
-                         "-ggdb",
                          "-pthread",
                          "-Wall",
                          "-Wsign-compare",
@@ -2413,9 +2421,9 @@ def doConfigure(myenv):
     if usingLibStdCxx:
         def CheckModernLibStdCxx(context):
             test_body = """
-            #if !__has_include(<experimental/filesystem>)
-            #error "libstdc++ from GCC 5.3.0 or newer is required"
-            #endif
+            //#if !__has_include(<experimental/filesystem>)
+            //#error "libstdc++ from GCC 5.3.0 or newer is required"
+            //#endif
             """
 
             context.Message('Checking for libstdc++ 5.3.0 or better... ')
@@ -2649,7 +2657,7 @@ def doConfigure(myenv):
         #
         myenv.Append( CCFLAGS=["/Zc:inline"])
 
-    if myenv.ToolchainIs('gcc', 'clang'):
+    if myenv.ToolchainIs('gcc', 'clang') and get_option('runtime-hardening') == "on":
         # This tells clang/gcc to use the gold linker if it is available - we prefer the gold linker
         # because it is much faster. Don't use it if the user has already configured another linker
         # selection manually.
@@ -3202,7 +3210,7 @@ def doConfigure(myenv):
         myenv.ConfError("Couldn't find SASL header/libraries")
 
     # requires ports devel/libexecinfo to be installed
-    if env.TargetOSIs('freebsd', 'openbsd'):
+    if env.TargetOSIs('dragonfly', 'freebsd', 'netbsd', 'openbsd'):
         if not conf.CheckLib("execinfo"):
             myenv.ConfError("Cannot find libexecinfo, please install devel/libexecinfo.")
 
@@ -3427,7 +3435,7 @@ def doConfigure(myenv):
 
         outputIndex = next((idx for idx in [0,1] if conf.CheckAltivecVbpermqOutput(idx)), None)
         if outputIndex is not None:
-	    conf.env.SetConfigHeaderDefine("MONGO_CONFIG_ALTIVEC_VEC_VBPERMQ_OUTPUT_INDEX", outputIndex)
+            conf.env.SetConfigHeaderDefine("MONGO_CONFIG_ALTIVEC_VEC_VBPERMQ_OUTPUT_INDEX", outputIndex)
         else:
             myenv.ConfError("Running on ppc64le, but can't find a correct vec_vbpermq output index.  Compiler or platform not supported")
 
