| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
APPNAME = 'libreplace' |
| 4 |
VERSION = '1.2.1' |
| 5 |
|
| 6 |
import sys |
| 7 |
import os |
| 8 |
|
| 9 |
# find the buildtools directory |
| 10 |
top = '.' |
| 11 |
while not os.path.exists(top+'/buildtools') and len(top.split('/')) < 5: |
| 12 |
top = top + '/..' |
| 13 |
sys.path.insert(0, top + '/buildtools/wafsamba') |
| 14 |
|
| 15 |
out = 'bin' |
| 16 |
|
| 17 |
import wafsamba |
| 18 |
from wafsamba import samba_dist |
| 19 |
from waflib import Options, Utils, Logs, Context |
| 20 |
|
| 21 |
samba_dist.DIST_DIRS('lib/replace buildtools:buildtools third_party/waf:third_party/waf') |
| 22 |
|
| 23 |
def options(opt): |
| 24 |
opt.BUILTIN_DEFAULT('NONE') |
| 25 |
opt.PRIVATE_EXTENSION_DEFAULT('') |
| 26 |
opt.RECURSE('buildtools/wafsamba') |
| 27 |
|
| 28 |
@Utils.run_once |
| 29 |
def configure(conf): |
| 30 |
conf.RECURSE('buildtools/wafsamba') |
| 31 |
|
| 32 |
conf.env.standalone_replace = conf.IN_LAUNCH_DIR() |
| 33 |
|
| 34 |
if sys.platform.rfind('linux') > -1: |
| 35 |
conf.DEFINE('LINUX', '1') |
| 36 |
|
| 37 |
conf.DEFINE('BOOL_DEFINED', 1) |
| 38 |
conf.DEFINE('HAVE_LIBREPLACE', 1) |
| 39 |
conf.DEFINE('LIBREPLACE_NETWORK_CHECKS', 1) |
| 40 |
|
| 41 |
conf.CHECK_HEADERS('linux/types.h crypt.h locale.h acl/libacl.h compat.h') |
| 42 |
conf.CHECK_HEADERS('acl/libacl.h attr/xattr.h compat.h ctype.h dustat.h') |
| 43 |
conf.CHECK_HEADERS('fcntl.h fnmatch.h glob.h history.h krb5.h langinfo.h') |
| 44 |
conf.CHECK_HEADERS('locale.h ndir.h pwd.h') |
| 45 |
conf.CHECK_HEADERS('shadow.h sys/acl.h') |
| 46 |
conf.CHECK_HEADERS('sys/attributes.h attr/attributes.h sys/capability.h sys/dir.h sys/epoll.h') |
| 47 |
conf.CHECK_HEADERS('sys/fcntl.h sys/filio.h sys/filsys.h sys/fs/s5param.h') |
| 48 |
conf.CHECK_HEADERS('sys/id.h sys/ioctl.h sys/ipc.h sys/mman.h sys/mode.h sys/ndir.h sys/priv.h') |
| 49 |
conf.CHECK_HEADERS('sys/resource.h sys/security.h sys/shm.h sys/statfs.h sys/statvfs.h sys/termio.h') |
| 50 |
conf.CHECK_HEADERS('sys/vfs.h sys/xattr.h termio.h termios.h sys/file.h') |
| 51 |
conf.CHECK_HEADERS('sys/ucontext.h sys/wait.h sys/stat.h') |
| 52 |
|
| 53 |
if not conf.CHECK_DECLS('malloc', headers='stdlib.h'): |
| 54 |
conf.CHECK_HEADERS('malloc.h') |
| 55 |
|
| 56 |
conf.CHECK_HEADERS('grp.h') |
| 57 |
conf.CHECK_HEADERS('sys/select.h setjmp.h utime.h sys/syslog.h syslog.h') |
| 58 |
conf.CHECK_HEADERS('stdarg.h vararg.h sys/mount.h mntent.h') |
| 59 |
conf.CHECK_HEADERS('stropts.h unix.h string.h strings.h sys/param.h limits.h') |
| 60 |
conf.CHECK_HEADERS('''sys/socket.h netinet/in.h netdb.h arpa/inet.h netinet/in_systm.h |
| 61 |
netinet/ip.h netinet/tcp.h netinet/in_ip.h |
| 62 |
sys/sockio.h sys/un.h''', together=True) |
| 63 |
conf.CHECK_HEADERS('sys/uio.h ifaddrs.h direct.h dirent.h') |
| 64 |
conf.CHECK_HEADERS('windows.h winsock2.h ws2tcpip.h') |
| 65 |
conf.CHECK_HEADERS('errno.h') |
| 66 |
conf.CHECK_HEADERS('getopt.h iconv.h') |
| 67 |
conf.CHECK_HEADERS('memory.h nss.h sasl/sasl.h') |
| 68 |
conf.CHECK_HEADERS('linux/openat2.h') |
| 69 |
|
| 70 |
conf.CHECK_FUNCS_IN('inotify_init', 'inotify', checklibc=True, |
| 71 |
headers='sys/inotify.h') |
| 72 |
|
| 73 |
conf.CHECK_HEADERS('security/pam_appl.h zlib.h asm/unistd.h') |
| 74 |
conf.CHECK_HEADERS('sys/unistd.h alloca.h float.h') |
| 75 |
|
| 76 |
conf.SET_TARGET_TYPE('tirpc', 'EMPTY') |
| 77 |
|
| 78 |
if conf.CHECK_CODE( |
| 79 |
'\n#ifndef _TIRPC_RPC_H\n#error "no tirpc headers in system path"\n#endif\n', |
| 80 |
'HAVE_RPC_RPC_HEADERS', |
| 81 |
headers=['rpc/rpc.h', 'rpc/nettype.h'], |
| 82 |
msg='Checking for tirpc rpc headers in default system path'): |
| 83 |
if conf.CONFIG_SET('HAVE_RPC_RPC_H'): |
| 84 |
conf.undefine('HAVE_RPC_RPC_H') |
| 85 |
|
| 86 |
if not conf.CONFIG_SET('HAVE_RPC_RPC_H'): |
| 87 |
if conf.CHECK_CFG(package='libtirpc', args='--cflags --libs', |
| 88 |
msg='Checking for libtirpc headers', |
| 89 |
uselib_store='TIRPC'): |
| 90 |
conf.CHECK_HEADERS('rpc/rpc.h rpc/nettype.h', lib='tirpc', together=True) |
| 91 |
conf.SET_TARGET_TYPE('tirpc', 'SYSLIB') |
| 92 |
if not conf.CONFIG_SET('HAVE_RPC_RPC_H'): |
| 93 |
if conf.CHECK_CFG(package='libntirpc', args='--cflags', |
| 94 |
msg='Checking for libntirpc headers', |
| 95 |
uselib_store='TIRPC'): |
| 96 |
conf.CHECK_HEADERS('rpc/rpc.h rpc/nettype.h', lib='tirpc', together=True) |
| 97 |
conf.SET_TARGET_TYPE('tirpc', 'SYSLIB') |
| 98 |
if not conf.CONFIG_SET('HAVE_RPC_RPC_H'): |
| 99 |
Logs.warn('No rpc/rpc.h header found, tirpc or libntirpc missing?') |
| 100 |
|
| 101 |
# This file is decprecated with glibc >= 2.30 so we need to check if it |
| 102 |
# includes a deprecation warning: |
| 103 |
# #warning "The <sys/sysctl.h> header is deprecated and will be removed." |
| 104 |
conf.CHECK_CODE(''' |
| 105 |
#include <sys/sysctl.h> |
| 106 |
int main(void) { return 0; } |
| 107 |
''', |
| 108 |
define='HAVE_SYS_SYSCTL_H', |
| 109 |
cflags=['-Werror=cpp'], |
| 110 |
addmain=False, |
| 111 |
msg='Checking for header sys/sysctl.h') |
| 112 |
|
| 113 |
conf.CHECK_HEADERS('sys/fileio.h sys/filesys.h sys/dustat.h sys/sysmacros.h') |
| 114 |
conf.CHECK_HEADERS('xfs/libxfs.h netgroup.h') |
| 115 |
|
| 116 |
conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h') |
| 117 |
conf.CHECK_HEADERS('valgrind/memcheck.h valgrind/helgrind.h valgrind/callgrind.h') |
| 118 |
conf.CHECK_HEADERS('nss_common.h nsswitch.h ns_api.h') |
| 119 |
conf.CHECK_HEADERS('sys/extattr.h sys/ea.h sys/proplist.h sys/cdefs.h') |
| 120 |
conf.CHECK_HEADERS('utmp.h utmpx.h lastlog.h') |
| 121 |
conf.CHECK_HEADERS('syscall.h sys/syscall.h inttypes.h') |
| 122 |
conf.CHECK_HEADERS('sys/atomic.h stdatomic.h') |
| 123 |
conf.CHECK_HEADERS('libgen.h') |
| 124 |
|
| 125 |
if conf.CHECK_CFLAGS('-Wno-format-truncation'): |
| 126 |
conf.define('HAVE_WNO_FORMAT_TRUNCATION', '1') |
| 127 |
|
| 128 |
if conf.CHECK_CFLAGS('-Wno-unused-function'): |
| 129 |
conf.define('HAVE_WNO_UNUSED_FUNCTION', '1') |
| 130 |
|
| 131 |
if conf.CHECK_CFLAGS('-Wno-strict-overflow'): |
| 132 |
conf.define('HAVE_WNO_STRICT_OVERFLOW', '1') |
| 133 |
|
| 134 |
if conf.CHECK_CFLAGS('-Wno-unused-but-set-variable'): |
| 135 |
conf.define('HAVE_WNO_UNUSED_BUT_SET_VARIABLE', '1') |
| 136 |
|
| 137 |
if conf.CHECK_CFLAGS('-Wuse-after-free=1'): |
| 138 |
conf.define('HAVE_WUSE_AFTER_FREE_1', '1') |
| 139 |
|
| 140 |
# Check for process set name support |
| 141 |
conf.CHECK_CODE(''' |
| 142 |
#include <sys/prctl.h> |
| 143 |
int main(void) { |
| 144 |
prctl(0); |
| 145 |
return 0; |
| 146 |
} |
| 147 |
''', |
| 148 |
'HAVE_PRCTL', |
| 149 |
addmain=False, |
| 150 |
headers='sys/prctl.h', |
| 151 |
msg='Checking for prctl syscall') |
| 152 |
|
| 153 |
conf.CHECK_CODE(''' |
| 154 |
#include <unistd.h> |
| 155 |
#ifdef HAVE_FCNTL_H |
| 156 |
#include <fcntl.h> |
| 157 |
#endif |
| 158 |
int main(void) { int fd = open("/dev/null", O_DIRECT); } |
| 159 |
''', |
| 160 |
define='HAVE_OPEN_O_DIRECT', |
| 161 |
addmain=False, |
| 162 |
msg='Checking for O_DIRECT flag to open(2)') |
| 163 |
|
| 164 |
conf.CHECK_TYPES('"long long" intptr_t uintptr_t ptrdiff_t comparison_fn_t') |
| 165 |
if not conf.CHECK_TYPE('bool', define='HAVE_BOOL', headers='stdbool.h'): |
| 166 |
raise Errors.WafError('Samba requires a genuine boolean type') |
| 167 |
|
| 168 |
conf.CHECK_TYPE('int8_t', 'char') |
| 169 |
conf.CHECK_TYPE('uint8_t', 'unsigned char') |
| 170 |
conf.CHECK_TYPE('int16_t', 'short') |
| 171 |
conf.CHECK_TYPE('uint16_t', 'unsigned short') |
| 172 |
conf.CHECK_TYPE('int32_t', 'int') |
| 173 |
conf.CHECK_TYPE('uint32_t', 'unsigned') |
| 174 |
conf.CHECK_TYPE('int64_t', 'long long') |
| 175 |
conf.CHECK_TYPE('uint64_t', 'unsigned long long') |
| 176 |
conf.CHECK_TYPE('size_t', 'unsigned int') |
| 177 |
conf.CHECK_TYPE('ssize_t', 'int') |
| 178 |
conf.CHECK_TYPE('ino_t', 'unsigned') |
| 179 |
conf.CHECK_TYPE('loff_t', 'off_t') |
| 180 |
conf.CHECK_TYPE('offset_t', 'loff_t') |
| 181 |
conf.CHECK_TYPE('volatile int', define='HAVE_VOLATILE') |
| 182 |
conf.CHECK_TYPE('uint_t', 'unsigned int') |
| 183 |
conf.CHECK_TYPE('blksize_t', 'long', headers='sys/types.h sys/stat.h unistd.h') |
| 184 |
conf.CHECK_TYPE('blkcnt_t', 'long', headers='sys/types.h sys/stat.h unistd.h') |
| 185 |
|
| 186 |
conf.CHECK_SIZEOF('bool char int "long long" long short size_t ssize_t') |
| 187 |
sizeof_int = conf.env["SIZEOF_INT"] |
| 188 |
if sizeof_int < 4: |
| 189 |
conf.fatal(f"Samba won't work with int of size {sizeof_int} (requires >= 4)") |
| 190 |
|
| 191 |
conf.CHECK_SIZEOF('int8_t uint8_t int16_t uint16_t int32_t uint32_t int64_t uint64_t') |
| 192 |
conf.CHECK_SIZEOF('void*', define='SIZEOF_VOID_P') |
| 193 |
conf.CHECK_SIZEOF('off_t dev_t ino_t time_t') |
| 194 |
|
| 195 |
conf.CHECK_TYPES('socklen_t', headers='sys/socket.h') |
| 196 |
conf.CHECK_TYPE_IN('struct ifaddrs', 'ifaddrs.h') |
| 197 |
conf.CHECK_TYPE_IN('struct addrinfo', 'netdb.h') |
| 198 |
conf.CHECK_TYPE_IN('struct sockaddr', 'sys/socket.h') |
| 199 |
conf.CHECK_CODE('struct sockaddr_in6 x', define='HAVE_STRUCT_SOCKADDR_IN6', |
| 200 |
headers='sys/socket.h netdb.h netinet/in.h') |
| 201 |
conf.CHECK_TYPE_IN('struct sockaddr_storage', 'sys/socket.h') |
| 202 |
conf.CHECK_TYPE_IN('sa_family_t', 'sys/socket.h') |
| 203 |
|
| 204 |
conf.CHECK_TYPE_IN('sig_atomic_t', 'signal.h', define='HAVE_SIG_ATOMIC_T_TYPE') |
| 205 |
conf.CHECK_FUNCS('sigsetmask siggetmask sigprocmask sigblock sigaction sigset') |
| 206 |
|
| 207 |
# Those functions are normally available in libc |
| 208 |
if not conf.CHECK_FUNCS(''' |
| 209 |
inet_ntoa |
| 210 |
inet_aton |
| 211 |
inet_ntop |
| 212 |
inet_pton |
| 213 |
connect |
| 214 |
gethostbyname |
| 215 |
getaddrinfo |
| 216 |
getnameinfo |
| 217 |
freeaddrinfo |
| 218 |
gai_strerror |
| 219 |
socketpair''', |
| 220 |
headers='sys/socket.h netinet/in.h arpa/inet.h netdb.h'): |
| 221 |
conf.CHECK_FUNCS_IN(''' |
| 222 |
inet_ntoa |
| 223 |
inet_aton |
| 224 |
inet_ntop |
| 225 |
inet_pton |
| 226 |
connect |
| 227 |
gethostbyname |
| 228 |
getaddrinfo |
| 229 |
getnameinfo |
| 230 |
freeaddrinfo |
| 231 |
gai_strerror |
| 232 |
socketpair''', |
| 233 |
'socket nsl', |
| 234 |
headers='sys/socket.h netinet/in.h arpa/inet.h netdb.h') |
| 235 |
conf.DEFINE('REPLACE_REQUIRES_LIBSOCKET_LIBNSL', 1) |
| 236 |
|
| 237 |
conf.CHECK_FUNCS('memset_s memset_explicit') |
| 238 |
|
| 239 |
conf.CHECK_CODE(''' |
| 240 |
#include <string.h> |
| 241 |
|
| 242 |
int main(void) |
| 243 |
{ |
| 244 |
char buf[] = "This is some content"; |
| 245 |
memset(buf, '\0', sizeof(buf)); __asm__ volatile("" : : "g"(&buf) : "memory"); |
| 246 |
return 0; |
| 247 |
} |
| 248 |
''', |
| 249 |
define='HAVE_GCC_VOLATILE_MEMORY_PROTECTION', |
| 250 |
addmain=False, |
| 251 |
msg='Checking for volatile memory protection', |
| 252 |
local_include=False) |
| 253 |
|
| 254 |
# Some old Linux systems have broken header files and |
| 255 |
# miss the IPV6_V6ONLY define in netinet/in.h, |
| 256 |
# but have it in linux/in6.h. |
| 257 |
# We can't include both files so we just check if the value |
| 258 |
# if defined and do the replacement in system/network.h |
| 259 |
if not conf.CHECK_VARIABLE('IPV6_V6ONLY', |
| 260 |
headers='sys/socket.h netdb.h netinet/in.h'): |
| 261 |
conf.CHECK_CODE(''' |
| 262 |
#include <linux/in6.h> |
| 263 |
#if (IPV6_V6ONLY != 26) |
| 264 |
#error no IPV6_V6ONLY support on linux |
| 265 |
#endif |
| 266 |
int main(void) { return IPV6_V6ONLY; } |
| 267 |
''', |
| 268 |
define='HAVE_LINUX_IPV6_V6ONLY_26', |
| 269 |
addmain=False, |
| 270 |
msg='Checking for IPV6_V6ONLY in linux/in6.h', |
| 271 |
local_include=False) |
| 272 |
|
| 273 |
conf.CHECK_CODE(''' |
| 274 |
struct sockaddr_storage sa_store; |
| 275 |
struct addrinfo *ai = NULL; |
| 276 |
struct in6_addr in6addr; |
| 277 |
int idx = if_nametoindex("iface1"); |
| 278 |
int s = socket(AF_INET6, SOCK_STREAM, 0); |
| 279 |
int ret = getaddrinfo(NULL, NULL, NULL, &ai); |
| 280 |
if (ret != 0) { |
| 281 |
const char *es = gai_strerror(ret); |
| 282 |
} |
| 283 |
freeaddrinfo(ai); |
| 284 |
{ |
| 285 |
int val = 1; |
| 286 |
#ifdef HAVE_LINUX_IPV6_V6ONLY_26 |
| 287 |
#define IPV6_V6ONLY 26 |
| 288 |
#endif |
| 289 |
ret = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, |
| 290 |
(const void *)&val, sizeof(val)); |
| 291 |
} |
| 292 |
''', |
| 293 |
define='HAVE_IPV6', |
| 294 |
lib='nsl socket', |
| 295 |
headers='sys/socket.h netdb.h netinet/in.h net/if.h') |
| 296 |
|
| 297 |
if conf.CONFIG_SET('HAVE_SYS_UCONTEXT_H') and conf.CONFIG_SET('HAVE_SIGNAL_H'): |
| 298 |
conf.CHECK_CODE(''' |
| 299 |
ucontext_t uc; |
| 300 |
sigaddset(&uc.uc_sigmask, SIGUSR1); |
| 301 |
''', |
| 302 |
'HAVE_UCONTEXT_T', |
| 303 |
msg="Checking whether we have ucontext_t", |
| 304 |
headers='signal.h sys/ucontext.h') |
| 305 |
|
| 306 |
# Check for atomic builtins. */ |
| 307 |
conf.CHECK_CODE(''' |
| 308 |
int i; |
| 309 |
(void)__sync_fetch_and_add(&i, 1); |
| 310 |
''', |
| 311 |
'HAVE___SYNC_FETCH_AND_ADD', |
| 312 |
msg='Checking for __sync_fetch_and_add compiler builtin') |
| 313 |
|
| 314 |
conf.CHECK_CODE(''' |
| 315 |
int i; |
| 316 |
(void)__sync_add_and_fetch(&i, 1); |
| 317 |
''', |
| 318 |
'HAVE___SYNC_ADD_AND_FETCH', |
| 319 |
msg='Checking for __sync_add_and_fetch compiler builtin') |
| 320 |
|
| 321 |
conf.CHECK_CODE(''' |
| 322 |
int32_t i; |
| 323 |
atomic_add_32(&i, 1); |
| 324 |
''', |
| 325 |
'HAVE_ATOMIC_ADD_32', |
| 326 |
headers='stdint.h sys/atomic.h', |
| 327 |
msg='Checking for atomic_add_32 compiler builtin') |
| 328 |
|
| 329 |
conf.CHECK_CODE(''' |
| 330 |
uint32_t i,j; |
| 331 |
j = __atomic_add_fetch(&i,1,__ATOMIC_SEQ_CST) |
| 332 |
''', |
| 333 |
'HAVE___ATOMIC_ADD_FETCH', |
| 334 |
headers='stdint.h', |
| 335 |
msg='Checking for __atomic_add_fetch compiler builtin') |
| 336 |
|
| 337 |
conf.CHECK_CODE(''' |
| 338 |
uint32_t i,j; |
| 339 |
__atomic_load(&i,&j,__ATOMIC_SEQ_CST) |
| 340 |
''', |
| 341 |
'HAVE___ATOMIC_ADD_LOAD', |
| 342 |
headers='stdint.h', |
| 343 |
msg='Checking for __atomic_load compiler builtin') |
| 344 |
|
| 345 |
# Check for thread fence. */ |
| 346 |
tf = conf.CHECK_CODE('atomic_thread_fence(memory_order_seq_cst);', |
| 347 |
'HAVE_ATOMIC_THREAD_FENCE', |
| 348 |
headers='stdatomic.h', |
| 349 |
msg='Checking for atomic_thread_fence(memory_order_seq_cst) in stdatomic.h') |
| 350 |
if not tf: |
| 351 |
tf = conf.CHECK_CODE('__atomic_thread_fence(__ATOMIC_SEQ_CST);', |
| 352 |
'HAVE___ATOMIC_THREAD_FENCE', |
| 353 |
msg='Checking for __atomic_thread_fence(__ATOMIC_SEQ_CST)') |
| 354 |
if not tf: |
| 355 |
# __sync_synchronize() is available since 2005 in gcc. |
| 356 |
tf = conf.CHECK_CODE('__sync_synchronize();', |
| 357 |
'HAVE___SYNC_SYNCHRONIZE', |
| 358 |
msg='Checking for __sync_synchronize') |
| 359 |
if tf: |
| 360 |
conf.DEFINE('HAVE_ATOMIC_THREAD_FENCE_SUPPORT', 1) |
| 361 |
|
| 362 |
conf.CHECK_CODE(''' |
| 363 |
#define FALL_THROUGH __attribute__((fallthrough)) |
| 364 |
|
| 365 |
enum direction_e { |
| 366 |
UP = 0, |
| 367 |
DOWN, |
| 368 |
}; |
| 369 |
|
| 370 |
int main(void) { |
| 371 |
enum direction_e key = UP; |
| 372 |
int i = 10; |
| 373 |
int j = 0; |
| 374 |
|
| 375 |
switch (key) { |
| 376 |
case UP: |
| 377 |
i = 5; |
| 378 |
FALL_THROUGH; |
| 379 |
case DOWN: |
| 380 |
j = i * 2; |
| 381 |
break; |
| 382 |
default: |
| 383 |
break; |
| 384 |
} |
| 385 |
|
| 386 |
if (j < i) { |
| 387 |
return 1; |
| 388 |
} |
| 389 |
|
| 390 |
return 0; |
| 391 |
} |
| 392 |
''', |
| 393 |
'HAVE_FALLTHROUGH_ATTRIBUTE', |
| 394 |
addmain=False, |
| 395 |
strict=True, |
| 396 |
cflags=['-Werror=missing-declarations'], |
| 397 |
msg='Checking for fallthrough attribute') |
| 398 |
|
| 399 |
# these may be builtins, so we need the link=False strategy |
| 400 |
conf.CHECK_FUNCS('strdup memmem printf memcpy memmove strcpy strncpy', link=False) |
| 401 |
|
| 402 |
# See https://bugzilla.samba.org/show_bug.cgi?id=1097 |
| 403 |
# |
| 404 |
# Ported in from autoconf where it was added with this commit: |
| 405 |
# commit 804cfb20a067b4b687089dc72a8271b3abf20f31 |
| 406 |
# Author: Simo Sorce <[email protected]> |
| 407 |
# Date: Wed Aug 25 14:24:16 2004 +0000 |
| 408 |
# r2070: Let's try to overload srnlen and strndup for AIX where they are natly broken. |
| 409 |
|
| 410 |
host_os = sys.platform |
| 411 |
if host_os.rfind('aix') > -1: |
| 412 |
conf.DEFINE('BROKEN_STRNLEN', 1) |
| 413 |
conf.DEFINE('BROKEN_STRNDUP', 1) |
| 414 |
|
| 415 |
conf.CHECK_FUNCS('shl_load shl_unload shl_findsym') |
| 416 |
conf.CHECK_FUNCS('pipe strftime srandom random srand rand usleep setbuffer') |
| 417 |
conf.CHECK_FUNCS('lstat getpgrp utime utimes setuid seteuid setreuid setresuid setgid setegid') |
| 418 |
conf.CHECK_FUNCS('setregid setresgid chroot strerror vsyslog setlinebuf mktime') |
| 419 |
conf.CHECK_FUNCS('ftruncate chsize rename waitpid wait4') |
| 420 |
conf.CHECK_FUNCS('initgroups pread pwrite strndup strcasestr strsep') |
| 421 |
conf.CHECK_FUNCS('strtok_r mkdtemp dup2 dprintf vdprintf isatty chown lchown') |
| 422 |
conf.CHECK_FUNCS('link readlink symlink realpath snprintf vsnprintf') |
| 423 |
conf.CHECK_FUNCS('asprintf vasprintf setenv unsetenv strnlen strtoull __strtoull') |
| 424 |
conf.CHECK_FUNCS('strtouq strtoll __strtoll strtoq memalign posix_memalign') |
| 425 |
conf.CHECK_FUNCS('fmemopen renameat2') |
| •426 |
conf.CHECK_FUNCS('openat2') |
| 427 |
|
| 428 |
if conf.CONFIG_SET('HAVE_MEMALIGN'): |
| 429 |
conf.CHECK_DECLS('memalign', headers='malloc.h') |
| 430 |
|
| 431 |
# glibc up to 2.3.6 had dangerously broken posix_fallocate(). DON'T USE IT. |
| 432 |
if conf.CHECK_CODE(''' |
| 433 |
#define _XOPEN_SOURCE 600 |
| 434 |
#include <stdlib.h> |
| 435 |
#if defined(__GLIBC__) && ((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 4)) |
| 436 |
#error probably broken posix_fallocate |
| 437 |
#endif |
| 438 |
''', |
| 439 |
'_POSIX_FALLOCATE_CAPABLE_LIBC', |
| 440 |
msg='Checking for posix_fallocate-capable libc'): |
| 441 |
conf.CHECK_FUNCS('posix_fallocate') |
| 442 |
|
| 443 |
conf.CHECK_FUNCS('dirname basename') |
| 444 |
|
| 445 |
strlcpy_in_bsd = False |
| 446 |
|
| 447 |
# libbsd on some platforms provides strlcpy and strlcat |
| 448 |
if not conf.CHECK_FUNCS('strlcpy strlcat'): |
| 449 |
if conf.CHECK_FUNCS_IN('strlcpy strlcat', 'bsd', headers='bsd/string.h', |
| 450 |
checklibc=True): |
| 451 |
strlcpy_in_bsd = True |
| 452 |
elif conf.env.enable_fuzzing: |
| 453 |
# Just to complicate it more, some versions of Honggfuzz have |
| 454 |
# got strlcpy and strlcat in libc, but not in <string.h> |
| 455 |
# (unless it is there coincidentally, on a BSD). Therefore we |
| 456 |
# can't use CHECK_FUNCS alone to decide whether to add the |
| 457 |
# headers to replace.h. |
| 458 |
# |
| 459 |
# As this is only known to happen on a fuzzing compiler, we'll |
| 460 |
# skip the check when not in fuzzing mode. |
| 461 |
conf.CHECK_HEADERS('bsd/string.h') |
| 462 |
|
| 463 |
if not conf.CHECK_FUNCS('getpeereid'): |
| 464 |
conf.CHECK_FUNCS_IN('getpeereid', 'bsd', headers='sys/types.h bsd/unistd.h') |
| 465 |
if not conf.CHECK_FUNCS_IN('setproctitle', 'setproctitle', headers='setproctitle.h'): |
| 466 |
conf.CHECK_FUNCS_IN('setproctitle', 'bsd', headers='sys/types.h bsd/unistd.h') |
| 467 |
if not conf.CHECK_FUNCS('setproctitle_init'): |
| 468 |
conf.CHECK_FUNCS_IN('setproctitle_init', 'bsd', headers='sys/types.h bsd/unistd.h') |
| 469 |
|
| 470 |
if not conf.CHECK_FUNCS('closefrom'): |
| 471 |
conf.CHECK_FUNCS_IN('closefrom', 'bsd', headers='bsd/unistd.h') |
| 472 |
|
| 473 |
conf.CHECK_CODE(''' |
| 474 |
struct ucred cred; |
| 475 |
socklen_t cred_len; |
| 476 |
int ret = getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len);''', |
| 477 |
'HAVE_PEERCRED', |
| 478 |
msg="Checking whether we can use SO_PEERCRED to get socket credentials", |
| 479 |
headers='sys/types.h sys/socket.h') |
| 480 |
|
| 481 |
#Some OS (ie. freebsd) return EINVAL if the conversion could not be done, it's not what we expect |
| 482 |
#Let's detect those cases |
| 483 |
if conf.CONFIG_SET('HAVE_STRTOLL'): |
| 484 |
conf.CHECK_CODE(''' |
| 485 |
long long nb = strtoll("Text", NULL, 0); |
| 486 |
if (errno == EINVAL) { |
| 487 |
return 0; |
| 488 |
} else { |
| 489 |
return 1; |
| 490 |
} |
| 491 |
''', |
| 492 |
msg="Checking correct behavior of strtoll", |
| 493 |
headers = 'errno.h', |
| 494 |
execute = True, |
| 495 |
define = 'HAVE_BSD_STRTOLL', |
| 496 |
) |
| 497 |
conf.CHECK_FUNCS('if_nameindex if_nametoindex strerror_r') |
| •498 |
conf.CHECK_FUNCS('__xpg_strerror_r') |
| 499 |
conf.CHECK_FUNCS('syslog') |
| 500 |
conf.CHECK_FUNCS('gai_strerror get_current_dir_name') |
| 501 |
conf.CHECK_FUNCS('timegm getifaddrs freeifaddrs mmap setgroups syscall setsid') |
| 502 |
conf.CHECK_FUNCS('getgrent_r getgrgid_r getgrnam_r getgrouplist getpagesize') |
| 503 |
conf.CHECK_FUNCS('getpwent_r getpwnam_r getpwuid_r epoll_create1') |
| 504 |
conf.CHECK_FUNCS('getprogname') |
| 505 |
if not conf.CHECK_FUNCS('copy_file_range'): |
| 506 |
conf.CHECK_CODE(''' |
| 507 |
syscall(SYS_copy_file_range,0,NULL,0,NULL,0,0); |
| 508 |
''', |
| 509 |
'HAVE_SYSCALL_COPY_FILE_RANGE', |
| 510 |
headers='sys/syscall.h unistd.h', |
| 511 |
msg='Checking whether we have copy_file_range system call') |
| 512 |
|
| 513 |
conf.SET_TARGET_TYPE('attr', 'EMPTY') |
| 514 |
|
| 515 |
xattr_headers='sys/attributes.h attr/xattr.h sys/xattr.h' |
| 516 |
|
| 517 |
# default to 1, we set it to 0 if we don't find any EA implementation below: |
| 518 |
conf.DEFINE('HAVE_XATTR_SUPPORT', 1) |
| 519 |
if conf.CHECK_FUNCS_IN('getxattr', 'attr', checklibc=True, headers=xattr_headers): |
| 520 |
conf.DEFINE('HAVE_XATTR_XATTR', 1) |
| 521 |
# Darwin has extra options to xattr-family functions |
| 522 |
conf.CHECK_CODE('getxattr(NULL, NULL, NULL, 0, 0, 0)', |
| 523 |
headers=xattr_headers, local_include=False, |
| 524 |
define='XATTR_ADDITIONAL_OPTIONS', |
| 525 |
msg="Checking whether xattr interface takes additional options") |
| 526 |
elif conf.CHECK_FUNCS_IN('attr_listf', 'attr', checklibc=True, headers=xattr_headers): |
| 527 |
conf.DEFINE('HAVE_XATTR_ATTR', 1) |
| 528 |
elif conf.CHECK_FUNCS('extattr_list_fd'): |
| 529 |
conf.DEFINE('HAVE_XATTR_EXTATTR', 1) |
| 530 |
elif conf.CHECK_FUNCS('flistea'): |
| 531 |
conf.DEFINE('HAVE_XATTR_EA', 1) |
| 532 |
elif not conf.CHECK_FUNCS('attropen'): |
| 533 |
conf.DEFINE('HAVE_XATTR_SUPPORT', 0) |
| 534 |
|
| 535 |
|
| 536 |
conf.CHECK_FUNCS_IN('dlopen dlsym dlerror dlclose', 'dl', |
| 537 |
checklibc=True, headers='dlfcn.h dl.h') |
| 538 |
|
| 539 |
conf.CHECK_C_PROTOTYPE('dlopen', 'void *dlopen(const char* filename, unsigned int flags)', |
| 540 |
define='DLOPEN_TAKES_UNSIGNED_FLAGS', headers='dlfcn.h dl.h') |
| 541 |
|
| 542 |
# |
| 543 |
# Check for clock_gettime and fdatasync |
| 544 |
# |
| 545 |
# First check libc to avoid linking libreplace against librt. |
| 546 |
# |
| 547 |
if conf.CHECK_FUNCS('fdatasync'): |
| 548 |
# some systems are missing the declaration |
| 549 |
conf.CHECK_DECLS('fdatasync') |
| 550 |
else: |
| 551 |
if conf.CHECK_FUNCS_IN('fdatasync', 'rt'): |
| 552 |
# some systems are missing the declaration |
| 553 |
conf.CHECK_DECLS('fdatasync') |
| 554 |
|
| 555 |
has_clock_gettime = False |
| 556 |
if conf.CHECK_FUNCS('clock_gettime'): |
| 557 |
has_clock_gettime = True |
| 558 |
|
| 559 |
if not has_clock_gettime: |
| 560 |
if conf.CHECK_FUNCS_IN('clock_gettime', 'rt', checklibc=True): |
| 561 |
has_clock_gettime = True |
| 562 |
|
| 563 |
if has_clock_gettime: |
| 564 |
for c in ['CLOCK_MONOTONIC', 'CLOCK_PROCESS_CPUTIME_ID', 'CLOCK_REALTIME']: |
| 565 |
conf.CHECK_CODE(''' |
| 566 |
#if TIME_WITH_SYS_TIME |
| 567 |
# include <sys/time.h> |
| 568 |
# include <time.h> |
| 569 |
#else |
| 570 |
# if HAVE_SYS_TIME_H |
| 571 |
# include <sys/time.h> |
| 572 |
# else |
| 573 |
# include <time.h> |
| 574 |
# endif |
| 575 |
#endif |
| 576 |
clockid_t clk = %s''' % c, |
| 577 |
'HAVE_%s' % c, |
| 578 |
msg='Checking whether the clock_gettime clock ID %s is available' % c) |
| 579 |
|
| 580 |
conf.CHECK_TYPE('struct timespec', headers='sys/time.h time.h') |
| 581 |
|
| 582 |
# these headers need to be tested as a group on freebsd |
| 583 |
conf.CHECK_HEADERS(headers='sys/socket.h net/if.h', together=True) |
| 584 |
conf.CHECK_HEADERS(headers='netinet/in.h arpa/nameser.h resolv.h', together=True) |
| 585 |
conf.CHECK_FUNCS_IN('res_search', 'resolv', checklibc=True, |
| 586 |
headers='netinet/in.h arpa/nameser.h resolv.h') |
| 587 |
|
| 588 |
|
| 589 |
# try to find libintl (if --without-gettext is not given) |
| 590 |
conf.env.intl_libs='' |
| 591 |
if not Options.options.disable_gettext: |
| 592 |
conf.CHECK_HEADERS('libintl.h') |
| 593 |
conf.CHECK_LIB('intl') |
| 594 |
conf.CHECK_DECLS('dgettext gettext bindtextdomain textdomain bind_textdomain_codeset', headers="libintl.h") |
| 595 |
# *textdomain functions are not strictly necessary |
| 596 |
conf.CHECK_FUNCS_IN('bindtextdomain textdomain bind_textdomain_codeset', |
| 597 |
'', checklibc=True, headers='libintl.h') |
| 598 |
# gettext and dgettext must exist |
| 599 |
# on some systems (the ones with glibc, those are in libc) |
| 600 |
if conf.CHECK_FUNCS_IN('dgettext gettext', '', checklibc=True, headers='libintl.h'): |
| 601 |
# save for dependency definitions |
| 602 |
conf.env.intl_libs='' |
| 603 |
# others (e.g. FreeBSD) have separate libintl |
| 604 |
elif conf.CHECK_FUNCS_IN('dgettext gettext', 'intl', checklibc=False, headers='libintl.h'): |
| 605 |
# save for dependency definitions |
| 606 |
conf.env.intl_libs='intl' |
| 607 |
# recheck with libintl |
| 608 |
conf.CHECK_FUNCS_IN('bindtextdomain textdomain bind_textdomain_codeset', |
| 609 |
'intl', checklibc=False, headers='libintl.h') |
| 610 |
else: |
| 611 |
# Some hosts need lib iconv for linking with lib intl |
| 612 |
# So we try with flags just in case it helps. |
| 613 |
oldflags = list(conf.env['EXTRA_LDFLAGS']); |
| 614 |
conf.env['EXTRA_LDFLAGS'].extend(["-liconv"]) |
| 615 |
conf.CHECK_FUNCS_IN('dgettext gettext bindtextdomain textdomain bind_textdomain_codeset', |
| 616 |
'intl', checklibc=False, headers='libintl.h') |
| 617 |
conf.env['EXTRA_LDFLAGS'] = oldflags |
| 618 |
if conf.env['HAVE_GETTEXT'] and conf.env['HAVE_DGETTEXT']: |
| 619 |
# save for dependency definitions |
| 620 |
conf.env.intl_libs='iconv intl' |
| 621 |
|
| 622 |
# did we find both prototypes and a library to link against? |
| 623 |
# if not, unset the detected values (see Bug #9911) |
| 624 |
if not (conf.env['HAVE_GETTEXT'] and conf.env['HAVE_DECL_GETTEXT']): |
| 625 |
conf.undefine('HAVE_GETTEXT') |
| 626 |
conf.undefine('HAVE_DECL_GETTEXT') |
| 627 |
if not (conf.env['HAVE_DGETTEXT'] and conf.env['HAVE_DECL_DGETTEXT']): |
| 628 |
conf.undefine('HAVE_DGETTEXT') |
| 629 |
conf.undefine('HAVE_DECL_DGETTEXT') |
| 630 |
|
| 631 |
conf.CHECK_FUNCS_IN('pthread_create', 'pthread', checklibc=True, headers='pthread.h') |
| 632 |
|
| 633 |
PTHREAD_CFLAGS='error' |
| 634 |
PTHREAD_LDFLAGS='error' |
| 635 |
|
| 636 |
if PTHREAD_LDFLAGS == 'error': |
| 637 |
# Check if pthread_attr_init() is provided by libc first! |
| 638 |
if conf.CHECK_FUNCS('pthread_attr_init'): |
| 639 |
PTHREAD_CFLAGS='-D_REENTRANT' |
| 640 |
PTHREAD_LDFLAGS='' |
| 641 |
if PTHREAD_LDFLAGS == 'error': |
| 642 |
if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthread'): |
| 643 |
PTHREAD_CFLAGS='-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS' |
| 644 |
PTHREAD_LDFLAGS='-lpthread' |
| 645 |
if PTHREAD_LDFLAGS == 'error': |
| 646 |
if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthreads'): |
| 647 |
PTHREAD_CFLAGS='-D_THREAD_SAFE' |
| 648 |
PTHREAD_LDFLAGS='-lpthreads' |
| 649 |
if PTHREAD_LDFLAGS == 'error': |
| 650 |
if conf.CHECK_FUNCS_IN('pthread_attr_init', 'c_r'): |
| 651 |
PTHREAD_CFLAGS='-D_THREAD_SAFE -pthread' |
| 652 |
PTHREAD_LDFLAGS='-pthread' |
| 653 |
|
| 654 |
# especially for HP-UX, where the CHECK_FUNC macro fails to test for |
| 655 |
# pthread_attr_init. On pthread_mutex_lock it works there... |
| 656 |
if PTHREAD_LDFLAGS == 'error': |
| 657 |
if conf.CHECK_FUNCS_IN('pthread_mutex_lock', 'pthread'): |
| 658 |
PTHREAD_CFLAGS='-D_REENTRANT' |
| 659 |
PTHREAD_LDFLAGS='-lpthread' |
| 660 |
|
| 661 |
if PTHREAD_CFLAGS != 'error' and PTHREAD_LDFLAGS != 'error': |
| 662 |
if conf.CONFIG_SET('replace_add_global_pthread'): |
| 663 |
conf.ADD_CFLAGS(PTHREAD_CFLAGS) |
| 664 |
conf.ADD_LDFLAGS(PTHREAD_LDFLAGS) |
| 665 |
conf.CHECK_HEADERS('pthread.h') |
| 666 |
conf.DEFINE('HAVE_PTHREAD', '1') |
| 667 |
|
| 668 |
if conf.CONFIG_SET('HAVE_PTHREAD'): |
| 669 |
|
| 670 |
conf.CHECK_FUNCS_IN('pthread_mutexattr_setrobust', 'pthread', |
| 671 |
checklibc=True, headers='pthread.h') |
| 672 |
if not conf.CONFIG_SET('HAVE_PTHREAD_MUTEXATTR_SETROBUST'): |
| 673 |
conf.CHECK_FUNCS_IN('pthread_mutexattr_setrobust_np', 'pthread', |
| 674 |
checklibc=True, headers='pthread.h') |
| 675 |
|
| 676 |
conf.CHECK_DECLS('PTHREAD_MUTEX_ROBUST', headers='pthread.h') |
| 677 |
if not conf.CONFIG_SET('HAVE_DECL_PTHREAD_MUTEX_ROBUST'): |
| 678 |
conf.CHECK_DECLS('PTHREAD_MUTEX_ROBUST_NP', headers='pthread.h') |
| 679 |
|
| 680 |
conf.CHECK_FUNCS_IN('pthread_mutex_consistent', 'pthread', |
| 681 |
checklibc=True, headers='pthread.h') |
| 682 |
if not conf.CONFIG_SET('HAVE_PTHREAD_MUTEX_CONSISTENT'): |
| 683 |
conf.CHECK_FUNCS_IN('pthread_mutex_consistent_np', 'pthread', |
| 684 |
checklibc=True, headers='pthread.h') |
| 685 |
|
| 686 |
if ((conf.CONFIG_SET('HAVE_PTHREAD_MUTEXATTR_SETROBUST') or |
| 687 |
conf.CONFIG_SET('HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP')) and |
| 688 |
(conf.CONFIG_SET('HAVE_DECL_PTHREAD_MUTEX_ROBUST') or |
| 689 |
conf.CONFIG_SET('HAVE_DECL_PTHREAD_MUTEX_ROBUST_NP')) and |
| 690 |
(conf.CONFIG_SET('HAVE_PTHREAD_MUTEX_CONSISTENT') or |
| 691 |
conf.CONFIG_SET('HAVE_PTHREAD_MUTEX_CONSISTENT_NP'))): |
| 692 |
conf.DEFINE('HAVE_ROBUST_MUTEXES', 1) |
| 693 |
|
| 694 |
# __thread is available in Solaris Studio, IBM XL, |
| 695 |
# gcc, Clang and Intel C Compiler |
| 696 |
conf.CHECK_CODE(''' |
| 697 |
__thread int tls; |
| 698 |
|
| 699 |
int main(void) { |
| 700 |
return 0; |
| 701 |
} |
| 702 |
''', |
| 703 |
'HAVE___THREAD', |
| 704 |
addmain=False, |
| 705 |
msg='Checking for __thread local storage') |
| 706 |
|
| 707 |
if conf.CONFIG_SET('HAVE_PTHREAD') and not conf.CONFIG_SET('HAVE___THREAD'): |
| 708 |
conf.fatal('Missing required TLS support in pthread library') |
| 709 |
|
| 710 |
conf.CHECK_FUNCS_IN('crypt', 'crypt', checklibc=True) |
| 711 |
conf.CHECK_FUNCS_IN('crypt_r', 'crypt', checklibc=True) |
| 712 |
conf.CHECK_FUNCS_IN('crypt_rn', 'crypt', checklibc=True) |
| 713 |
|
| 714 |
conf.CHECK_VARIABLE('rl_event_hook', define='HAVE_DECL_RL_EVENT_HOOK', always=True, |
| 715 |
headers='readline.h readline/readline.h readline/history.h') |
| 716 |
conf.CHECK_VARIABLE('program_invocation_short_name', headers='errno.h') |
| 717 |
|
| 718 |
conf.CHECK_DECLS('snprintf vsnprintf asprintf vasprintf') |
| 719 |
|
| 720 |
conf.CHECK_DECLS('errno', headers='errno.h', reverse=True) |
| 721 |
conf.CHECK_DECLS('EWOULDBLOCK', headers='errno.h') |
| 722 |
conf.CHECK_DECLS('environ', reverse=True, headers='unistd.h') |
| 723 |
conf.CHECK_DECLS('getgrent_r getpwent_r', reverse=True, headers='pwd.h grp.h') |
| 724 |
conf.CHECK_DECLS('pread pwrite setenv setresgid setresuid', reverse=True) |
| 725 |
|
| 726 |
if conf.CONFIG_SET('HAVE_EPOLL_CREATE1') and conf.CONFIG_SET('HAVE_SYS_EPOLL_H'): |
| 727 |
conf.DEFINE('HAVE_EPOLL', 1) |
| 728 |
|
| 729 |
if conf.CHECK_FUNCS('eventfd', headers='sys/eventfd.h'): |
| 730 |
conf.DEFINE('HAVE_EVENTFD', 1) |
| 731 |
|
| 732 |
conf.CHECK_HEADERS('poll.h') |
| 733 |
conf.CHECK_FUNCS('poll') |
| 734 |
|
| 735 |
conf.CHECK_FUNCS('strptime') |
| 736 |
conf.CHECK_DECLS('strptime', headers='time.h') |
| 737 |
conf.CHECK_CODE('''#define LIBREPLACE_CONFIGURE_TEST_STRPTIME |
| 738 |
#include "tests/strptime.c"''', |
| 739 |
define='HAVE_WORKING_STRPTIME', |
| 740 |
execute=True, |
| 741 |
addmain=False, |
| 742 |
msg='Checking for working strptime') |
| 743 |
|
| 744 |
conf.CHECK_C_PROTOTYPE('gettimeofday', |
| 745 |
'int gettimeofday(struct timeval *tv, struct timezone *tz)', |
| 746 |
define='HAVE_GETTIMEOFDAY_TZ', headers='sys/time.h') |
| 747 |
|
| 748 |
conf.CHECK_C_PROTOTYPE('gettimeofday', |
| 749 |
'int gettimeofday(struct timeval *tv, void *tz)', |
| 750 |
define='HAVE_GETTIMEOFDAY_TZ_VOID', |
| 751 |
headers='sys/time.h') |
| 752 |
|
| 753 |
conf.CHECK_CODE('#include "tests/snprintf.c"', |
| 754 |
define="HAVE_C99_VSNPRINTF", |
| 755 |
execute=True, |
| 756 |
addmain=False, |
| 757 |
msg="Checking for C99 vsnprintf") |
| 758 |
|
| 759 |
conf.CHECK_CODE('#include "tests/shared_mmap.c"', |
| 760 |
addmain=False, add_headers=False, execute=True, |
| 761 |
define='HAVE_SHARED_MMAP', |
| 762 |
msg="Checking for HAVE_SHARED_MMAP") |
| 763 |
|
| 764 |
conf.CHECK_CODE('#include "tests/shared_mremap.c"', |
| 765 |
addmain=False, add_headers=False, execute=True, |
| 766 |
define='HAVE_MREMAP', |
| 767 |
msg="Checking for HAVE_MREMAP") |
| 768 |
|
| 769 |
# OpenBSD (and I've heard HPUX) doesn't sync between mmap and write. |
| 770 |
# FIXME: Anything other than a 0 or 1 exit code should abort configure! |
| 771 |
conf.CHECK_CODE('#include "tests/incoherent_mmap.c"', |
| 772 |
addmain=False, add_headers=False, execute=True, |
| 773 |
define='HAVE_INCOHERENT_MMAP', |
| 774 |
msg="Checking for HAVE_INCOHERENT_MMAP") |
| 775 |
|
| 776 |
conf.SAMBA_BUILD_ENV() |
| 777 |
|
| 778 |
conf.CHECK_CODE(''' |
| 779 |
typedef struct {unsigned x;} FOOBAR; |
| 780 |
#define X_FOOBAR(x) ((FOOBAR) { x }) |
| 781 |
#define FOO_ONE X_FOOBAR(1) |
| 782 |
FOOBAR f = FOO_ONE; |
| 783 |
static const struct { |
| 784 |
FOOBAR y; |
| 785 |
} f2[] = { |
| 786 |
{FOO_ONE} |
| 787 |
}; |
| 788 |
static const FOOBAR f3[] = {FOO_ONE}; |
| 789 |
''', |
| 790 |
define='HAVE_IMMEDIATE_STRUCTURES') |
| 791 |
|
| 792 |
conf.CHECK_CODE('mkdir("foo",0777)', define='HAVE_MKDIR_MODE', headers='sys/stat.h') |
| 793 |
|
| 794 |
# we need the st_rdev test under two names |
| 795 |
conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev', |
| 796 |
define='HAVE_STRUCT_STAT_ST_RDEV', |
| 797 |
headers='sys/stat.h') |
| 798 |
conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev', define='HAVE_ST_RDEV', |
| 799 |
headers='sys/stat.h') |
| 800 |
conf.CHECK_STRUCTURE_MEMBER('struct sockaddr_storage', 'ss_family', |
| 801 |
headers='sys/socket.h netinet/in.h') |
| 802 |
conf.CHECK_STRUCTURE_MEMBER('struct sockaddr_storage', '__ss_family', |
| 803 |
headers='sys/socket.h netinet/in.h') |
| 804 |
|
| 805 |
|
| 806 |
if conf.CHECK_STRUCTURE_MEMBER('struct sockaddr', 'sa_len', |
| 807 |
headers='sys/socket.h netinet/in.h', |
| 808 |
define='HAVE_SOCKADDR_SA_LEN'): |
| 809 |
# the old build system produced both defines |
| 810 |
conf.DEFINE('HAVE_STRUCT_SOCKADDR_SA_LEN', 1) |
| 811 |
|
| 812 |
conf.CHECK_STRUCTURE_MEMBER('struct sockaddr_in', 'sin_len', |
| 813 |
headers='sys/socket.h netinet/in.h', |
| 814 |
define='HAVE_SOCK_SIN_LEN') |
| 815 |
|
| 816 |
conf.CHECK_STRUCTURE_MEMBER('struct sockaddr_in6', 'sin6_len', |
| 817 |
headers='sys/socket.h netinet/in.h', |
| 818 |
define='HAVE_SOCK_SIN6_LEN') |
| 819 |
|
| 820 |
conf.CHECK_CODE('struct sockaddr_un sunaddr; sunaddr.sun_family = AF_UNIX;', |
| 821 |
define='HAVE_UNIXSOCKET', headers='sys/socket.h sys/un.h') |
| 822 |
|
| 823 |
|
| 824 |
conf.CHECK_CODE(''' |
| 825 |
struct stat st; |
| 826 |
char tpl[20]="/tmp/test.XXXXXX"; |
| 827 |
char tpl2[20]="/tmp/test.XXXXXX"; |
| 828 |
int fd = mkstemp(tpl); |
| 829 |
int fd2 = mkstemp(tpl2); |
| 830 |
if (fd == -1) { |
| 831 |
if (fd2 != -1) { |
| 832 |
unlink(tpl2); |
| 833 |
} |
| 834 |
exit(1); |
| 835 |
} |
| 836 |
if (fd2 == -1) exit(1); |
| 837 |
unlink(tpl); |
| 838 |
unlink(tpl2); |
| 839 |
if (fstat(fd, &st) != 0) exit(1); |
| 840 |
if ((st.st_mode & 0777) != 0600) exit(1); |
| 841 |
if (strcmp(tpl, "/tmp/test.XXXXXX") == 0) { |
| 842 |
exit(1); |
| 843 |
} |
| 844 |
if (strcmp(tpl, tpl2) == 0) { |
| 845 |
exit(1); |
| 846 |
} |
| 847 |
exit(0); |
| 848 |
''', |
| 849 |
define='HAVE_SECURE_MKSTEMP', |
| 850 |
execute=True, |
| 851 |
mandatory=True) # lets see if we get a mandatory failure for this one |
| 852 |
|
| 853 |
# look for a method of finding the list of network interfaces |
| 854 |
for method in ['HAVE_IFACE_GETIFADDRS', 'HAVE_IFACE_AIX', 'HAVE_IFACE_IFCONF', 'HAVE_IFACE_IFREQ']: |
| 855 |
bsd_for_strlcpy = '' |
| 856 |
if strlcpy_in_bsd: |
| 857 |
bsd_for_strlcpy = ' bsd' |
| 858 |
if conf.CHECK_CODE(''' |
| 859 |
#define %s 1 |
| 860 |
#define NO_CONFIG_H 1 |
| 861 |
#define AUTOCONF_TEST 1 |
| 862 |
#include "replace.c" |
| 863 |
#include "inet_ntop.c" |
| 864 |
#include "snprintf.c" |
| 865 |
#include "getifaddrs.c" |
| 866 |
#define getifaddrs_test main |
| 867 |
#include "tests/getifaddrs.c" |
| 868 |
''' % method, |
| 869 |
method, |
| 870 |
lib='nsl socket' + bsd_for_strlcpy, |
| 871 |
addmain=False, |
| 872 |
execute=True): |
| 873 |
break |
| 874 |
|
| 875 |
conf.RECURSE('system') |
| 876 |
conf.SAMBA_CONFIG_H() |
| 877 |
if conf.CHECK_FUNCS('strerror_r'): |
| 878 |
# Check if strerror_r is XSI-Compatable, the default GNU implementation |
| 879 |
# is not |
| 880 |
conf.CHECK_CODE('int strerror_r(int errnum, char *buf, size_t buflen);', |
| 881 |
'STRERROR_R_XSI_NOT_GNU', |
| 882 |
headers='string.h', addmain=False, link=False, |
| 883 |
msg="Checking for XSI (rather than GNU) prototype for strerror_r") |
| 884 |
|
| 885 |
|
| 886 |
REPLACEMENT_FUNCTIONS = { |
| 887 |
'replace.c': ['ftruncate', 'strlcpy', 'strlcat', 'mktime', 'initgroups', |
| 888 |
'memmove', 'strdup', 'setlinebuf', 'vsyslog', 'strnlen', |
| 889 |
'strndup', 'waitpid', 'seteuid', 'setegid', 'chroot', |
| 890 |
'mkstemp', 'mkdtemp', 'pread', 'pwrite', 'strcasestr', |
| 891 |
'strsep', 'strtok_r', 'strtoll', 'strtoull', 'setenv', 'unsetenv', |
| 892 |
'utime', 'utimes', 'dup2', 'chown', 'link', 'readlink', |
| 893 |
'symlink', 'lchown', 'realpath', 'memmem', 'vdprintf', |
| 894 |
'dprintf', 'get_current_dir_name', 'copy_file_range', |
| 895 |
'strerror_r', 'clock_gettime', 'memset_explicit'], |
| 896 |
'timegm.c': ['timegm'], |
| 897 |
# Note: C99_VSNPRINTF is not a function, but a special condition |
| 898 |
# for replacement |
| 899 |
'snprintf.c': ['C99_VSNPRINTF', 'snprintf', 'vsnprintf', 'asprintf', 'vasprintf'], |
| 900 |
# Note: WORKING_STRPTIME is not a function, but a special condition |
| 901 |
# for replacement |
| 902 |
'strptime.c': ['WORKING_STRPTIME', 'strptime'], |
| 903 |
} |
| 904 |
|
| 905 |
|
| 906 |
def build(bld): |
| 907 |
bld.RECURSE('buildtools/wafsamba') |
| 908 |
|
| 909 |
REPLACE_HOSTCC_SOURCE = '' |
| 910 |
|
| 911 |
for filename in REPLACEMENT_FUNCTIONS.keys(): |
| 912 |
for function in REPLACEMENT_FUNCTIONS[filename]: |
| 913 |
if not bld.CONFIG_SET('HAVE_%s' % function.upper()): |
| 914 |
REPLACE_HOSTCC_SOURCE += ' %s' % filename |
| 915 |
break |
| 916 |
|
| 917 |
extra_libs = '' |
| 918 |
if bld.CONFIG_SET('HAVE_LIBBSD'): extra_libs += ' bsd' |
| 919 |
if bld.CONFIG_SET('HAVE_LIBRT'): extra_libs += ' rt' |
| 920 |
if bld.CONFIG_SET('REPLACE_REQUIRES_LIBSOCKET_LIBNSL'): extra_libs += ' socket nsl' |
| 921 |
|
| 922 |
if not bld.CONFIG_SET('HAVE_CLOSEFROM'): |
| 923 |
REPLACE_HOSTCC_SOURCE += ' closefrom.c' |
| 924 |
|
| 925 |
bld.SAMBA_SUBSYSTEM('LIBREPLACE_HOSTCC', |
| 926 |
REPLACE_HOSTCC_SOURCE, |
| 927 |
use_hostcc=True, |
| 928 |
use_global_deps=False, |
| 929 |
group='hostcc_base_build_main', |
| 930 |
deps = extra_libs |
| 931 |
) |
| 932 |
|
| 933 |
REPLACE_SOURCE = REPLACE_HOSTCC_SOURCE |
| 934 |
|
| 935 |
if not bld.CONFIG_SET('HAVE_DLOPEN'): REPLACE_SOURCE += ' dlfcn.c' |
| 936 |
if not bld.CONFIG_SET('HAVE_POLL'): REPLACE_SOURCE += ' poll.c' |
| 937 |
|
| 938 |
if not bld.CONFIG_SET('HAVE_SOCKETPAIR'): REPLACE_SOURCE += ' socketpair.c' |
| 939 |
if not bld.CONFIG_SET('HAVE_CONNECT'): REPLACE_SOURCE += ' socket.c' |
| 940 |
if not bld.CONFIG_SET('HAVE_GETIFADDRS'): REPLACE_SOURCE += ' getifaddrs.c' |
| 941 |
if not bld.CONFIG_SET('HAVE_GETADDRINFO'): REPLACE_SOURCE += ' getaddrinfo.c' |
| 942 |
if not bld.CONFIG_SET('HAVE_INET_NTOA'): REPLACE_SOURCE += ' inet_ntoa.c' |
| 943 |
if not bld.CONFIG_SET('HAVE_INET_ATON'): REPLACE_SOURCE += ' inet_aton.c' |
| 944 |
if not bld.CONFIG_SET('HAVE_INET_NTOP'): REPLACE_SOURCE += ' inet_ntop.c' |
| 945 |
if not bld.CONFIG_SET('HAVE_INET_PTON'): REPLACE_SOURCE += ' inet_pton.c' |
| 946 |
if not bld.CONFIG_SET('HAVE_GETXATTR') or bld.CONFIG_SET('XATTR_ADDITIONAL_OPTIONS'): |
| 947 |
REPLACE_SOURCE += ' xattr.c' |
| 948 |
|
| 949 |
if not bld.CONFIG_SET('HAVE_CLOSEFROM'): |
| 950 |
REPLACE_SOURCE += ' closefrom.c' |
| 951 |
|
| 952 |
bld.SAMBA_LIBRARY('replace', |
| 953 |
source=REPLACE_SOURCE, |
| 954 |
group='base_libraries', |
| 955 |
# FIXME: Ideally symbols should be hidden here so they |
| 956 |
# don't appear in the global namespace when Samba |
| 957 |
# libraries are loaded, but this doesn't appear to work |
| 958 |
# at the moment: |
| 959 |
# hide_symbols=bld.BUILTIN_LIBRARY('replace'), |
| 960 |
private_library=True, |
| 961 |
provide_builtin_linking=True, |
| 962 |
deps='dl attr' + extra_libs) |
| 963 |
|
| 964 |
replace_test_cflags = '' |
| 965 |
if bld.CONFIG_SET('HAVE_WNO_FORMAT_TRUNCATION'): |
| 966 |
replace_test_cflags += " -Wno-format-truncation" |
| 967 |
bld.SAMBA_SUBSYSTEM('replace-test', |
| 968 |
source='''tests/testsuite.c tests/strptime.c |
| 969 |
tests/os2_delete.c tests/getifaddrs.c''', |
| 970 |
deps='replace', |
| 971 |
cflags=replace_test_cflags) |
| 972 |
|
| 973 |
bld.SAMBA_BINARY('replace_testsuite', |
| 974 |
source='tests/main.c', |
| 975 |
deps='replace replace-test', |
| 976 |
install=False) |
| 977 |
|
| 978 |
bld.SAMBA_BINARY('test_memset_explicit', |
| 979 |
source='tests/test_memset_explicit.c', |
| 980 |
deps='cmocka replace', |
| 981 |
for_selftest=True) |
| 982 |
|
| 983 |
# build replacements for stdint.h and stdbool.h if needed |
| 984 |
bld.SAMBA_GENERATOR('replace_stdint_h', |
| 985 |
rule='cp ${SRC} ${TGT}', |
| 986 |
source='hdr_replace.h', |
| 987 |
target='stdint.h', |
| 988 |
enabled = not bld.CONFIG_SET('HAVE_STDINT_H')) |
| 989 |
bld.SAMBA_GENERATOR('replace_stdbool_h', |
| 990 |
rule='cp ${SRC} ${TGT}', |
| 991 |
source='hdr_replace.h', |
| 992 |
target='stdbool.h', |
| 993 |
enabled = not bld.CONFIG_SET('HAVE_STDBOOL_H')) |
| 994 |
|
| 995 |
bld.SAMBA_SUBSYSTEM('samba_intl', source='', use_global_deps=False,deps=bld.env.intl_libs) |
| 996 |
|
| 997 |
def testonly(ctx): |
| 998 |
'''run talloc testsuite''' |
| 999 |
import samba_utils |
| 1000 |
|
| 1001 |
samba_utils.ADD_LD_LIBRARY_PATH('bin/shared') |
| 1002 |
samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private') |
| 1003 |
|
| 1004 |
cmd = os.path.join(Context.g_module.out, 'replace_testsuite') |
| 1005 |
ret = samba_utils.RUN_COMMAND(cmd) |
| 1006 |
print("testsuite returned %d" % ret) |
| 1007 |
sys.exit(ret) |
| 1008 |
|
| 1009 |
# WAF doesn't build the unit tests for this, maybe because they don't link with talloc? |
| 1010 |
# This forces it |
| 1011 |
def test(ctx): |
| 1012 |
Options.commands.append('build') |
| 1013 |
Options.commands.append('testonly') |
| 1014 |
|
| 1015 |
def dist(): |
| 1016 |
'''makes a tarball for distribution''' |
| 1017 |
samba_dist.dist() |