1 # a waf tool to add autoconf-like macros to the configure section
2 # and for SAMBA_ macros for building libraries, binaries etc
4 import os
, sys
, re
, shutil
, fnmatch
5 from waflib
import Build
, Options
, Task
, Utils
, TaskGen
, Logs
, Context
, Errors
6 from waflib
.Configure
import conf
7 from waflib
.Logs
import debug
8 from samba_utils
import SUBST_VARS_RECURSIVE
9 TaskGen
.task_gen
.apply_verif
= Utils
.nada
11 # bring in the other samba modules
12 from samba_utils
import *
13 from samba_utils
import symlink
14 from samba_version
import *
15 from samba_autoconf
import *
16 from samba_patterns
import *
17 from samba_pidl
import *
18 from samba_autoproto
import *
19 from samba_python
import *
20 from samba_perl
import *
21 from samba_deps
import *
22 from samba_bundled
import *
23 from samba_third_party
import *
26 import samba_conftests
40 os
.environ
['PYTHONUNBUFFERED'] = '1'
42 if Context
.HEXVERSION
not in (0x2001a00,):
44 Please use the version of waf that comes with Samba, not
45 a system installed version. See http://wiki.samba.org/index.php/Waf
48 Alternatively, please run ./configure and make as usual. That will
49 call the right version of waf.''')
53 def SAMBA_BUILD_ENV(conf
):
54 '''create the samba build environment'''
55 conf
.env
.BUILD_DIRECTORY
= conf
.bldnode
.abspath()
56 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, LIB_PATH
))
57 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, LIB_PATH
, "private"))
58 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, "modules"))
59 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, "plugins"))
60 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, 'python/samba/dcerpc'))
61 # this allows all of the bin/shared and bin/python targets
62 # to be expressed in terms of build directory paths
63 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, 'default'))
64 for (source
, target
) in [('shared', 'shared'), ('modules', 'modules'), ('plugins', 'plugins'), ('python', 'python')]:
65 link_target
= os
.path
.join(conf
.env
.BUILD_DIRECTORY
, 'default/' + target
)
66 if not os
.path
.lexists(link_target
):
67 symlink('../' + source
, link_target
)
69 # get perl to put the blib files in the build directory
70 blib_bld
= os
.path
.join(conf
.env
.BUILD_DIRECTORY
, 'default/pidl/blib')
71 blib_src
= os
.path
.join(conf
.srcnode
.abspath(), 'pidl/blib')
72 mkdir_p(blib_bld
+ '/man1')
73 mkdir_p(blib_bld
+ '/man3')
74 if os
.path
.islink(blib_src
):
76 elif os
.path
.exists(blib_src
):
77 shutil
.rmtree(blib_src
)
80 def ADD_INIT_FUNCTION(bld
, subsystem
, target
, init_function
):
81 '''add an init_function to the list for a subsystem'''
82 if init_function
is None:
84 bld
.ASSERT(subsystem
is not None, "You must specify a subsystem for init_function '%s'" % init_function
)
85 cache
= LOCAL_CACHE(bld
, 'INIT_FUNCTIONS')
86 if subsystem
not in cache
:
88 cache
[subsystem
].append( { 'TARGET':target
, 'INIT_FUNCTION':init_function
} )
89 Build
.BuildContext
.ADD_INIT_FUNCTION
= ADD_INIT_FUNCTION
92 def generate_empty_file(task
):
93 task
.outputs
[0].write('')
96 #################################################################
97 def SAMBA_LIBRARY(bld
, libname
, source
,
102 public_headers_install
=True,
103 private_headers
=None,
111 external_library
=False,
114 autoproto_extra_source
='',
125 target_type
='LIBRARY',
130 orig_vscript_map
=None,
133 private_library
=False,
134 grouping_library
=False,
135 require_builtin_deps
=False,
136 provide_builtin_linking
=False,
138 force_unversioned
=False,
139 allow_undefined_symbols
=False,
140 allow_warnings
=False,
142 '''define a Samba library'''
145 # - LIBRARY: this can be used to link via -llibname
146 # - MODULE: this is module from SAMBA_MODULE()
147 # - PLUGIN: this is plugin for external consumers to be
148 # loaded via dlopen()
149 # - PYTHON: a python C binding library
151 if target_type
not in ['LIBRARY', 'MODULE', 'PLUGIN', 'PYTHON']:
152 raise Errors
.WafError("target_type[%s] not supported in SAMBA_LIBRARY('%s')" %
153 (target_type
, libname
))
155 if require_builtin_deps
:
156 # For now we only support require_builtin_deps only for libraries, plugins
157 if target_type
not in ['LIBRARY', 'PLUGIN']:
158 raise Errors
.WafError("target_type[%s] not supported SAMBA_LIBRARY('%s', require_builtin_deps=True)" %
159 (target_type
, libname
))
161 if private_library
and public_headers
:
162 raise Errors
.WafError("private library '%s' must not have public header files" %
165 if orig_vscript_map
and not private_library
:
166 raise Errors
.WafError("public library '%s' must not have orig_vscript_map" %
169 if orig_vscript_map
and abi_directory
:
170 raise Errors
.WafError("private library '%s' with orig_vscript_map must not have abi_directory" %
172 if orig_vscript_map
and abi_match
:
173 raise Errors
.WafError("private library '%s' with orig_vscript_map must not have abi_match" %
176 if force_unversioned
and private_library
:
177 raise Errors
.WafError("private library '%s': can't have force_unversioned=True" %
180 if force_unversioned
and realname
is None:
181 raise Errors
.WafError("library '%s': force_unversioned=True needs realname too" %
184 if LIB_MUST_BE_PRIVATE(bld
, libname
) and target_type
not in ['PLUGIN']:
185 private_library
= True
186 public_headers_install
= False
188 if force_unversioned
:
189 private_library
= False
192 SET_TARGET_TYPE(bld
, libname
, 'DISABLED')
195 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
197 source
= bld
.SUBDIR(subdir
, source
)
199 # remember empty libraries, so we can strip the dependencies
200 if ((source
== '') or (source
== [])):
201 if deps
== '' and public_deps
== '':
202 SET_TARGET_TYPE(bld
, libname
, 'EMPTY')
204 empty_c
= libname
+ '.empty.c'
205 bld
.SAMBA_GENERATOR('%s_empty_c' % libname
,
206 rule
=generate_empty_file
,
210 samba_deps
= deps
+ ' ' + public_deps
211 samba_deps
= TO_LIST(samba_deps
)
213 if BUILTIN_LIBRARY(bld
, libname
):
214 builtin_target
= libname
+ '.builtin.objlist'
215 builtin_cflags_end
= '-D_PUBLIC_=_PRIVATE_'
216 empty_target
= libname
219 if provide_builtin_linking
:
220 builtin_target
= libname
+ '.builtin.objlist'
221 builtin_cflags_end
= '-D_PUBLIC_=_PRIVATE_'
223 builtin_target
= None
225 obj_target
= libname
+ '.objlist'
226 if require_builtin_deps
:
227 # hide the builtin deps from the callers
228 samba_deps
= TO_LIST('')
229 dep_target
= obj_target
231 if group
== 'libraries':
232 subsystem_group
= 'main'
234 subsystem_group
= group
236 # first create a target for building the object files for this library
237 # by separating in this way, we avoid recompiling the C files
238 # separately for the install library and the build library
240 __t
= __SAMBA_SUBSYSTEM_BUILTIN(bld
, builtin_target
, source
,
242 public_deps
=public_deps
,
244 header_path
=header_path
,
245 builtin_cflags
=builtin_cflags
,
246 builtin_cflags_end
=builtin_cflags_end
,
248 depends_on
=depends_on
,
249 local_include
=local_include
,
250 global_include
=global_include
,
251 allow_warnings
=allow_warnings
)
252 builtin_subsystem
= __t
254 builtin_subsystem
= None
256 bld
.SAMBA_SUBSYSTEM(obj_target
,
259 public_deps
= public_deps
,
261 public_headers
= public_headers
,
262 public_headers_install
= public_headers_install
,
263 private_headers
= private_headers
,
264 header_path
= header_path
,
266 cflags_end
= cflags_end
,
267 group
= subsystem_group
,
268 autoproto
= autoproto
,
269 autoproto_extra_source
=autoproto_extra_source
,
270 depends_on
= depends_on
,
271 hide_symbols
= hide_symbols
,
272 allow_warnings
= allow_warnings
,
275 local_include
= local_include
,
276 __require_builtin_deps
=require_builtin_deps
,
277 global_include
= global_include
)
279 et
= bld
.SAMBA_SUBSYSTEM(empty_target
,
282 __require_builtin_deps
=True)
283 et
.samba_builtin_subsystem
= builtin_subsystem
285 if BUILTIN_LIBRARY(bld
, libname
):
288 if not SET_TARGET_TYPE(bld
, libname
, target_type
):
291 # the library itself will depend on that object target
292 samba_deps
.append(dep_target
)
294 realname
= bld
.map_shlib_extension(realname
, python
=(target_type
=='PYTHON'))
295 link_name
= bld
.map_shlib_extension(link_name
, python
=(target_type
=='PYTHON'))
297 # we don't want any public libraries without version numbers
298 if (not private_library
and target_type
!= 'PYTHON' and not realname
):
299 if vnum
is None and soname
is None:
300 raise Errors
.WafError("public library '%s' must have a vnum" %
303 raise Errors
.WafError("public library '%s' must have pkg-config file" %
305 if public_headers
is None:
306 raise Errors
.WafError("public library '%s' must have header files" %
311 if bundled_name
is not None:
313 elif target_type
== 'PYTHON' or realname
or not private_library
:
314 bundled_name
= libname
.replace('_', '-')
316 assert (private_library
is True and realname
is None)
317 bundled_name
= PRIVATE_NAME(bld
, libname
.replace('_', '-'))
320 ldflags
= TO_LIST(ldflags
)
321 if bld
.env
['ENABLE_RELRO'] is True:
322 ldflags
.extend(TO_LIST('-Wl,-z,relro,-z,now'))
324 features
= 'c cshlib symlink_lib install_lib'
328 features
+= ' pyembed'
331 features
+= ' abi_check'
333 if pyembed
and bld
.env
['PYTHON_SO_ABI_FLAG']:
334 # For ABI checking, we don't care about the Python version.
335 # Remove the Python ABI tag (e.g. ".cpython-35m")
336 abi_flag
= bld
.env
['PYTHON_SO_ABI_FLAG']
338 version_libname
= libname
.replace(abi_flag
, replacement
)
340 version_libname
= libname
343 if bld
.env
.HAVE_LD_VERSION_SCRIPT
:
344 if force_unversioned
:
346 elif private_library
:
347 version
= bld
.env
.PRIVATE_VERSION
349 version
= "%s_%s" % (libname
, vnum
)
353 vscript
= "%s.vscript" % libname
355 bld
.VSCRIPT_MAP_PRIVATE(version_libname
, orig_vscript_map
, version
, vscript
)
357 bld
.ABI_VSCRIPT(version_libname
, abi_directory
, version
, vscript
,
358 abi_match
, private_library
)
359 fullname
= apply_pattern(bundled_name
, bld
.env
.cshlib_PATTERN
)
360 fullpath
= bld
.path
.find_or_declare(fullname
)
361 vscriptpath
= bld
.path
.find_or_declare(vscript
)
363 raise Errors
.WafError("unable to find fullpath for %s" % fullname
)
365 raise Errors
.WafError("unable to find vscript path for %s" % vscript
)
366 bld
.add_manual_dependency(fullpath
, vscriptpath
)
368 # also make the .inst file depend on the vscript
369 instname
= apply_pattern(bundled_name
+ '.inst', bld
.env
.cshlib_PATTERN
)
370 bld
.add_manual_dependency(bld
.path
.find_or_declare(instname
), bld
.path
.find_or_declare(vscript
))
371 vscript
= os
.path
.join(bld
.path
.abspath(bld
.env
), vscript
)
373 bld
.SET_BUILD_GROUP(group
)
377 target
= bundled_name
,
378 depends_on
= depends_on
,
379 samba_ldflags
= ldflags
,
380 samba_deps
= samba_deps
,
381 samba_includes
= includes
,
382 version_script
= vscript
,
383 version_libname
= version_libname
,
384 local_include
= local_include
,
385 global_include
= global_include
,
389 samba_inst_path
= install_path
,
391 samba_realname
= realname
,
392 samba_install
= install
,
393 abi_directory
= "%s/%s" % (bld
.path
.abspath(), abi_directory
),
394 abi_match
= abi_match
,
396 private_library
= private_library
,
397 grouping_library
=grouping_library
,
398 allow_undefined_symbols
=allow_undefined_symbols
,
399 samba_require_builtin_deps
=False,
400 samba_builtin_subsystem
=builtin_subsystem
,
403 if realname
and not link_name
:
404 link_name
= 'shared/%s' % realname
407 if 'waflib.extras.compat15' in sys
.modules
:
408 link_name
= 'default/' + link_name
409 t
.link_name
= link_name
411 if pc_files
is not None and not private_library
:
413 bld
.PKG_CONFIG_FILES(pc_files
, vnum
=vnum
, extra_name
=bld
.env
['PYTHON_SO_ABI_FLAG'])
415 bld
.PKG_CONFIG_FILES(pc_files
, vnum
=vnum
)
417 if (manpages
is not None and 'XSLTPROC_MANPAGES' in bld
.env
and
418 bld
.env
['XSLTPROC_MANPAGES']):
419 bld
.MANPAGES(manpages
, install
)
422 Build
.BuildContext
.SAMBA_LIBRARY
= SAMBA_LIBRARY
425 #################################################################
426 def SAMBA_BINARY(bld
, binname
, source
,
430 private_headers
=None,
438 use_global_deps
=True,
445 allow_warnings
=False,
454 '''define a Samba binary'''
458 if not bld
.CONFIG_GET('ENABLE_SELFTEST'):
462 SET_TARGET_TYPE(bld
, binname
, 'DISABLED')
465 # Fuzzing builds do not build normal binaries
466 # however we must build asn1compile etc
468 if not use_hostcc
and bld
.env
.enable_fuzzing
!= fuzzer
:
469 SET_TARGET_TYPE(bld
, binname
, 'DISABLED')
475 ldflags
= bld
.env
['FUZZ_TARGET_LDFLAGS']
477 if not SET_TARGET_TYPE(bld
, binname
, 'BINARY'):
480 features
= 'c cprogram symlink_bin install_bin'
482 features
+= ' pyembed'
484 obj_target
= binname
+ '.objlist'
486 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
488 source
= bld
.SUBDIR(subdir
, source
)
489 source
= unique_list(TO_LIST(source
))
491 if group
== 'binaries':
492 subsystem_group
= 'main'
493 elif group
== 'build_compilers':
494 subsystem_group
= 'compiler_libraries'
496 subsystem_group
= group
498 # only specify PIE flags for binaries
499 pie_cflags
= TO_LIST(cflags
)
500 pie_ldflags
= TO_LIST(ldflags
)
501 if bld
.env
['ENABLE_PIE'] is True:
502 pie_cflags
.extend(TO_LIST('-fPIE'))
503 pie_ldflags
.extend(TO_LIST('-pie'))
504 if bld
.env
['ENABLE_RELRO'] is True:
505 pie_ldflags
.extend(TO_LIST('-Wl,-z,relro,-z,now'))
507 # first create a target for building the object files for this binary
508 # by separating in this way, we avoid recompiling the C files
509 # separately for the install binary and the build binary
510 bld
.SAMBA_SUBSYSTEM(obj_target
,
515 cflags_end
= cflags_end
,
516 group
= subsystem_group
,
517 autoproto
= autoproto
,
518 subsystem_name
= subsystem_name
,
519 local_include
= local_include
,
520 global_include
= global_include
,
521 use_hostcc
= use_hostcc
,
523 allow_warnings
= allow_warnings
,
524 use_global_deps
= use_global_deps
)
526 bld
.SET_BUILD_GROUP(group
)
528 # the binary itself will depend on that object target
530 deps
.append(obj_target
)
537 samba_includes
= includes
,
538 local_include
= local_include
,
539 global_include
= global_include
,
540 samba_modules
= modules
,
542 samba_subsystem
= subsystem_name
,
544 samba_inst_path
= install_path
,
545 samba_install
= install
,
546 samba_ldflags
= pie_ldflags
549 if manpages
is not None and 'XSLTPROC_MANPAGES' in bld
.env
and bld
.env
['XSLTPROC_MANPAGES']:
550 bld
.MANPAGES(manpages
, install
)
552 Build
.BuildContext
.SAMBA_BINARY
= SAMBA_BINARY
555 #################################################################
556 def SAMBA_MODULE(bld
, modname
, source
,
561 module_init_name
='samba_init_module',
563 autoproto_extra_source
='',
566 internal_module
=True,
574 allow_undefined_symbols
=False,
575 allow_warnings
=False,
577 '''define a Samba module.'''
579 bld
.ASSERT(subsystem
, "You must specify a subsystem for SAMBA_MODULE(%s)" % modname
)
581 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
583 source
= bld
.SUBDIR(subdir
, source
)
585 if internal_module
or BUILTIN_LIBRARY(bld
, modname
):
586 # Do not create modules for disabled subsystems
587 if GET_TARGET_TYPE(bld
, subsystem
) == 'DISABLED':
589 bld
.SAMBA_SUBSYSTEM(modname
, source
,
593 autoproto_extra_source
=autoproto_extra_source
,
595 cflags_end
=cflags_end
,
596 local_include
=local_include
,
597 global_include
=global_include
,
598 allow_warnings
=allow_warnings
,
601 bld
.ADD_INIT_FUNCTION(subsystem
, modname
, init_function
)
605 SET_TARGET_TYPE(bld
, modname
, 'DISABLED')
608 # Do not create modules for disabled subsystems
609 if GET_TARGET_TYPE(bld
, subsystem
) == 'DISABLED':
613 deps
+= ' ' + subsystem
614 while realname
.startswith("lib"+subsystem
+"_"):
615 realname
= realname
[len("lib"+subsystem
+"_"):]
616 while realname
.startswith(subsystem
+"_"):
617 realname
= realname
[len(subsystem
+"_"):]
619 build_name
= "%s_module_%s" % (subsystem
, realname
)
621 realname
= bld
.make_libname(realname
)
622 while realname
.startswith("lib"):
623 realname
= realname
[len("lib"):]
625 build_link_name
= "modules/%s/%s" % (subsystem
, realname
)
627 if f
'{subsystem}_modules_install_dir' in bld
.env
:
628 install_path
= bld
.env
[f
'{subsystem}_modules_install_dir']
630 install_path
= "${MODULESDIR}/%s" % subsystem
633 cflags
+= " -D%s=%s" % (init_function
, module_init_name
)
635 bld
.SAMBA_LIBRARY(modname
,
640 cflags_end
=cflags_end
,
642 autoproto
= autoproto
,
643 local_include
=local_include
,
644 global_include
=global_include
,
646 bundled_name
=build_name
,
647 link_name
=build_link_name
,
648 install_path
=install_path
,
651 allow_undefined_symbols
=allow_undefined_symbols
,
652 allow_warnings
=allow_warnings
,
653 private_library
=True,
658 Build
.BuildContext
.SAMBA_MODULE
= SAMBA_MODULE
660 #################################################################
661 def SAMBA_PLUGIN(bld
, pluginname
, source
,
674 autoproto_extra_source
='',
678 require_builtin_deps
=True,
679 allow_undefined_symbols
=False,
681 '''define an external plugin.'''
683 bld
.ASSERT(realname
, "You must specify a realname for SAMBA_PLUGIN(%s)" % pluginname
)
685 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
687 source
= bld
.SUBDIR(subdir
, source
)
689 build_name
= "_plugin_%s" % (pluginname
)
690 build_link_name
= "plugins/%s" % (realname
)
692 bld
.SAMBA_LIBRARY(pluginname
,
694 bundled_name
=build_name
,
695 link_name
=build_link_name
,
696 target_type
='PLUGIN',
705 autoproto_extra_source
=autoproto_extra_source
,
706 local_include
=local_include
,
707 global_include
=global_include
,
710 install_path
=install_path
,
713 require_builtin_deps
=require_builtin_deps
,
714 builtin_cflags
=cflags
,
717 public_headers_install
=False,
719 allow_undefined_symbols
=allow_undefined_symbols
,
720 allow_warnings
=False,
722 Build
.BuildContext
.SAMBA_PLUGIN
= SAMBA_PLUGIN
724 def __SAMBA_SUBSYSTEM_BUILTIN(bld
, builtin_target
, source
,
729 public_headers_install
=True,
730 private_headers
=None,
733 builtin_cflags_end
=None,
736 autoproto_extra_source
='',
740 allow_warnings
=False):
742 bld
.ASSERT(builtin_target
.endswith('.builtin.objlist'),
743 "builtin_target[%s] does not end with '.builtin.objlist'" %
745 return bld
.SAMBA_SUBSYSTEM(builtin_target
, source
,
747 public_deps
=public_deps
,
749 public_headers
=public_headers
,
750 public_headers_install
=public_headers_install
,
751 private_headers
=private_headers
,
752 header_path
=header_path
,
753 cflags
=builtin_cflags
,
754 cflags_end
=builtin_cflags_end
,
757 target_type
='BUILTIN',
759 autoproto_extra_source
=autoproto_extra_source
,
760 depends_on
=depends_on
,
761 local_include
=local_include
,
762 global_include
=global_include
,
763 allow_warnings
=allow_warnings
,
764 __require_builtin_deps
=True)
766 #################################################################
767 def SAMBA_SUBSYSTEM(bld
, modname
, source
,
773 public_headers_install
=True,
774 private_headers
=None,
779 target_type
='SUBSYSTEM',
780 init_function_sentinel
=None,
782 autoproto_extra_source
='',
785 local_include_first
=True,
790 use_global_deps
=True,
794 __require_builtin_deps
=False,
795 provide_builtin_linking
=False,
797 allow_warnings
=False,
800 '''define a Samba subsystem'''
803 # - SUBSYSTEM: a normal subsystem from SAMBA_SUBSYSTEM()
804 # - BUILTIN: a hidden subsystem from __SAMBA_SUBSYSTEM_BUILTIN()
805 if target_type
not in ['SUBSYSTEM', 'BUILTIN']:
806 raise Errors
.WafError("target_type[%s] not supported in SAMBA_SUBSYSTEM('%s')" %
807 (target_type
, modname
))
810 SET_TARGET_TYPE(bld
, modname
, 'DISABLED')
813 # remember empty subsystems, so we can strip the dependencies
814 if ((source
== '') or (source
== [])):
815 if not __force_empty
and deps
== '' and public_deps
== '':
816 SET_TARGET_TYPE(bld
, modname
, 'EMPTY')
818 empty_c
= modname
+ '.empty.c'
819 bld
.SAMBA_GENERATOR('%s_empty_c' % modname
,
820 rule
=generate_empty_file
,
824 if not SET_TARGET_TYPE(bld
, modname
, target_type
):
827 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
829 source
= bld
.SUBDIR(subdir
, source
)
830 source
= unique_list(TO_LIST(source
))
832 deps
+= ' ' + public_deps
834 bld
.SET_BUILD_GROUP(group
)
840 features
+= ' pyembed'
846 samba_cflags
= CURRENT_CFLAGS(bld
, modname
, cflags
,
847 allow_warnings
=allow_warnings
,
848 use_hostcc
=use_hostcc
,
849 hide_symbols
=hide_symbols
),
850 depends_on
= depends_on
,
851 samba_deps
= TO_LIST(deps
),
852 samba_includes
= includes
,
853 local_include
= local_include
,
854 local_include_first
= local_include_first
,
855 global_include
= global_include
,
856 samba_subsystem
= subsystem_name
,
857 samba_use_hostcc
= use_hostcc
,
858 samba_use_global_deps
= use_global_deps
,
859 samba_require_builtin_deps
= __require_builtin_deps
,
860 samba_builtin_subsystem
= None,
863 if cflags_end
is not None:
864 t
.samba_cflags
.extend(TO_LIST(cflags_end
))
866 if autoproto
is not None:
867 bld
.SAMBA_AUTOPROTO(autoproto
, source
+ TO_LIST(autoproto_extra_source
))
868 if public_headers
is not None:
869 bld
.PUBLIC_HEADERS(public_headers
, header_path
=header_path
,
870 public_headers_install
=public_headers_install
)
872 if provide_builtin_linking
:
875 raise Errors
.WafError("subsystem[%s] provide_builtin_linking=True " +
876 "not allowed with use_hostcc=True" %
880 raise Errors
.WafError("subsystem[%s] provide_builtin_linking=True " +
881 "not allowed with pyext=True nor pyembed=True" %
884 if __require_builtin_deps
:
885 raise Errors
.WafError("subsystem[%s] provide_builtin_linking=True " +
886 "not allowed with __require_builtin_deps=True" %
889 builtin_target
= modname
+ '.builtin.objlist'
890 tbuiltin
= __SAMBA_SUBSYSTEM_BUILTIN(bld
, builtin_target
, source
,
892 public_deps
=public_deps
,
894 header_path
=header_path
,
895 builtin_cflags
=builtin_cflags
,
896 builtin_cflags_end
='-D_PUBLIC_=_PRIVATE_',
898 depends_on
=depends_on
,
899 local_include
=local_include
,
900 global_include
=global_include
,
901 allow_warnings
=allow_warnings
)
902 t
.samba_builtin_subsystem
= tbuiltin
907 Build
.BuildContext
.SAMBA_SUBSYSTEM
= SAMBA_SUBSYSTEM
910 def SAMBA_GENERATOR(bld
, name
, rule
, source
='', target
='',
911 group
='generators', enabled
=True,
913 public_headers_install
=True,
914 private_headers
=None,
919 '''A generic source generator target'''
923 if not SET_TARGET_TYPE(bld
, name
, 'GENERATOR'):
929 dep_vars
= TO_LIST(dep_vars
)
930 dep_vars
.append('ruledeps')
931 dep_vars
.append('SAMBA_GENERATOR_VARS')
933 shell
=isinstance(rule
, str)
935 # This ensures that if the command (executed in the shell) fails
936 # (returns non-zero), the build fails
938 rule
= "set -e; " + rule
940 bld
.SET_BUILD_GROUP(group
)
943 source
=bld
.EXPAND_VARIABLES(source
, vars=vars),
949 samba_type
='GENERATOR',
955 t
.env
.SAMBA_GENERATOR_VARS
= vars
960 if public_headers
is not None:
961 bld
.PUBLIC_HEADERS(public_headers
, header_path
=header_path
,
962 public_headers_install
=public_headers_install
)
964 Build
.BuildContext
.SAMBA_GENERATOR
= SAMBA_GENERATOR
969 def SETUP_BUILD_GROUPS(bld
):
970 '''setup build groups used to ensure that the different build
971 phases happen consecutively'''
972 bld
.p_ln
= bld
.srcnode
# we do want to see all targets!
973 bld
.env
['USING_BUILD_GROUPS'] = True
974 bld
.add_group('setup')
975 bld
.add_group('generators')
976 bld
.add_group('hostcc_base_build_source')
977 bld
.add_group('hostcc_base_build_main')
978 bld
.add_group('hostcc_build_source')
979 bld
.add_group('hostcc_build_main')
980 bld
.add_group('vscripts')
981 bld
.add_group('base_libraries')
982 bld
.add_group('build_source')
983 bld
.add_group('prototypes')
984 bld
.add_group('headers')
985 bld
.add_group('main')
986 bld
.add_group('symbolcheck')
987 bld
.add_group('syslibcheck')
988 bld
.add_group('final')
989 Build
.BuildContext
.SETUP_BUILD_GROUPS
= SETUP_BUILD_GROUPS
992 def SET_BUILD_GROUP(bld
, group
):
993 '''set the current build group'''
994 if not 'USING_BUILD_GROUPS' in bld
.env
:
997 Build
.BuildContext
.SET_BUILD_GROUP
= SET_BUILD_GROUP
1001 def SAMBA_SCRIPT(bld
, name
, pattern
, installdir
, installname
=None):
1002 '''used to copy scripts from the source tree into the build directory
1003 for use by selftest'''
1005 source
= bld
.path
.ant_glob(pattern
, flat
=True)
1007 bld
.SET_BUILD_GROUP('build_source')
1008 for s
in TO_LIST(source
):
1010 if installname
is not None:
1012 target
= os
.path
.join(installdir
, iname
)
1013 tgtdir
= os
.path
.dirname(os
.path
.join(bld
.srcnode
.abspath(bld
.env
), '..', target
))
1015 link_src
= os
.path
.normpath(os
.path
.join(bld
.path
.abspath(), s
))
1016 link_dst
= os
.path
.join(tgtdir
, os
.path
.basename(iname
))
1017 if os
.path
.islink(link_dst
) and os
.readlink(link_dst
) == link_src
:
1019 if os
.path
.islink(link_dst
):
1021 Logs
.info("symlink: %s -> %s/%s" % (s
, installdir
, iname
))
1022 symlink(link_src
, link_dst
)
1023 Build
.BuildContext
.SAMBA_SCRIPT
= SAMBA_SCRIPT
1026 def copy_and_fix_python_path(task
):
1027 pattern
='sys.path.insert(0, "bin/python")'
1028 if task
.env
["PYTHONARCHDIR"] in sys
.path
and task
.env
["PYTHONDIR"] in sys
.path
:
1030 elif task
.env
["PYTHONARCHDIR"] == task
.env
["PYTHONDIR"]:
1031 replacement
="""sys.path.insert(0, "%s")""" % task
.env
["PYTHONDIR"]
1033 replacement
="""sys.path.insert(0, "%s")
1034 sys.path.insert(1, "%s")""" % (task
.env
["PYTHONARCHDIR"], task
.env
["PYTHONDIR"])
1036 if task
.env
["PYTHON"][0].startswith("/"):
1037 replacement_shebang
= "#!%s\n" % task
.env
["PYTHON"][0]
1039 replacement_shebang
= "#!/usr/bin/env %s\n" % task
.env
["PYTHON"][0]
1041 installed_location
=task
.outputs
[0].bldpath(task
.env
)
1042 source_file
= open(task
.inputs
[0].srcpath(task
.env
))
1043 installed_file
= open(installed_location
, 'w')
1045 for line
in source_file
:
1049 newline
= replacement_shebang
1050 elif pattern
in line
:
1051 newline
= line
.replace(pattern
, replacement
)
1052 installed_file
.write(newline
)
1054 installed_file
.close()
1055 os
.chmod(installed_location
, 0o755)
1058 def copy_and_fix_perl_path(task
):
1059 pattern
='use lib "$RealBin/lib";'
1062 if not task
.env
["PERL_LIB_INSTALL_DIR"] in task
.env
["PERL_INC"]:
1063 replacement
= 'use lib "%s";' % task
.env
["PERL_LIB_INSTALL_DIR"]
1065 if task
.env
["PERL"][0] == "/":
1066 replacement_shebang
= "#!%s\n" % task
.env
["PERL"]
1068 replacement_shebang
= "#!/usr/bin/env %s\n" % task
.env
["PERL"]
1070 installed_location
=task
.outputs
[0].bldpath(task
.env
)
1071 source_file
= open(task
.inputs
[0].srcpath(task
.env
))
1072 installed_file
= open(installed_location
, 'w')
1074 for line
in source_file
:
1076 if lineno
== 0 and task
.env
["PERL_SPECIFIED"] is True and line
[:2] == "#!":
1077 newline
= replacement_shebang
1078 elif pattern
in line
:
1079 newline
= line
.replace(pattern
, replacement
)
1080 installed_file
.write(newline
)
1082 installed_file
.close()
1083 os
.chmod(installed_location
, 0o755)
1087 def install_file(bld
, destdir
, file, chmod
=MODE_644
, flat
=False,
1088 python_fixup
=False, perl_fixup
=False,
1089 destname
=None, base_name
=None):
1090 '''install a file'''
1091 if not isinstance(file, str):
1092 file = file.abspath()
1093 destdir
= bld
.EXPAND_VARIABLES(destdir
)
1097 destname
= os
.path
.basename(destname
)
1098 dest
= os
.path
.join(destdir
, destname
)
1100 # fix the path python will use to find Samba modules
1101 inst_file
= file + '.inst'
1102 bld
.SAMBA_GENERATOR('python_%s' % destname
,
1103 rule
=copy_and_fix_python_path
,
1104 dep_vars
=["PYTHON","PYTHON_SPECIFIED","PYTHONDIR","PYTHONARCHDIR"],
1109 # fix the path perl will use to find Samba modules
1110 inst_file
= file + '.inst'
1111 bld
.SAMBA_GENERATOR('perl_%s' % destname
,
1112 rule
=copy_and_fix_perl_path
,
1113 dep_vars
=["PERL","PERL_SPECIFIED","PERL_LIB_INSTALL_DIR"],
1118 file = os
.path
.join(base_name
, file)
1119 bld
.install_as(dest
, file, chmod
=chmod
)
1122 def INSTALL_FILES(bld
, destdir
, files
, chmod
=MODE_644
, flat
=False,
1123 python_fixup
=False, perl_fixup
=False,
1124 destname
=None, base_name
=None):
1125 '''install a set of files'''
1126 for f
in TO_LIST(files
):
1127 install_file(bld
, destdir
, f
, chmod
=chmod
, flat
=flat
,
1128 python_fixup
=python_fixup
, perl_fixup
=perl_fixup
,
1129 destname
=destname
, base_name
=base_name
)
1130 Build
.BuildContext
.INSTALL_FILES
= INSTALL_FILES
1133 def INSTALL_WILDCARD(bld
, destdir
, pattern
, chmod
=MODE_644
, flat
=False,
1134 python_fixup
=False, exclude
=None, trim_path
=None):
1135 '''install a set of files matching a wildcard pattern'''
1136 files
=TO_LIST(bld
.path
.ant_glob(pattern
, flat
=True))
1140 files2
.append(os
.path
.relpath(f
, trim_path
))
1145 if fnmatch
.fnmatch(f
, exclude
):
1147 INSTALL_FILES(bld
, destdir
, files
, chmod
=chmod
, flat
=flat
,
1148 python_fixup
=python_fixup
, base_name
=trim_path
)
1149 Build
.BuildContext
.INSTALL_WILDCARD
= INSTALL_WILDCARD
1151 def INSTALL_DIR(bld
, path
, chmod
=0o755):
1152 """Install a directory if it doesn't exist, always set permissions."""
1157 destpath
= bld
.EXPAND_VARIABLES(path
)
1158 if Options
.options
.destdir
:
1159 destpath
= os
.path
.join(Options
.options
.destdir
, destpath
.lstrip(os
.sep
))
1161 if bld
.is_install
> 0:
1162 if not os
.path
.isdir(destpath
):
1164 Logs
.info('* create %s', destpath
)
1165 os
.makedirs(destpath
)
1166 os
.chmod(destpath
, chmod
)
1167 except OSError as e
:
1168 if not os
.path
.isdir(destpath
):
1169 raise Errors
.WafError("Cannot create the folder '%s' (error: %s)" % (path
, e
))
1170 Build
.BuildContext
.INSTALL_DIR
= INSTALL_DIR
1172 def INSTALL_DIRS(bld
, destdir
, dirs
, chmod
=0o755):
1173 '''install a set of directories'''
1174 destdir
= bld
.EXPAND_VARIABLES(destdir
)
1175 dirs
= bld
.EXPAND_VARIABLES(dirs
)
1176 for d
in TO_LIST(dirs
):
1177 INSTALL_DIR(bld
, os
.path
.join(destdir
, d
), chmod
)
1178 Build
.BuildContext
.INSTALL_DIRS
= INSTALL_DIRS
1181 def MANPAGES(bld
, manpages
, install
):
1182 '''build and install manual pages'''
1183 bld
.env
.MAN_XSL
= 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
1184 for m
in manpages
.split():
1186 bld
.SAMBA_GENERATOR(m
,
1190 rule
='${XSLTPROC} --xinclude -o ${TGT} --nonet ${MAN_XSL} ${SRC}'
1193 bld
.INSTALL_FILES('${MANDIR}/man%s' % m
[-1], m
, flat
=True)
1194 Build
.BuildContext
.MANPAGES
= MANPAGES
1196 def SAMBAMANPAGES(bld
, manpages
, extra_source
=None):
1197 '''build and install manual pages'''
1198 bld
.env
.SAMBA_EXPAND_XSL
= bld
.srcnode
.abspath() + '/docs-xml/xslt/expand-sambadoc.xsl'
1199 bld
.env
.SAMBA_MAN_XSL
= bld
.srcnode
.abspath() + '/docs-xml/xslt/man.xsl'
1200 bld
.env
.SAMBA_CATALOG
= bld
.bldnode
.abspath() + '/docs-xml/build/catalog.xml'
1201 bld
.env
.SAMBA_CATALOGS
= os
.getenv('XML_CATALOG_FILES', 'file:///etc/xml/catalog file:///usr/local/share/xml/catalog') + ' file://' + bld
.env
.SAMBA_CATALOG
1203 for m
in manpages
.split():
1204 source
= [m
+ '.xml']
1205 if extra_source
is not None:
1206 source
= [source
, extra_source
]
1207 # ${SRC[1]}, ${SRC[2]} and ${SRC[3]} are not referenced in the
1208 # SAMBA_GENERATOR but trigger the dependency calculation so
1209 # ensures that manpages are rebuilt when these change.
1210 source
+= ['build/DTD/samba.build.pathconfig', 'build/DTD/samba.entities', 'build/DTD/samba.build.version']
1211 bld
.SAMBA_GENERATOR(m
,
1215 dep_vars
=['SAMBA_MAN_XSL', 'SAMBA_EXPAND_XSL', 'SAMBA_CATALOG'],
1216 rule
='''XML_CATALOG_FILES="${SAMBA_CATALOGS}"
1217 export XML_CATALOG_FILES
1218 ${XSLTPROC} --xinclude --stringparam noreference 0 -o ${TGT}.xml --nonet ${SAMBA_EXPAND_XSL} ${SRC[0].abspath(env)}
1219 ${XSLTPROC} --nonet -o ${TGT} ${SAMBA_MAN_XSL} ${TGT}.xml'''
1221 bld
.INSTALL_FILES('${MANDIR}/man%s' % m
[-1], m
, flat
=True)
1222 Build
.BuildContext
.SAMBAMANPAGES
= SAMBAMANPAGES
1224 @after('apply_link')
1226 def apply_bundle_remove_dynamiclib_patch(self
):
1227 if self
.env
['MACBUNDLE'] or getattr(self
,'mac_bundle',False):
1228 if not getattr(self
,'vnum',None):
1230 self
.env
['LINKFLAGS'].remove('-dynamiclib')
1231 self
.env
['LINKFLAGS'].remove('-single_module')