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 # magic rpath handling
61 # we want a different rpath when installing and when building
62 # Note that this should really check if rpath is available on this platform
63 # and it should also honor an --enable-rpath option
66 if Options.is_install:
67 bld.env['RPATH'] = ['-Wl,-rpath=' + bld.env.PREFIX + '/lib']
69 bld.env.append_value('RPATH', '-Wl,-rpath=build/default')
70 Build.BuildContext.set_rpath = set_rpath
73 ################################################################
74 # create a list of files by pre-pending each with a subdir name
75 def SUBDIR(bld, subdir, list):
77 for l in list.split():
78 ret = ret + subdir + '/' + l + ' '
80 Build.BuildContext.SUBDIR = SUBDIR
82 ################################################################
83 # this will contain the set of includes needed per Samba library
84 Build.BuildContext.SAMBA_LIBRARY_INCLUDES = {}
86 ################################################################
87 # this will contain the library dependencies of each Samba library
88 Build.BuildContext.SAMBA_LIBRARY_DEPS = {}
90 #################################################################
91 # return a include list for a set of library dependencies
92 def SAMBA_LIBRARY_INCLUDE_LIST(bld, libdeps):
93 ret = bld.curdir + ' '
94 for l in libdeps.split():
95 if l in bld.SAMBA_LIBRARY_INCLUDES:
96 ret = ret + bld.SAMBA_LIBRARY_INCLUDES[l] + ' '
98 Build.BuildContext.SAMBA_LIBRARY_INCLUDE_LIST = SAMBA_LIBRARY_INCLUDE_LIST
101 #################################################################
102 # define a Samba library
103 def SAMBA_LIBRARY(bld, libname, source_list,
104 libdeps='', include_list='.', vnum=None):
105 ilist = bld.SAMBA_LIBRARY_INCLUDE_LIST(libdeps) + bld.SUBDIR(bld.curdir, include_list)
107 features = 'cc cshlib',
108 source = source_list,
110 includes='. ' + ilist,
112 bld.SAMBA_LIBRARY_INCLUDES[libname] = ilist
113 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
115 #################################################################
116 # define a Samba binary
117 def SAMBA_BINARY(bld, binname, source_list, libdeps='', include_list=''):
119 features = 'cc cprogram',
120 source = source_list,
122 uselib_local = libdeps,
123 includes = '. ' + bld.SAMBA_LIBRARY_INCLUDE_LIST(libdeps) + include_list)
124 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
126 ############################################################
127 # this overrides the 'waf -v' debug output to be in a nice
128 # unix like format instead of a python list.
129 # Thanks to ita on #waf for this
130 def exec_command(self, cmd, **kw):
133 if isinstance(cmd, list):
135 Logs.debug('runner: %s' % _cmd)
137 self.log.write('%s\n' % cmd)
140 if not kw.get('cwd', None):
142 except AttributeError:
143 self.cwd = kw['cwd'] = self.bldnode.abspath()
144 return Utils.exec_command(cmd, **kw)
145 Build.BuildContext.exec_command = exec_command
148 ######################################################
149 # this is used as a decorator to make functions only
150 # run once. Based on the idea from
151 # http://stackoverflow.com/questions/815110/is-there-a-decorator-to-simply-cache-function-return-values
153 def runonce(function):
155 if args in runonce_ret:
156 return runonce_ret[args]
158 ret = function(*args)
159 runonce_ret[args] = ret