1 # a waf tool to add autoconf-like macros to the configure section
3 import Build, os, Logs, sys, Configure, Options
4 import string, Task, Utils, optparse
5 from Configure import conf
7 from TaskGen import extension
8 from samba_utils import *
10 ####################################################
11 # some autoconf like helpers, to make the transition
12 # to waf a bit easier for those used to autoconf
17 def DEFINE(conf, d, v, add_to_cflags=False):
18 '''define a config option'''
19 conf.define(d, v, quote=False)
21 conf.env.append_value('CCDEFINES', d + '=' + str(v))
24 def CHECK_HEADER(conf, h, add_headers=True):
25 '''check for a header'''
26 if conf.check(header_name=h) and add_headers:
27 conf.env.hlist.append(h)
33 def CHECK_HEADERS(conf, list, add_headers=True):
34 '''check for a list of headers'''
36 for hdr in TO_LIST(list):
37 if not CHECK_HEADER(conf, hdr, add_headers):
43 def CHECK_TYPES(conf, list):
44 '''check for a list of types'''
47 for t in TO_LIST(list):
48 if not conf.check(type_name=t, header_name=conf.env.hlist):
54 def CHECK_TYPE_IN(conf, t, hdr, define=None):
55 '''check for a type in a specific header'''
56 if conf.check(header_name=hdr):
58 ret = conf.check(type_name=t, header_name=hdr)
60 ret = conf.check(type_name=t, header_name=hdr, define_name=define)
66 def CHECK_TYPE(conf, t, alternate=None, headers=None, define=None):
67 '''check for a type with an alternate'''
69 headers = conf.env.hlist
70 if define is not None:
71 ret = conf.check(type_name=t, header_name=headers, define_name=define)
73 ret = conf.check(type_name=t, header_name=headers)
74 if not ret and alternate is not None:
75 conf.DEFINE(t, alternate)
80 def CHECK_VARIABLE(conf, v, define=None, always=False, headers=None):
81 '''check for a variable declaration (or define)'''
83 if headers is not None:
84 hlist = TO_LIST(headers)
86 hlist = conf.env.hlist
88 hdrs += '#include <%s>\n' % h
90 define = 'HAVE_%s' % v.upper()
91 if conf.check(fragment=
96 void *_x; _x=(void *)&%s;
102 msg="Checking for variable %s" % v):
103 conf.DEFINE(define, 1)
106 conf.DEFINE(define, 0)
110 def CHECK_DECLS(conf, vars, reverse=False, headers=None):
111 '''check a list of variable declarations, using the HAVE_DECL_xxx form
114 When reverse==True then use HAVE_xxx_DECL instead of HAVE_DECL_xxx
117 for v in TO_LIST(vars):
119 define='HAVE_DECL_%s' % v.upper()
121 define='HAVE_%s_DECL' % v.upper()
122 if not CHECK_VARIABLE(conf, v, define=define, headers=headers):
128 def CHECK_FUNC(conf, f, checklink=False):
129 '''check for a function'''
131 return CHECK_CODE(conf, '%s()' % f, execute=False, define='HAVE_%s' % f.upper())
132 return conf.check(function_name=f, header_name=conf.env.hlist)
136 def CHECK_FUNCS(conf, list, checklink=False):
137 '''check for a list of functions'''
139 for f in TO_LIST(list):
140 if not CHECK_FUNC(conf, f, checklink):
146 def CHECK_SIZEOF(conf, vars, headers=None, define=None):
147 '''check the size of a type'''
149 if headers is not None:
150 hlist = TO_LIST(headers)
152 hlist = conf.env.hlist
154 hdrs += '#include <%s>\n' % h
155 for v in TO_LIST(vars):
157 define_name = 'SIZEOF_%s' % string.replace(v.upper(), ' ', '_')
164 printf("%%u\\n", (unsigned)sizeof(%s));
170 define_name=define_name,
172 msg="Checking size of %s" % v)
176 def CHECK_CODE(conf, code, define,
177 always=False, execute=False, addmain=True, mandatory=False,
178 headers=None, msg=None, cflags='', includes='# . ../default',
180 '''check if some code compiles and/or runs'''
182 if headers is not None:
183 hlist = TO_LIST(headers)
185 hlist = conf.env.hlist
187 hdrs += '#include <%s>\n' % h
195 fragment='#include "__confdefs.h"\n%s\n int main(void) { %s; return 0; }' % (hdrs, code)
197 fragment='#include "__confdefs.h"\n%s\n%s' % (hdrs, code)
199 conf.write_config_header('__confdefs.h', top=True)
202 msg="Checking for %s" % define
205 cflags = cflags + ' -I%s' % conf.curdir
207 if conf.check(fragment=fragment,
209 define_name = define,
210 mandatory = mandatory,
211 ccflags=TO_LIST(cflags),
214 conf.DEFINE(define, 1)
217 conf.DEFINE(define, 0)
223 def CHECK_STRUCTURE_MEMBER(conf, structname, member,
224 always=False, define=None, headers=None):
225 '''check for a structure member'''
227 if headers is not None:
228 hlist = TO_LIST(headers)
230 hlist = conf.env.hlist
232 hdrs += '#include <%s>\n' % h
234 define = 'HAVE_%s' % member.upper()
235 if conf.check(fragment=
240 void *_x; _x=(void *)&s.%s;
243 ''' % (hdrs, structname, member),
245 msg="Checking for member %s in %s" % (member, structname)):
246 conf.DEFINE(define, 1)
249 conf.DEFINE(define, 0)
254 def CHECK_CFLAGS(conf, cflags, variable):
255 '''check if the given cflags are accepted by the compiler'''
256 if conf.check(fragment='int main(void) { return 0; }',
259 msg="Checking compiler accepts %s" % cflags):
260 conf.env[variable] = cflags
265 #################################################
266 # return True if a configuration option was found
268 def CONFIG_SET(conf, option):
269 return (option in conf.env) and (conf.env[option] != ())
270 Build.BuildContext.CONFIG_SET = CONFIG_SET
273 ###########################################################
274 # check that the functions in 'list' are available in 'library'
275 # if they are, then make that library available as a dependency
277 # if the library is not available and mandatory==True, then
280 # If the library is not available and mandatory==False, then
281 # add the library to the list of dependencies to remove from
284 # optionally check for the functions first in libc
286 def CHECK_FUNCS_IN(conf, list, library, mandatory=False, checklibc=False):
287 # first see if the functions are in libc
290 for f in TO_LIST(list):
291 if not CHECK_FUNC(conf, f):
294 remaining = TO_LIST(list)
297 SET_TARGET_TYPE(conf, library, 'EMPTY')
300 if not conf.check(lib=library, uselib_store=library):
301 conf.ASSERT(not mandatory,
302 "Mandatory library '%s' not found for functions '%s'" % (library, list))
303 # if it isn't a mandatory library, then remove it from dependency lists
304 SET_TARGET_TYPE(conf, library, 'EMPTY')
307 conf.define('HAVE_LIB%s' % string.replace(library.upper(),'-','_'), 1)
311 if not conf.check(function_name=f, lib=library, header_name=conf.env.hlist):
313 conf.env['LIB_' + library.upper()] = library
314 LOCAL_CACHE_SET(conf, 'TARGET_TYPE', library, 'SYSLIB')
318 #################################################
319 # write out config.h in the right directory
321 def SAMBA_CONFIG_H(conf, path=None):
322 if os.path.normpath(conf.curdir) != os.path.normpath(os.environ.get('PWD')):
325 conf.write_config_header('config.h', top=True)
327 conf.write_config_header(path)
330 ##############################################################
331 # setup a configurable path
333 def CONFIG_PATH(conf, name, default):
334 if not name in conf.env:
335 if default[0] == '/':
336 conf.env[name] = default
338 conf.env[name] = conf.env['PREFIX'] + default
339 conf.define(name, conf.env[name], quote=True)
341 ##############################################################
342 # add some CFLAGS to the command line
344 def ADD_CFLAGS(conf, flags):
345 if not 'EXTRA_CFLAGS' in conf.env:
346 conf.env['EXTRA_CFLAGS'] = []
347 conf.env['EXTRA_CFLAGS'].extend(TO_LIST(flags))
349 ##############################################################
350 # add some extra include directories to all builds
352 def ADD_EXTRA_INCLUDES(conf, includes):
353 if not 'EXTRA_INCLUDES' in conf.env:
354 conf.env['EXTRA_INCLUDES'] = []
355 conf.env['EXTRA_INCLUDES'].extend(TO_LIST(includes))
358 ##############################################################
359 # work out the current flags. local flags are added first
360 def CURRENT_CFLAGS(bld, target, cflags):
361 if not 'EXTRA_CFLAGS' in bld.env:
364 list = bld.env['EXTRA_CFLAGS'];
365 ret = TO_LIST(cflags)