f45d0e7d5acded55e610dfcb34056b2d1082b949
[jelmer/samba4-debian.git] / source / lib / replace / SConscript
1 #!/usr/bin/env python
2 Import('hostenv defines')
3
4 rep_files = ['replace.c', 'snprintf.c','dlfcn.c']
5
6 if hostenv['configure']:
7         conf = Configure(hostenv)
8         for f in ['memset','syslog','setnetgrent','getnetgrent','endnetgrent', \
9                         'mktemp', 'memcpy']:
10                 if not conf.CheckFunc(f,'c'):
11                         print "Required function `%s' not found" % f
12                         exit(1)
13         
14         for f in ['strtoull','__strtoull','strtouq','strtoll','__strtoll','strtoq',
15                           'seteuid','setresuid','setegid','setresgid','dlsym','dlopen',
16                           'dlerror','dlclose','waitpid','getcwd','strdup','strndup',
17                           'strnlen','strerror','bzero','chroot','strlcpy','strlcat',
18                           'memmove','vsnprintf','asprintf','snprintf','vasprintf',
19                           'innetgr','mktime','rename','ftruncate','chsize','setlinebuf',
20                           'setenv','vsyslog','pread','pwrite']:
21                 if conf.CheckFunc(f,'c'):
22                         defines['HAVE_' + f.upper()] = 1
23
24         # Check for errno declaration
25         if conf.TryCompile("""
26 #include <errno.h>
27
28 int main() {
29         int i = (int)errno;
30         return 0;
31 }""", '.c'):
32                 defines['HAVE_ERRNO_DECL'] = 1
33
34         for h in ['dlfcn.h']:
35                 if conf.CheckCHeader('dlfcn.h'):
36                         defines['HAVE_' + h.upper().replace('.','_').replace('/','_')] = 1
37
38         if not conf.CheckType('socklen_t', "#include <sys/socket.h>"):
39                 defines['socklen_t'] = 'int'
40
41         needed_types = { 
42                 'uint_t': 'unsigned int',
43                 'int8_t': 'signed char',
44                 'uint8_t': 'unsigned char',
45                 'u_int8_t': 'unsigned char',
46                 'int16_t': 'short',
47                 'uint16_t': 'unsigned short',
48                 'u_int16_t': 'unsigned short',
49                 'int32_t': 'long',
50                 'uint32_t': 'unsigned long',
51                 'u_int32_t': 'unsigned long',
52                 'int64_t': 'long long',
53                 'uint64_t': 'unsigned long long',
54                 'ssize_t': 'int'
55         }
56
57         type_headers = """
58 #include <stdint.h>
59 #include <sys/types.h>
60 """     
61         for t in needed_types:
62                 if not conf.CheckType(t,type_headers):
63                         defines[t] = needed_types[t]
64
65         if not conf.TryRun(open("../../build/tests/os2_delete.c").read(), '.c'):
66                 rep_files += ['repdir/repdir.c']
67
68         conf.Finish()
69
70 hostenv.StaticLibrary('replace', rep_files)
71 SConscript(dirs=['win32'])