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
16 def DEFINE(conf, d, v):
17 conf.define(d, v, quote=False)
18 conf.env.append_value('CCDEFINES', d + '=' + str(v))
21 def CHECK_HEADER(conf, h, add_headers=True):
22 if conf.check(header_name=h) and add_headers:
23 conf.env.hlist.append(h)
28 def CHECK_HEADERS(conf, list, add_headers=True):
30 for hdr in to_list(list):
31 if not CHECK_HEADER(conf, hdr, add_headers):
36 def CHECK_TYPES(conf, list):
38 for t in to_list(list):
39 if not conf.check(type_name=t, header_name=conf.env.hlist):
44 def CHECK_TYPE_IN(conf, t, hdr):
45 if conf.check(header_name=hdr):
46 conf.check(type_name=t, header_name=hdr)
51 def CHECK_TYPE(conf, t, alternate):
52 if not conf.check(type_name=t, header_name=conf.env.hlist):
53 conf.DEFINE(t, alternate)
58 def CHECK_VARIABLE(conf, v, define=None, always=False, headers=None):
60 if headers is not None:
61 hlist = to_list(headers)
63 hlist = conf.env.hlist
65 hdrs += '#include <%s>\n' % h
67 define = 'HAVE_%s' % v.upper()
68 if conf.check(fragment=
73 void *_x; _x=(void *)&%s;
79 msg="Checking for variable %s" % v):
80 conf.DEFINE(define, 1)
83 conf.DEFINE(define, 0)
87 def CHECK_DECLS(conf, vars, reverse=False, headers=None):
88 '''check a list of variable declarations, using the HAVE_DECL_xxx form
91 When reverse==True then use HAVE_xxx_DECL instead of HAVE_DECL_xxx
94 for v in to_list(vars):
96 define='HAVE_DECL_%s' % v.upper()
98 define='HAVE_%s_DECL' % v.upper()
99 if not CHECK_VARIABLE(conf, v, define=define, headers=headers):
105 def CHECK_FUNC(conf, f):
106 return conf.check(function_name=f, header_name=conf.env.hlist)
110 def CHECK_FUNCS(conf, list):
112 for f in to_list(list):
113 if not CHECK_FUNC(conf, f):
118 def CHECK_SIZEOF(conf, vars, headers=None, define=None):
120 if headers is not None:
121 hlist = to_list(headers)
123 hlist = conf.env.hlist
125 hdrs += '#include <%s>\n' % h
126 for v in to_list(vars):
128 define_name = 'SIZEOF_%s' % string.replace(v.upper(), ' ', '_')
135 printf("%%u\\n", (unsigned)sizeof(%s));
141 define_name=define_name,
143 msg="Checking size of %s" % v)
146 #################################################
147 # return True if a configuration option was found
149 def CONFIG_SET(conf, option):
150 return (option in conf.env) and (conf.env[option] != ())
151 Build.BuildContext.CONFIG_SET = CONFIG_SET
154 ###########################################################
155 # check that the functions in 'list' are available in 'library'
156 # if they are, then make that library available as a dependency
158 # if the library is not available and mandatory==True, then
161 # If the library is not available and mandatory==False, then
162 # add the library to the list of dependencies to remove from
165 # optionally check for the functions first in libc
167 def CHECK_FUNCS_IN(conf, list, library, mandatory=False, checklibc=False):
168 # first see if the functions are in libc
171 for f in to_list(list):
172 if not CHECK_FUNC(conf, f):
175 remaining = to_list(list)
178 LOCAL_CACHE_SET(conf, 'EMPTY_TARGETS', library.upper(), True)
181 if not conf.check(lib=library, uselib_store=library):
182 conf.ASSERT(not mandatory,
183 "Mandatory library '%s' not found for functions '%s'" % (library, list))
184 # if it isn't a mandatory library, then remove it from dependency lists
185 LOCAL_CACHE_SET(conf, 'EMPTY_TARGETS', library.upper(), True)
190 if not conf.check(function_name=f, lib=library, header_name=conf.env.hlist):
192 conf.env['LIB_' + library.upper()] = library
193 LOCAL_CACHE_SET(conf, 'TARGET_TYPE', library, 'SYSLIB')
197 #################################################
198 # write out config.h in the right directory
200 def SAMBA_CONFIG_H(conf, path=None):
201 if os.path.normpath(conf.curdir) != os.path.normpath(os.environ.get('PWD')):
204 conf.write_config_header('config.h', top=True)
206 conf.write_config_header(path)
209 ##############################################################
210 # setup a configurable path
212 def CONFIG_PATH(conf, name, default):
213 if not name in conf.env:
214 conf.env[name] = conf.env['PREFIX'] + default
215 conf.define(name, conf.env[name], quote=True)
217 ##############################################################
218 # add some CFLAGS to the command line
220 def ADD_CFLAGS(conf, flags):
221 if not 'EXTRA_CFLAGS' in conf.env:
222 conf.env['EXTRA_CFLAGS'] = []
223 conf.env['EXTRA_CFLAGS'].extend(to_list(flags))
225 ##############################################################
226 # add some extra include directories to all builds
228 def ADD_EXTRA_INCLUDES(conf, includes):
229 if not 'EXTRA_INCLUDES' in conf.env:
230 conf.env['EXTRA_INCLUDES'] = []
231 conf.env['EXTRA_INCLUDES'].extend(to_list(includes))
234 ##############################################################
235 # work out the current flags. local flags are added first
236 def CURRENT_CFLAGS(bld, cflags):
237 if not 'EXTRA_CFLAGS' in bld.env:
240 list = bld.env['EXTRA_CFLAGS'];
241 ret = to_list(cflags)