10b7c5f64f9eb2581bbf99aa71e32c80a167639e
[bbaumbach/samba-autobuild/.git] / source4 / SConstruct
1 #!/usr/bin/env python
2
3 # This is the experimental scons build script for Samba 4. For a proper 
4 # build use the old build system (configure + make). scons may
5 # eventually replace this system.
6 #
7 # Copyright (C) 2005 Jelmer Vernooij <jelmer@samba.org>
8 # Published under the GNU GPL
9 #
10 # TODO:
11 # - finish fallback code
12 # - finish proto code
13 # - support for init functions
14 # - separate config file for lib/replace/
15
16 import cPickle, string, os
17
18 opts = Options(None, ARGUMENTS)
19 opts.AddOptions(
20                 BoolOption('developer','enable developer flags', False),
21                 PathOption('prefix','installation prefix','/usr/local/samba'),
22                 BoolOption('configure','run configure checks', False),
23 )
24
25 hostenv = Environment(
26                 toolpath=['build/scons','.'],
27                 tools=['default','pidl','proto','et','asn1'],
28                 options=opts,
29                 CPPPATH=['#include','#','#lib'], 
30         CPPDEFINES={'_SAMBA_BUILD_': None},
31                 )
32
33 # We don't care about NFS builds...
34 hostenv.SetOption('max_drift', 1)
35
36 if hostenv['developer']:
37         hostenv.Append(CCFLAGS='-Wall')
38         hostenv.Append(CCFLAGS='-Wshadow')
39         hostenv.Append(CCFLAGS='-Werror-implicit-function-declaration')
40         hostenv.Append(CCFLAGS='-Wstrict-prototypes')
41         hostenv.Append(CCFLAGS='-Wpointer-arith')
42         hostenv.Append(CCFLAGS='-Wcast-qual')
43         hostenv.Append(CCFLAGS='-Wcast-align')
44         hostenv.Append(CCFLAGS='-Wwrite-strings')
45         hostenv.Append(CCFLAGS='-Wmissing-format-attribute')
46         hostenv.Append(CCFLAGS='-Wformat=2')
47         hostenv.Append(CCFLAGS='-Wno-format-y2k')
48         hostenv.Append(CCFLAGS='-Wno-declaration-after-statement')
49
50 # Some tools get confused if $HOME isn't defined
51 hostenv.Append(ENV={'HOME': os.environ['HOME']})
52
53 # Store configuration data in a dictionary.
54
55 def saveconfig(data):
56         """Save configuration dict to a file."""
57         cached = cPickle.dump(data, open('sconf.cache', 'w'))
58
59 def loadconfig():
60         """Load configuration dict from a file."""
61         try:
62                 return cPickle.load(open('sconf.cache', 'r'))
63         except IOError:
64                 return None
65
66 defines = loadconfig()
67
68 if defines == None:
69         hostenv['configure'] = 1
70         defines = {}
71
72 Export('defines')
73
74 hostenv.Append(CPPPATH = ['#heimdal_build', '#heimdal/lib/krb5',
75                           '#heimdal/lib/hdb', '#heimdal/lib/gssapi',
76                           '#heimdal/lib/asn1', '#heimdal/lib/des',
77                           '#heimdal/kdc', '#heimdal/lib/roken',
78                           '#heimdal/lib/com_err'])
79
80 Export('hostenv')
81
82 buildenv = hostenv
83
84 Export('buildenv')
85
86 cross_compiling = 0
87
88 if cross_compiling:
89         buildenv = hostenv.Copy()
90         buildenv.BuildDir('build-env','.')
91
92 dynenv = hostenv.Copy()
93
94 paths = { 
95         'BINDIR': 'bin',
96         'SBINDIR': 'sbin',
97         'CONFIGFILE': 'cfg',
98         'LOGFILEBASE': 'lfb',
99         'NCALRPCDIR': 'ncalrpc',
100         'LMHOSTSFILE': 'lmhosts',
101         'LIBDIR': 'libdir',
102         'SHLIBEXT': 'ext',
103         'LOCKDIR': 'lockdir',
104         'PIDDIR': 'piddir',
105         'PRIVATE_DIR': 'private',
106         'SWATDIR': 'swat'
107 }
108
109 Export('paths')
110
111 if hostenv['configure']:
112         
113         conf = hostenv.Configure()
114
115         for h in ['sys/select.h','fcntl.h','sys/fcntl.h'] + \
116                 ['utime.h','grp.h','sys/id.h','limits.h','memory.h'] + \
117                 ['compat.h','math.h','sys/param.h','ctype.h','sys/wait.h'] + \
118                 ['sys/resource.h','sys/ioctl.h','sys/ipc.h','sys/mode.h'] + \
119                 ['sys/mman.h','sys/filio.h','sys/priv.h','sys/shm.h','string.h'] + \
120                 ['strings.h','stdlib.h','sys/vfs.h','sys/fs/s5param.h','sys/filsys.h'] + \
121                 ['termios.h','termio.h','fnmatch.h','pwd.h','sys/termio.h'] + \
122                 ['sys/time.h','sys/statfs.h','sys/statvfs.h','stdarg.h'] + \
123                 ['sys/syslog.h','syslog.h','stdint.h','inttypes.h','locale.h'] + \
124                 ['shadow.h','nss.h','nss_common.h','ns_api.h','sys/security.h'] + \
125                 ['security/pam_appl.h','sys/capability.h'] + \
126                 ['sys/acl.h','stdbool.h', 'netinet/in.h', 'sys/socket.h', 'arpa/inet.h', 'netdb.h']:
127                 if conf.CheckCHeader(h):
128                         defines['HAVE_' + h.upper().replace('.','_').replace('/','_')] = 1
129
130         for f in ['setsid','pipe','crypt16','getauthuid','strftime','sigprocmask',
131                 'sigblock','sigaction','initgroups','setgroups','sysconf', 'getpwanam',
132                 'setlinebuf','srandom','random','srand','rand','usleep','timegm',
133                 'backtrace','setbuffer']:
134                 if conf.CheckFunc(f):
135                         defines['HAVE_' + f.upper()] = 1
136
137         # Pull in GNU extensions
138         defines['_GNU_SOURCE'] = 1
139
140         # Hardcode signal return type for now
141         defines['RETSIGTYPE'] = 'void'
142         
143         if conf.CheckType('comparison_fn_t', '#define _GNU_SOURCE\n#include <stdlib.h>'):
144                 defines['HAVE_COMPARISON_FN_T'] = 1
145
146         if conf.CheckType('sig_atomic_t', '#include <signal.h>'):
147                 defines['HAVE_SIG_ATOMIC_T_TYPE'] = 1
148
149         if conf.TryCompile("""
150 #include <sys/types.h>
151
152 int main() 
153 {
154         volatile int i = 0;
155         return 0;
156 }""", '.c'):
157                 defines['HAVE_VOLATILE'] = 1
158
159         if conf.TryCompile("""
160 #include <stdio.h>
161
162 int main() 
163 {
164    typedef struct {unsigned x;} FOOBAR;
165    #define X_FOOBAR(x) ((FOOBAR) { x })
166    #define FOO_ONE X_FOOBAR(1)
167    FOOBAR f = FOO_ONE;   
168    static struct {
169         FOOBAR y; 
170         } f2[] = {
171                 {FOO_ONE}
172         };   
173         return 0;
174 }""", '.c'):
175                 defines['HAVE_IMMEDIATE_STRUCTURES'] = 1
176
177         hostenv.AlwaysBuild('include/config.h')
178
179         if conf.TryCompile("""
180 #include <sys/types.h>
181 #include <sys/time.h>
182 #include <time.h>
183
184 int
185 main ()
186 {
187 if ((struct tm *) 0)
188 return 0;
189   return 0;
190 }
191 """, '.c'):
192                 defines['TIME_WITH_SYS_TIME'] = 1
193
194         if conf.TryCompile("""
195 #include <sys/time.h>
196 #include <unistd.h>
197 main() { struct timeval tv; exit(gettimeofday(&tv, NULL));}
198 """, '.c'):
199                 defines['HAVE_GETTIMEOFDAY_TZ'] = 1
200
201         conf.Finish()
202
203 [dynenv.Append(CPPDEFINES = {p: '\\"%s\\"' % paths[p]}) for p in paths]
204         
205 dynconfig = dynenv.Object('dynconfig.c')
206 Export('dynconfig')
207
208 hostenv.proto_headers = []
209
210 SConscript(
211                 dirs=['dsdb', 'libcli', 'lib','torture','rpc_server','cldap_server',
212                 'nbt_server','client','ldap_server','libnet','nsswitch','web_server',
213                 'smbd','dsdb','heimdal_build','ntptr','kdc','smb_server','ntvfs',
214                 'winbind','scripting','auth', 'librpc','script/tests'])
215
216 # proto.h
217
218 def create_global_proto(env, target, source):
219         fd = open(str(target[0]), 'w')
220         [fd.write('#include "%s"\n' % x) for x in source]
221         fd.close()
222
223 def create_global_proto_print(*args, **kwargs):
224         print 'Building global proto.h'
225
226 hostenv.Command('include/proto.h', hostenv.proto_headers,
227         Action(create_global_proto, create_global_proto_print))
228
229 # Save configuration
230
231 if hostenv['configure']:
232         saveconfig(defines)
233
234 # How to create config.h file
235 def create_config_h(env, target, source):
236         fd = open(str(target[0]), 'w')
237         [fd.write('#define %s %s\n' % (x, defines[x])) for x in defines]
238         fd.close()
239
240 def create_config_h_print(*args, **kwargs):
241         print 'Building config.h'
242
243 hostenv.Command('include/config.h', [],
244                 Action(create_config_h, create_config_h_print))
245 hostenv.Append(CPPDEFINES = {'HAVE_CONFIG_H': 1})