s4-waf: mark the wscript files as python so vim/emacs knows how to highlight them
[sfrench/samba-autobuild/.git] / buildtools / wafsamba / wscript
1 #!/usr/bin/env python
2
3 # this is a base set of waf rules that everything else pulls in first
4
5 import sys, wafsamba
6 import Options, os, preproc
7
8 def set_options(opt):
9     opt.tool_options('compiler_cc')
10
11     opt.tool_options('gnu_dirs')
12     opt.add_option('--libdir',
13                    help=("object code libraries [PREFIX/lib"),
14                    action="store", dest='LIBDIR', default='${PREFIX}/lib')
15     opt.add_option('--bindir',
16                    help=("user executables [PREFIX/bin]"),
17                    action="store", dest='BINDIR', default='${PREFIX}/bin')
18     opt.add_option('--sbindir',
19                    help=("system admin executables [PREFIX/sbin]"),
20                    action="store", dest='SBINDIR', default='${PREFIX}/sbin')
21     opt.add_option('--with-modulesdir',
22                    help=("modules directory [PREFIX/modules]"),
23                    action="store", dest='MODULESDIR', default='${PREFIX}/modules')
24     opt.add_option('--disable-shared',
25                    help=("Disable all use of shared libraries"),
26                    action="store_true", dest='disable_shared', default=False)
27     opt.add_option('--disable-rpath',
28                    help=("Disable use of rpath for build binaries"),
29                    action="store_true", dest='disable_rpath_build', default=False)
30     opt.add_option('--disable-rpath-install',
31                    help=("Disable use of rpath for installed binaries"),
32                    action="store_true", dest='disable_rpath_install', default=False)
33     opt.add_option('--enable-developer',
34                    help=("Turn on developer warnings and debugging"),
35                    action="store_true", dest='developer', default=False)
36     opt.add_option('--enable-gccdeps',
37                    help=("Enable use gcc -MD dependency module"),
38                    action="store_true", dest='enable_gccdeps', default=False)
39     opt.add_option('--timestamp-dependencies',
40                    help=("use file timestamps instead of content for build dependencies (BROKEN)"),
41                    action="store_true", dest='timestamp_dependencies', default=False)
42     opt.add_option('-C',
43                    help='enable configure cacheing',
44                    action='store_true', dest='enable_configure_cache')
45     opt.add_option('--pedantic',
46                    help=("Enable even more compiler warnings"),
47                    action='store_true', dest='pedantic', default=False)
48
49 @wafsamba.runonce
50 def configure(conf):
51     conf.env.hlist = []
52     conf.env.srcdir = conf.srcdir
53
54     if Options.options.timestamp_dependencies:
55         conf.ENABLE_TIMESTAMP_DEPENDENCIES()
56
57     conf.SETUP_CONFIGURE_CACHE(Options.options.enable_configure_cache)
58
59     # load our local waf extensions
60     conf.check_tool('gnu_dirs')
61     conf.check_tool('wafsamba')
62
63     conf.CHECK_CC_ENV()
64
65     conf.check_tool('compiler_cc')
66
67     if Options.options.enable_gccdeps:
68         # don't enable gccdeps by default as it needs a very recent version gcc
69         conf.check_tool('gccdeps', tooldir=conf.srcdir + "/buildtools/wafsamba")
70
71     # make the install paths available in environment
72     conf.env.LIBDIR = Options.options.LIBDIR
73     conf.env.BINDIR = Options.options.BINDIR
74     conf.env.SBINDIR = Options.options.SBINDIR
75     conf.env.MODULESDIR = Options.options.MODULESDIR
76
77     conf.env.DISABLE_SHARED = Options.options.disable_shared
78
79     # see if we can compile and run a simple C program
80     conf.CHECK_CODE('printf("hello world\\n")',
81                     define='HAVE_SIMPLE_C_PROG',
82                     mandatory=True,
83                     execute=True,
84                     headers='stdio.h',
85                     msg='Checking simple C program')
86
87     # check for rpath
88     if not conf.env.DISABLE_SHARED and conf.CHECK_RPATH_SUPPORT():
89         conf.env.RPATH_ON_BUILD   = not Options.options.disable_rpath_build
90         conf.env.RPATH_ON_INSTALL = (conf.env.RPATH_ON_BUILD and
91                                      not Options.options.disable_rpath_install)
92     else:
93         conf.env.RPATH_ON_INSTALL = False
94         conf.env.RPATH_ON_BUILD   = False
95
96     # we should use the PIC options in waf instead
97     conf.ADD_CFLAGS('-fPIC')
98
99     # check for pkgconfig
100     conf.check_cfg(atleast_pkgconfig_version='0.0.0')
101
102     conf.DEFINE('_GNU_SOURCE', 1, add_to_cflags=True)
103     conf.DEFINE('_XOPEN_SOURCE_EXTENDED', 1, add_to_cflags=True)
104
105     # get the base headers we'll use for the rest of the tests
106     conf.CHECK_HEADERS('stdio.h sys/types.h sys/stat.h stdlib.h stddef.h memory.h string.h',
107                        add_headers=True)
108     conf.CHECK_HEADERS('strings.h inttypes.h stdint.h unistd.h minix/config.h', add_headers=True)
109     conf.CHECK_HEADERS('ctype.h standards.h stdbool.h stdint.h stdarg.h vararg.h', add_headers=True)
110
111     # see if we need special largefile flags
112     conf.CHECK_LARGEFILE()
113
114     if 'HAVE_STDDEF_H' in conf.env and 'HAVE_STDLIB_H' in conf.env:
115         conf.DEFINE('STDC_HEADERS', 1)
116
117     conf.CHECK_HEADERS('sys/time.h time.h', together=True)
118
119     if 'HAVE_SYS_TIME_H' in conf.env and 'HAVE_TIME_H' in conf.env:
120         conf.DEFINE('TIME_WITH_SYS_TIME', 1)
121
122     conf.define('SHLIBEXT', "so", quote=True)
123
124     conf.CHECK_CODE('long one = 1; return ((char *)(&one))[0]',
125                     execute=True,
126                     define='WORDS_BIGENDIAN')
127
128     # check if signal() takes a void function
129     if conf.CHECK_CODE('return *(signal (0, 0)) (0) == 1',
130                        define='RETSIGTYPE_INT',
131                        execute=False,
132                        headers='signal.h',
133                        msg='Checking if signal handlers return int'):
134         conf.DEFINE('RETSIGTYPE', 'int')
135     else:
136         conf.DEFINE('RETSIGTYPE', 'void')
137
138     conf.CHECK_VARIABLE('__FUNCTION__', define='HAVE_FUNCTION_MACRO')
139
140     conf.CHECK_CODE('va_list ap1,ap2; va_copy(ap1,ap2)',
141                     define="HAVE_VA_COPY",
142                     msg="Checking for va_copy")
143
144     conf.CHECK_CODE('''
145                     #define eprintf(...) fprintf(stderr, __VA_ARGS__)
146                     eprintf("bla", "bar")
147                     ''', define='HAVE__VA_ARGS__MACRO')
148
149     conf.SAMBA_BUILD_ENV()
150
151
152 def build(bld):
153     bld.SETUP_BUILD_GROUPS()
154     bld.ENFORCE_GROUP_ORDERING()
155     bld.CHECK_PROJECT_RULES()