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