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