build: renamed autoconf.py to wafsamba.py and added SAMBA_*() functions
[nivanova/samba-autobuild/.git] / lib / replace / wafsamba.py
1 # a waf tool to add autoconf-like macros to the configure section
2
3 import Build
4 from Configure import conf
5
6 @conf
7 def DEFUN(conf, d, v):
8     conf.define(d, v, quote=False)
9     conf.env.append_value('CCDEFINES', d + '=' + str(v))
10
11 @conf
12 def CHECK_HEADERS(conf, list):
13     for hdr in list.rsplit(' '):
14         if conf.check(header_name=hdr):
15             conf.env.hlist.append(hdr)
16
17 @conf
18 def CHECK_TYPES(conf, list):
19     for t in list.rsplit(' '):
20         conf.check(type_name=t, header_name=conf.env.hlist)
21
22 @conf
23 def CHECK_TYPE_IN(conf, t, hdr):
24     if conf.check(header_name=hdr):
25         conf.check(type_name=t, header_name=hdr)
26
27 @conf
28 def CHECK_TYPE(conf, t, alternate):
29     if not conf.check(type_name=t, header_name=conf.env.hlist):
30         conf.DEFUN(t, alternate)
31
32 @conf
33 def CHECK_FUNCS(conf, list):
34     for f in list.rsplit(' '):
35         conf.check(function_name=f, header_name=conf.env.hlist)
36
37 @conf
38 def CHECK_FUNCS_IN(conf, list, library):
39     if conf.check(lib=library, uselib_store=library):
40         for f in list.rsplit(' '):
41             conf.check(function_name=f, lib=library, header_name=conf.env.hlist)
42
43 # we want a different rpath when installing and when building
44 # this should really check if rpath is available on this platform
45 # and it should also honor an --enable-rpath option
46 def set_rpath(bld):
47     import Options
48     if Options.is_install:
49         bld.env['RPATH'] = ['-Wl,-rpath=' + bld.env.PREFIX + '/lib']
50     else:
51         bld.env.append_value('RPATH', '-Wl,-rpath=build/default')
52 Build.BuildContext.set_rpath = set_rpath
53
54 # this will contain the set of includes needed per Samba library
55 Build.BuildContext.SAMBA_LIBRARY_INCLUDES = {}
56
57 # this will contain the library dependencies of each Samba library
58 Build.BuildContext.SAMBA_LIBRARY_DEPS = {}
59
60 #################################################################
61 # return a include list for a set of library dependencies
62 def SAMBA_LIBRARY_INCLUDE_LIST(bld, libdeps):
63     ret = bld.curdir + ' '
64     for l in libdeps.rsplit(' '):
65         if l in bld.SAMBA_LIBRARY_INCLUDES:
66             ret = ret + bld.SAMBA_LIBRARY_INCLUDES[l] + ' '
67     return ret
68 Build.BuildContext.SAMBA_LIBRARY_INCLUDE_LIST = SAMBA_LIBRARY_INCLUDE_LIST
69
70 #################################################################
71 # define a Samba library
72 def SAMBA_LIBRARY(bld, libname, source_list, libdeps='', include_list=''):
73     ilist = bld.SAMBA_LIBRARY_INCLUDE_LIST(libdeps) + include_list
74     bld(
75         features = 'cc cshlib',
76         source = source_list,
77         target=libname,
78         includes=ilist)
79     bld.SAMBA_LIBRARY_INCLUDES[libname] = ilist
80 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
81
82 #################################################################
83 # define a Samba binary
84 def SAMBA_BINARY(bld, binname, source_list, libdeps='', include_list=''):
85     bld(
86         features = 'cc cprogram',
87         source = source_list,
88         target = binname,
89         uselib_local = libdeps,
90         includes = bld.SAMBA_LIBRARY_INCLUDE_LIST(libdeps) + include_list)
91 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
92
93
94 # this overrides the normal -v debug output to be in a nice
95 # unix like format
96 def exec_command(self, cmd, **kw):
97     import Utils
98     from Logs import debug
99     _cmd = cmd
100     if isinstance(cmd, list):
101         _cmd = ' '.join(cmd)
102     debug('runner: %s' % _cmd)
103     if self.log:
104         self.log.write('%s\n' % cmd)
105         kw['log'] = self.log
106     try:
107         if not kw.get('cwd', None):
108             kw['cwd'] = self.cwd
109     except AttributeError:
110         self.cwd = kw['cwd'] = self.bldnode.abspath()
111     return Utils.exec_command(cmd, **kw)
112
113 import Build
114 Build.BuildContext.exec_command = exec_command