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)
26 def CHECK_HEADERS(conf, list, add_headers=True):
27 for hdr in list.split():
28 CHECK_HEADER(conf, hdr, add_header)
31 def CHECK_TYPES(conf, list):
32 for t in list.split():
33 conf.check(type_name=t, header_name=conf.env.hlist)
36 def CHECK_TYPE_IN(conf, t, hdr):
37 if conf.check(header_name=hdr):
38 conf.check(type_name=t, header_name=hdr)
41 def CHECK_TYPE(conf, t, alternate):
42 if not conf.check(type_name=t, header_name=conf.env.hlist):
43 conf.DEFINE(t, alternate)
46 def CHECK_VARIABLE(conf, v, define=None, always=False):
48 for h in conf.env.hlist:
49 hdrs += '#include <%s>\n' % h
51 define = 'HAVE_%s' % v.upper()
52 if conf.check(fragment=
53 '%s\nint main(void) {void *_x; _x=(void *)&%s; return 0;}\n' % (hdrs, v),
55 msg="Checking for variable %s" % v):
56 conf.DEFINE(define, 1)
58 conf.DEFINE(define, 0)
62 def CHECK_FUNC(conf, f):
63 conf.check(function_name=f, header_name=conf.env.hlist)
67 def CHECK_FUNCS(conf, list):
68 for f in list.split():
72 #################################################
73 # return True if a configuration option was found
75 def CONFIG_SET(conf, option):
76 return (option in conf.env) and (conf.env[option] != ())
77 Build.BuildContext.CONFIG_SET = CONFIG_SET
80 ###########################################################
81 # check that the functions in 'list' are available in 'library'
82 # if they are, then make that library available as a dependency
84 # if the library is not available and mandatory==True, then
87 # If the library is not available and mandatory==False, then
88 # add the library to the list of dependencies to remove from
91 def CHECK_FUNCS_IN(conf, list, library, mandatory=False):
92 if not conf.check(lib=library, uselib_store=library):
93 conf.ASSERT(not mandatory,
94 "Mandatory library '%s' not found for functions '%s'" % (library, list))
95 # if it isn't a mandatory library, then remove it from dependency lists
96 LOCAL_CACHE_SET(conf, 'EMPTY_TARGETS', library.upper(), True)
98 for f in list.split():
99 conf.check(function_name=f, lib=library, header_name=conf.env.hlist)
100 conf.env['LIB_' + library.upper()] = library
101 LOCAL_CACHE_SET(conf, 'TARGET_TYPE', library, 'SYSLIB')
104 #################################################
105 # write out config.h in the right directory
107 def SAMBA_CONFIG_H(conf, path=None):
108 if os.path.normpath(conf.curdir) != os.path.normpath(os.environ.get('PWD')):
111 conf.write_config_header('config.h', top=True)
113 conf.write_config_header(path)
116 ##############################################################
117 # setup a configurable path
119 def CONFIG_PATH(conf, name, default):
120 if not name in conf.env:
121 conf.env[name] = conf.env['PREFIX'] + default
122 conf.define(name, conf.env[name], quote=True)
124 ##############################################################
125 # add some CFLAGS to the command line
127 def ADD_CFLAGS(conf, flags):
128 if not 'EXTRA_CFLAGS' in conf.env:
129 conf.env['EXTRA_CFLAGS'] = []
130 conf.env['EXTRA_CFLAGS'].extend(flags.split())
132 ##############################################################
133 # add some extra include directories to all builds
135 def ADD_EXTRA_INCLUDES(conf, includes):
136 if not 'EXTRA_INCLUDES' in conf.env:
137 conf.env['EXTRA_INCLUDES'] = []
138 conf.env['EXTRA_INCLUDES'].extend(includes.split())
141 ##############################################################
142 # work out the current flags. local flags are added first
143 def CURRENT_CFLAGS(bld, cflags):
144 if not 'EXTRA_CFLAGS' in bld.env:
147 list = bld.env['EXTRA_CFLAGS'];