28283cb0a4e22742dcf955f4e795c4840e9bc87a
[nivanova/samba-autobuild/.git] / lib / replace / wscript
1 #! /usr/bin/env python
2
3 srcdir = '../..'
4 blddir = 'bin'
5
6 import sys
7 sys.path.insert(0, srcdir+"/buildtools/wafsamba")
8 import wafsamba
9 import Options, os
10
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)
29
30 @wafsamba.runonce
31 def configure(conf):
32     conf.env.hlist = []
33     conf.env.srcdir = conf.srcdir
34
35     # load our local waf extensions
36     conf.check_tool('wafsamba', tooldir=conf.srcdir + "/buildtools/wafsamba")
37
38     conf.check_tool('compiler_cc')
39
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
44
45     conf.env['RPATH_ON_INSTALL'] = Options.options.enable_rpath
46
47     conf.DEFINE('_GNU_SOURCE', 1)
48     conf.DEFINE('_XOPEN_SOURCE_EXTENDED', 1)
49     conf.DEFINE('LIBREPLACE_NETWORK_CHECKS', 1)
50
51     conf.CHECK_HEADERS('unistd.h sys/types.h stdlib.h stdio.h stddef.h')
52     conf.CHECK_HEADERS('ctype.h locale.h acl/libacl.h compat.h')
53     conf.CHECK_HEADERS('acl/libacl.h attr/xattr.h compat.h ctype.h dustat.h')
54     conf.CHECK_HEADERS('fcntl.h fnmatch.h glob.h history.h krb5.h langinfo.h')
55     conf.CHECK_HEADERS('libaio.h locale.h ndir.h net/if.h pwd.h readline.h')
56     conf.CHECK_HEADERS('readline/history.h readline/readline.h shadow.h sys/acl.h')
57     conf.CHECK_HEADERS('sys/attributes.h sys/capability.h sys/dir.h sys/epoll.h')
58     conf.CHECK_HEADERS('sys/fcntl.h sys/filio.h sys/filsys.h sys/fs/s5param.h sys/fs/vx/quota.h')
59     conf.CHECK_HEADERS('sys/id.h sys/ioctl.h sys/ipc.h sys/mman.h sys/mode.h sys/ndir.h sys/priv.h')
60     conf.CHECK_HEADERS('sys/resource.h sys/security.h sys/shm.h sys/statfs.h sys/statvfs.h sys/termio.h')
61     conf.CHECK_HEADERS('sys/vfs.h sys/xattr.h termio.h termios.h')
62     conf.CHECK_HEADERS('sys/wait.h sys/stat.h malloc.h grp.h')
63     conf.CHECK_HEADERS('crypt.h dlfcn.h dl.h standards.h stdbool.h stdint.h')
64     conf.CHECK_HEADERS('sys/select.h setjmp.h utime.h sys/syslog.h syslog.h')
65     conf.CHECK_HEADERS('sys/time.h time.h stdarg.h vararg.h sys/mount.h mntent.h')
66     conf.CHECK_HEADERS('stropts.h unix.h string.h strings.h sys/param.h limits.h')
67     conf.CHECK_HEADERS('sys/socket.h netinet/in.h netdb.h arpa/inet.h netinet/in_systm.h')
68     conf.CHECK_HEADERS('netinet/ip.h netinet/tcp.h netinet/in_ip.h sys/sockio.h sys/un.h')
69     conf.CHECK_HEADERS('sys/uio.h ifaddrs.h direct.h dirent.h')
70     conf.CHECK_HEADERS('windows.h winsock2.h ws2tcpip.h')
71     conf.CHECK_HEADERS('resolv.h libintl.h')
72
73     if 'HAVE_STDDEF_H' in conf.env and 'HAVE_STDLIB_H' in conf.env:
74         conf.DEFINE('STDC_HEADERS', 1)
75
76     if 'HAVE_SYS_TIME_H' in conf.env and 'HAVE_TIME_H' in conf.env:
77         conf.DEFINE('TIME_WITH_SYS_TIME', 1)
78
79     conf.define('SHLIBEXT', "so", quote=True)
80
81     conf.check(type_name='long long')
82     conf.CHECK_TYPES('intptr_t uintptr_t ptrdiff_t')
83     conf.CHECK_TYPES('comparison_fn_t socklen_t bool')
84
85     conf.CHECK_TYPE('int8_t', 'char')
86     conf.CHECK_TYPE('int16_t', 'short')
87     conf.CHECK_TYPE('uint16_t', 'unsigned short')
88     conf.CHECK_TYPE('int32_t', 'int')
89     conf.CHECK_TYPE('uint32_t', 'unsigned')
90     conf.CHECK_TYPE('int64_t', 'long long')
91     conf.CHECK_TYPE('uint64_t', 'unsigned long long')
92     conf.CHECK_TYPE('size_t', 'unsigned int')
93     conf.CHECK_TYPE('ssize_t', 'int')
94     conf.CHECK_TYPE('ino_t', 'unsigned')
95     conf.CHECK_TYPE('loff_t', 'off_t')
96     conf.CHECK_TYPE('bool', 'off_t')
97
98     conf.CHECK_TYPE_IN('struct ifaddrs', 'ifaddrs.h')
99     conf.CHECK_TYPE_IN('struct addrinfo', 'netdb.h')
100     conf.CHECK_TYPE_IN('struct sockaddr', 'sys/socket.h')
101
102     conf.CHECK_FUNCS('shl_load shl_unload shl_findsym')
103     conf.CHECK_FUNCS('pipe strftime srandom random srand rand usleep setbuffer')
104     conf.CHECK_FUNCS('lstat getpgrp utime utimes seteuid setresuid setegid')
105     conf.CHECK_FUNCS('setresgid chroot bzero strerror vsyslog setlinebuf mktime')
106     conf.CHECK_FUNCS('ftruncate chsize rename waitpid wait4 strlcpy strlcat')
107     conf.CHECK_FUNCS('initgroups memmove strdup pread pwrite strndup strcasestr')
108     conf.CHECK_FUNCS('strtok_r mkdtemp dup2 dprintf vdprintf isatty chown lchown')
109     conf.CHECK_FUNCS('link readlink symlink realpath fdatasync snprintf vsnprintf')
110     conf.CHECK_FUNCS('asprintf vasprintf setenv unsetenv strnlen strtoull __strtoull')
111     conf.CHECK_FUNCS('strtouq strtoll __strtoll strtoq memmem printf memset memcpy')
112     conf.CHECK_FUNCS('connect gethostbyname if_nametoindex socketpair')
113     conf.CHECK_FUNCS('inet_ntoa inet_aton inet_ntop inet_pton')
114     conf.CHECK_FUNCS('dirfd getdirentries getdents syslog')
115     conf.CHECK_FUNCS('timegm getifaddrs freeifaddrs  crypt')
116
117     conf.CHECK_FUNCS_IN('dlopen dlsym dlerror dlclose', 'dl')
118     conf.CHECK_FUNCS_IN('poptGetContext', 'popt')
119     conf.CHECK_FUNCS_IN('res_search', 'resolv')
120     conf.CHECK_FUNCS_IN('gettext', 'intl')
121
122     conf.check_cc(fragment='''
123     #include <stdarg.h>
124     va_list ap1,ap2;
125     va_copy(ap1,ap2);
126     int main(void)
127     { return 0; }''',
128                 define_name="HAVE_VA_COPY",
129                 execute=0,
130                 link=0,
131                 define_ret=0,
132                 quote=0,
133                 msg="Checking for va_copy")
134
135
136     # we could also put code fragments like this in separate files,
137     # for example in test/snprintf.c
138     conf.check_cc(fragment='''
139 #include <sys/types.h>
140 #include <stdio.h>
141 #include <stdarg.h>
142 #include <stdlib.h>
143 void foo(const char *format, ...) {
144        va_list ap;
145        int len;
146        char buf[20];
147        long long l = 1234567890;
148        l *= 100;
149
150        va_start(ap, format);
151        len = vsnprintf(buf, 0, format, ap);
152        va_end(ap);
153        if (len != 5) exit(1);
154
155        va_start(ap, format);
156        len = vsnprintf(0, 0, format, ap);
157        va_end(ap);
158        if (len != 5) exit(2);
159
160        if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
161
162        if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
163        if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
164        if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
165        if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
166
167        printf("1");
168        exit(0);
169 }
170 main() { foo("hello"); }
171 ''',
172                 define_name="HAVE_C99_VSNPRINTF",
173                 execute=1,
174                 define_ret=1,
175                 quote=0,
176                 msg="Checking for C99 vsnprintf")
177
178     if Options.options.developer:
179         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')
180
181     conf.SAMBA_CONFIG_H()
182     conf.SAMBA_BUILD_ENV()
183
184 def build(bld):
185     bld.set_rpath()
186
187     # libreplace needs to put the library in the right build groups
188     # as libreplace is a base library for everything, even for our
189     # compilers, we need libreplace to build very early
190     bld.SETUP_BUILD_GROUPS()
191
192     REPLACE_SOURCE = 'replace.c snprintf.c'
193
194     bld.SAMBA_LIBRARY('replace',
195                       source=REPLACE_SOURCE,
196                       group='base_libraries')
197
198     TEST_SOURCES = '''test/testsuite.c test/main.c test/strptime.c
199                       test/os2_delete.c test/getifaddrs.c'''
200
201     bld.SAMBA_BINARY('replace_testsuite',
202                      TEST_SOURCES,
203                      deps='replace')
204
205     NET_SOURCES = []
206     if bld.CONFIG_SET('HAVE_INET_NTOA'):  NET_SOURCES.append('inet_ntoa.c')
207     if bld.CONFIG_SET('HAVE_INET_ATON'):  NET_SOURCES.append('inet_aton.c')
208     if bld.CONFIG_SET('HAVE_INET_NTOP'):  NET_SOURCES.append('inet_ntop.c')
209     if bld.CONFIG_SET('HAVE_INET_PTON'):  NET_SOURCES.append('inet_pton.c')
210     if bld.CONFIG_SET('HAVE_SOCKETPAIR'): NET_SOURCES.append('socketpair.c')
211
212     bld.SAMBA_SUBSYSTEM('LIBREPLACE_NETWORK', NET_SOURCES)
213
214
215     CRYPT_SOURCES = []
216     if not 'HAVE_CRYPT' in bld.env: CRYPT_SOURCES.append('crypt.c')
217
218     bld.SAMBA_SUBSYSTEM('LIBREPLACE_EXT', CRYPT_SOURCES)