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 list.split():
31 if not CHECK_HEADER(conf, hdr, add_headers):
36 def CHECK_TYPES(conf, list):
38 for t in list.split():
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 = headers.split()
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 vars.split():
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 list.split():
113 if not CHECK_FUNC(conf, f):
118 #################################################
119 # return True if a configuration option was found
121 def CONFIG_SET(conf, option):
122 return (option in conf.env) and (conf.env[option] != ())
123 Build.BuildContext.CONFIG_SET = CONFIG_SET
126 ###########################################################
127 # check that the functions in 'list' are available in 'library'
128 # if they are, then make that library available as a dependency
130 # if the library is not available and mandatory==True, then
133 # If the library is not available and mandatory==False, then
134 # add the library to the list of dependencies to remove from
137 # optionally check for the functions first in libc
139 def CHECK_FUNCS_IN(conf, list, library, mandatory=False, checklibc=False):
140 # first see if the functions are in libc
143 for f in list.split():
144 if not CHECK_FUNC(conf, f):
147 remaining = list.split()
150 LOCAL_CACHE_SET(conf, 'EMPTY_TARGETS', library.upper(), True)
153 if not conf.check(lib=library, uselib_store=library):
154 conf.ASSERT(not mandatory,
155 "Mandatory library '%s' not found for functions '%s'" % (library, list))
156 # if it isn't a mandatory library, then remove it from dependency lists
157 LOCAL_CACHE_SET(conf, 'EMPTY_TARGETS', library.upper(), True)
162 if not conf.check(function_name=f, lib=library, header_name=conf.env.hlist):
164 conf.env['LIB_' + library.upper()] = library
165 LOCAL_CACHE_SET(conf, 'TARGET_TYPE', library, 'SYSLIB')
169 #################################################
170 # write out config.h in the right directory
172 def SAMBA_CONFIG_H(conf, path=None):
173 if os.path.normpath(conf.curdir) != os.path.normpath(os.environ.get('PWD')):
176 conf.write_config_header('config.h', top=True)
178 conf.write_config_header(path)
181 ##############################################################
182 # setup a configurable path
184 def CONFIG_PATH(conf, name, default):
185 if not name in conf.env:
186 conf.env[name] = conf.env['PREFIX'] + default
187 conf.define(name, conf.env[name], quote=True)
189 ##############################################################
190 # add some CFLAGS to the command line
192 def ADD_CFLAGS(conf, flags):
193 if not 'EXTRA_CFLAGS' in conf.env:
194 conf.env['EXTRA_CFLAGS'] = []
195 conf.env['EXTRA_CFLAGS'].extend(flags.split())
197 ##############################################################
198 # add some extra include directories to all builds
200 def ADD_EXTRA_INCLUDES(conf, includes):
201 if not 'EXTRA_INCLUDES' in conf.env:
202 conf.env['EXTRA_INCLUDES'] = []
203 conf.env['EXTRA_INCLUDES'].extend(includes.split())
206 ##############################################################
207 # work out the current flags. local flags are added first
208 def CURRENT_CFLAGS(bld, cflags):
209 if not 'EXTRA_CFLAGS' in bld.env:
212 list = bld.env['EXTRA_CFLAGS'];