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