build: an optimisation for includes file handling
[nivanova/samba-autobuild/.git] / source4 / wscript
1 #! /usr/bin/env python
2
3 srcdir = '..'
4 blddir = 'bin'
5
6 import sys
7 sys.path.insert(0, srcdir+"/buildtools/wafsamba")
8 import wafsamba, Options
9
10 def set_options(opt):
11     opt.recurse('../lib/replace')
12     opt.recurse('dynconfig')
13     opt.recurse('scripting/python')
14     opt.recurse('lib/ldb')
15     opt.recurse('selftest')
16     opt.recurse('lib/tls')
17     opt.recurse('../lib/nss_wrapper')
18     opt.recurse('../lib/socket_wrapper')
19     opt.recurse('../lib/uid_wrapper')
20
21 def configure(conf):
22     conf.define('PACKAGE_NAME', 'samba')
23     conf.define('PACKAGE_STRING', 'samba 4')
24     conf.define('PACKAGE_TARNAME',  'samba')
25     conf.define('PACKAGE_URL', "")
26     conf.define('PACKAGE_VERSION', "4")
27     conf.define('PACKAGE_BUGREPORT', 'samba-technical@samba.org')
28
29     conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
30     conf.DEFINE('_SAMBA_BUILD_', 4, add_to_cflags=True)
31     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
32     if Options.options.developer:
33         conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
34
35     # set a lower limit on recursing in waf preprocessor
36     conf.env.preprocessor_recursion_limit = 10
37
38     conf.ADD_EXTRA_INCLUDES('#source4 #lib #source4/lib #source4/include #lib/replace #lib/talloc #lib/tevent')
39
40     conf.sub_config('../lib/replace')
41
42     conf.find_program('python', var='PYTHON', mandatory=True)
43     conf.find_program('perl', var='PERL', mandatory=True)
44
45     # enable tool to build python extensions
46     conf.check_tool('python')
47     conf.check_python_version((2,4,2))
48     conf.check_python_headers()
49
50     conf.sub_config('dynconfig')
51     conf.sub_config('scripting/python')
52     conf.sub_config('lib/ldb')
53     conf.sub_config('heimdal_build')
54     conf.sub_config('lib/tls')
55     conf.sub_config('ntvfs/sysdep')
56     conf.sub_config('../lib/util')
57     conf.sub_config('../lib/zlib')
58     conf.sub_config('../lib/util/charset')
59     conf.sub_config('auth')
60     conf.sub_config('../lib/nss_wrapper')
61     conf.sub_config('../lib/socket_wrapper')
62     conf.sub_config('../lib/uid_wrapper')
63     conf.sub_config('lib/smbreadline')
64
65     conf.SAMBA_CONFIG_H('include/config.h')
66
67
68
69 from TaskGen import feature, before, after
70
71 kak = {}
72 @feature('cc', 'cxx')
73 @after('apply_type_vars', 'apply_lib_vars', 'apply_core')
74 def apply_incpaths(self):
75     """used by the scanner
76     after processing the uselib for CPPPATH
77     after apply_core because some processing may add include paths
78     """
79     lst = []
80     # TODO move the uselib processing out of here
81     for lib in self.to_list(self.uselib):
82         for path in self.env['CPPPATH_' + lib]:
83             if not path in lst:
84                 lst.append(path)
85     if preproc.go_absolute:
86         for path in preproc.standard_includes:
87             if not path in lst:
88                 lst.append(path)
89
90     for path in self.to_list(self.includes):
91         if not path in lst:
92             if preproc.go_absolute or not os.path.isabs(path):
93                 lst.append(path)
94             else:
95                 self.env.prepend_value('CPPPATH', path)
96
97     for path in lst:
98         try:
99             #print len(kak.items())
100             node = kak[(self.path.id, path)]
101         except KeyError:
102
103             node = None
104             if os.path.isabs(path):
105                 if preproc.go_absolute:
106                     node = self.bld.root.find_dir(path)
107             elif path[0] == '#':
108                 node = self.bld.srcnode
109                 if len(path) > 1:
110                     node = node.find_dir(path[1:])
111             else:
112                 node = self.path.find_dir(path)
113
114             kak[(self.path.id, path)] = node
115         if node:
116             self.env.append_value('INC_PATHS', node)
117     # TODO WAF 1.6
118     if USE_TOP_LEVEL:
119         self.env.append_value('INC_PATHS', self.bld.srcnode)
120
121
122
123 cac = {}
124 @feature('cc')
125 @after('apply_incpaths')
126 def apply_obj_vars_cc(self):
127     """after apply_incpaths for INC_PATHS"""
128     env = self.env
129     app = env.append_unique
130     cpppath_st = env['CPPPATH_ST']
131
132     global cac
133
134     # local flags come first
135     # set the user-defined includes paths
136     for i in env['INC_PATHS']:
137
138         try:
139             app('_CCINCFLAGS', cac[i.id])
140         except KeyError:
141             cac[i.id] = [cpppath_st % i.bldpath(env), cpppath_st % i.srcpath(env)]
142             app('_CCINCFLAGS', cac[i.id])
143
144     # set the library include paths
145     for i in env['CPPPATH']:
146         app('_CCINCFLAGS', cpppath_st % i)