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_rust
import *
23 from samba_bundled
import *
24 from samba_third_party
import *
27 import samba_conftests
41 os
.environ
['PYTHONUNBUFFERED'] = '1'
43 if Context
.HEXVERSION
not in (0x2001a00,):
45 Please use the version of waf that comes with Samba, not
46 a system installed version. See http://wiki.samba.org/index.php/Waf
49 Alternatively, please run ./configure and make as usual. That will
50 call the right version of waf.''')
54 def SAMBA_BUILD_ENV(conf
):
55 '''create the samba build environment'''
56 conf
.env
.BUILD_DIRECTORY
= conf
.bldnode
.abspath()
57 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, LIB_PATH
))
58 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, LIB_PATH
, "private"))
59 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, "modules"))
60 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, "plugins"))
61 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, 'python/samba/dcerpc'))
62 # this allows all of the bin/shared and bin/python targets
63 # to be expressed in terms of build directory paths
64 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, 'default'))
65 for (source
, target
) in [('shared', 'shared'), ('modules', 'modules'), ('plugins', 'plugins'), ('python', 'python')]:
66 link_target
= os
.path
.join(conf
.env
.BUILD_DIRECTORY
, 'default/' + target
)
67 if not os
.path
.lexists(link_target
):
68 symlink('../' + source
, link_target
)
70 # get perl to put the blib files in the build directory
71 blib_bld
= os
.path
.join(conf
.env
.BUILD_DIRECTORY
, 'default/pidl/blib')
72 blib_src
= os
.path
.join(conf
.srcnode
.abspath(), 'pidl/blib')
73 mkdir_p(blib_bld
+ '/man1')
74 mkdir_p(blib_bld
+ '/man3')
75 if os
.path
.islink(blib_src
):
77 elif os
.path
.exists(blib_src
):
78 shutil
.rmtree(blib_src
)
81 def ADD_INIT_FUNCTION(bld
, subsystem
, target
, init_function
):
82 '''add an init_function to the list for a subsystem'''
83 if init_function
is None:
85 bld
.ASSERT(subsystem
is not None, "You must specify a subsystem for init_function '%s'" % init_function
)
86 cache
= LOCAL_CACHE(bld
, 'INIT_FUNCTIONS')
87 if subsystem
not in cache
:
89 cache
[subsystem
].append( { 'TARGET':target
, 'INIT_FUNCTION':init_function
} )
90 Build
.BuildContext
.ADD_INIT_FUNCTION
= ADD_INIT_FUNCTION
93 def generate_empty_file(task
):
94 task
.outputs
[0].write('')
97 #################################################################
98 def SAMBA_LIBRARY(bld
, libname
, source
,
103 public_headers_install
=True,
104 private_headers
=None,
112 external_library
=False,
115 autoproto_extra_source
='',
126 target_type
='LIBRARY',
131 orig_vscript_map
=None,
134 private_library
=False,
135 grouping_library
=False,
136 require_builtin_deps
=False,
137 provide_builtin_linking
=False,
139 force_unversioned
=False,
140 allow_undefined_symbols
=False,
141 allow_warnings
=False,
143 '''define a Samba library'''
146 # - LIBRARY: this can be used to link via -llibname
147 # - MODULE: this is module from SAMBA_MODULE()
148 # - PLUGIN: this is plugin for external consumers to be
149 # loaded via dlopen()
150 # - PYTHON: a python C binding library
152 if target_type
not in ['LIBRARY', 'MODULE', 'PLUGIN', 'PYTHON']:
153 raise Errors
.WafError("target_type[%s] not supported in SAMBA_LIBRARY('%s')" %
154 (target_type
, libname
))
156 if require_builtin_deps
:
157 # For now we only support require_builtin_deps only for libraries, plugins
158 if target_type
not in ['LIBRARY', 'PLUGIN']:
159 raise Errors
.WafError("target_type[%s] not supported SAMBA_LIBRARY('%s', require_builtin_deps=True)" %
160 (target_type
, libname
))
162 if private_library
and public_headers
:
163 raise Errors
.WafError("private library '%s' must not have public header files" %
166 if orig_vscript_map
and not private_library
:
167 raise Errors
.WafError("public library '%s' must not have orig_vscript_map" %
170 if orig_vscript_map
and abi_directory
:
171 raise Errors
.WafError("private library '%s' with orig_vscript_map must not have abi_directory" %
173 if orig_vscript_map
and abi_match
:
174 raise Errors
.WafError("private library '%s' with orig_vscript_map must not have abi_match" %
177 if force_unversioned
and private_library
:
178 raise Errors
.WafError("private library '%s': can't have force_unversioned=True" %
181 if force_unversioned
and realname
is None:
182 raise Errors
.WafError("library '%s': force_unversioned=True needs realname too" %
185 if LIB_MUST_BE_PRIVATE(bld
, libname
) and target_type
not in ['PLUGIN']:
186 private_library
= True
187 public_headers_install
= False
189 if force_unversioned
:
190 private_library
= False
193 SET_TARGET_TYPE(bld
, libname
, 'DISABLED')
196 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
198 source
= bld
.SUBDIR(subdir
, source
)
200 # remember empty libraries, so we can strip the dependencies
201 if ((source
== '') or (source
== [])):
202 if deps
== '' and public_deps
== '':
203 SET_TARGET_TYPE(bld
, libname
, 'EMPTY')
205 empty_c
= libname
+ '.empty.c'
206 bld
.SAMBA_GENERATOR('%s_empty_c' % libname
,
207 rule
=generate_empty_file
,
211 samba_deps
= deps
+ ' ' + public_deps
212 samba_deps
= TO_LIST(samba_deps
)
214 if BUILTIN_LIBRARY(bld
, libname
):
215 builtin_target
= libname
+ '.builtin.objlist'
216 builtin_cflags_end
= '-D_PUBLIC_=_PRIVATE_'
217 empty_target
= libname
220 if provide_builtin_linking
:
221 builtin_target
= libname
+ '.builtin.objlist'
222 builtin_cflags_end
= '-D_PUBLIC_=_PRIVATE_'
224 builtin_target
= None
226 obj_target
= libname
+ '.objlist'
227 if require_builtin_deps
:
228 # hide the builtin deps from the callers
229 samba_deps
= TO_LIST('')
230 dep_target
= obj_target
232 if group
== 'libraries':
233 subsystem_group
= 'main'
235 subsystem_group
= group
237 # first create a target for building the object files for this library
238 # by separating in this way, we avoid recompiling the C files
239 # separately for the install library and the build library
241 __t
= __SAMBA_SUBSYSTEM_BUILTIN(bld
, builtin_target
, source
,
243 public_deps
=public_deps
,
245 header_path
=header_path
,
246 builtin_cflags
=builtin_cflags
,
247 builtin_cflags_end
=builtin_cflags_end
,
249 depends_on
=depends_on
,
250 local_include
=local_include
,
251 global_include
=global_include
,
252 allow_warnings
=allow_warnings
)
253 builtin_subsystem
= __t
255 builtin_subsystem
= None
257 bld
.SAMBA_SUBSYSTEM(obj_target
,
260 public_deps
= public_deps
,
262 public_headers
= public_headers
,
263 public_headers_install
= public_headers_install
,
264 private_headers
= private_headers
,
265 header_path
= header_path
,
267 cflags_end
= cflags_end
,
268 group
= subsystem_group
,
269 autoproto
= autoproto
,
270 autoproto_extra_source
=autoproto_extra_source
,
271 depends_on
= depends_on
,
272 hide_symbols
= hide_symbols
,
273 allow_warnings
= allow_warnings
,
276 local_include
= local_include
,
277 __require_builtin_deps
=require_builtin_deps
,
278 global_include
= global_include
)
280 et
= bld
.SAMBA_SUBSYSTEM(empty_target
,
283 __require_builtin_deps
=True)
284 et
.samba_builtin_subsystem
= builtin_subsystem
286 if BUILTIN_LIBRARY(bld
, libname
):
289 if not SET_TARGET_TYPE(bld
, libname
, target_type
):
292 # the library itself will depend on that object target
293 samba_deps
.append(dep_target
)
295 realname
= bld
.map_shlib_extension(realname
, python
=(target_type
=='PYTHON'))
296 link_name
= bld
.map_shlib_extension(link_name
, python
=(target_type
=='PYTHON'))
298 # we don't want any public libraries without version numbers
299 if (not private_library
and target_type
!= 'PYTHON' and not realname
):
300 if vnum
is None and soname
is None:
301 raise Errors
.WafError("public library '%s' must have a vnum" %
304 raise Errors
.WafError("public library '%s' must have pkg-config file" %
306 if public_headers
is None:
307 raise Errors
.WafError("public library '%s' must have header files" %
312 if bundled_name
is not None:
314 elif target_type
== 'PYTHON' or realname
or not private_library
:
315 bundled_name
= libname
.replace('_', '-')
317 assert (private_library
is True and realname
is None)
318 bundled_name
= PRIVATE_NAME(bld
, libname
.replace('_', '-'))
321 ldflags
= TO_LIST(ldflags
)
322 if bld
.env
['ENABLE_RELRO'] is True:
323 ldflags
.extend(TO_LIST('-Wl,-z,relro,-z,now'))
325 features
= 'c cshlib symlink_lib install_lib'
329 features
+= ' pyembed'
332 features
+= ' abi_check'
334 if pyembed
and bld
.env
['PYTHON_SO_ABI_FLAG']:
335 # For ABI checking, we don't care about the Python version.
336 # Remove the Python ABI tag (e.g. ".cpython-35m")
337 abi_flag
= bld
.env
['PYTHON_SO_ABI_FLAG']
339 version_libname
= libname
.replace(abi_flag
, replacement
)
341 version_libname
= libname
344 if bld
.env
.HAVE_LD_VERSION_SCRIPT
:
345 if force_unversioned
:
347 elif private_library
:
348 version
= bld
.env
.PRIVATE_VERSION
350 version
= "%s_%s" % (libname
, vnum
)
354 vscript
= "%s.vscript" % libname
356 bld
.VSCRIPT_MAP_PRIVATE(version_libname
, orig_vscript_map
, version
, vscript
)
358 bld
.ABI_VSCRIPT(version_libname
, abi_directory
, version
, vscript
,
359 abi_match
, private_library
)
360 fullname
= apply_pattern(bundled_name
, bld
.env
.cshlib_PATTERN
)
361 fullpath
= bld
.path
.find_or_declare(fullname
)
362 vscriptpath
= bld
.path
.find_or_declare(vscript
)
364 raise Errors
.WafError("unable to find fullpath for %s" % fullname
)
366 raise Errors
.WafError("unable to find vscript path for %s" % vscript
)
367 bld
.add_manual_dependency(fullpath
, vscriptpath
)
369 # also make the .inst file depend on the vscript
370 instname
= apply_pattern(bundled_name
+ '.inst', bld
.env
.cshlib_PATTERN
)
371 bld
.add_manual_dependency(bld
.path
.find_or_declare(instname
), bld
.path
.find_or_declare(vscript
))
372 vscript
= os
.path
.join(bld
.path
.abspath(bld
.env
), vscript
)
374 bld
.SET_BUILD_GROUP(group
)
378 target
= bundled_name
,
379 depends_on
= depends_on
,
380 samba_ldflags
= ldflags
,
381 samba_deps
= samba_deps
,
382 samba_includes
= includes
,
383 version_script
= vscript
,
384 version_libname
= version_libname
,
385 local_include
= local_include
,
386 global_include
= global_include
,
390 samba_inst_path
= install_path
,
392 samba_realname
= realname
,
393 samba_install
= install
,
394 abi_directory
= "%s/%s" % (bld
.path
.abspath(), abi_directory
),
395 abi_match
= abi_match
,
397 private_library
= private_library
,
398 grouping_library
=grouping_library
,
399 allow_undefined_symbols
=allow_undefined_symbols
,
400 samba_require_builtin_deps
=False,
401 samba_builtin_subsystem
=builtin_subsystem
,
404 if realname
and not link_name
:
405 link_name
= 'shared/%s' % realname
408 if 'waflib.extras.compat15' in sys
.modules
:
409 link_name
= 'default/' + link_name
410 t
.link_name
= link_name
412 if pc_files
is not None and not private_library
:
414 bld
.PKG_CONFIG_FILES(pc_files
, vnum
=vnum
, extra_name
=bld
.env
['PYTHON_SO_ABI_FLAG'])
416 bld
.PKG_CONFIG_FILES(pc_files
, vnum
=vnum
)
418 if (manpages
is not None and 'XSLTPROC_MANPAGES' in bld
.env
and
419 bld
.env
['XSLTPROC_MANPAGES']):
420 bld
.MANPAGES(manpages
, install
)
423 Build
.BuildContext
.SAMBA_LIBRARY
= SAMBA_LIBRARY
426 #################################################################
427 def SAMBA_BINARY(bld
, binname
, source
,
431 private_headers
=None,
439 use_global_deps
=True,
446 allow_warnings
=False,
455 '''define a Samba binary'''
459 if not bld
.CONFIG_GET('ENABLE_SELFTEST'):
463 SET_TARGET_TYPE(bld
, binname
, 'DISABLED')
466 # Fuzzing builds do not build normal binaries
467 # however we must build asn1compile etc
469 if not use_hostcc
and bld
.env
.enable_fuzzing
!= fuzzer
:
470 SET_TARGET_TYPE(bld
, binname
, 'DISABLED')
476 ldflags
= bld
.env
['FUZZ_TARGET_LDFLAGS']
478 if not SET_TARGET_TYPE(bld
, binname
, 'BINARY'):
481 features
= 'c cprogram symlink_bin install_bin'
483 features
+= ' pyembed'
485 obj_target
= binname
+ '.objlist'
487 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
489 source
= bld
.SUBDIR(subdir
, source
)
490 source
= unique_list(TO_LIST(source
))
492 if group
== 'binaries':
493 subsystem_group
= 'main'
494 elif group
== 'build_compilers':
495 subsystem_group
= 'compiler_libraries'
497 subsystem_group
= group
499 # only specify PIE flags for binaries
500 pie_cflags
= TO_LIST(cflags
)
501 pie_ldflags
= TO_LIST(ldflags
)
502 if bld
.env
['ENABLE_PIE'] is True:
503 pie_cflags
.extend(TO_LIST('-fPIE'))
504 pie_ldflags
.extend(TO_LIST('-pie'))
505 if bld
.env
['ENABLE_RELRO'] is True:
506 pie_ldflags
.extend(TO_LIST('-Wl,-z,relro,-z,now'))
508 # first create a target for building the object files for this binary
509 # by separating in this way, we avoid recompiling the C files
510 # separately for the install binary and the build binary
511 bld
.SAMBA_SUBSYSTEM(obj_target
,
516 cflags_end
= cflags_end
,
517 group
= subsystem_group
,
518 autoproto
= autoproto
,
519 subsystem_name
= subsystem_name
,
520 local_include
= local_include
,
521 global_include
= global_include
,
522 use_hostcc
= use_hostcc
,
524 allow_warnings
= allow_warnings
,
525 use_global_deps
= use_global_deps
)
527 bld
.SET_BUILD_GROUP(group
)
529 # the binary itself will depend on that object target
531 deps
.append(obj_target
)
538 samba_includes
= includes
,
539 local_include
= local_include
,
540 global_include
= global_include
,
541 samba_modules
= modules
,
543 samba_subsystem
= subsystem_name
,
545 samba_inst_path
= install_path
,
546 samba_install
= install
,
547 samba_ldflags
= pie_ldflags
550 if manpages
is not None and 'XSLTPROC_MANPAGES' in bld
.env
and bld
.env
['XSLTPROC_MANPAGES']:
551 bld
.MANPAGES(manpages
, install
)
553 Build
.BuildContext
.SAMBA_BINARY
= SAMBA_BINARY
556 #################################################################
557 def SAMBA_MODULE(bld
, modname
, source
,
562 module_init_name
='samba_init_module',
564 autoproto_extra_source
='',
567 internal_module
=True,
575 allow_undefined_symbols
=False,
576 allow_warnings
=False,
578 '''define a Samba module.'''
580 bld
.ASSERT(subsystem
, "You must specify a subsystem for SAMBA_MODULE(%s)" % modname
)
582 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
584 source
= bld
.SUBDIR(subdir
, source
)
586 if internal_module
or BUILTIN_LIBRARY(bld
, modname
):
587 # Do not create modules for disabled subsystems
588 if GET_TARGET_TYPE(bld
, subsystem
) == 'DISABLED':
590 bld
.SAMBA_SUBSYSTEM(modname
, source
,
594 autoproto_extra_source
=autoproto_extra_source
,
596 cflags_end
=cflags_end
,
597 local_include
=local_include
,
598 global_include
=global_include
,
599 allow_warnings
=allow_warnings
,
602 bld
.ADD_INIT_FUNCTION(subsystem
, modname
, init_function
)
606 SET_TARGET_TYPE(bld
, modname
, 'DISABLED')
609 # Do not create modules for disabled subsystems
610 if GET_TARGET_TYPE(bld
, subsystem
) == 'DISABLED':
614 deps
+= ' ' + subsystem
615 while realname
.startswith("lib"+subsystem
+"_"):
616 realname
= realname
[len("lib"+subsystem
+"_"):]
617 while realname
.startswith(subsystem
+"_"):
618 realname
= realname
[len(subsystem
+"_"):]
620 build_name
= "%s_module_%s" % (subsystem
, realname
)
622 realname
= bld
.make_libname(realname
)
623 while realname
.startswith("lib"):
624 realname
= realname
[len("lib"):]
626 build_link_name
= "modules/%s/%s" % (subsystem
, realname
)
628 if f
'{subsystem}_modules_install_dir' in bld
.env
:
629 install_path
= bld
.env
[f
'{subsystem}_modules_install_dir']
631 install_path
= "${MODULESDIR}/%s" % subsystem
634 cflags
+= " -D%s=%s" % (init_function
, module_init_name
)
636 bld
.SAMBA_LIBRARY(modname
,
641 cflags_end
=cflags_end
,
643 autoproto
= autoproto
,
644 local_include
=local_include
,
645 global_include
=global_include
,
647 bundled_name
=build_name
,
648 link_name
=build_link_name
,
649 install_path
=install_path
,
652 allow_undefined_symbols
=allow_undefined_symbols
,
653 allow_warnings
=allow_warnings
,
654 private_library
=True,
659 Build
.BuildContext
.SAMBA_MODULE
= SAMBA_MODULE
661 #################################################################
662 def SAMBA_PLUGIN(bld
, pluginname
, source
,
675 autoproto_extra_source
='',
679 require_builtin_deps
=True,
680 allow_undefined_symbols
=False,
682 '''define an external plugin.'''
684 bld
.ASSERT(realname
, "You must specify a realname for SAMBA_PLUGIN(%s)" % pluginname
)
686 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
688 source
= bld
.SUBDIR(subdir
, source
)
690 build_name
= "_plugin_%s" % (pluginname
)
691 build_link_name
= "plugins/%s" % (realname
)
693 bld
.SAMBA_LIBRARY(pluginname
,
695 bundled_name
=build_name
,
696 link_name
=build_link_name
,
697 target_type
='PLUGIN',
706 autoproto_extra_source
=autoproto_extra_source
,
707 local_include
=local_include
,
708 global_include
=global_include
,
711 install_path
=install_path
,
714 require_builtin_deps
=require_builtin_deps
,
715 builtin_cflags
=cflags
,
718 public_headers_install
=False,
720 allow_undefined_symbols
=allow_undefined_symbols
,
721 allow_warnings
=False,
723 Build
.BuildContext
.SAMBA_PLUGIN
= SAMBA_PLUGIN
725 def __SAMBA_SUBSYSTEM_BUILTIN(bld
, builtin_target
, source
,
730 public_headers_install
=True,
731 private_headers
=None,
734 builtin_cflags_end
=None,
737 autoproto_extra_source
='',
741 allow_warnings
=False):
743 bld
.ASSERT(builtin_target
.endswith('.builtin.objlist'),
744 "builtin_target[%s] does not end with '.builtin.objlist'" %
746 return bld
.SAMBA_SUBSYSTEM(builtin_target
, source
,
748 public_deps
=public_deps
,
750 public_headers
=public_headers
,
751 public_headers_install
=public_headers_install
,
752 private_headers
=private_headers
,
753 header_path
=header_path
,
754 cflags
=builtin_cflags
,
755 cflags_end
=builtin_cflags_end
,
758 target_type
='BUILTIN',
760 autoproto_extra_source
=autoproto_extra_source
,
761 depends_on
=depends_on
,
762 local_include
=local_include
,
763 global_include
=global_include
,
764 allow_warnings
=allow_warnings
,
765 __require_builtin_deps
=True)
767 #################################################################
768 def SAMBA_SUBSYSTEM(bld
, modname
, source
,
774 public_headers_install
=True,
775 private_headers
=None,
780 target_type
='SUBSYSTEM',
781 init_function_sentinel
=None,
783 autoproto_extra_source
='',
786 local_include_first
=True,
791 use_global_deps
=True,
795 __require_builtin_deps
=False,
796 provide_builtin_linking
=False,
798 allow_warnings
=False,
801 '''define a Samba subsystem'''
804 # - SUBSYSTEM: a normal subsystem from SAMBA_SUBSYSTEM()
805 # - BUILTIN: a hidden subsystem from __SAMBA_SUBSYSTEM_BUILTIN()
806 if target_type
not in ['SUBSYSTEM', 'BUILTIN']:
807 raise Errors
.WafError("target_type[%s] not supported in SAMBA_SUBSYSTEM('%s')" %
808 (target_type
, modname
))
811 SET_TARGET_TYPE(bld
, modname
, 'DISABLED')
814 # remember empty subsystems, so we can strip the dependencies
815 if ((source
== '') or (source
== [])):
816 if not __force_empty
and deps
== '' and public_deps
== '':
817 SET_TARGET_TYPE(bld
, modname
, 'EMPTY')
819 empty_c
= modname
+ '.empty.c'
820 bld
.SAMBA_GENERATOR('%s_empty_c' % modname
,
821 rule
=generate_empty_file
,
825 if not SET_TARGET_TYPE(bld
, modname
, target_type
):
828 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
830 source
= bld
.SUBDIR(subdir
, source
)
831 source
= unique_list(TO_LIST(source
))
833 deps
+= ' ' + public_deps
835 bld
.SET_BUILD_GROUP(group
)
841 features
+= ' pyembed'
847 samba_cflags
= CURRENT_CFLAGS(bld
, modname
, cflags
,
848 allow_warnings
=allow_warnings
,
849 use_hostcc
=use_hostcc
,
850 hide_symbols
=hide_symbols
),
851 depends_on
= depends_on
,
852 samba_deps
= TO_LIST(deps
),
853 samba_includes
= includes
,
854 local_include
= local_include
,
855 local_include_first
= local_include_first
,
856 global_include
= global_include
,
857 samba_subsystem
= subsystem_name
,
858 samba_use_hostcc
= use_hostcc
,
859 samba_use_global_deps
= use_global_deps
,
860 samba_require_builtin_deps
= __require_builtin_deps
,
861 samba_builtin_subsystem
= None,
864 if cflags_end
is not None:
865 t
.samba_cflags
.extend(TO_LIST(cflags_end
))
867 if autoproto
is not None:
868 bld
.SAMBA_AUTOPROTO(autoproto
, source
+ TO_LIST(autoproto_extra_source
))
869 if public_headers
is not None:
870 bld
.PUBLIC_HEADERS(public_headers
, header_path
=header_path
,
871 public_headers_install
=public_headers_install
)
873 if provide_builtin_linking
:
876 raise Errors
.WafError("subsystem[%s] provide_builtin_linking=True " +
877 "not allowed with use_hostcc=True" %
881 raise Errors
.WafError("subsystem[%s] provide_builtin_linking=True " +
882 "not allowed with pyext=True nor pyembed=True" %
885 if __require_builtin_deps
:
886 raise Errors
.WafError("subsystem[%s] provide_builtin_linking=True " +
887 "not allowed with __require_builtin_deps=True" %
890 builtin_target
= modname
+ '.builtin.objlist'
891 tbuiltin
= __SAMBA_SUBSYSTEM_BUILTIN(bld
, builtin_target
, source
,
893 public_deps
=public_deps
,
895 header_path
=header_path
,
896 builtin_cflags
=builtin_cflags
,
897 builtin_cflags_end
='-D_PUBLIC_=_PRIVATE_',
899 depends_on
=depends_on
,
900 local_include
=local_include
,
901 global_include
=global_include
,
902 allow_warnings
=allow_warnings
)
903 t
.samba_builtin_subsystem
= tbuiltin
908 Build
.BuildContext
.SAMBA_SUBSYSTEM
= SAMBA_SUBSYSTEM
911 def SAMBA_GENERATOR(bld
, name
, rule
, source
='', target
='',
912 group
='generators', enabled
=True,
914 public_headers_install
=True,
915 private_headers
=None,
920 '''A generic source generator target'''
924 if not SET_TARGET_TYPE(bld
, name
, 'GENERATOR'):
930 dep_vars
= TO_LIST(dep_vars
)
931 dep_vars
.append('ruledeps')
932 dep_vars
.append('SAMBA_GENERATOR_VARS')
934 shell
=isinstance(rule
, str)
936 # This ensures that if the command (executed in the shell) fails
937 # (returns non-zero), the build fails
939 rule
= "set -e; " + rule
941 bld
.SET_BUILD_GROUP(group
)
944 source
=bld
.EXPAND_VARIABLES(source
, vars=vars),
950 samba_type
='GENERATOR',
956 t
.env
.SAMBA_GENERATOR_VARS
= vars
961 if public_headers
is not None:
962 bld
.PUBLIC_HEADERS(public_headers
, header_path
=header_path
,
963 public_headers_install
=public_headers_install
)
965 Build
.BuildContext
.SAMBA_GENERATOR
= SAMBA_GENERATOR
970 def SETUP_BUILD_GROUPS(bld
):
971 '''setup build groups used to ensure that the different build
972 phases happen consecutively'''
973 bld
.p_ln
= bld
.srcnode
# we do want to see all targets!
974 bld
.env
['USING_BUILD_GROUPS'] = True
975 bld
.add_group('setup')
976 bld
.add_group('generators')
977 bld
.add_group('hostcc_base_build_source')
978 bld
.add_group('hostcc_base_build_main')
979 bld
.add_group('hostcc_build_source')
980 bld
.add_group('hostcc_build_main')
981 bld
.add_group('vscripts')
982 bld
.add_group('base_libraries')
983 bld
.add_group('build_source')
984 bld
.add_group('prototypes')
985 bld
.add_group('headers')
986 bld
.add_group('main')
987 bld
.add_group('symbolcheck')
988 bld
.add_group('syslibcheck')
989 bld
.add_group('final')
990 Build
.BuildContext
.SETUP_BUILD_GROUPS
= SETUP_BUILD_GROUPS
993 def SET_BUILD_GROUP(bld
, group
):
994 '''set the current build group'''
995 if not 'USING_BUILD_GROUPS' in bld
.env
:
998 Build
.BuildContext
.SET_BUILD_GROUP
= SET_BUILD_GROUP
1002 def SAMBA_SCRIPT(bld
, name
, pattern
, installdir
, installname
=None):
1003 '''used to copy scripts from the source tree into the build directory
1004 for use by selftest'''
1006 source
= bld
.path
.ant_glob(pattern
, flat
=True)
1008 bld
.SET_BUILD_GROUP('build_source')
1009 for s
in TO_LIST(source
):
1011 if installname
is not None:
1013 target
= os
.path
.join(installdir
, iname
)
1014 tgtdir
= os
.path
.dirname(os
.path
.join(bld
.srcnode
.abspath(bld
.env
), '..', target
))
1016 link_src
= os
.path
.normpath(os
.path
.join(bld
.path
.abspath(), s
))
1017 link_dst
= os
.path
.join(tgtdir
, os
.path
.basename(iname
))
1018 if os
.path
.islink(link_dst
) and os
.readlink(link_dst
) == link_src
:
1020 if os
.path
.islink(link_dst
):
1022 Logs
.info("symlink: %s -> %s/%s" % (s
, installdir
, iname
))
1023 symlink(link_src
, link_dst
)
1024 Build
.BuildContext
.SAMBA_SCRIPT
= SAMBA_SCRIPT
1027 def copy_and_fix_python_path(task
):
1028 pattern
='sys.path.insert(0, "bin/python")'
1029 if task
.env
["PYTHONARCHDIR"] in sys
.path
and task
.env
["PYTHONDIR"] in sys
.path
:
1031 elif task
.env
["PYTHONARCHDIR"] == task
.env
["PYTHONDIR"]:
1032 replacement
="""sys.path.insert(0, "%s")""" % task
.env
["PYTHONDIR"]
1034 replacement
="""sys.path.insert(0, "%s")
1035 sys.path.insert(1, "%s")""" % (task
.env
["PYTHONARCHDIR"], task
.env
["PYTHONDIR"])
1037 if task
.env
["PYTHON"][0].startswith("/"):
1038 replacement_shebang
= "#!%s\n" % task
.env
["PYTHON"][0]
1040 replacement_shebang
= "#!/usr/bin/env %s\n" % task
.env
["PYTHON"][0]
1042 installed_location
=task
.outputs
[0].bldpath(task
.env
)
1043 source_file
= open(task
.inputs
[0].srcpath(task
.env
))
1044 installed_file
= open(installed_location
, 'w')
1046 for line
in source_file
:
1050 newline
= replacement_shebang
1051 elif pattern
in line
:
1052 newline
= line
.replace(pattern
, replacement
)
1053 installed_file
.write(newline
)
1055 installed_file
.close()
1056 os
.chmod(installed_location
, 0o755)
1059 def copy_and_fix_perl_path(task
):
1060 pattern
='use lib "$RealBin/lib";'
1063 if not task
.env
["PERL_LIB_INSTALL_DIR"] in task
.env
["PERL_INC"]:
1064 replacement
= 'use lib "%s";' % task
.env
["PERL_LIB_INSTALL_DIR"]
1066 if task
.env
["PERL"][0] == "/":
1067 replacement_shebang
= "#!%s\n" % task
.env
["PERL"]
1069 replacement_shebang
= "#!/usr/bin/env %s\n" % task
.env
["PERL"]
1071 installed_location
=task
.outputs
[0].bldpath(task
.env
)
1072 source_file
= open(task
.inputs
[0].srcpath(task
.env
))
1073 installed_file
= open(installed_location
, 'w')
1075 for line
in source_file
:
1077 if lineno
== 0 and task
.env
["PERL_SPECIFIED"] is True and line
[:2] == "#!":
1078 newline
= replacement_shebang
1079 elif pattern
in line
:
1080 newline
= line
.replace(pattern
, replacement
)
1081 installed_file
.write(newline
)
1083 installed_file
.close()
1084 os
.chmod(installed_location
, 0o755)
1088 def install_file(bld
, destdir
, file, chmod
=MODE_644
, flat
=False,
1089 python_fixup
=False, perl_fixup
=False,
1090 destname
=None, base_name
=None):
1091 '''install a file'''
1092 if not isinstance(file, str):
1093 file = file.abspath()
1094 destdir
= bld
.EXPAND_VARIABLES(destdir
)
1098 destname
= os
.path
.basename(destname
)
1099 dest
= os
.path
.join(destdir
, destname
)
1101 # fix the path python will use to find Samba modules
1102 inst_file
= file + '.inst'
1103 bld
.SAMBA_GENERATOR('python_%s' % destname
,
1104 rule
=copy_and_fix_python_path
,
1105 dep_vars
=["PYTHON","PYTHON_SPECIFIED","PYTHONDIR","PYTHONARCHDIR"],
1110 # fix the path perl will use to find Samba modules
1111 inst_file
= file + '.inst'
1112 bld
.SAMBA_GENERATOR('perl_%s' % destname
,
1113 rule
=copy_and_fix_perl_path
,
1114 dep_vars
=["PERL","PERL_SPECIFIED","PERL_LIB_INSTALL_DIR"],
1119 file = os
.path
.join(base_name
, file)
1120 bld
.install_as(dest
, file, chmod
=chmod
)
1123 def INSTALL_FILES(bld
, destdir
, files
, chmod
=MODE_644
, flat
=False,
1124 python_fixup
=False, perl_fixup
=False,
1125 destname
=None, base_name
=None):
1126 '''install a set of files'''
1127 for f
in TO_LIST(files
):
1128 install_file(bld
, destdir
, f
, chmod
=chmod
, flat
=flat
,
1129 python_fixup
=python_fixup
, perl_fixup
=perl_fixup
,
1130 destname
=destname
, base_name
=base_name
)
1131 Build
.BuildContext
.INSTALL_FILES
= INSTALL_FILES
1134 def INSTALL_WILDCARD(bld
, destdir
, pattern
, chmod
=MODE_644
, flat
=False,
1135 python_fixup
=False, exclude
=None, trim_path
=None):
1136 '''install a set of files matching a wildcard pattern'''
1137 files
=TO_LIST(bld
.path
.ant_glob(pattern
, flat
=True))
1141 files2
.append(os
.path
.relpath(f
, trim_path
))
1146 if fnmatch
.fnmatch(f
, exclude
):
1148 INSTALL_FILES(bld
, destdir
, files
, chmod
=chmod
, flat
=flat
,
1149 python_fixup
=python_fixup
, base_name
=trim_path
)
1150 Build
.BuildContext
.INSTALL_WILDCARD
= INSTALL_WILDCARD
1152 def INSTALL_DIR(bld
, path
, chmod
=0o755):
1153 """Install a directory if it doesn't exist, always set permissions."""
1158 destpath
= bld
.EXPAND_VARIABLES(path
)
1159 if Options
.options
.destdir
:
1160 destpath
= os
.path
.join(Options
.options
.destdir
, destpath
.lstrip(os
.sep
))
1162 if bld
.is_install
> 0:
1163 if not os
.path
.isdir(destpath
):
1165 Logs
.info('* create %s', destpath
)
1166 os
.makedirs(destpath
)
1167 os
.chmod(destpath
, chmod
)
1168 except OSError as e
:
1169 if not os
.path
.isdir(destpath
):
1170 raise Errors
.WafError("Cannot create the folder '%s' (error: %s)" % (path
, e
))
1171 Build
.BuildContext
.INSTALL_DIR
= INSTALL_DIR
1173 def INSTALL_DIRS(bld
, destdir
, dirs
, chmod
=0o755):
1174 '''install a set of directories'''
1175 destdir
= bld
.EXPAND_VARIABLES(destdir
)
1176 dirs
= bld
.EXPAND_VARIABLES(dirs
)
1177 for d
in TO_LIST(dirs
):
1178 INSTALL_DIR(bld
, os
.path
.join(destdir
, d
), chmod
)
1179 Build
.BuildContext
.INSTALL_DIRS
= INSTALL_DIRS
1182 def MANPAGES(bld
, manpages
, install
):
1183 '''build and install manual pages'''
1184 bld
.env
.MAN_XSL
= 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
1185 for m
in manpages
.split():
1187 bld
.SAMBA_GENERATOR(m
,
1191 rule
='${XSLTPROC} --xinclude -o ${TGT} --nonet ${MAN_XSL} ${SRC}'
1194 bld
.INSTALL_FILES('${MANDIR}/man%s' % m
[-1], m
, flat
=True)
1195 Build
.BuildContext
.MANPAGES
= MANPAGES
1197 def SAMBAMANPAGES(bld
, manpages
, extra_source
=None):
1198 '''build and install manual pages'''
1199 bld
.env
.SAMBA_EXPAND_XSL
= bld
.srcnode
.abspath() + '/docs-xml/xslt/expand-sambadoc.xsl'
1200 bld
.env
.SAMBA_MAN_XSL
= bld
.srcnode
.abspath() + '/docs-xml/xslt/man.xsl'
1201 bld
.env
.SAMBA_CATALOG
= bld
.bldnode
.abspath() + '/docs-xml/build/catalog.xml'
1202 bld
.env
.SAMBA_CATALOGS
= os
.getenv('XML_CATALOG_FILES', 'file:///etc/xml/catalog file:///usr/local/share/xml/catalog') + ' file://' + bld
.env
.SAMBA_CATALOG
1204 for m
in manpages
.split():
1205 source
= [m
+ '.xml']
1206 if extra_source
is not None:
1207 source
= [source
, extra_source
]
1208 # ${SRC[1]}, ${SRC[2]} and ${SRC[3]} are not referenced in the
1209 # SAMBA_GENERATOR but trigger the dependency calculation so
1210 # ensures that manpages are rebuilt when these change.
1211 source
+= ['build/DTD/samba.build.pathconfig', 'build/DTD/samba.entities', 'build/DTD/samba.build.version']
1212 bld
.SAMBA_GENERATOR(m
,
1216 dep_vars
=['SAMBA_MAN_XSL', 'SAMBA_EXPAND_XSL', 'SAMBA_CATALOG'],
1217 rule
='''XML_CATALOG_FILES="${SAMBA_CATALOGS}"
1218 export XML_CATALOG_FILES
1219 ${XSLTPROC} --xinclude --stringparam noreference 0 -o ${TGT}.xml --nonet ${SAMBA_EXPAND_XSL} ${SRC[0].abspath(env)}
1220 ${XSLTPROC} --nonet -o ${TGT} ${SAMBA_MAN_XSL} ${TGT}.xml'''
1222 bld
.INSTALL_FILES('${MANDIR}/man%s' % m
[-1], m
, flat
=True)
1223 Build
.BuildContext
.SAMBAMANPAGES
= SAMBAMANPAGES
1225 @after('apply_link')
1227 def apply_bundle_remove_dynamiclib_patch(self
):
1228 if self
.env
['MACBUNDLE'] or getattr(self
,'mac_bundle',False):
1229 if not getattr(self
,'vnum',None):
1231 self
.env
['LINKFLAGS'].remove('-dynamiclib')
1232 self
.env
['LINKFLAGS'].remove('-single_module')