9 import sys
, os
, tempfile
10 sys
.path
.insert(0, srcdir
+"/buildtools/wafsamba")
11 import wafsamba
, Options
, samba_dist
, samba_git
, Scripting
, Utils
, samba_version
12 import Logs
, samba_utils
15 samba_dist
.DIST_DIRS('.')
16 samba_dist
.DIST_BLACKLIST('.gitignore .bzrignore source4/selftest/provisions')
18 # install in /usr/local/samba by default
19 default_prefix
= Options
.default_prefix
= '/usr/local/samba'
21 # This callback optionally takes a list of paths as arguments:
22 # --with-system_mitkrb5 /path/to/krb5 /another/path
23 def system_mitkrb5_callback(option
, opt
, value
, parser
):
24 setattr(parser
.values
, option
.dest
, True)
26 for arg
in parser
.rargs
:
27 # stop on --foo like options
28 if arg
[:2] == "--" and len(arg
) > 2:
32 del parser
.rargs
[:len(value
)]
33 setattr(parser
.values
, option
.dest
, value
)
36 opt
.BUILTIN_DEFAULT('NONE')
37 opt
.PRIVATE_EXTENSION_DEFAULT('samba4')
38 opt
.RECURSE('lib/replace')
39 opt
.RECURSE('dynconfig')
40 opt
.RECURSE('lib/ldb')
41 opt
.RECURSE('selftest')
42 opt
.RECURSE('source4/lib/tls')
43 opt
.RECURSE('source4/dsdb/samdb/ldb_modules')
45 opt
.RECURSE('source3')
46 opt
.RECURSE('lib/util')
48 opt
.samba_add_onoff_option('pthreadpool', with_name
="enable", without_name
="disable", default
=True)
50 opt
.add_option('--with-system-mitkrb5',
51 help='enable system MIT krb5 build (includes Samba 4 client and Samba 3 code base).'+
52 'You may specify list of paths where Kerberos is installed (e.g. /usr/local /usr/kerberos) to search krb5-config',
53 action
='callback', callback
=system_mitkrb5_callback
, dest
='with_system_mitkrb5', default
=False)
55 opt
.add_option('--without-ad-dc',
56 help='disable AD DC functionality (enables Samba 4 client and Samba 3 code base).',
57 action
='store_true', dest
='without_ad_dc', default
=False)
59 opt
.add_option('--with-ntvfs-fileserver',
60 help='enable the depricated NTVFS file server from the original Samba4 branch (default if --enable-selftest specicifed). Conflicts with --with-system-mitkrb5 and --without-ad-dc',
61 action
='store_true', dest
='with_ntvfs_fileserver')
63 opt
.add_option('--without-ntvfs-fileserver',
64 help='disable the depricated NTVFS file server from the original Samba4 branch',
65 action
='store_false', dest
='with_ntvfs_fileserver')
67 opt
.add_option('--with-pie',
68 help=("Build Position Independent Executables " +
69 "(default if supported by compiler)"),
70 action
="store_true", dest
='enable_pie')
71 opt
.add_option('--without-pie',
72 help=("Disable Position Independent Executable builds"),
73 action
="store_false", dest
='enable_pie')
75 opt
.add_option('--with-relro',
76 help=("Build with full RELocation Read-Only (RELRO)" +
77 "(default if supported by compiler)"),
78 action
="store_true", dest
='enable_relro')
79 opt
.add_option('--without-relro',
80 help=("Disable RELRO builds"),
81 action
="store_false", dest
='enable_relro')
83 gr
= opt
.option_group('developer options')
85 opt
.tool_options('python') # options for disabling pyc or pyo compilation
86 # enable options related to building python extensions
90 version
= samba_version
.load_version(env
=conf
.env
)
92 conf
.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
93 conf
.DEFINE('_SAMBA_BUILD_', version
.MAJOR
, add_to_cflags
=True)
94 conf
.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags
=True)
96 if Options
.options
.developer
:
97 conf
.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
98 conf
.env
.DEVELOPER
= True
100 conf
.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
102 conf
.env
.replace_add_global_pthread
= True
103 conf
.RECURSE('lib/replace')
105 conf
.RECURSE('examples/fuse')
107 conf
.SAMBA_CHECK_PERL(mandatory
=True)
108 conf
.find_program('xsltproc', var
='XSLTPROC')
110 conf
.SAMBA_CHECK_PYTHON(mandatory
=True, version
=(2, 6, 0))
111 conf
.SAMBA_CHECK_PYTHON_HEADERS(mandatory
=True)
113 if sys
.platform
== 'darwin' and not conf
.env
['HAVE_ENVIRON_DECL']:
114 # Mac OSX needs to have this and it's also needed that the python is compiled with this
115 # otherwise you face errors about common symbols
116 if not conf
.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
117 conf
.ADD_CFLAGS('-fno-common')
118 if not conf
.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
119 conf
.env
.append_value('shlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
121 if sys
.platform
== 'darwin':
122 conf
.ADD_LDFLAGS('-framework CoreFoundation')
124 if int(conf
.env
['PYTHON_VERSION'][0]) >= 3:
125 raise Utils
.WafError('Python version 3.x is not supported by Samba yet')
127 conf
.RECURSE('dynconfig')
129 if conf
.CHECK_FOR_THIRD_PARTY():
130 conf
.RECURSE('third_party')
132 if not conf
.CHECK_ZLIB():
133 raise Utils
.WafError('zlib development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
135 conf
.define('USING_SYSTEM_ZLIB',1)
137 if not conf
.CHECK_POPT():
138 raise Utils
.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
140 conf
.define('USING_SYSTEM_POPT', 1)
142 conf
.RECURSE('lib/ldb')
144 if not (Options
.options
.without_ad_dc
):
145 conf
.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
147 if Options
.options
.with_system_mitkrb5
:
148 conf
.PROCESS_SEPARATE_RULE('system_mitkrb5')
149 if not (Options
.options
.without_ad_dc
or Options
.options
.with_system_mitkrb5
):
150 conf
.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
152 # Only process heimdal_build for non-MIT KRB5 builds
153 # When MIT KRB5 checks are done as above, conf.env.KRB5_VENDOR will be set
154 # to the lowcased output of 'krb5-config --vendor'.
155 # If it is not set or the output is 'heimdal', we are dealing with
156 # system-provided or embedded Heimdal build
157 if conf
.CONFIG_GET('KRB5_VENDOR') in (None, 'heimdal'):
158 conf
.RECURSE('source4/heimdal_build')
159 conf
.RECURSE('source4/lib/tls')
160 conf
.RECURSE('source4/dsdb/samdb/ldb_modules')
161 conf
.RECURSE('source4/ntvfs/sysdep')
162 conf
.RECURSE('lib/util')
163 conf
.RECURSE('lib/util/charset')
164 conf
.RECURSE('source4/auth')
165 conf
.RECURSE('nsswitch')
166 conf
.RECURSE('libcli/smbreadline')
167 conf
.RECURSE('lib/crypto')
169 conf
.RECURSE('selftest')
170 if conf
.CONFIG_GET('ENABLE_SELFTEST'):
171 conf
.RECURSE('lib/nss_wrapper')
172 conf
.RECURSE('lib/resolv_wrapper')
173 conf
.RECURSE('lib/socket_wrapper')
174 conf
.RECURSE('lib/uid_wrapper')
175 if Options
.options
.with_ntvfs_fileserver
!= False:
176 if not (Options
.options
.without_ad_dc
or Options
.options
.with_system_mitkrb5
):
177 conf
.DEFINE('WITH_NTVFS_FILESERVER', 1)
178 if Options
.options
.with_ntvfs_fileserver
== False:
179 if not (Options
.options
.without_ad_dc
or Options
.options
.with_system_mitkrb5
):
180 raise Utils
.WafError('--without-ntvfs-fileserver conflicts with --enable-selftest while building the AD DC')
182 if Options
.options
.with_ntvfs_fileserver
== True:
183 if Options
.options
.without_ad_dc
:
184 raise Utils
.WafError('--with-ntvfs-fileserver conflicts with --without-ad-dc')
185 if Options
.options
.with_system_mitkrb5
:
186 raise Utils
.WafError('--with-ntvfs-fileserver conflicts with --with-system-mitkrb5')
187 conf
.DEFINE('WITH_NTVFS_FILESERVER', 1)
189 if Options
.options
.with_pthreadpool
:
190 if conf
.CONFIG_SET('HAVE_PTHREAD'):
191 conf
.DEFINE('WITH_PTHREADPOOL', '1')
193 Logs
.warn("pthreadpool support cannot be enabled when pthread support was not found")
194 conf
.undefine('WITH_PTHREADPOOL')
196 conf
.RECURSE('source3')
197 conf
.RECURSE('lib/texpect')
198 if conf
.env
.with_ctdb
:
200 conf
.RECURSE('lib/socket')
201 conf
.RECURSE('testsuite/unittests')
203 conf
.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
205 # gentoo always adds this. We want our normal build to be as
206 # strict as the strictest OS we support, so adding this here
207 # allows us to find problems on our development hosts faster.
208 # It also results in faster load time.
210 conf
.env
.asneeded_ldflags
= conf
.ADD_LDFLAGS('-Wl,--as-needed', testflags
=True)
212 if not conf
.CHECK_NEED_LC("-lc not needed"):
213 conf
.ADD_LDFLAGS('-lc', testflags
=False)
215 if not conf
.CHECK_CODE('#include "tests/summary.c"',
216 define
='SUMMARY_PASSES',
218 msg
='Checking configure summary'):
219 raise Utils
.WafError('configure summary failed')
221 if Options
.options
.enable_pie
!= False:
222 if Options
.options
.enable_pie
== True:
225 # not specified, only build PIEs if supported by compiler
227 if conf
.check_cc(cflags
='-fPIE', ldflags
='-pie', mandatory
=need_pie
,
228 msg
="Checking compiler for PIE support"):
229 conf
.env
['ENABLE_PIE'] = True
231 if Options
.options
.enable_relro
!= False:
232 if Options
.options
.enable_relro
== True:
235 # not specified, only build RELROs if supported by compiler
237 if conf
.check_cc(cflags
='', ldflags
='-Wl,-z,relro,-z,now', mandatory
=need_relro
,
238 msg
="Checking compiler for full RELRO support"):
239 conf
.env
['ENABLE_RELRO'] = True
241 conf
.SAMBA_CONFIG_H('include/config.h')
244 '''build TAGS file using etags'''
246 source_root
= os
.path
.dirname(Utils
.g_module
.root_path
)
247 cmd
= 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root
, source_root
)
248 print("Running: %s" % cmd
)
249 status
= os
.system(cmd
)
250 if os
.WEXITSTATUS(status
):
251 raise Utils
.WafError('etags failed')
254 "build 'tags' file using ctags"
256 source_root
= os
.path
.dirname(Utils
.g_module
.root_path
)
257 cmd
= 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root
, source_root
)
258 print("Running: %s" % cmd
)
259 status
= os
.system(cmd
)
260 if os
.WEXITSTATUS(status
):
261 raise Utils
.WafError('ctags failed')
264 # putting this here enabled build in the list
265 # of commands in --help
267 '''build all targets'''
268 samba_version
.load_version(env
=bld
.env
, is_install
=bld
.is_install
)
272 '''build python apidocs'''
273 bp
= os
.path
.abspath('bin/python')
275 modules
= ['talloc', 'tdb', 'ldb']
277 f
= os
.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp
, m
, m
), 'r')
279 mpaths
[m
] = f
.read().strip()
283 cmd
= ('PYTHONPATH=%(main)s pydoctor --introspect-c-modules --project-name=Samba '
284 '--project-url=http://www.samba.org --make-html --docformat=restructuredtext '
285 '--add-package bin/python/samba ' + ''.join('--add-module %s ' % n
for n
in modules
))
287 print("Running: %s" % cmd
)
288 status
= os
.system(cmd
)
289 if os
.WEXITSTATUS(status
):
290 raise Utils
.WafError('pydoctor failed')
294 '''run pep8 validator'''
295 cmd
='PYTHONPATH=bin/python pep8 -r bin/python/samba'
296 print("Running: %s" % cmd
)
297 status
= os
.system(cmd
)
298 if os
.WEXITSTATUS(status
):
299 raise Utils
.WafError('pep8 failed')
303 '''build wafsamba apidocs'''
304 from samba_utils
import recursive_dirlist
306 list = recursive_dirlist('../buildtools/wafsamba', '.', pattern
='*.py')
308 cmd
='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext'
311 cmd
+= ' --add-module %s' % f
312 print("Running: %s" % cmd
)
313 status
= os
.system(cmd
)
314 if os
.WEXITSTATUS(status
):
315 raise Utils
.WafError('wafdocs failed')
319 '''makes a tarball for distribution'''
320 sambaversion
= samba_version
.load_version(env
=None)
322 os
.system("make -C ctdb/doc")
323 samba_dist
.DIST_FILES('ctdb/doc:ctdb/doc', extend
=True)
325 os
.system(srcdir
+ "/release-scripts/build-manpages-nogit")
326 samba_dist
.DIST_FILES('bin/docs:docs', extend
=True)
328 if sambaversion
.IS_SNAPSHOT
:
329 # write .distversion file and add to tar
330 if not os
.path
.isdir(blddir
):
332 distversionf
= tempfile
.NamedTemporaryFile(mode
='w', prefix
='.distversion',dir=blddir
)
333 for field
in sambaversion
.vcs_fields
:
334 distveroption
= field
+ '=' + str(sambaversion
.vcs_fields
[field
])
335 distversionf
.write(distveroption
+ '\n')
337 samba_dist
.DIST_FILES('%s:.distversion' % distversionf
.name
, extend
=True)
346 '''test that distribution tarball builds and installs'''
347 samba_version
.load_version(env
=None)
349 d
= Scripting
.distcheck
352 def wildcard_cmd(cmd
):
353 '''called on a unknown command'''
354 from samba_wildcard
import run_named_build_task
355 run_named_build_task(cmd
)
358 from samba_wildcard
import wildcard_main
360 wildcard_main(wildcard_cmd
)
361 Scripting
.main
= main
363 def reconfigure(ctx
):
364 '''reconfigure if config scripts have changed'''
366 samba_utils
.reconfigure(ctx
)
369 if os
.path
.isdir(os
.path
.join(srcdir
, ".git")):
370 # Check if there are submodules that are checked out but out of date.
371 for submodule
, status
in samba_git
.read_submodule_status(srcdir
):
372 if status
== "out-of-date":
373 raise Utils
.WafError("some submodules are out of date. Please run 'git submodule update'")