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):
18 '''define a config option'''
19 conf.define(d, v, quote=False)
20 conf.env.append_value('CCDEFINES', d + '=' + str(v))
23 def CHECK_HEADER(conf, h, add_headers=True):
24 '''check for a header'''
25 if conf.check(header_name=h) and add_headers:
26 conf.env.hlist.append(h)
32 def CHECK_HEADERS(conf, list, add_headers=True):
33 '''check for a list of headers'''
35 for hdr in to_list(list):
36 if not CHECK_HEADER(conf, hdr, add_headers):
42 def CHECK_TYPES(conf, list):
43 '''check for a list of types'''
45 for t in to_list(list):
46 if not conf.check(type_name=t, header_name=conf.env.hlist):
52 def CHECK_TYPE_IN(conf, t, hdr):
53 '''check for a type in a specific header'''
54 if conf.check(header_name=hdr):
55 conf.check(type_name=t, header_name=hdr)
61 def CHECK_TYPE(conf, t, alternate=None, headers=None, define=None):
62 '''check for a type with an alternate'''
64 headers = conf.env.hlist
65 if define is not None:
66 ret = conf.check(type_name=t, header_name=headers, define_name=define)
68 ret = conf.check(type_name=t, header_name=headers)
69 if not ret and alternate is not None:
70 conf.DEFINE(t, alternate)
75 def CHECK_VARIABLE(conf, v, define=None, always=False, headers=None):
76 '''check for a variable declaration (or define)'''
78 if headers is not None:
79 hlist = to_list(headers)
81 hlist = conf.env.hlist
83 hdrs += '#include <%s>\n' % h
85 define = 'HAVE_%s' % v.upper()
86 if conf.check(fragment=
91 void *_x; _x=(void *)&%s;
97 msg="Checking for variable %s" % v):
98 conf.DEFINE(define, 1)
101 conf.DEFINE(define, 0)
105 def CHECK_DECLS(conf, vars, reverse=False, headers=None):
106 '''check a list of variable declarations, using the HAVE_DECL_xxx form
109 When reverse==True then use HAVE_xxx_DECL instead of HAVE_DECL_xxx
112 for v in to_list(vars):
114 define='HAVE_DECL_%s' % v.upper()
116 define='HAVE_%s_DECL' % v.upper()
117 if not CHECK_VARIABLE(conf, v, define=define, headers=headers):
123 def CHECK_FUNC(conf, f):
124 '''check for a function'''
125 return conf.check(function_name=f, header_name=conf.env.hlist)
129 def CHECK_FUNCS(conf, list):
130 '''check for a list of functions'''
132 for f in to_list(list):
133 if not CHECK_FUNC(conf, f):
139 def CHECK_SIZEOF(conf, vars, headers=None, define=None):
140 '''check the size of a type'''
142 if headers is not None:
143 hlist = to_list(headers)
145 hlist = conf.env.hlist
147 hdrs += '#include <%s>\n' % h
148 for v in to_list(vars):
150 define_name = 'SIZEOF_%s' % string.replace(v.upper(), ' ', '_')
157 printf("%%u\\n", (unsigned)sizeof(%s));
163 define_name=define_name,
165 msg="Checking size of %s" % v)
169 def CHECK_STRUCTURE_MEMBER(conf, structname, member,
170 always=False, define=None, headers=None):
171 '''check for a structure member'''
173 if headers is not None:
174 hlist = to_list(headers)
176 hlist = conf.env.hlist
178 hdrs += '#include <%s>\n' % h
180 define = 'HAVE_%s' % member.upper()
181 if conf.check(fragment=
186 void *_x; _x=(void *)&s.%s;
189 ''' % (hdrs, structname, member),
191 msg="Checking for member %s in %s" % (member, structname)):
192 conf.DEFINE(define, 1)
195 conf.DEFINE(define, 0)
199 #################################################
200 # return True if a configuration option was found
202 def CONFIG_SET(conf, option):
203 return (option in conf.env) and (conf.env[option] != ())
204 Build.BuildContext.CONFIG_SET = CONFIG_SET
207 ###########################################################
208 # check that the functions in 'list' are available in 'library'
209 # if they are, then make that library available as a dependency
211 # if the library is not available and mandatory==True, then
214 # If the library is not available and mandatory==False, then
215 # add the library to the list of dependencies to remove from
218 # optionally check for the functions first in libc
220 def CHECK_FUNCS_IN(conf, list, library, mandatory=False, checklibc=False):
221 # first see if the functions are in libc
224 for f in to_list(list):
225 if not CHECK_FUNC(conf, f):
228 remaining = to_list(list)
231 LOCAL_CACHE_SET(conf, 'EMPTY_TARGETS', library.upper(), True)
234 if not conf.check(lib=library, uselib_store=library):
235 conf.ASSERT(not mandatory,
236 "Mandatory library '%s' not found for functions '%s'" % (library, list))
237 # if it isn't a mandatory library, then remove it from dependency lists
238 LOCAL_CACHE_SET(conf, 'EMPTY_TARGETS', library.upper(), True)
243 if not conf.check(function_name=f, lib=library, header_name=conf.env.hlist):
245 conf.env['LIB_' + library.upper()] = library
246 LOCAL_CACHE_SET(conf, 'TARGET_TYPE', library, 'SYSLIB')
250 #################################################
251 # write out config.h in the right directory
253 def SAMBA_CONFIG_H(conf, path=None):
254 if os.path.normpath(conf.curdir) != os.path.normpath(os.environ.get('PWD')):
257 conf.write_config_header('config.h', top=True)
259 conf.write_config_header(path)
262 ##############################################################
263 # setup a configurable path
265 def CONFIG_PATH(conf, name, default):
266 if not name in conf.env:
267 conf.env[name] = conf.env['PREFIX'] + default
268 conf.define(name, conf.env[name], quote=True)
270 ##############################################################
271 # add some CFLAGS to the command line
273 def ADD_CFLAGS(conf, flags):
274 if not 'EXTRA_CFLAGS' in conf.env:
275 conf.env['EXTRA_CFLAGS'] = []
276 conf.env['EXTRA_CFLAGS'].extend(to_list(flags))
278 ##############################################################
279 # add some extra include directories to all builds
281 def ADD_EXTRA_INCLUDES(conf, includes):
282 if not 'EXTRA_INCLUDES' in conf.env:
283 conf.env['EXTRA_INCLUDES'] = []
284 conf.env['EXTRA_INCLUDES'].extend(to_list(includes))
287 ##############################################################
288 # work out the current flags. local flags are added first
289 def CURRENT_CFLAGS(bld, cflags):
290 if not 'EXTRA_CFLAGS' in bld.env:
293 list = bld.env['EXTRA_CFLAGS'];
294 ret = to_list(cflags)