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.
7 # Copyright (C) 2005 Jelmer Vernooij <jelmer@samba.org>
8 # Published under the GNU GPL
11 # - finish fallback code
12 # - support for init functions
13 # - separate config file for lib/replace/
16 import cPickle, string, os
18 opts = Options(None, ARGUMENTS)
20 BoolOption('developer','enable developer flags', False),
21 PathOption('prefix','installation prefix','/usr/local/samba'),
22 BoolOption('configure','run configure checks', False),
25 hostenv = Environment(
26 toolpath=['build/scons','.'],
27 tools=['default','pidl','proto','et','asn1'],
29 CPPPATH=['#include','#','#lib'],
30 CPPDEFINES={'_SAMBA_BUILD_': None},
33 hostenv.Help(opts.GenerateHelpText(hostenv))
35 # We don't care about NFS builds...
36 hostenv.SetOption('max_drift', 1)
38 if hostenv['developer']:
39 hostenv.Append(CCFLAGS='-Wall')
40 hostenv.Append(CCFLAGS='-Wshadow')
41 hostenv.Append(CCFLAGS='-Werror-implicit-function-declaration')
42 hostenv.Append(CCFLAGS='-Wstrict-prototypes')
43 hostenv.Append(CCFLAGS='-Wpointer-arith')
44 hostenv.Append(CCFLAGS='-Wcast-qual')
45 hostenv.Append(CCFLAGS='-Wcast-align')
46 hostenv.Append(CCFLAGS='-Wwrite-strings')
47 hostenv.Append(CCFLAGS='-Wmissing-format-attribute')
48 hostenv.Append(CCFLAGS='-Wformat=2')
49 hostenv.Append(CCFLAGS='-Wno-format-y2k')
50 hostenv.Append(CCFLAGS='-Wno-declaration-after-statement')
52 # Some tools get confused if $HOME isn't defined
53 hostenv.Append(ENV={'HOME': os.environ['HOME']})
55 # Store configuration data in a dictionary.
58 """Save configuration dict to a file."""
59 cached = cPickle.dump(data, open('sconf.cache', 'w'))
62 """Load configuration dict from a file."""
64 return cPickle.load(open('sconf.cache', 'r'))
68 defines = loadconfig()
71 hostenv['configure'] = 1
73 if hostenv['configure']:
78 hostenv.Append(CPPPATH = ['#heimdal_build', '#heimdal/lib/krb5',
79 '#heimdal/lib/hdb', '#heimdal/lib/gssapi',
80 '#heimdal/lib/asn1', '#heimdal/lib/des',
81 '#heimdal/kdc', '#heimdal/lib/roken',
82 '#heimdal/lib/com_err'])
93 buildenv = hostenv.Copy()
94 buildenv.BuildDir('build-env','.')
96 dynenv = hostenv.Copy()
102 'LOGFILEBASE': 'lfb',
103 'NCALRPCDIR': 'ncalrpc',
104 'LMHOSTSFILE': 'lmhosts',
107 'LOCKDIR': 'lockdir',
109 'PRIVATE_DIR': 'private',
115 if hostenv['configure']:
117 conf = hostenv.Configure()
119 for h in ['sys/select.h','fcntl.h','sys/fcntl.h'] + \
120 ['utime.h','grp.h','sys/id.h','limits.h','memory.h'] + \
121 ['compat.h','math.h','sys/param.h','ctype.h','sys/wait.h'] + \
122 ['sys/resource.h','sys/ioctl.h','sys/ipc.h','sys/mode.h'] + \
123 ['sys/mman.h','sys/filio.h','sys/priv.h','sys/shm.h','string.h'] + \
124 ['strings.h','stdlib.h','sys/vfs.h','sys/fs/s5param.h','sys/filsys.h'] + \
125 ['termios.h','termio.h','fnmatch.h','pwd.h','sys/termio.h'] + \
126 ['sys/time.h','sys/statfs.h','sys/statvfs.h','stdarg.h'] + \
127 ['sys/syslog.h','syslog.h','stdint.h','inttypes.h','locale.h'] + \
128 ['shadow.h','nss.h','nss_common.h','ns_api.h','sys/security.h'] + \
129 ['security/pam_appl.h','sys/capability.h'] + \
130 ['sys/acl.h','stdbool.h', 'netinet/in.h', 'sys/socket.h', 'arpa/inet.h', 'netdb.h']:
131 if conf.CheckCHeader(h):
132 defines['HAVE_' + h.upper().replace('.','_').replace('/','_')] = 1
134 for f in ['setsid','pipe','crypt16','getauthuid','strftime','sigprocmask',
135 'sigblock','sigaction','initgroups','setgroups','sysconf', 'getpwanam',
136 'setlinebuf','srandom','random','srand','rand','usleep','timegm',
137 'backtrace','setbuffer']:
138 if conf.CheckFunc(f):
139 defines['HAVE_' + f.upper()] = 1
141 # Pull in GNU extensions
142 defines['_GNU_SOURCE'] = 1
144 # Hardcode signal return type for now
145 defines['RETSIGTYPE'] = 'void'
147 if conf.CheckType('comparison_fn_t', '#define _GNU_SOURCE\n#include <stdlib.h>'):
148 defines['HAVE_COMPARISON_FN_T'] = 1
150 if conf.CheckType('sig_atomic_t', '#include <signal.h>'):
151 defines['HAVE_SIG_ATOMIC_T_TYPE'] = 1
153 if conf.TryCompile("""
154 #include <sys/types.h>
161 defines['HAVE_VOLATILE'] = 1
163 if conf.TryCompile("""
168 typedef struct {unsigned x;} FOOBAR;
169 #define X_FOOBAR(x) ((FOOBAR) { x })
170 #define FOO_ONE X_FOOBAR(1)
179 defines['HAVE_IMMEDIATE_STRUCTURES'] = 1
181 hostenv.AlwaysBuild('include/config.h')
183 if conf.TryCompile("""
184 #include <sys/types.h>
185 #include <sys/time.h>
196 defines['TIME_WITH_SYS_TIME'] = 1
198 if conf.TryCompile("""
199 #include <sys/time.h>
201 main() { struct timeval tv; exit(gettimeofday(&tv, NULL));}
203 defines['HAVE_GETTIMEOFDAY_TZ'] = 1
205 # Check for header that defines "DIR"
206 for h in ['dirent.h','sys/ndir.h','sys/dir.h','ndir.h']:
207 if conf.TryCompile("""
210 int main() { DIR *x; return 0; }""" % h, '.c'):
211 defines['HAVE_' + h.upper().replace('.','_').replace('/','_')] = 1
216 [dynenv.Append(CPPDEFINES = {p: '\\"%s\\"' % paths[p]}) for p in paths]
218 dynconfig = dynenv.Object('dynconfig.c')
221 hostenv.proto_headers = []
224 dirs=['dsdb', 'libcli', 'lib','torture','rpc_server','cldap_server',
225 'nbt_server','client','ldap_server','libnet','nsswitch','web_server',
226 'smbd','dsdb','heimdal_build','ntptr','kdc','smb_server','ntvfs',
227 'winbind','scripting','auth', 'librpc','script/tests'])
231 def create_global_proto(env, target, source):
232 fd = open(str(target[0]), 'w')
233 [fd.write('#include "%s"\n' % x) for x in source]
236 def create_global_proto_print(*args, **kwargs):
237 print 'Building global proto.h'
239 hostenv.Command('include/proto.h', hostenv.proto_headers,
240 Action(create_global_proto, create_global_proto_print))
244 if hostenv['configure']:
247 # How to create config.h file
248 def create_config_h(env, target, source):
249 fd = open(str(target[0]), 'w')
250 [fd.write('#define %s %s\n' % (x, defines[x])) for x in defines]
253 def create_config_h_print(*args, **kwargs):
254 print 'Building config.h'
256 hostenv.Command('include/config.h', [],
257 Action(create_config_h, create_config_h_print))
258 hostenv.Append(CPPDEFINES = {'HAVE_CONFIG_H': 1})