From 20d3c077c805ba64331e1a733a09638365abf7a0 Mon Sep 17 00:00:00 2001
From: Bernd Zeimetz <bernd@bzed.de>
Date: Sun, 1 May 2016 15:21:45 +0200
Subject: [PATCH] Work around yet another scons fuckup.

Scons' CheckFunc does not work with recent compiler versions and
-Wstrict-prototypes being enabled.
---
 SConstruct | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 48 insertions(+), 2 deletions(-)

--- a/SConstruct
+++ b/SConstruct
@@ -383,6 +383,52 @@ values can be listed with 'scons -h'.
 
 ## Configuration
 
+# CheckFunc from upstream scons fails always with -Wstrict-prototypes
+
+def CheckFuncFor_Wstrict_prototypes(context, function_name, header = None, language = None):
+    if context.headerfilename:
+        includetext = '#include "%s"' % context.headerfilename
+    else:
+        includetext = ''
+    if not header:
+        header = """
+#ifdef __cplusplus
+extern "C"
+#endif
+char %s(void);""" % function_name
+
+    if not language or language in ["C", "c"]:
+        lang, suffix, msg = ("C", ".c", None)
+    elif language in ["c++", "C++", "cpp", "CXX", "cxx"]:
+        lang, suffix, msg = ("C++", ".cpp", None)
+
+    if msg:
+        context.Display("Cannot check for %s(): %s\n" % (function_name, msg))
+        return msg
+
+    text = """
+%(include)s
+#include <assert.h>
+%(hdr)s
+
+int main(void) {
+#if defined (__stub_%(name)s) || defined (__stub___%(name)s)
+  fail fail fail
+#else
+  %(name)s();
+#endif
+
+  return 0;
+}
+""" % { 'name': function_name,
+        'include': includetext,
+        'hdr': header }
+
+    context.Display("Checking for %s function %s()... " % (lang, function_name))
+    ret = context.TryBuild(context.env.Program, text, suffix)
+    context.Result(ret)
+    return ret
+
 def CheckPKG(context, name):
     context.Message( 'Checking for %s... ' % name )
     ret = context.TryAction('%s --exists \'%s\'' % (env['PKG_CONFIG'], name))[0]
@@ -488,7 +534,8 @@ if env.GetOption("clean") or env.GetOpti
     htmlbuilder = False
     qt_env = None
 else:
-    config = Configure(env, custom_tests = { 'CheckPKG' : CheckPKG,
+    config = Configure(env, custom_tests = { 'CheckFuncFor_Wstrict_prototypes': CheckFuncFor_Wstrict_prototypes,
+                                             'CheckPKG' : CheckPKG,
                                              'CheckXsltproc' : CheckXsltproc,
                                              'CheckCompilerOption' : CheckCompilerOption,
                                              'CheckCompilerDefines' : CheckCompilerDefines,
@@ -668,7 +715,7 @@ else:
     # check function after libraries, because some function require libraries
     # for example clock_gettime() require librt on Linux glibc < 2.17
     for f in ("daemon", "strlcpy", "strlcat", "clock_gettime"):
-        if config.CheckFunc(f):
+        if config.CheckFuncFor_Wstrict_prototypes(f):
             confdefs.append("#define HAVE_%s 1\n" % f.upper())
         else:
             confdefs.append("/* #undef HAVE_%s */\n" % f.upper())
