waf: added --symbol-check option
[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, Configure
6 import Options, os, preproc
7 from samba_utils import *
8 from optparse import SUPPRESS_HELP
9
10 # this forces configure to be re-run if any of the configure
11 # sections of the build scripts change. We have to check
12 # for this in sys.argv as options have not yet been parsed when
13 # we need to set this. This is off by default until some issues
14 # are resolved related to WAFCACHE. It will need a lot of testing
15 # before it is enabled by default.
16 if '--enable-auto-reconfigure' in sys.argv:
17     Configure.autoconfig = True
18
19 def set_options(opt):
20     opt.tool_options('compiler_cc')
21
22     opt.tool_options('gnu_dirs')
23
24     gr = opt.option_group('library handling options')
25
26     gr.add_option('--bundled-libraries',
27                    help=("comma separated list of bundled libraries. May include !LIBNAME to disable bundling a library. Can be 'NONE' or 'ALL' [auto]"),
28                    action="store", dest='BUNDLED_LIBS', default='')
29
30     extension_default = Options.options['PRIVATE_EXTENSION_DEFAULT']
31     gr.add_option('--private-library-extension',
32                    help=("name extension for private libraries [%s]" % extension_default),
33                    action="store", dest='PRIVATE_EXTENSION', default=extension_default)
34
35     extension_exception = Options.options['PRIVATE_EXTENSION_EXCEPTION']
36     gr.add_option('--private-extension-exception',
37                    help=("comma separated list of libraries to not apply extension to [%s]" % extension_exception),
38                    action="store", dest='PRIVATE_EXTENSION_EXCEPTION', default=extension_exception)
39
40     builtin_defauilt = Options.options['BUILTIN_LIBRARIES_DEFAULT']
41     gr.add_option('--builtin-libraries',
42                    help=("command separated list of libraries to build directly into binaries [%s]" % builtin_defauilt),
43                    action="store", dest='BUILTIN_LIBRARIES', default=builtin_defauilt)
44
45     gr.add_option('--minimum-library-version',
46                    help=("list of minimum system library versions (LIBNAME1:version,LIBNAME2:version)"),
47                    action="store", dest='MINIMUM_LIBRARY_VERSION', default='')
48
49     gr.add_option('--disable-shared',
50                    help=("Disable all use of shared libraries"),
51                    action="store_true", dest='disable_shared', default=False)
52     gr.add_option('--disable-rpath',
53                    help=("Disable use of rpath for build binaries"),
54                    action="store_true", dest='disable_rpath_build', default=False)
55     gr.add_option('--disable-rpath-install',
56                    help=("Disable use of rpath for installed binaries"),
57                    action="store_true", dest='disable_rpath_install', default=False)
58     gr.add_option('--nonshared-binary',
59                    help=("Disable use of shared libs for the listed binaries"),
60                    action="store", dest='NONSHARED_BINARIES', default='')
61
62     opt.add_option('--with-modulesdir',
63                    help=("modules directory [PREFIX/modules]"),
64                    action="store", dest='MODULESDIR', default='${PREFIX}/modules')
65
66     gr = opt.option_group('developer options')
67
68     gr.add_option('-C',
69                    help='enable configure cacheing',
70                    action='store_true', dest='enable_configure_cache')
71     gr.add_option('--enable-auto-reconfigure',
72                    help='enable automatic reconfigure on build',
73                    action='store_true', dest='enable_auto_reconfigure')
74     gr.add_option('--enable-developer',
75                    help=("Turn on developer warnings and debugging"),
76                    action="store_true", dest='developer', default=False)
77     gr.add_option('--picky-developer',
78                    help=("Treat all warnings as errors (enable -Werror)"),
79                    action="store_true", dest='picky_developer', default=False)
80     gr.add_option('--fatal-errors',
81                    help=("Stop compilation on first error (enable -Wfatal-errors)"),
82                    action="store_true", dest='fatal_errors', default=False)
83     gr.add_option('--enable-gccdeps',
84                    help=("Enable use of gcc -MD dependency module"),
85                    action="store_true", dest='enable_gccdeps', default=True)
86     gr.add_option('--timestamp-dependencies',
87                    help=("use file timestamps instead of content for build dependencies (BROKEN)"),
88                    action="store_true", dest='timestamp_dependencies', default=False)
89     gr.add_option('--pedantic',
90                    help=("Enable even more compiler warnings"),
91                    action='store_true', dest='pedantic', default=False)
92
93     gr.add_option('--abi-check',
94                    help=("Check ABI signatures for libraries"),
95                    action='store_true', dest='ABI_CHECK', default=False)
96     gr.add_option('--abi-check-disable',
97                    help=("Disable ABI checking (used with --enable-developer)"),
98                    action='store_true', dest='ABI_CHECK_DISABLE', default=False)
99     gr.add_option('--abi-update',
100                    help=("Update ABI signature files for libraries"),
101                    action='store_true', dest='ABI_UPDATE', default=False)
102
103     gr.add_option('--show-deps',
104                    help=("Show dependency tree for the given target"),
105                    dest='SHOWDEPS', default='')
106
107     gr.add_option('--symbol-check',
108                   help=("check symbols in object files against project rules"),
109                   action='store_true', dest='SYMBOLCHECK', default=False)
110
111     gr.add_option('--show-duplicates',
112                   help=("Show objects which are included in multiple binaries or libraries"),
113                   action='store_true', dest='SHOW_DUPLICATES', default=False)
114
115     gr = opt.add_option_group('cross compilation options')
116
117     gr.add_option('--cross-compile',
118                    help=("configure for cross-compilation"),
119                    action='store_true', dest='CROSS_COMPILE', default=False)
120     gr.add_option('--cross-execute',
121                    help=("command prefix to use for cross-execution in configure"),
122                    action='store', dest='CROSS_EXECUTE', default='')
123     gr.add_option('--cross-answers',
124                    help=("answers to cross-compilation configuration (auto modified)"),
125                    action='store', dest='CROSS_ANSWERS', default='')
126     gr.add_option('--hostcc',
127                    help=("set host compiler when cross compiling"),
128                    action='store', dest='HOSTCC', default=False)
129
130     # we use SUPPRESS_HELP for these, as they are ignored, and are there only
131     # to allow existing RPM spec files to work
132     opt.add_option('--build',
133                    help=SUPPRESS_HELP,
134                    action='store', dest='AUTOCONF_BUILD', default='')
135     opt.add_option('--host',
136                    help=SUPPRESS_HELP,
137                    action='store', dest='AUTOCONF_HOST', default='')
138     opt.add_option('--program-prefix',
139                    help=SUPPRESS_HELP,
140                    action='store', dest='AUTOCONF_PROGRAM_PREFIX', default='')
141     opt.add_option('--disable-dependency-tracking',
142                    help=SUPPRESS_HELP,
143                    action='store_true', dest='AUTOCONF_DISABLE_DEPENDENCY_TRACKING', default=False)
144
145     gr = opt.option_group('dist options')
146     gr.add_option('--sign-release',
147                    help='sign the release tarball created by waf dist',
148                    action='store_true', dest='SIGN_RELEASE')
149     gr.add_option('--tag',
150                    help='tag release in git at the same time',
151                    type='string', action='store', dest='TAG_RELEASE')
152
153
154 @wafsamba.runonce
155 def configure(conf):
156     conf.env.hlist = []
157     conf.env.srcdir = conf.srcdir
158
159     if Options.options.timestamp_dependencies:
160         conf.ENABLE_TIMESTAMP_DEPENDENCIES()
161
162     conf.SETUP_CONFIGURE_CACHE(Options.options.enable_configure_cache)
163
164     # load our local waf extensions
165     conf.check_tool('gnu_dirs')
166     conf.check_tool('wafsamba')
167
168     conf.CHECK_CC_ENV()
169
170     conf.check_tool('compiler_cc')
171
172     # we need git for 'waf dist'
173     conf.find_program('git', var='GIT')
174
175     # older gcc versions (< 4.4) does not work with gccdeps, so we have to see if the .d file is generated
176     if Options.options.enable_gccdeps:
177         from TaskGen import feature, after
178         @feature('testd')
179         @after('apply_core')
180         def check_d(self):
181             tsk = self.compiled_tasks[0]
182             tsk.outputs.append(tsk.outputs[0].change_ext('.d'))
183
184         import Task
185         cc = Task.TaskBase.classes['cc']
186         oldmeth = cc.run
187
188         cc.run = Task.compile_fun_noshell('cc', '${CC} ${CCFLAGS} ${CPPFLAGS} ${_CCINCFLAGS} ${_CCDEFFLAGS} ${CC_SRC_F}${SRC} ${CC_TGT_F}${TGT[0].abspath(env)}')[0]
189         try:
190             try:
191                 conf.check(features='cc testd', fragment='int main() {return 0;}\n', ccflags=['-MD'], mandatory=True, msg='Check for -MD')
192             except:
193                 pass
194             else:
195                 conf.check_tool('gccdeps', tooldir=conf.srcdir + "/buildtools/wafsamba")
196         finally:
197             cc.run = oldmeth
198
199     # make the install paths available in environment
200     conf.env.LIBDIR = Options.options.LIBDIR or '${PREFIX}/lib'
201     conf.env.BINDIR = Options.options.BINDIR or '${PREFIX}/bin'
202     conf.env.SBINDIR = Options.options.SBINDIR or '${PREFIX}/sbin'
203     conf.env.MODULESDIR = Options.options.MODULESDIR
204     conf.env.BUNDLED_LIBS = Options.options.BUNDLED_LIBS.split(',')
205     conf.env.BUILTIN_LIBRARIES = Options.options.BUILTIN_LIBRARIES.split(',')
206     conf.env.DISABLE_SHARED = Options.options.disable_shared
207     conf.env.NONSHARED_BINARIES = Options.options.NONSHARED_BINARIES.split(',')
208
209     conf.env.PRIVATE_EXTENSION = Options.options.PRIVATE_EXTENSION
210     conf.env.PRIVATE_EXTENSION_EXCEPTION = Options.options.PRIVATE_EXTENSION_EXCEPTION.split(',')
211
212     conf.env.CROSS_COMPILE = Options.options.CROSS_COMPILE
213     conf.env.CROSS_EXECUTE = Options.options.CROSS_EXECUTE
214     conf.env.CROSS_ANSWERS = Options.options.CROSS_ANSWERS
215     conf.env.HOSTCC        = Options.options.HOSTCC
216
217     conf.env.AUTOCONF_BUILD = Options.options.AUTOCONF_BUILD
218     conf.env.AUTOCONF_HOST  = Options.options.AUTOCONF_HOST
219     conf.env.AUTOCONF_PROGRAM_PREFIX = Options.options.AUTOCONF_PROGRAM_PREFIX
220
221     if (conf.env.AUTOCONF_HOST and
222         conf.env.AUTOCONF_BUILD and
223         conf.env.AUTOCONF_BUILD != conf.env.AUTOCONF_HOST):
224         Logs.error('ERROR: Mismatch between --build and --host. Please use --cross-compile instead')
225         sys.exit(1)
226     if conf.env.AUTOCONF_PROGRAM_PREFIX:
227         Logs.error('ERROR: --program-prefix not supported')
228         sys.exit(1)
229
230     # enable ABI checking for developers
231     conf.env.ABI_CHECK = Options.options.ABI_CHECK or Options.options.developer
232     if Options.options.ABI_CHECK_DISABLE:
233         conf.env.ABI_CHECK = False
234     try:
235         conf.find_program('gdb', mandatory=True)
236     except:
237         conf.env.ABI_CHECK = False
238
239     conf.CHECK_COMMAND(['uname', '-a'],
240                        msg='Checking build system',
241                        define='BUILD_SYSTEM',
242                        on_target=False)
243     conf.CHECK_UNAME()
244
245     # see if we can compile and run a simple C program
246     conf.CHECK_CODE('printf("hello world")',
247                     define='HAVE_SIMPLE_C_PROG',
248                     mandatory=True,
249                     execute=True,
250                     headers='stdio.h',
251                     msg='Checking simple C program')
252
253     # see if we can build shared libs
254     if not conf.CHECK_LIBRARY_SUPPORT():
255         conf.env.DISABLE_SHARED = True
256
257     # check for rpath
258     if not conf.env.DISABLE_SHARED and conf.CHECK_LIBRARY_SUPPORT(rpath=True):
259         conf.env.RPATH_ON_BUILD   = not Options.options.disable_rpath_build
260         conf.env.RPATH_ON_INSTALL = (conf.env.RPATH_ON_BUILD and
261                                      not Options.options.disable_rpath_install)
262     else:
263         conf.env.RPATH_ON_INSTALL = False
264         conf.env.RPATH_ON_BUILD   = False
265
266     # we should use the PIC options in waf instead
267     # Some compilo didn't support -fPIC but just print a warning
268     if conf.env['COMPILER_CC'] == "suncc":
269         conf.ADD_CFLAGS('-KPIC', testflags=True)
270         # we really want define here as we need to have this
271         # define even during the tests otherwise detection of
272         # boolean is broken
273         conf.DEFINE('_STDC_C99', 1, add_to_cflags=True)
274         conf.DEFINE('_XPG6', 1, add_to_cflags=True)
275     else:
276         conf.ADD_CFLAGS('-fPIC', testflags=True)
277
278     if sys.platform == 'darwin':
279         conf.ADD_LDFLAGS('-fno-common', testflags=True)
280     conf.CHECK_INLINE()
281
282     # check for pkgconfig
283     conf.check_cfg(atleast_pkgconfig_version='0.0.0')
284
285     conf.DEFINE('_GNU_SOURCE', 1, add_to_cflags=True)
286     conf.DEFINE('_XOPEN_SOURCE_EXTENDED', 1, add_to_cflags=True)
287
288     # get the base headers we'll use for the rest of the tests
289     conf.CHECK_HEADERS('stdio.h sys/types.h sys/stat.h stdlib.h stddef.h memory.h string.h',
290                        add_headers=True)
291     conf.CHECK_HEADERS('strings.h inttypes.h stdint.h unistd.h minix/config.h', add_headers=True)
292     conf.CHECK_HEADERS('ctype.h standards.h stdbool.h stdint.h stdarg.h vararg.h', add_headers=True)
293     conf.CHECK_HEADERS('limits.h assert.h')
294
295     # see if we need special largefile flags
296     conf.CHECK_LARGEFILE()
297
298     if 'HAVE_STDDEF_H' in conf.env and 'HAVE_STDLIB_H' in conf.env:
299         conf.DEFINE('STDC_HEADERS', 1)
300
301     conf.CHECK_HEADERS('sys/time.h time.h', together=True)
302
303     if 'HAVE_SYS_TIME_H' in conf.env and 'HAVE_TIME_H' in conf.env:
304         conf.DEFINE('TIME_WITH_SYS_TIME', 1)
305
306     # cope with different extensions for libraries
307     (root, ext) = os.path.splitext(conf.env.shlib_PATTERN)
308     if ext[0] == '.':
309         conf.define('SHLIBEXT', ext[1:], quote=True)
310     else:
311         conf.define('SHLIBEXT', "so", quote=True)
312
313     conf.CHECK_CODE('long one = 1; return ((char *)(&one))[0]',
314                     execute=True,
315                     define='WORDS_BIGENDIAN')
316
317     # check if signal() takes a void function
318     if conf.CHECK_CODE('return *(signal (0, 0)) (0) == 1',
319                        define='RETSIGTYPE_INT',
320                        execute=False,
321                        headers='signal.h',
322                        msg='Checking if signal handlers return int'):
323         conf.DEFINE('RETSIGTYPE', 'int')
324     else:
325         conf.DEFINE('RETSIGTYPE', 'void')
326
327     conf.CHECK_VARIABLE('__FUNCTION__', define='HAVE_FUNCTION_MACRO')
328
329     conf.CHECK_CODE('va_list ap1,ap2; va_copy(ap1,ap2)',
330                     define="HAVE_VA_COPY",
331                     msg="Checking for va_copy")
332
333     conf.CHECK_CODE('''
334                     #define eprintf(...) fprintf(stderr, __VA_ARGS__)
335                     eprintf("bla", "bar")
336                     ''', define='HAVE__VA_ARGS__MACRO')
337
338     conf.SAMBA_BUILD_ENV()
339
340
341 def build(bld):
342     # give a more useful message if the source directory has moved
343     relpath = os_path_relpath(bld.curdir, bld.srcnode.abspath())
344     if relpath.find('../') != -1:
345         Logs.error('bld.curdir %s is not a child of %s' % (bld.curdir, bld.srcnode.abspath()))
346         raise Utils.WafError('''The top source directory has moved. Please run distclean and reconfigure''')
347
348     bld.CHECK_MAKEFLAGS()
349     bld.SETUP_BUILD_GROUPS()
350     bld.ENFORCE_GROUP_ORDERING()
351     bld.CHECK_PROJECT_RULES()