from upstream:
https://git.samba.org/?p=samba.git;a=commit;h=c0a463d94abb5c50eaca7b1d402c979684f96a97

--- ./wscript.orig
+++ ./wscript
@@ -156,15 +156,16 @@
     conf.RECURSE('lib/ntdb')
     conf.RECURSE('lib/util/charset')
     conf.RECURSE('source4/auth')
-    conf.RECURSE('lib/nss_wrapper')
     conf.RECURSE('nsswitch')
-    conf.RECURSE('lib/socket_wrapper')
-    conf.RECURSE('lib/uid_wrapper')
     conf.RECURSE('lib/subunit/c')
     conf.RECURSE('libcli/smbreadline')
     conf.RECURSE('lib/crypto')
     conf.RECURSE('pidl')
     conf.RECURSE('selftest')
+    if conf.CONFIG_GET('ENABLE_SELFTEST'):
+        conf.RECURSE('lib/nss_wrapper')
+        conf.RECURSE('lib/socket_wrapper')
+        conf.RECURSE('lib/uid_wrapper')
     conf.RECURSE('source3')
     conf.RECURSE('lib/texpect')
     if conf.env.with_ctdb:
--- ./wscript_build.orig
+++ ./wscript_build
@@ -2,6 +2,7 @@
 
 # top level waf build script for samba4
 
+import Options
 import os
 srcdir = "."
 
@@ -70,9 +71,12 @@
 bld.RECURSE('source4/lib/events')
 bld.RECURSE('source4/lib/cmdline')
 bld.RECURSE('source4/lib/http')
-bld.RECURSE('lib/socket_wrapper')
-bld.RECURSE('lib/nss_wrapper')
-bld.RECURSE('lib/uid_wrapper')
+if bld.CONFIG_GET('NSS_WRAPPER'):
+    bld.RECURSE('lib/nss_wrapper')
+if bld.CONFIG_GET('SOCKET_WRAPPER'):
+    bld.RECURSE('lib/socket_wrapper')
+if bld.CONFIG_GET('UID_WRAPPER'):
+    bld.RECURSE('lib/uid_wrapper')
 if bld.CHECK_FOR_THIRD_PARTY():
     bld.RECURSE('third_party/zlib')
     bld.RECURSE('third_party/popt')