waf: Add autoconf --target support.
[obnox/samba/samba-obnox.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, Logs
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 library path in installed files"),
57                    action="store_true", dest='disable_rpath_install', default=False)
58     gr.add_option('--disable-rpath-private-install',
59                    help=("Disable use of rpath for private library path in installed files"),
60                    action="store_true", dest='disable_rpath_private_install', default=False)
61     gr.add_option('--nonshared-binary',
62                    help=("Disable use of shared libs for the listed binaries"),
63                    action="store", dest='NONSHARED_BINARIES', default='')
64     gr.add_option('--disable-symbol-versions',
65                    help=("Disable use of the --version-script linker option"),
66                    action="store_true", dest='disable_symbol_versions', default=False)
67
68     opt.add_option('--with-modulesdir',
69                    help=("modules directory [PREFIX/modules]"),
70                    action="store", dest='MODULESDIR', default='${PREFIX}/modules')
71
72     opt.add_option('--with-privatelibdir',
73                    help=("private library directory [PREFIX/lib/%s]" % Utils.g_module.APPNAME),
74                    action="store", dest='PRIVATELIBDIR', default=None)
75
76     gr = opt.option_group('developer options')
77
78     gr.add_option('-C',
79                    help='enable configure cacheing',
80                    action='store_true', dest='enable_configure_cache')
81     gr.add_option('--enable-auto-reconfigure',
82                    help='enable automatic reconfigure on build',
83                    action='store_true', dest='enable_auto_reconfigure')
84     gr.add_option('--enable-developer',
85                    help=("Turn on developer warnings and debugging"),
86                    action="store_true", dest='developer', default=False)
87     gr.add_option('--picky-developer',
88                    help=("Treat all warnings as errors (enable -Werror)"),
89                    action="store_true", dest='picky_developer', default=False)
90     gr.add_option('--fatal-errors',
91                    help=("Stop compilation on first error (enable -Wfatal-errors)"),
92                    action="store_true", dest='fatal_errors', default=False)
93     gr.add_option('--enable-gccdeps',
94                    help=("Enable use of gcc -MD dependency module"),
95                    action="store_true", dest='enable_gccdeps', default=True)
96     gr.add_option('--timestamp-dependencies',
97                    help=("use file timestamps instead of content for build dependencies (BROKEN)"),
98                    action="store_true", dest='timestamp_dependencies', default=False)
99     gr.add_option('--pedantic',
100                    help=("Enable even more compiler warnings"),
101                    action='store_true', dest='pedantic', default=False)
102     gr.add_option('--git-local-changes',
103                    help=("mark version with + if local git changes"),
104                    action='store_true', dest='GIT_LOCAL_CHANGES', default=False)
105
106     gr.add_option('--abi-check',
107                    help=("Check ABI signatures for libraries"),
108                    action='store_true', dest='ABI_CHECK', default=False)
109     gr.add_option('--abi-check-disable',
110                    help=("Disable ABI checking (used with --enable-developer)"),
111                    action='store_true', dest='ABI_CHECK_DISABLE', default=False)
112     gr.add_option('--abi-update',
113                    help=("Update ABI signature files for libraries"),
114                    action='store_true', dest='ABI_UPDATE', default=False)
115
116     gr.add_option('--show-deps',
117                    help=("Show dependency tree for the given target"),
118                    dest='SHOWDEPS', default='')
119
120     gr.add_option('--symbol-check',
121                   help=("check symbols in object files against project rules"),
122                   action='store_true', dest='SYMBOLCHECK', default=False)
123
124     gr.add_option('--dup-symbol-check',
125                   help=("check for duplicate symbols in object files and system libs (must be configured with --enable-developer)"),
126                   action='store_true', dest='DUP_SYMBOLCHECK', default=False)
127
128     gr.add_option('--why-needed',
129                   help=("TARGET:DEPENDENCY check why TARGET needs DEPENDENCY"),
130                   action='store', type='str', dest='WHYNEEDED', default=None)
131
132     gr.add_option('--show-duplicates',
133                   help=("Show objects which are included in multiple binaries or libraries"),
134                   action='store_true', dest='SHOW_DUPLICATES', default=False)
135
136     gr = opt.add_option_group('cross compilation options')
137
138     gr.add_option('--cross-compile',
139                    help=("configure for cross-compilation"),
140                    action='store_true', dest='CROSS_COMPILE', default=False)
141     gr.add_option('--cross-execute',
142                    help=("command prefix to use for cross-execution in configure"),
143                    action='store', dest='CROSS_EXECUTE', default='')
144     gr.add_option('--cross-answers',
145                    help=("answers to cross-compilation configuration (auto modified)"),
146                    action='store', dest='CROSS_ANSWERS', default='')
147     gr.add_option('--hostcc',
148                    help=("set host compiler when cross compiling"),
149                    action='store', dest='HOSTCC', default=False)
150
151     # we use SUPPRESS_HELP for these, as they are ignored, and are there only
152     # to allow existing RPM spec files to work
153     opt.add_option('--build',
154                    help=SUPPRESS_HELP,
155                    action='store', dest='AUTOCONF_BUILD', default='')
156     opt.add_option('--host',
157                    help=SUPPRESS_HELP,
158                    action='store', dest='AUTOCONF_HOST', default='')
159     opt.add_option('--target',
160                    help=SUPPRESS_HELP,
161                    action='store', dest='AUTOCONF_TARGET', default='')
162     opt.add_option('--program-prefix',
163                    help=SUPPRESS_HELP,
164                    action='store', dest='AUTOCONF_PROGRAM_PREFIX', default='')
165     opt.add_option('--disable-dependency-tracking',
166                    help=SUPPRESS_HELP,
167                    action='store_true', dest='AUTOCONF_DISABLE_DEPENDENCY_TRACKING', default=False)
168     opt.add_option('--disable-silent-rules',
169                    help=SUPPRESS_HELP,
170                    action='store_true', dest='AUTOCONF_DISABLE_SILENT_RULES', default=False)
171
172     gr = opt.option_group('dist options')
173     gr.add_option('--sign-release',
174                    help='sign the release tarball created by waf dist',
175                    action='store_true', dest='SIGN_RELEASE')
176     gr.add_option('--tag',
177                    help='tag release in git at the same time',
178                    type='string', action='store', dest='TAG_RELEASE')
179
180
181 @wafsamba.runonce
182 def configure(conf):
183     conf.env.hlist = []
184     conf.env.srcdir = conf.srcdir
185
186     if Options.options.timestamp_dependencies:
187         conf.ENABLE_TIMESTAMP_DEPENDENCIES()
188
189     conf.SETUP_CONFIGURE_CACHE(Options.options.enable_configure_cache)
190
191     # load our local waf extensions
192     conf.check_tool('gnu_dirs')
193     conf.check_tool('wafsamba')
194
195     conf.CHECK_CC_ENV()
196
197     conf.check_tool('compiler_cc')
198
199     # we need git for 'waf dist'
200     conf.find_program('git', var='GIT')
201
202     # older gcc versions (< 4.4) does not work with gccdeps, so we have to see if the .d file is generated
203     if Options.options.enable_gccdeps:
204         from TaskGen import feature, after
205         @feature('testd')
206         @after('apply_core')
207         def check_d(self):
208             tsk = self.compiled_tasks[0]
209             tsk.outputs.append(tsk.outputs[0].change_ext('.d'))
210
211         import Task
212         cc = Task.TaskBase.classes['cc']
213         oldmeth = cc.run
214
215         cc.run = Task.compile_fun_noshell('cc', '${CC} ${CCFLAGS} ${CPPFLAGS} ${_CCINCFLAGS} ${_CCDEFFLAGS} ${CC_SRC_F}${SRC} ${CC_TGT_F}${TGT[0].abspath(env)}')[0]
216         try:
217             try:
218                 conf.check(features='cc testd', fragment='int main() {return 0;}\n', ccflags=['-MD'], mandatory=True, msg='Check for -MD')
219             except:
220                 pass
221             else:
222                 conf.check_tool('gccdeps', tooldir=conf.srcdir + "/buildtools/wafsamba")
223         finally:
224             cc.run = oldmeth
225
226     # make the install paths available in environment
227     conf.env.LIBDIR = Options.options.LIBDIR or '${PREFIX}/lib'
228     conf.env.BINDIR = Options.options.BINDIR or '${PREFIX}/bin'
229     conf.env.SBINDIR = Options.options.SBINDIR or '${PREFIX}/sbin'
230     conf.env.MODULESDIR = Options.options.MODULESDIR
231     conf.env.PRIVATELIBDIR = Options.options.PRIVATELIBDIR
232     conf.env.BUNDLED_LIBS = Options.options.BUNDLED_LIBS.split(',')
233     conf.env.BUILTIN_LIBRARIES = Options.options.BUILTIN_LIBRARIES.split(',')
234     conf.env.DISABLE_SHARED = Options.options.disable_shared
235     conf.env.NONSHARED_BINARIES = Options.options.NONSHARED_BINARIES.split(',')
236
237     conf.env.PRIVATE_EXTENSION = Options.options.PRIVATE_EXTENSION
238     conf.env.PRIVATE_EXTENSION_EXCEPTION = Options.options.PRIVATE_EXTENSION_EXCEPTION.split(',')
239
240     conf.env.CROSS_COMPILE = Options.options.CROSS_COMPILE
241     conf.env.CROSS_EXECUTE = Options.options.CROSS_EXECUTE
242     conf.env.CROSS_ANSWERS = Options.options.CROSS_ANSWERS
243     conf.env.HOSTCC        = Options.options.HOSTCC
244
245     conf.env.AUTOCONF_BUILD = Options.options.AUTOCONF_BUILD
246     conf.env.AUTOCONF_HOST  = Options.options.AUTOCONF_HOST
247     conf.env.AUTOCONF_PROGRAM_PREFIX = Options.options.AUTOCONF_PROGRAM_PREFIX
248
249     if (conf.env.AUTOCONF_HOST and
250         conf.env.AUTOCONF_BUILD and
251         conf.env.AUTOCONF_BUILD != conf.env.AUTOCONF_HOST):
252         Logs.error('ERROR: Mismatch between --build and --host. Please use --cross-compile instead')
253         sys.exit(1)
254     if conf.env.AUTOCONF_PROGRAM_PREFIX:
255         Logs.error('ERROR: --program-prefix not supported')
256         sys.exit(1)
257
258     # enable ABI checking for developers
259     conf.env.ABI_CHECK = Options.options.ABI_CHECK or Options.options.developer
260     if Options.options.ABI_CHECK_DISABLE:
261         conf.env.ABI_CHECK = False
262     try:
263         conf.find_program('gdb', mandatory=True)
264     except:
265         conf.env.ABI_CHECK = False
266
267     conf.env.GIT_LOCAL_CHANGES = Options.options.GIT_LOCAL_CHANGES
268
269     conf.CHECK_COMMAND(['uname', '-a'],
270                        msg='Checking build system',
271                        define='BUILD_SYSTEM',
272                        on_target=False)
273     conf.CHECK_UNAME()
274
275     # see if we can compile and run a simple C program
276     conf.CHECK_CODE('printf("hello world")',
277                     define='HAVE_SIMPLE_C_PROG',
278                     mandatory=True,
279                     execute=True,
280                     headers='stdio.h',
281                     msg='Checking simple C program')
282
283     # see if we can build shared libs
284     if not conf.CHECK_LIBRARY_SUPPORT():
285         conf.env.DISABLE_SHARED = True
286
287     # check for rpath
288     if not conf.env.DISABLE_SHARED and conf.CHECK_LIBRARY_SUPPORT(rpath=True):
289         support_rpath = True
290         conf.env.RPATH_ON_BUILD   = not Options.options.disable_rpath_build
291         conf.env.RPATH_ON_INSTALL = (conf.env.RPATH_ON_BUILD and
292                                      not Options.options.disable_rpath_install)
293         if not conf.env.PRIVATELIBDIR:
294             conf.env.PRIVATELIBDIR = '%s/%s' % (conf.env.LIBDIR, Utils.g_module.APPNAME)
295         conf.env.RPATH_ON_INSTALL_PRIVATE = (
296             not Options.options.disable_rpath_private_install)
297     else:
298         support_rpath = False
299         conf.env.RPATH_ON_INSTALL = False
300         conf.env.RPATH_ON_BUILD   = False
301         conf.env.RPATH_ON_INSTALL_PRIVATE = False
302         if not conf.env.PRIVATELIBDIR:
303             # rpath is not possible so there is no sense in having a
304             # private library directory by default.
305             # the user can of course always override it.
306             conf.env.PRIVATELIBDIR = conf.env.LIBDIR
307
308     if (not conf.env.DISABLE_SHARED and
309         not Options.options.disable_symbol_versions and
310         conf.CHECK_LIBRARY_SUPPORT(rpath=support_rpath,
311                                    version_script=True,
312                                    msg='-Wl,--version-script support')):
313         conf.env.HAVE_LD_VERSION_SCRIPT = True
314     else:
315         conf.env.HAVE_LD_VERSION_SCRIPT = False
316
317     if sys.platform == "aix5":
318         conf.DEFINE('_ALL_SOURCE', 1, add_to_cflags=True)
319         # Might not be needed if ALL_SOURCE is defined
320         # conf.DEFINE('_XOPEN_SOURCE', 600, add_to_cflags=True)
321
322     # we should use the PIC options in waf instead
323     # Some compilo didn't support -fPIC but just print a warning
324     if conf.env['COMPILER_CC'] == "suncc":
325         conf.ADD_CFLAGS('-KPIC', testflags=True)
326         # we really want define here as we need to have this
327         # define even during the tests otherwise detection of
328         # boolean is broken
329         conf.DEFINE('_STDC_C99', 1, add_to_cflags=True)
330         conf.DEFINE('_XPG6', 1, add_to_cflags=True)
331     else:
332         conf.ADD_CFLAGS('-fPIC', testflags=True)
333
334     # On Solaris 8 with suncc (at least) the flags for the linker to define the name of the
335     # library are not always working (if the command line is very very long and with a lot
336     # files)
337
338     if conf.env['COMPILER_CC'] == "suncc":
339         save = conf.env['SONAME_ST']
340         conf.env['SONAME_ST'] = '-Wl,-h,%s'
341         if not conf.CHECK_SHLIB_INTRASINC_NAME_FLAGS("Checking if flags %s are ok" % conf.env['SONAME_ST']):
342             conf.env['SONAME_ST'] = save
343
344     conf.CHECK_INLINE()
345
346     # check for pkgconfig
347     conf.check_cfg(atleast_pkgconfig_version='0.0.0')
348
349     conf.DEFINE('_GNU_SOURCE', 1, add_to_cflags=True)
350     conf.DEFINE('_XOPEN_SOURCE_EXTENDED', 1, add_to_cflags=True)
351
352     # get the base headers we'll use for the rest of the tests
353     conf.CHECK_HEADERS('stdio.h sys/types.h sys/stat.h stdlib.h stddef.h memory.h string.h',
354                        add_headers=True)
355     conf.CHECK_HEADERS('strings.h inttypes.h stdint.h unistd.h minix/config.h', add_headers=True)
356     conf.CHECK_HEADERS('ctype.h', add_headers=True)
357
358     if sys.platform != 'darwin':
359         conf.CHECK_HEADERS('standards.h', add_headers=True)
360
361     conf.CHECK_HEADERS('stdbool.h stdint.h stdarg.h vararg.h', add_headers=True)
362     conf.CHECK_HEADERS('limits.h assert.h')
363
364     # see if we need special largefile flags
365     conf.CHECK_LARGEFILE()
366
367     if 'HAVE_STDDEF_H' in conf.env and 'HAVE_STDLIB_H' in conf.env:
368         conf.DEFINE('STDC_HEADERS', 1)
369
370     conf.CHECK_HEADERS('sys/time.h time.h', together=True)
371
372     if 'HAVE_SYS_TIME_H' in conf.env and 'HAVE_TIME_H' in conf.env:
373         conf.DEFINE('TIME_WITH_SYS_TIME', 1)
374
375     # cope with different extensions for libraries
376     (root, ext) = os.path.splitext(conf.env.shlib_PATTERN)
377     if ext[0] == '.':
378         conf.define('SHLIBEXT', ext[1:], quote=True)
379     else:
380         conf.define('SHLIBEXT', "so", quote=True)
381
382     conf.CHECK_CODE('long one = 1; return ((char *)(&one))[0]',
383                     execute=True,
384                     define='WORDS_BIGENDIAN')
385
386     # check if signal() takes a void function
387     if conf.CHECK_CODE('return *(signal (0, 0)) (0) == 1',
388                        define='RETSIGTYPE_INT',
389                        execute=False,
390                        headers='signal.h',
391                        msg='Checking if signal handlers return int'):
392         conf.DEFINE('RETSIGTYPE', 'int')
393     else:
394         conf.DEFINE('RETSIGTYPE', 'void')
395
396     conf.CHECK_VARIABLE('__FUNCTION__', define='HAVE_FUNCTION_MACRO')
397
398     conf.CHECK_CODE('va_list ap1,ap2; va_copy(ap1,ap2)',
399                     define="HAVE_VA_COPY",
400                     msg="Checking for va_copy")
401
402     conf.CHECK_CODE('''
403                     #define eprintf(...) fprintf(stderr, __VA_ARGS__)
404                     eprintf("bla", "bar")
405                     ''', define='HAVE__VA_ARGS__MACRO')
406
407     conf.SAMBA_BUILD_ENV()
408
409
410 def build(bld):
411     # give a more useful message if the source directory has moved
412     relpath = os_path_relpath(bld.curdir, bld.srcnode.abspath())
413     if relpath.find('../') != -1:
414         Logs.error('bld.curdir %s is not a child of %s' % (bld.curdir, bld.srcnode.abspath()))
415         raise Utils.WafError('''The top source directory has moved. Please run distclean and reconfigure''')
416
417     bld.CHECK_MAKEFLAGS()
418     bld.SETUP_BUILD_GROUPS()
419     bld.ENFORCE_GROUP_ORDERING()
420     bld.CHECK_PROJECT_RULES()