build: Reduce build systems to just top level waf and autoconf
[amitay/samba.git] / wscript
1 #! /usr/bin/env python
2
3 srcdir = '.'
4 blddir = 'bin'
5
6 APPNAME='samba'
7 VERSION=None
8
9 import sys, os
10 sys.path.insert(0, srcdir+"/buildtools/wafsamba")
11 import wafsamba, Options, samba_dist, Scripting, Utils, samba_version
12
13
14 samba_dist.DIST_DIRS('.')
15
16 # install in /usr/local/samba by default
17 Options.default_prefix = '/usr/local/samba'
18
19 def set_options(opt):
20     opt.BUILTIN_DEFAULT('NONE')
21     opt.PRIVATE_EXTENSION_DEFAULT('samba4')
22     opt.RECURSE('lib/replace')
23     opt.RECURSE('dynconfig')
24     opt.RECURSE('lib/ldb')
25     opt.RECURSE('selftest')
26     opt.RECURSE('source4/lib/tls')
27     opt.RECURSE('lib/nss_wrapper')
28     opt.RECURSE('lib/socket_wrapper')
29     opt.RECURSE('lib/uid_wrapper')
30     opt.RECURSE('pidl')
31     opt.RECURSE('source3')
32
33     gr = opt.option_group('developer options')
34     gr.add_option('--enable-build-farm',
35                    help='enable special build farm options',
36                    action='store_true', dest='BUILD_FARM')
37
38     opt.tool_options('python') # options for disabling pyc or pyo compilation
39     # enable options related to building python extensions
40
41
42 def configure(conf):
43     version = samba_version.load_version(env=conf.env)
44
45     conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
46     conf.DEFINE('_SAMBA_WAF_BUILD_', version.MAJOR)
47     conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
48     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
49
50     if Options.options.developer:
51         conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
52         conf.env.DEVELOPER = True
53
54     # this enables smbtorture.static for s3 in the build farm
55     conf.env.BUILD_FARM = Options.options.BUILD_FARM or os.environ.get('RUN_FROM_BUILD_FARM')
56
57     conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
58
59     conf.RECURSE('lib/replace')
60
61     conf.find_program('python', var='PYTHON', mandatory=True)
62     conf.find_program('perl', var='PERL', mandatory=True)
63     conf.find_program('xsltproc', var='XSLTPROC')
64
65     # enable tool to build python extensions
66     conf.check_tool('python')
67     conf.check_python_version((2,4,2))
68     conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=True)
69
70     if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']:
71         # Mac OSX needs to have this and it's also needed that the python is compiled with this
72         # otherwise you face errors about common symbols
73         if not conf.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
74             conf.ADD_CFLAGS('-fno-common')
75         if not conf.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
76             conf.env.append_value('shlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
77
78     if sys.platform == 'darwin':
79         conf.ADD_LDFLAGS('-framework CoreFoundation')
80
81     if int(conf.env['PYTHON_VERSION'][0]) >= 3:
82         raise Utils.WafError('Python version 3.x is not supported by Samba yet')
83
84     conf.RECURSE('dynconfig')
85     conf.RECURSE('lib/ldb')
86     conf.RECURSE('source4/heimdal_build')
87     conf.RECURSE('source4/lib/tls')
88     conf.RECURSE('source4/ntvfs/sysdep')
89     conf.RECURSE('lib/util')
90     conf.RECURSE('lib/ccan')
91     conf.RECURSE('lib/zlib')
92     conf.RECURSE('lib/util/charset')
93     conf.RECURSE('source4/auth')
94     conf.RECURSE('lib/nss_wrapper')
95     conf.RECURSE('nsswitch')
96     conf.RECURSE('lib/socket_wrapper')
97     conf.RECURSE('lib/uid_wrapper')
98     conf.RECURSE('lib/popt')
99     conf.RECURSE('lib/subunit/c')
100     conf.RECURSE('libcli/smbreadline')
101     conf.RECURSE('pidl')
102     conf.RECURSE('selftest')
103     conf.RECURSE('source3')
104
105     # we don't want any libraries or modules to rely on runtime
106     # resolution of symbols
107     if sys.platform != "openbsd4":
108         conf.env.undefined_ldflags = conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
109
110     if sys.platform != "openbsd4" and conf.env.undefined_ignore_ldflags == []:
111         if conf.CHECK_LDFLAGS(['-undefined', 'dynamic_lookup']):
112             conf.env.undefined_ignore_ldflags = ['-undefined', 'dynamic_lookup']
113
114
115     # gentoo always adds this. We want our normal build to be as
116     # strict as the strictest OS we support, so adding this here
117     # allows us to find problems on our development hosts faster.
118     # It also results in faster load time.
119
120     if sys.platform != "openbsd4":
121         conf.env.asneeded_ldflags = conf.ADD_LDFLAGS('-Wl,--as-needed', testflags=True)
122
123     if not conf.CHECK_NEED_LC("-lc not needed"):
124         conf.ADD_LDFLAGS('-lc', testflags=False)
125
126     # we don't want PYTHONDIR in config.h, as otherwise changing
127     # --prefix causes a complete rebuild
128     del(conf.env.defines['PYTHONDIR'])
129     del(conf.env.defines['PYTHONARCHDIR'])
130
131     conf.SAMBA_CONFIG_H('include/config.h')
132
133
134 def etags(ctx):
135     '''build TAGS file using etags'''
136     import Utils
137     source_root = os.path.dirname(Utils.g_module.root_path)
138     cmd = 'etags $(find %s -name "*.[ch]" | egrep -v \.inst\.)' % source_root
139     print("Running: %s" % cmd)
140     os.system(cmd)
141
142 def ctags(ctx):
143     "build 'tags' file using ctags"
144     import Utils
145     source_root = os.path.dirname(Utils.g_module.root_path)
146     cmd = 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root, source_root)
147     print("Running: %s" % cmd)
148     os.system(cmd)
149
150 # putting this here enabled build in the list
151 # of commands in --help
152 def build(bld):
153     '''build all targets'''
154     samba_version.load_version(env=bld.env, is_install=bld.is_install)
155     pass
156
157
158 def pydoctor(ctx):
159     '''build python apidocs'''
160     cmd='PYTHONPATH=bin/python pydoctor --project-name=Samba --project-url=http://www.samba.org --make-html --docformat=restructuredtext --add-package bin/python/samba'
161     print("Running: %s" % cmd)
162     os.system(cmd)
163
164 def wafdocs(ctx):
165     '''build wafsamba apidocs'''
166     from samba_utils import recursive_dirlist
167     os.system('pwd')
168     list = recursive_dirlist('../buildtools/wafsamba', '.', pattern='*.py')
169
170     cmd='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext'
171     print(list)
172     for f in list:
173         cmd += ' --add-module %s' % f
174     print("Running: %s" % cmd)
175     os.system(cmd)
176
177
178 def dist():
179     '''makes a tarball for distribution'''
180     samba_version.load_version(env=None)
181     samba_dist.dist()
182
183 def distcheck():
184     '''test that distribution tarball builds and installs'''
185     samba_version.load_version(env=None)
186     import Scripting
187     d = Scripting.distcheck
188     d(subdir='source4')
189
190 def wildcard_cmd(cmd):
191     '''called on a unknown command'''
192     from samba_wildcard import run_named_build_task
193     run_named_build_task(cmd)
194
195 def main():
196     from samba_wildcard import wildcard_main
197     wildcard_main(wildcard_cmd)
198 Scripting.main = main
199
200 def reconfigure(ctx):
201     '''reconfigure if config scripts have changed'''
202     import samba_utils
203     samba_utils.reconfigure(ctx)