From 18e3d62f5c8f957acc45695cb99c24510d23b457 Mon Sep 17 00:00:00 2001
From: Wang Mingyu <wangmy@cn.fujitsu.com>
Date: Fri, 25 Dec 2020 14:14:08 +0900
Subject: [PATCH] talloc: Add configure options for packages

Add configure options for the following packages:
 - acl
 - attr
 - libbsd
 - libcap
 - valgrind

Upstream-Status: Inappropriate [oe deterministic build specific]

Signed-off-by: Jackie Huang <jackie.huang@windriver.com>

Modified to apply to version 2.1.10.

Signed-off-by: Joe Slater <joe.slater@windriver.com>

Modified tp apply to version 2.2.0
Signed-off-by: Changqing Li <changqing.li@windriver.com>

Rebase to 2.4.1
Remove libaio option
Signed-off-by: Yi Zhao <yi.zhao@windriver.com>

Rebase to 2.4.2
Signed-off-by: Wang Mingyu <wangmy@fujitsu.com>
---
 lib/replace/wscript | 100 ++++++++++++++++++++++++++++++--------------
 wscript             |   7 +++-
 2 files changed, 75 insertions(+), 32 deletions(-)

diff --git a/lib/replace/wscript b/lib/replace/wscript
index 77e655b..2fd7dfb 100644
--- a/lib/replace/wscript
+++ b/lib/replace/wscript
@@ -25,6 +25,34 @@ def options(opt):
     opt.PRIVATE_EXTENSION_DEFAULT('')
     opt.RECURSE('buildtools/wafsamba')
 
+    opt.add_option('--with-acl',
+                   help=("Enable use of acl"),
+                   action="store_true", dest='enable_acl')
+    opt.add_option('--without-acl',
+                   help=("Disable use of acl"),
+                   action="store_false", dest='enable_acl', default=False)
+
+    opt.add_option('--with-attr',
+                   help=("Enable use of attr"),
+                   action="store_true", dest='enable_attr')
+    opt.add_option('--without-attr',
+                   help=("Disable use of attr"),
+                   action="store_false", dest='enable_attr', default=False)
+
+    opt.add_option('--with-libbsd',
+                   help=("Enable use of libbsd"),
+                   action="store_true", dest='enable_libbsd')
+    opt.add_option('--without-libbsd',
+                   help=("Disable use of libbsd"),
+                   action="store_false", dest='enable_libbsd', default=False)
+
+    opt.add_option('--with-libcap',
+                   help=("Enable use of libcap"),
+                   action="store_true", dest='enable_libcap')
+    opt.add_option('--without-libcap',
+                   help=("Disable use of libcap"),
+                   action="store_false", dest='enable_libcap', default=False)
+
 @Utils.run_once
 def configure(conf):
     conf.RECURSE('buildtools/wafsamba')
@@ -38,18 +66,27 @@ def configure(conf):
     conf.DEFINE('HAVE_LIBREPLACE', 1)
     conf.DEFINE('LIBREPLACE_NETWORK_CHECKS', 1)
 
-    conf.CHECK_HEADERS('linux/types.h crypt.h locale.h acl/libacl.h compat.h')
-    conf.CHECK_HEADERS('acl/libacl.h attr/xattr.h compat.h ctype.h dustat.h')
+    conf.CHECK_HEADERS('linux/types.h crypt.h locale.h compat.h')
+    conf.CHECK_HEADERS('compat.h ctype.h dustat.h')
     conf.CHECK_HEADERS('fcntl.h fnmatch.h glob.h history.h krb5.h langinfo.h')
     conf.CHECK_HEADERS('locale.h ndir.h pwd.h')
-    conf.CHECK_HEADERS('shadow.h sys/acl.h')
-    conf.CHECK_HEADERS('sys/attributes.h attr/attributes.h sys/capability.h sys/dir.h sys/epoll.h')
+    conf.CHECK_HEADERS('shadow.h')
+    conf.CHECK_HEADERS('sys/attributes.h sys/dir.h sys/epoll.h')
     conf.CHECK_HEADERS('sys/fcntl.h sys/filio.h sys/filsys.h sys/fs/s5param.h')
     conf.CHECK_HEADERS('sys/id.h sys/ioctl.h sys/ipc.h sys/mman.h sys/mode.h sys/ndir.h sys/priv.h')
     conf.CHECK_HEADERS('sys/resource.h sys/security.h sys/shm.h sys/statfs.h sys/statvfs.h sys/termio.h')
     conf.CHECK_HEADERS('sys/vfs.h sys/xattr.h termio.h termios.h sys/file.h')
     conf.CHECK_HEADERS('sys/ucontext.h sys/wait.h sys/stat.h')
 
+    if Options.options.enable_acl:
+        conf.CHECK_HEADERS('acl/libacl.h sys/acl.h')
+
+    if Options.options.enable_attr:
+        conf.CHECK_HEADERS('attr/attributes.h attr/xattr.h')
+
+    if Options.options.enable_libcap:
+        conf.CHECK_HEADERS('sys/capability.h')
+
     if not conf.CHECK_DECLS('malloc', headers='stdlib.h'):
         conf.CHECK_HEADERS('malloc.h')
 
@@ -113,8 +150,9 @@ def configure(conf):
     conf.CHECK_HEADERS('sys/fileio.h sys/filesys.h sys/dustat.h sys/sysmacros.h')
     conf.CHECK_HEADERS('xfs/libxfs.h netgroup.h')
 
-    conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h')
-    conf.CHECK_HEADERS('valgrind/memcheck.h valgrind/helgrind.h valgrind/callgrind.h')
+    if Options.options.enable_valgrind:
+        conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h')
+        conf.CHECK_HEADERS('valgrind/memcheck.h valgrind/helgrind.h valgrind/callgrind.h')
     conf.CHECK_HEADERS('nss_common.h nsswitch.h ns_api.h')
     conf.CHECK_HEADERS('sys/extattr.h sys/ea.h sys/proplist.h sys/cdefs.h')
     conf.CHECK_HEADERS('utmp.h utmpx.h lastlog.h')
@@ -443,31 +481,31 @@ def configure(conf):
 
     strlcpy_in_bsd = False
 
-    # libbsd on some platforms provides strlcpy and strlcat
-    if not conf.CHECK_FUNCS('strlcpy strlcat'):
-        if conf.CHECK_FUNCS_IN('strlcpy strlcat', 'bsd', headers='bsd/string.h',
-                               checklibc=True):
-            strlcpy_in_bsd = True
-    elif conf.env.enable_fuzzing:
-        # Just to complicate it more, some versions of Honggfuzz have
-        # got strlcpy and strlcat in libc, but not in <string.h>
-        # (unless it is there coincidentally, on a BSD). Therefore we
-        # can't use CHECK_FUNCS alone to decide whether to add the
-        # headers to replace.h.
-        #
-        # As this is only known to happen on a fuzzing compiler, we'll
-        # skip the check when not in fuzzing mode.
-        conf.CHECK_HEADERS('bsd/string.h')
-
-    if not conf.CHECK_FUNCS('getpeereid'):
-        conf.CHECK_FUNCS_IN('getpeereid', 'bsd', headers='sys/types.h bsd/unistd.h')
-    if not conf.CHECK_FUNCS_IN('setproctitle', 'setproctitle', headers='setproctitle.h'):
-        conf.CHECK_FUNCS_IN('setproctitle', 'bsd', headers='sys/types.h bsd/unistd.h')
-    if not conf.CHECK_FUNCS('setproctitle_init'):
-        conf.CHECK_FUNCS_IN('setproctitle_init', 'bsd', headers='sys/types.h bsd/unistd.h')
-
-    if not conf.CHECK_FUNCS('closefrom'):
-        conf.CHECK_FUNCS_IN('closefrom', 'bsd', headers='bsd/unistd.h')
+    if Options.options.enable_libbsd:
+        # libbsd on some platforms provides strlcpy and strlcat
+        if not conf.CHECK_FUNCS('strlcpy strlcat'):
+            if conf.CHECK_FUNCS_IN('strlcpy strlcat', 'bsd', headers='bsd/string.h',
+                checklibc=True):
+                strlcpy_in_bsd = True
+        elif conf.env.enable_fuzzing:
+            # Just to complicate it more, some versions of Honggfuzz have
+            # got strlcpy and strlcat in libc, but not in <string.h>
+            # (unless it is there coincidentally, on a BSD). Therefore we
+            # can't use CHECK_FUNCS alone to decide whether to add the
+            # headers to replace.h.
+            #
+            # As this is only known to happen on a fuzzing compiler, we'll
+            # skip the check when not in fuzzing mode.
+            conf.CHECK_HEADERS('bsd/string.h')
+
+        if not conf.CHECK_FUNCS('getpeereid'):
+            conf.CHECK_FUNCS_IN('getpeereid', 'bsd', headers='sys/types.h bsd/unistd.h')
+        if not conf.CHECK_FUNCS_IN('setproctitle', 'setproctitle', headers='setproctitle.h'):
+            conf.CHECK_FUNCS_IN('setproctitle', 'bsd', headers='sys/types.h bsd/unistd.h')
+        if not conf.CHECK_FUNCS('setproctitle_init'):
+            conf.CHECK_FUNCS_IN('setproctitle_init', 'bsd', headers='sys/types.h bsd/unistd.h')
+        if not conf.CHECK_FUNCS('closefrom'):
+            conf.CHECK_FUNCS_IN('closefrom', 'bsd', headers='bsd/unistd.h')
 
     conf.CHECK_CODE('''
                 struct ucred cred;
diff --git a/wscript b/wscript
index 8b5e02d..b6e2614 100644
--- a/wscript
+++ b/wscript
@@ -31,7 +31,12 @@ def options(opt):
         opt.add_option('--enable-talloc-compat1',
                        help=("Build talloc 1.x.x compat library [False]"),
                        action="store_true", dest='TALLOC_COMPAT1', default=False)
-
+        opt.add_option('--with-valgrind',
+                       help=("enable use of valgrind"),
+                       action="store_true", dest='enable_valgrind')
+        opt.add_option('--without-valgrind',
+                       help=("disable use of valgrind"),
+                       action="store_false", dest='enable_valgrind', default=False)
 
 def configure(conf):
     conf.RECURSE('lib/replace')
-- 
2.34.1

