build: add_headers flag to CHECK_HEADER()
[samba.git] / buildtools / wafsamba / samba_autoconf.py
1 # a waf tool to add autoconf-like macros to the configure section
2
3 import Build, os, Logs, sys, Configure, Options
4 import string, Task, Utils, optparse
5 from Configure import conf
6 from Logs import debug
7 from TaskGen import extension
8 from samba_utils import *
9
10 ####################################################
11 # some autoconf like helpers, to make the transition
12 # to waf a bit easier for those used to autoconf
13 # m4 files
14 @runonce
15 @conf
16 def DEFINE(conf, d, v):
17     conf.define(d, v, quote=False)
18     conf.env.append_value('CCDEFINES', d + '=' + str(v))
19
20 @runonce
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)
24
25 @conf
26 def CHECK_HEADERS(conf, list, add_headers=True):
27     for hdr in list.split():
28         CHECK_HEADER(conf, hdr, add_header)
29
30 @conf
31 def CHECK_TYPES(conf, list):
32     for t in list.split():
33         conf.check(type_name=t, header_name=conf.env.hlist)
34
35 @conf
36 def CHECK_TYPE_IN(conf, t, hdr):
37     if conf.check(header_name=hdr):
38         conf.check(type_name=t, header_name=hdr)
39
40 @conf
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)
44
45 @conf
46 def CHECK_VARIABLE(conf, v, define=None, always=False):
47     hdrs=''
48     for h in conf.env.hlist:
49         hdrs += '#include <%s>\n' % h
50     if define is None:
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),
54                   execute=0,
55                   msg="Checking for variable %s" % v):
56         conf.DEFINE(define, 1)
57     elif always:
58         conf.DEFINE(define, 0)
59
60
61 @runonce
62 def CHECK_FUNC(conf, f):
63     conf.check(function_name=f, header_name=conf.env.hlist)
64
65
66 @conf
67 def CHECK_FUNCS(conf, list):
68     for f in list.split():
69         CHECK_FUNC(conf, f)
70
71
72 #################################################
73 # return True if a configuration option was found
74 @conf
75 def CONFIG_SET(conf, option):
76     return (option in conf.env) and (conf.env[option] != ())
77 Build.BuildContext.CONFIG_SET = CONFIG_SET
78
79
80 ###########################################################
81 # check that the functions in 'list' are available in 'library'
82 # if they are, then make that library available as a dependency
83 #
84 # if the library is not available and mandatory==True, then
85 # raise an error.
86 #
87 # If the library is not available and mandatory==False, then
88 # add the library to the list of dependencies to remove from
89 # build rules
90 @conf
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)
97         return
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')
102
103
104 #################################################
105 # write out config.h in the right directory
106 @conf
107 def SAMBA_CONFIG_H(conf, path=None):
108     if os.path.normpath(conf.curdir) != os.path.normpath(os.environ.get('PWD')):
109         return
110     if path is None:
111         conf.write_config_header('config.h', top=True)
112     else:
113         conf.write_config_header(path)
114
115
116 ##############################################################
117 # setup a configurable path
118 @conf
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)
123
124 ##############################################################
125 # add some CFLAGS to the command line
126 @conf
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())
131
132 ##############################################################
133 # add some extra include directories to all builds
134 @conf
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())
139
140
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:
145         list = []
146     else:
147         list = bld.env['EXTRA_CFLAGS'];
148     ret = cflags.split()
149     ret.extend(list)
150     return ret