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