1 # a waf tool to add autoconf-like macros to the configure section
2 # and for SAMBA_ macros for building libraries, binaries etc
5 from Configure import conf
8 ####################################################
9 # some autoconf like helpers, to make the transition
10 # to waf a bit easier for those used to autoconf
13 def DEFUN(conf, d, v):
14 conf.define(d, v, quote=False)
15 conf.env.append_value('CCDEFINES', d + '=' + str(v))
18 def CHECK_HEADERS(conf, list):
19 for hdr in list.split():
20 if conf.check(header_name=hdr):
21 conf.env.hlist.append(hdr)
24 def CHECK_TYPES(conf, list):
25 for t in list.split():
26 conf.check(type_name=t, header_name=conf.env.hlist)
29 def CHECK_TYPE_IN(conf, t, hdr):
30 if conf.check(header_name=hdr):
31 conf.check(type_name=t, header_name=hdr)
34 def CHECK_TYPE(conf, t, alternate):
35 if not conf.check(type_name=t, header_name=conf.env.hlist):
36 conf.DEFUN(t, alternate)
39 def CHECK_FUNCS(conf, list):
40 for f in list.split():
41 conf.check(function_name=f, header_name=conf.env.hlist)
44 def CHECK_FUNCS_IN(conf, list, library):
45 if conf.check(lib=library, uselib_store=library):
46 for f in list.split():
47 conf.check(function_name=f, lib=library, header_name=conf.env.hlist)
49 #################################################
50 # write out config.h in the right directory
52 def SAMBA_CONFIG_H(conf):
54 if os.path.normpath(conf.curdir) == os.path.normpath(conf.srcdir):
55 conf.write_config_header('config.h')
58 ##############################################################
59 # setup a configurable path
61 def CONFIG_PATH(conf, name, default):
62 if not name in conf.env:
63 conf.env[name] = conf.env['PREFIX'] + default
64 conf.define(name, conf.env[name], quote=True)
67 ################################################################
68 # magic rpath handling
70 # we want a different rpath when installing and when building
71 # Note that this should really check if rpath is available on this platform
72 # and it should also honor an --enable-rpath option
75 if Options.is_install:
76 bld.env['RPATH'] = ['-Wl,-rpath=' + bld.env.PREFIX + '/lib']
78 bld.env.append_value('RPATH', '-Wl,-rpath=build/default')
79 Build.BuildContext.set_rpath = set_rpath
82 ################################################################
83 # create a list of files by pre-pending each with a subdir name
84 def SUBDIR(bld, subdir, list):
86 for l in list.split():
87 ret = ret + subdir + '/' + l + ' '
89 Build.BuildContext.SUBDIR = SUBDIR
92 ################################################################
93 # this will contain the set of includes needed per Samba library
94 Build.BuildContext.SAMBA_LIBRARY_INCLUDES = {}
96 ################################################################
97 # this will contain the library dependencies of each Samba library
98 Build.BuildContext.SAMBA_LIBRARY_DEPS = {}
100 #################################################################
101 # return a include list for a set of library dependencies
102 def SAMBA_LIBRARY_INCLUDE_LIST(bld, libdeps):
103 ret = bld.curdir + ' '
104 for l in libdeps.split():
105 if l in bld.SAMBA_LIBRARY_INCLUDES:
106 ret = ret + bld.SAMBA_LIBRARY_INCLUDES[l] + ' '
108 Build.BuildContext.SAMBA_LIBRARY_INCLUDE_LIST = SAMBA_LIBRARY_INCLUDE_LIST
110 #################################################################
111 # return a library list for a set of library dependencies
112 def SAMBA_LIBRARY_LIB_LIST(bld, libdeps):
114 for l in libdeps.split():
115 if l in bld.SAMBA_LIBRARY_DEPS:
116 ret = ret + l + ' ' + bld.SAMBA_LIBRARY_LIB_LIST(bld.SAMBA_LIBRARY_DEPS[l])
118 Build.BuildContext.SAMBA_LIBRARY_LIB_LIST = SAMBA_LIBRARY_LIB_LIST
121 #################################################################
122 # define a Samba library
123 def SAMBA_LIBRARY(bld, libname, source_list,
124 libdeps='', include_list='.', vnum=None):
125 ilist = bld.SAMBA_LIBRARY_INCLUDE_LIST(libdeps) + bld.SUBDIR(bld.curdir, include_list)
127 features = 'cc cshlib',
128 source = source_list,
130 includes='. ' + ilist,
132 bld.SAMBA_LIBRARY_INCLUDES[libname] = ilist
133 bld.SAMBA_LIBRARY_DEPS[libname] = libdeps
134 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
136 #################################################################
137 # define a Samba binary
138 def SAMBA_BINARY(bld, binname, source_list, libdeps='', include_list=''):
140 features = 'cc cprogram',
141 source = source_list,
143 uselib_local = bld.SAMBA_LIBRARY_LIB_LIST(libdeps),
144 includes = '. ' + bld.SAMBA_LIBRARY_INCLUDE_LIST(libdeps) + include_list)
145 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
147 ############################################################
148 # this overrides the 'waf -v' debug output to be in a nice
149 # unix like format instead of a python list.
150 # Thanks to ita on #waf for this
151 def exec_command(self, cmd, **kw):
154 if isinstance(cmd, list):
156 Logs.debug('runner: %s' % _cmd)
158 self.log.write('%s\n' % cmd)
161 if not kw.get('cwd', None):
163 except AttributeError:
164 self.cwd = kw['cwd'] = self.bldnode.abspath()
165 return Utils.exec_command(cmd, **kw)
166 Build.BuildContext.exec_command = exec_command
169 ######################################################
170 # this is used as a decorator to make functions only
171 # run once. Based on the idea from
172 # http://stackoverflow.com/questions/815110/is-there-a-decorator-to-simply-cache-function-return-values
174 def runonce(function):
176 if args in runonce_ret:
177 return runonce_ret[args]
179 ret = function(*args)
180 runonce_ret[args] = ret