2005-09-19 22:01:57 +00:00
#!/usr/bin/env python
2005-09-19 21:37:38 +00:00
2005-09-19 19:19:10 +00:00
# This is the experimental scons build script for Samba 4. For a proper
2005-09-19 21:50:53 +00:00
# build use the old build system (configure + make). scons may
2005-09-19 19:19:10 +00:00
# eventually replace this system.
2005-09-19 22:01:57 +00:00
#
# Copyright (C) 2005 Jelmer Vernooij <jelmer@samba.org>
# Published under the GNU GPL
2005-09-22 08:47:32 +00:00
import cPickle , string , os
2005-09-21 05:39:18 +00:00
2005-09-20 22:10:40 +00:00
opts = Options ( None , ARGUMENTS )
opts . AddOptions (
2005-09-21 15:18:11 +00:00
BoolOption ( ' developer ' , ' enable developer flags ' , False ) ,
2005-09-21 00:38:23 +00:00
PathOption ( ' prefix ' , ' installation prefix ' , ' /usr/local/samba ' ) ,
2005-09-21 05:39:18 +00:00
BoolOption ( ' configure ' , ' run configure checks ' , False ) ,
2005-09-20 22:10:40 +00:00
)
2005-09-19 22:01:57 +00:00
hostenv = Environment (
toolpath = [ ' build/scons ' , ' . ' ] ,
2005-09-20 22:10:40 +00:00
tools = [ ' default ' , ' pidl ' , ' proto ' , ' et ' , ' asn1 ' ] ,
options = opts ,
2005-09-19 22:01:57 +00:00
CPPPATH = [ ' #include ' , ' # ' , ' #lib ' ] ,
2005-09-19 23:37:01 +00:00
CPPDEFINES = { ' _SAMBA_BUILD_ ' : None } ,
2005-09-19 22:01:57 +00:00
)
2005-09-19 23:37:01 +00:00
2005-09-23 00:38:22 +00:00
# We don't care about NFS builds...
2005-09-21 00:38:23 +00:00
hostenv . SetOption ( ' max_drift ' , 1 )
2005-09-20 22:10:40 +00:00
if hostenv [ ' developer ' ] :
2005-09-20 23:00:45 +00:00
hostenv . Append ( CCFLAGS = ' -Wall ' )
hostenv . Append ( CCFLAGS = ' -Wshadow ' )
hostenv . Append ( CCFLAGS = ' -Werror-implicit-function-declaration ' )
hostenv . Append ( CCFLAGS = ' -Wstrict-prototypes ' )
hostenv . Append ( CCFLAGS = ' -Wpointer-arith ' )
hostenv . Append ( CCFLAGS = ' -Wcast-qual ' )
hostenv . Append ( CCFLAGS = ' -Wcast-align ' )
hostenv . Append ( CCFLAGS = ' -Wwrite-strings ' )
hostenv . Append ( CCFLAGS = ' -Wmissing-format-attribute ' )
hostenv . Append ( CCFLAGS = ' -Wformat=2 ' )
hostenv . Append ( CCFLAGS = ' -Wno-format-y2k ' )
hostenv . Append ( CCFLAGS = ' -Wno-declaration-after-statement ' )
2005-09-20 22:10:40 +00:00
2005-09-22 08:47:32 +00:00
# Some tools get confused if $HOME isn't defined
hostenv . Append ( ENV = { ' HOME ' : os . environ [ ' HOME ' ] } )
2005-09-21 05:39:18 +00:00
# Store configuration data in a dictionary.
def saveconfig ( data ) :
""" Save configuration dict to a file. """
cached = cPickle . dump ( data , open ( ' sconf.cache ' , ' w ' ) )
def loadconfig ( ) :
""" Load configuration dict from a file. """
try :
return cPickle . load ( open ( ' sconf.cache ' , ' r ' ) )
except IOError :
return None
defines = loadconfig ( )
if defines == None :
hostenv [ ' configure ' ] = 1
defines = { }
2005-09-21 00:38:23 +00:00
Export ( ' defines ' )
2005-09-20 22:10:40 +00:00
2005-09-19 21:37:38 +00:00
hostenv . Append ( CPPPATH = [ ' #heimdal_build ' , ' #heimdal/lib/krb5 ' ,
' #heimdal/lib/hdb ' , ' #heimdal/lib/gssapi ' ,
' #heimdal/lib/asn1 ' , ' #heimdal/lib/des ' ,
' #heimdal/kdc ' , ' #heimdal/lib/roken ' ,
' #heimdal/lib/com_err ' ] )
2005-09-20 22:10:40 +00:00
Export ( ' hostenv ' )
2005-09-20 11:59:03 +00:00
buildenv = hostenv
2005-09-20 22:10:40 +00:00
Export ( ' buildenv ' )
2005-09-20 11:59:03 +00:00
cross_compiling = 0
if cross_compiling :
buildenv = hostenv . Copy ( )
buildenv . BuildDir ( ' build-env ' , ' . ' )
2005-09-19 19:19:10 +00:00
dynenv = hostenv . Copy ( )
paths = {
2005-09-20 23:00:45 +00:00
' BINDIR ' : ' bin ' ,
' SBINDIR ' : ' sbin ' ,
' CONFIGFILE ' : ' cfg ' ,
' LOGFILEBASE ' : ' lfb ' ,
' NCALRPCDIR ' : ' ncalrpc ' ,
' LMHOSTSFILE ' : ' lmhosts ' ,
' LIBDIR ' : ' libdir ' ,
' SHLIBEXT ' : ' ext ' ,
' LOCKDIR ' : ' lockdir ' ,
' PIDDIR ' : ' piddir ' ,
2005-09-19 19:19:10 +00:00
' PRIVATE_DIR ' : ' private ' ,
2005-09-19 21:37:38 +00:00
' SWATDIR ' : ' swat '
2005-09-19 19:19:10 +00:00
}
2005-09-20 22:10:40 +00:00
Export ( ' paths ' )
2005-09-21 05:39:18 +00:00
if hostenv [ ' configure ' ] :
conf = hostenv . Configure ( )
for h in [ ' sys/select.h ' , ' fcntl.h ' , ' sys/fcntl.h ' , ' sys/time.h ' ] + \
[ ' utime.h ' , ' grp.h ' , ' sys/id.h ' , ' limits.h ' , ' memory.h ' ] + \
[ ' compat.h ' , ' math.h ' , ' sys/param.h ' , ' ctype.h ' , ' sys/wait.h ' ] + \
[ ' sys/resource.h ' , ' sys/ioctl.h ' , ' sys/ipc.h ' , ' sys/mode.h ' ] + \
[ ' sys/mman.h ' , ' sys/filio.h ' , ' sys/priv.h ' , ' sys/shm.h ' , ' string.h ' ] + \
[ ' strings.h ' , ' stdlib.h ' , ' sys/vfs.h ' , ' sys/fs/s5param.h ' , ' sys/filsys.h ' ] + \
[ ' termios.h ' , ' termio.h ' , ' fnmatch.h ' , ' pwd.h ' , ' sys/termio.h ' ] + \
[ ' sys/time.h ' , ' sys/statfs.h ' , ' sys/statvfs.h ' , ' stdarg.h ' ] + \
[ ' security/pam_modules.h ' , ' security/_pam_macros.h ' , ' dlfcn.h ' ] + \
[ ' sys/syslog.h ' , ' syslog.h ' , ' stdint.h ' , ' inttypes.h ' , ' locale.h ' ] + \
[ ' shadow.h ' , ' nss.h ' , ' nss_common.h ' , ' ns_api.h ' , ' sys/security.h ' ] + \
[ ' security/pam_appl.h ' , ' sys/capability.h ' , ' syscall.h ' , ' sys/syscall.h ' ] + \
2005-09-21 15:18:11 +00:00
[ ' sys/acl.h ' , ' stdbool.h ' ] :
2005-09-21 05:39:18 +00:00
if conf . CheckCHeader ( h ) :
defines [ ' HAVE_ ' + h . upper ( ) . replace ( ' . ' , ' _ ' ) . replace ( ' / ' , ' _ ' ) ] = 1
for f in [ ' dlopen ' , ' dlsym ' , ' dlerror ' , ' waitpid ' , ' getcwd ' , ' strdup ' ] + \
[ ' strndup ' , ' strnlen ' , ' strerror ' , ' chroot ' , ' bzero ' , ' memset ' , ' strlcpy ' ] + \
[ ' strlcat ' , ' memmove ' , ' vsnprintf ' , ' snprintf ' , ' asprintf ' , ' vasprintf ' ] + \
[ ' setsid ' , ' pipe ' , ' crypt16 ' , ' getauthuid ' , ' strftime ' , ' sigprocmask ' ] + \
[ ' sigblock ' , ' sigaction ' , ' innetgr ' , ' setnetgrent ' , ' getnetgrent ' ] + \
[ ' endnetgrent ' , ' initgroups ' , ' setgroups ' , ' sysconf ' , ' mktime ' , ' rename ' ] + \
[ ' ftruncate ' , ' chsize ' , ' getpwanam ' , ' setlinebuf ' , ' srandom ' , ' random ' ] + \
[ ' srand ' , ' rand ' , ' setenv ' , ' usleep ' , ' syslog ' , ' vsyslog ' , ' timegm ' ] + \
[ ' backtrace ' , ' setbuffer ' , ' pread ' , ' pwrite ' ] :
if conf . CheckFunc ( f ) :
defines [ ' HAVE_ ' + f . upper ( ) ] = 1
2005-09-22 12:23:44 +00:00
# Pull in GNU extensions
defines [ ' _GNU_SOURCE ' ] = 1
2005-09-21 15:18:11 +00:00
needed_types = {
' uint_t ' : ' unsigned int ' ,
' int8_t ' : ' signed char ' ,
' uint8_t ' : ' unsigned char ' ,
' int16_t ' : ' short ' ,
' uint16_t ' : ' unsigned short ' ,
' int32_t ' : ' long ' ,
' uint32_t ' : ' unsigned long ' ,
' int64_t ' : ' long long ' ,
' uint64_t ' : ' unsigned long long '
}
type_headers = """
#include <stdint.h>
2005-09-22 07:17:24 +00:00
#include <sys/types.h>
2005-09-21 15:18:11 +00:00
"""
for t in needed_types :
if not conf . CheckType ( t , type_headers ) :
defines [ t ] = needed_types [ t ]
2005-09-22 07:17:24 +00:00
for t in [ ' u_int32_t ' , ' u_int16_t ' , ' u_int8_t ' ] :
if conf . CheckType ( t , type_headers ) :
defines [ ' HAVE_ %s ' % string . upper ( t ) ] = 1
2005-09-22 08:47:32 +00:00
if conf . CheckType ( ' comparison_fn_t ' , ' #include <stdlib.h> ' ) :
2005-09-22 07:17:24 +00:00
defines [ ' HAVE_COMPARISON_FN_T ' ] = 1
if conf . CheckType ( ' sig_atomic_t ' , ' #include <signal.h> ' ) :
defines [ ' HAVE_SIG_ATOMIC_T_TYPE ' ] = 1
2005-09-21 15:18:11 +00:00
if conf . TryCompile ( """
#include <sys/types.h>
int main ( )
{
volatile int i = 0 ;
return 0 ;
} """ , ' .c ' ):
defines [ ' HAVE_VOLATILE ' ] = 1
if conf . TryCompile ( """
#include <stdio.h>
int main ( )
{
typedef struct { unsigned x ; } FOOBAR ;
#define X_FOOBAR(x) ((FOOBAR) { x })
#define FOO_ONE X_FOOBAR(1)
FOOBAR f = FOO_ONE ;
static struct {
FOOBAR y ;
} f2 [ ] = {
{ FOO_ONE }
} ;
return 0 ;
} """ , ' .c ' ):
defines [ ' HAVE_IMMEDIATE_STRUCTURES ' ] = 1
hostenv . AlwaysBuild ( ' include/config.h ' )
2005-09-21 05:39:18 +00:00
conf . Finish ( )
2005-09-20 22:10:40 +00:00
2005-09-19 21:37:38 +00:00
[ dynenv . Append ( CPPDEFINES = { p : ' \\ " %s \\ " ' % paths [ p ] } ) for p in paths ]
2005-09-19 19:19:10 +00:00
dynconfig = dynenv . Object ( ' dynconfig.c ' )
Export ( ' dynconfig ' )
2005-09-19 22:01:57 +00:00
2005-09-20 17:49:19 +00:00
proto_files = [ ]
2005-09-20 22:10:40 +00:00
Export ( ' proto_files ' )
2005-09-20 17:49:19 +00:00
2005-09-20 00:39:19 +00:00
SConscript (
2005-09-21 00:38:23 +00:00
dirs = [ ' lib ' , ' torture ' , ' rpc_server ' , ' cldap_server ' , ' libcli ' ,
2005-09-20 00:39:19 +00:00
' nbt_server ' , ' client ' , ' ldap_server ' , ' libnet ' , ' nsswitch ' , ' web_server ' ,
2005-09-20 11:59:03 +00:00
' smbd ' , ' dsdb ' , ' heimdal_build ' , ' ntptr ' , ' kdc ' , ' smb_server ' , ' ntvfs ' ,
2005-09-20 22:10:40 +00:00
' winbind ' , ' scripting ' , ' auth ' ] )
2005-09-20 17:49:19 +00:00
2005-09-20 22:10:40 +00:00
hostenv . CProtoHeader ( target = ' include/proto.h ' , source = proto_files )
2005-09-21 00:38:23 +00:00
2005-09-21 05:39:18 +00:00
# Save configuration
if hostenv [ ' configure ' ] :
saveconfig ( defines )
2005-09-21 07:12:23 +00:00
# How to create config.h file
def create_config_h ( env , target , source ) :
fd = open ( str ( target [ 0 ] ) , ' w ' )
2005-09-21 15:18:11 +00:00
[ fd . write ( ' #define %s %s \n ' % ( x , defines [ x ] ) ) for x in defines ]
2005-09-21 07:12:23 +00:00
fd . close ( )
def create_config_h_print ( * args , * * kwargs ) :
print ' Building config.h '
hostenv . Command ( ' include/config.h ' , [ ] ,
Action ( create_config_h , create_config_h_print ) )
hostenv . Append ( CPPDEFINES = { ' HAVE_CONFIG_H ' : 1 } )