build: added getpass() tests
[Samba/gebeck_regimport.git] / lib / replace / wscript
bloba7955a699265bf85dcc53d3ebee2c60ed26f5242
1 #! /usr/bin/env python
3 srcdir = '../..'
4 blddir = 'bin'
6 import sys
7 sys.path.insert(0, srcdir+"/buildtools/wafsamba")
8 import wafsamba
9 import Options, os
11 def set_options(opt):
12 opt.tool_options('compiler_cc')
13 # TODO: we are not yet obeying these default paths at install time
14 opt.add_option('--libdir',
15 help=("object code libraries [PREFIX/lib"),
16 action="store", dest='LIBDIR', default='${PREFIX}/lib')
17 opt.add_option('--bindir',
18 help=("user executables [PREFIX/bin]"),
19 action="store", dest='BINDIR', default='${PREFIX}/bin')
20 opt.add_option('--sbindir',
21 help=("system admin executables [PREFIX/sbin]"),
22 action="store", dest='SBINDIR', default='${PREFIX}/sbin')
23 opt.add_option('--enable-rpath',
24 help=("Enable use of rpath for installed binaries"),
25 action="store_true", dest='enable_rpath', default=False)
26 opt.add_option('--enable-developer',
27 help=("Turn on developer warnings and debugging"),
28 action="store_true", dest='developer', default=False)
30 @wafsamba.runonce
31 def configure(conf):
32 conf.env.hlist = []
33 conf.env.srcdir = conf.srcdir
35 # load our local waf extensions
36 conf.check_tool('wafsamba', tooldir=conf.srcdir + "/buildtools/wafsamba")
38 conf.check_tool('compiler_cc')
40 # make the install paths available in environment
41 conf.env.LIBDIR = Options.options.LIBDIR
42 conf.env.BINDIR = Options.options.BINDIR
43 conf.env.SBINDIR = Options.options.SBINDIR
45 conf.env.RPATH_ON_INSTALL = Options.options.enable_rpath
47 # check for pkgconfig
48 conf.check_cfg(atleast_pkgconfig_version='0.0.0')
50 conf.DEFINE('_GNU_SOURCE', 1)
51 conf.DEFINE('_XOPEN_SOURCE_EXTENDED', 1)
52 conf.DEFINE('LIBREPLACE_NETWORK_CHECKS', 1)
54 conf.CHECK_HEADERS('unistd.h sys/types.h stdlib.h stdio.h stddef.h')
55 conf.CHECK_HEADERS('ctype.h locale.h acl/libacl.h compat.h')
56 conf.CHECK_HEADERS('acl/libacl.h attr/xattr.h compat.h ctype.h dustat.h')
57 conf.CHECK_HEADERS('fcntl.h fnmatch.h glob.h history.h krb5.h langinfo.h')
58 conf.CHECK_HEADERS('libaio.h locale.h ndir.h net/if.h pwd.h readline.h')
59 conf.CHECK_HEADERS('readline/history.h readline/readline.h shadow.h sys/acl.h')
60 conf.CHECK_HEADERS('sys/attributes.h sys/capability.h sys/dir.h sys/epoll.h')
61 conf.CHECK_HEADERS('sys/fcntl.h sys/filio.h sys/filsys.h sys/fs/s5param.h sys/fs/vx/quota.h')
62 conf.CHECK_HEADERS('sys/id.h sys/ioctl.h sys/ipc.h sys/mman.h sys/mode.h sys/ndir.h sys/priv.h')
63 conf.CHECK_HEADERS('sys/resource.h sys/security.h sys/shm.h sys/statfs.h sys/statvfs.h sys/termio.h')
64 conf.CHECK_HEADERS('sys/vfs.h sys/xattr.h termio.h termios.h')
65 conf.CHECK_HEADERS('sys/wait.h sys/stat.h malloc.h grp.h')
66 conf.CHECK_HEADERS('crypt.h dlfcn.h dl.h standards.h stdbool.h stdint.h')
67 conf.CHECK_HEADERS('sys/select.h setjmp.h utime.h sys/syslog.h syslog.h')
68 conf.CHECK_HEADERS('sys/time.h time.h stdarg.h vararg.h sys/mount.h mntent.h')
69 conf.CHECK_HEADERS('stropts.h unix.h string.h strings.h sys/param.h limits.h')
70 conf.CHECK_HEADERS('sys/socket.h netinet/in.h netdb.h arpa/inet.h netinet/in_systm.h')
71 conf.CHECK_HEADERS('netinet/ip.h netinet/tcp.h netinet/in_ip.h sys/sockio.h sys/un.h')
72 conf.CHECK_HEADERS('sys/uio.h ifaddrs.h direct.h dirent.h')
73 conf.CHECK_HEADERS('windows.h winsock2.h ws2tcpip.h')
74 conf.CHECK_HEADERS('resolv.h libintl.h errno.h')
75 conf.CHECK_HEADERS('gcrypt.h getopt.h iconv.h')
76 conf.CHECK_HEADERS('sys/inotify.h memory.h nss.h popt.h sasl/sasl.h')
77 conf.CHECK_HEADERS('security/pam_appl.h sys/inotify.h zlib.h asm/unistd.h')
79 if 'HAVE_STDDEF_H' in conf.env and 'HAVE_STDLIB_H' in conf.env:
80 conf.DEFINE('STDC_HEADERS', 1)
82 if 'HAVE_SYS_TIME_H' in conf.env and 'HAVE_TIME_H' in conf.env:
83 conf.DEFINE('TIME_WITH_SYS_TIME', 1)
85 conf.define('SHLIBEXT', "so", quote=True)
87 conf.CHECK_TYPES('"long long" intptr_t uintptr_t ptrdiff_t')
88 conf.CHECK_TYPES('comparison_fn_t socklen_t bool')
89 conf.CHECK_TYPE('_Bool', define='HAVE__Bool')
91 conf.CHECK_TYPE('int8_t', 'char')
92 conf.CHECK_TYPE('int16_t', 'short')
93 conf.CHECK_TYPE('uint16_t', 'unsigned short')
94 conf.CHECK_TYPE('int32_t', 'int')
95 conf.CHECK_TYPE('uint32_t', 'unsigned')
96 conf.CHECK_TYPE('int64_t', 'long long')
97 conf.CHECK_TYPE('uint64_t', 'unsigned long long')
98 conf.CHECK_TYPE('size_t', 'unsigned int')
99 conf.CHECK_TYPE('ssize_t', 'int')
100 conf.CHECK_TYPE('ino_t', 'unsigned')
101 conf.CHECK_TYPE('loff_t', 'off_t')
102 conf.CHECK_TYPE('bool', 'off_t')
103 conf.CHECK_TYPE('offset_t', 'loff_t')
104 conf.CHECK_TYPE('volatile int', define='HAVE_VOLATILE')
106 conf.CHECK_TYPE_IN('struct ifaddrs', 'ifaddrs.h')
107 conf.CHECK_TYPE_IN('struct addrinfo', 'netdb.h')
108 conf.CHECK_TYPE_IN('struct sockaddr', 'sys/socket.h')
109 conf.CHECK_CODE('struct sockaddr_in6 x', define='HAVE_STRUCT_SOCKADDR_IN6')
110 conf.CHECK_TYPE_IN('struct sockaddr_storage', 'sys/socket.h')
111 conf.CHECK_TYPE_IN('sa_family_t', 'sys/socket.h')
113 conf.CHECK_TYPE_IN('sig_atomic_t', 'signal.h', define='HAVE_SIG_ATOMIC_T_TYPE')
115 conf.CHECK_CODE('''
116 struct sockaddr_storage sa_store;
117 struct addrinfo *ai = NULL;
118 struct in6_addr in6addr;
119 int idx = if_nametoindex("iface1");
120 int s = socket(AF_INET6, SOCK_STREAM, 0);
121 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
122 if (ret != 0) {
123 const char *es = gai_strerror(ret);
125 freeaddrinfo(ai);
126 ''',
127 define='HAVE_IPV6')
129 # check if signal() takes a void function
130 if conf.CHECK_CODE('return *(signal (0, 0)) (0) == 1', define='RETSIGTYPE_INT', msg='Checking return type of signal handlers'):
131 conf.DEFINE('RETSIGTYPE', 'int')
132 else:
133 conf.DEFINE('RETSIGTYPE', 'void')
135 conf.CHECK_FUNCS('shl_load shl_unload shl_findsym')
136 conf.CHECK_FUNCS('pipe strftime srandom random srand rand usleep setbuffer')
137 conf.CHECK_FUNCS('lstat getpgrp utime utimes seteuid setresuid setegid')
138 conf.CHECK_FUNCS('setresgid chroot bzero strerror vsyslog setlinebuf mktime')
139 conf.CHECK_FUNCS('ftruncate chsize rename waitpid wait4 strlcpy strlcat')
140 conf.CHECK_FUNCS('initgroups memmove strdup pread pwrite strndup strcasestr')
141 conf.CHECK_FUNCS('strtok_r mkdtemp dup2 dprintf vdprintf isatty chown lchown')
142 conf.CHECK_FUNCS('link readlink symlink realpath fdatasync snprintf vsnprintf')
143 conf.CHECK_FUNCS('asprintf vasprintf setenv unsetenv strnlen strtoull __strtoull')
144 conf.CHECK_FUNCS('strtouq strtoll __strtoll strtoq memmem printf memset memcpy')
145 conf.CHECK_FUNCS('connect gethostbyname if_nametoindex socketpair')
146 conf.CHECK_FUNCS('inet_ntoa inet_aton inet_ntop inet_pton')
147 conf.CHECK_FUNCS('dirfd getdirentries getdents syslog getaddrinfo freeaddrinfo')
148 conf.CHECK_FUNCS('gai_strerror get_current_dir_name')
149 conf.CHECK_FUNCS('timegm getifaddrs freeifaddrs mmap setgroups setsid')
150 conf.CHECK_FUNCS('getgrent_r getgrgid_r getgrnam_r getgrouplist getpagesize')
151 conf.CHECK_FUNCS('getpwent_r getpwnam_r getpwuid_r epoll_create')
154 conf.CHECK_FUNCS_IN('dlopen dlsym dlerror dlclose', 'dl')
155 conf.CHECK_FUNCS_IN('poptGetContext', 'popt')
156 conf.CHECK_FUNCS_IN('res_search', 'resolv')
157 conf.CHECK_FUNCS_IN('gettext', 'intl')
159 conf.CHECK_FUNCS_IN('crypt', 'crypt', checklibc=True)
161 conf.CHECK_VARIABLE('rl_event_hook', define='HAVE_DECL_RL_EVENT_HOOK', always=True)
163 conf.CHECK_VARIABLE('__FUNCTION__', define='HAVE_FUNCTION_MACRO')
165 conf.CHECK_DECLS('snprintf vsnprintf asprintf vasprintf')
167 conf.CHECK_DECLS('dirfd environ errno getgrent_r getpwent_r', reverse=True)
168 conf.CHECK_DECLS('pread pwrite setenv setresgid setresuid', reverse=True)
170 conf.CHECK_SIZEOF('char int "long long" long off_t short size_t ssize_t')
171 conf.CHECK_SIZEOF('void*', define='SIZEOF_VOID_P')
173 if conf.CONFIG_SET('HAVE_EPOLL_CREATE') and conf.CONFIG_SET('HAVE_SYS_EPOLL_H'):
174 conf.DEFINE('HAVE_EPOLL', 1)
176 conf.CHECK_CODE('va_list ap1,ap2; va_copy(ap1,ap2)',
177 define="HAVE_VA_COPY",
178 msg="Checking for va_copy")
180 conf.CHECK_CODE('''
181 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
182 eprintf("bla", "bar")
183 ''', define='HAVE__VA_ARGS__MACRO')
185 conf.CHECK_CODE('gettimeofday(NULL, NULL)', 'HAVE_GETTIMEOFDAY_TZ', execute=False)
187 conf.CHECK_CODE('#include "test/snprintf.c"',
188 define="HAVE_C99_VSNPRINTF",
189 execute=1,
190 addmain=False,
191 msg="Checking for C99 vsnprintf")
193 if Options.options.developer:
194 conf.ADD_CFLAGS('-Wall -g -Wfatal-errors -DDEVELOPER -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Werror-implicit-function-declaration -Wformat=2 -Wno-format-y2k')
196 conf.SAMBA_CONFIG_H()
197 conf.SAMBA_BUILD_ENV()
199 # look for a method of finding the list of network interfaces
200 for method in ['HAVE_IFACE_GETIFADDRS', 'HAVE_IFACE_AIX', 'HAVE_IFACE_IFCONF', 'HAVE_IFACE_IFREQ']:
201 if conf.CHECK_CODE('''
202 #define %s 1
203 #define NO_CONFIG_H 1
204 #define AUTOCONF_TEST 1
205 #define SOCKET_WRAPPER_NOT_REPLACE
206 #include "replace.c"
207 #include "inet_ntop.c"
208 #include "snprintf.c"
209 #include "getifaddrs.c"
210 #define getifaddrs_test main
211 #include "test/getifaddrs.c"
212 ''' % method,
213 method,
214 addmain=False,
215 execute=True):
216 break
218 conf.CHECK_CODE('''
219 typedef struct {unsigned x;} FOOBAR;
220 #define X_FOOBAR(x) ((FOOBAR) { x })
221 #define FOO_ONE X_FOOBAR(1)
222 FOOBAR f = FOO_ONE;
223 static const struct {
224 FOOBAR y;
225 } f2[] = {
226 {FOO_ONE}
228 static const FOOBAR f3[] = {FOO_ONE};
229 ''',
230 define='HAVE_IMMEDIATE_STRUCTURES')
232 conf.CHECK_CODE('mkdir("foo",0777)', define='HAVE_MKDIR_MODE')
234 conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtim.tv_nsec', define='HAVE_STAT_TV_NSEC')
235 # we need the st_rdev test under two names
236 conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev', define='HAVE_STRUCT_STAT_ST_RDEV')
237 conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev', define='HAVE_ST_RDEV')
238 conf.CHECK_STRUCTURE_MEMBER('struct sockaddr_storage', 'ss_family')
240 conf.CHECK_CODE('struct sockaddr_un sunaddr; sunaddr.sun_family = AF_UNIX;',
241 define='HAVE_UNIXSOCKET')
244 conf.CHECK_CODE('''
245 struct stat st;
246 char tpl[20]="/tmp/test.XXXXXX";
247 int fd = mkstemp(tpl);
248 if (fd == -1) exit(1);
249 unlink(tpl);
250 if (fstat(fd, &st) != 0) exit(1);
251 if ((st.st_mode & 0777) != 0600) exit(1);
252 exit(0);
253 ''',
254 define='HAVE_SECURE_MKSTEMP',
255 execute=True,
256 mandatory=True) # lets see if we get a mandatory failure for this one
258 if conf.CHECK_CFLAGS('-fvisibility=hidden', 'VISIBILITY_CFLAGS'):
259 conf.CHECK_CODE('''void vis_foo1(void) {}
260 __attribute__((visibility("default"))) void vis_foo2(void) {}''',
261 cflags=conf.env.VISIBILITY_CFLAGS,
262 define='HAVE_VISIBILITY_ATTR')
264 # use this later -> conf.recurse('.', name='getpass')
266 if conf.CHECK_FUNCS('getpass getpassphrase'):
267 # if we have both, then we prefer getpassphrase
268 conf.DEFINE(REPLACE_GETPASS_BY_GETPASSPHRASE, 1)
269 conf.DEFINE(REPLACE_GETPASS, 1)
271 conf.CHECK_CODE('''#include "getpass.c"
272 int main(void) { return 0; }''',
273 addmain=False,
274 define='REPLACE_GETPASS',
275 cflags='-DNO_CONFIG_H')
277 def build(bld):
278 bld.set_rpath()
280 # libreplace needs to put the library in the right build groups
281 # as libreplace is a base library for everything, even for our
282 # compilers, we need libreplace to build very early
283 bld.SETUP_BUILD_GROUPS()
285 REPLACE_SOURCE = 'replace.c snprintf.c'
287 bld.SAMBA_LIBRARY('replace',
288 source=REPLACE_SOURCE,
289 group='base_libraries')
291 TEST_SOURCES = '''test/testsuite.c test/main.c test/strptime.c
292 test/os2_delete.c test/getifaddrs.c'''
294 bld.SAMBA_BINARY('replace_testsuite',
295 TEST_SOURCES,
296 deps='replace')
298 NET_SOURCES = []
299 if bld.CONFIG_SET('HAVE_INET_NTOA'): NET_SOURCES.append('inet_ntoa.c')
300 if bld.CONFIG_SET('HAVE_INET_ATON'): NET_SOURCES.append('inet_aton.c')
301 if bld.CONFIG_SET('HAVE_INET_NTOP'): NET_SOURCES.append('inet_ntop.c')
302 if bld.CONFIG_SET('HAVE_INET_PTON'): NET_SOURCES.append('inet_pton.c')
303 if bld.CONFIG_SET('HAVE_SOCKETPAIR'): NET_SOURCES.append('socketpair.c')
305 bld.SAMBA_SUBSYSTEM('LIBREPLACE_NETWORK', NET_SOURCES)
308 CRYPT_SOURCES = []
309 if not 'HAVE_CRYPT' in bld.env: CRYPT_SOURCES.append('crypt.c')
311 bld.SAMBA_SUBSYSTEM('LIBREPLACE_EXT', CRYPT_SOURCES)