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
39 os
.environ
['PYTHONUNBUFFERED'] = '1'
41 if Context
.HEXVERSION
not in (0x2001a00,):
43 Please use the version of waf that comes with Samba, not
44 a system installed version. See http://wiki.samba.org/index.php/Waf
47 Alternatively, please run ./configure and make as usual. That will
48 call the right version of waf.''')
52 def SAMBA_BUILD_ENV(conf
):
53 '''create the samba build environment'''
54 conf
.env
.BUILD_DIRECTORY
= conf
.bldnode
.abspath()
55 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, LIB_PATH
))
56 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, LIB_PATH
, "private"))
57 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, "modules"))
58 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, "plugins"))
59 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, 'python/samba/dcerpc'))
60 # this allows all of the bin/shared and bin/python targets
61 # to be expressed in terms of build directory paths
62 mkdir_p(os
.path
.join(conf
.env
.BUILD_DIRECTORY
, 'default'))
63 for (source
, target
) in [('shared', 'shared'), ('modules', 'modules'), ('plugins', 'plugins'), ('python', 'python')]:
64 link_target
= os
.path
.join(conf
.env
.BUILD_DIRECTORY
, 'default/' + target
)
65 if not os
.path
.lexists(link_target
):
66 symlink('../' + source
, link_target
)
68 # get perl to put the blib files in the build directory
69 blib_bld
= os
.path
.join(conf
.env
.BUILD_DIRECTORY
, 'default/pidl/blib')
70 blib_src
= os
.path
.join(conf
.srcnode
.abspath(), 'pidl/blib')
71 mkdir_p(blib_bld
+ '/man1')
72 mkdir_p(blib_bld
+ '/man3')
73 if os
.path
.islink(blib_src
):
75 elif os
.path
.exists(blib_src
):
76 shutil
.rmtree(blib_src
)
79 def ADD_INIT_FUNCTION(bld
, subsystem
, target
, init_function
):
80 '''add an init_function to the list for a subsystem'''
81 if init_function
is None:
83 bld
.ASSERT(subsystem
is not None, "You must specify a subsystem for init_function '%s'" % init_function
)
84 cache
= LOCAL_CACHE(bld
, 'INIT_FUNCTIONS')
85 if subsystem
not in cache
:
87 cache
[subsystem
].append( { 'TARGET':target
, 'INIT_FUNCTION':init_function
} )
88 Build
.BuildContext
.ADD_INIT_FUNCTION
= ADD_INIT_FUNCTION
91 def generate_empty_file(task
):
92 task
.outputs
[0].write('')
95 #################################################################
96 def SAMBA_LIBRARY(bld
, libname
, source
,
101 public_headers_install
=True,
102 private_headers
=None,
110 external_library
=False,
113 autoproto_extra_source
='',
124 target_type
='LIBRARY',
129 orig_vscript_map
=None,
132 private_library
=False,
133 grouping_library
=False,
134 require_builtin_deps
=False,
135 provide_builtin_linking
=False,
137 force_unversioned
=False,
138 allow_undefined_symbols
=False,
139 allow_warnings
=False,
141 '''define a Samba library'''
144 # - LIBRARY: this can be used to link via -llibname
145 # - MODULE: this is module from SAMBA_MODULE()
146 # - PLUGIN: this is plugin for external consumers to be
147 # loaded via dlopen()
148 # - PYTHON: a python C binding library
150 if target_type
not in ['LIBRARY', 'MODULE', 'PLUGIN', 'PYTHON']:
151 raise Errors
.WafError("target_type[%s] not supported in SAMBA_LIBRARY('%s')" %
152 (target_type
, libname
))
154 if require_builtin_deps
:
155 # For now we only support require_builtin_deps only for libraries, plugins
156 if target_type
not in ['LIBRARY', 'PLUGIN']:
157 raise Errors
.WafError("target_type[%s] not supported SAMBA_LIBRARY('%s', require_builtin_deps=True)" %
158 (target_type
, libname
))
160 if private_library
and public_headers
:
161 raise Errors
.WafError("private library '%s' must not have public header files" %
164 if orig_vscript_map
and not private_library
:
165 raise Errors
.WafError("public library '%s' must not have orig_vscript_map" %
168 if orig_vscript_map
and abi_directory
:
169 raise Errors
.WafError("private library '%s' with orig_vscript_map must not have abi_directory" %
171 if orig_vscript_map
and abi_match
:
172 raise Errors
.WafError("private library '%s' with orig_vscript_map must not have abi_match" %
175 if force_unversioned
and private_library
:
176 raise Errors
.WafError("private library '%s': can't have force_unversioned=True" %
179 if force_unversioned
and realname
is None:
180 raise Errors
.WafError("library '%s': force_unversioned=True needs realname too" %
183 if LIB_MUST_BE_PRIVATE(bld
, libname
) and target_type
not in ['PLUGIN']:
184 private_library
= True
186 if force_unversioned
:
187 private_library
= False
190 SET_TARGET_TYPE(bld
, libname
, 'DISABLED')
193 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
195 source
= bld
.SUBDIR(subdir
, source
)
197 # remember empty libraries, so we can strip the dependencies
198 if ((source
== '') or (source
== [])):
199 if deps
== '' and public_deps
== '':
200 SET_TARGET_TYPE(bld
, libname
, 'EMPTY')
202 empty_c
= libname
+ '.empty.c'
203 bld
.SAMBA_GENERATOR('%s_empty_c' % libname
,
204 rule
=generate_empty_file
,
208 samba_deps
= deps
+ ' ' + public_deps
209 samba_deps
= TO_LIST(samba_deps
)
211 if BUILTIN_LIBRARY(bld
, libname
):
212 builtin_target
= libname
+ '.builtin.objlist'
213 builtin_cflags_end
= '-D_PUBLIC_=_PRIVATE_'
214 empty_target
= libname
217 if provide_builtin_linking
:
218 builtin_target
= libname
+ '.builtin.objlist'
219 builtin_cflags_end
= '-D_PUBLIC_=_PRIVATE_'
221 builtin_target
= None
223 obj_target
= libname
+ '.objlist'
224 if require_builtin_deps
:
225 # hide the builtin deps from the callers
226 samba_deps
= TO_LIST('')
227 dep_target
= obj_target
229 if group
== 'libraries':
230 subsystem_group
= 'main'
232 subsystem_group
= group
234 # first create a target for building the object files for this library
235 # by separating in this way, we avoid recompiling the C files
236 # separately for the install library and the build library
238 __t
= __SAMBA_SUBSYSTEM_BUILTIN(bld
, builtin_target
, source
,
240 public_deps
=public_deps
,
242 header_path
=header_path
,
243 builtin_cflags
=builtin_cflags
,
244 builtin_cflags_end
=builtin_cflags_end
,
246 depends_on
=depends_on
,
247 local_include
=local_include
,
248 global_include
=global_include
,
249 allow_warnings
=allow_warnings
)
250 builtin_subsystem
= __t
252 builtin_subsystem
= None
254 bld
.SAMBA_SUBSYSTEM(obj_target
,
257 public_deps
= public_deps
,
259 public_headers
= public_headers
,
260 public_headers_install
= public_headers_install
,
261 private_headers
= private_headers
,
262 header_path
= header_path
,
264 cflags_end
= cflags_end
,
265 group
= subsystem_group
,
266 autoproto
= autoproto
,
267 autoproto_extra_source
=autoproto_extra_source
,
268 depends_on
= depends_on
,
269 hide_symbols
= hide_symbols
,
270 allow_warnings
= allow_warnings
,
273 local_include
= local_include
,
274 __require_builtin_deps
=require_builtin_deps
,
275 global_include
= global_include
)
277 et
= bld
.SAMBA_SUBSYSTEM(empty_target
,
280 __require_builtin_deps
=True)
281 et
.samba_builtin_subsystem
= builtin_subsystem
283 if BUILTIN_LIBRARY(bld
, libname
):
286 if not SET_TARGET_TYPE(bld
, libname
, target_type
):
289 # the library itself will depend on that object target
290 samba_deps
.append(dep_target
)
292 realname
= bld
.map_shlib_extension(realname
, python
=(target_type
=='PYTHON'))
293 link_name
= bld
.map_shlib_extension(link_name
, python
=(target_type
=='PYTHON'))
295 # we don't want any public libraries without version numbers
296 if (not private_library
and target_type
!= 'PYTHON' and not realname
):
297 if vnum
is None and soname
is None:
298 raise Errors
.WafError("public library '%s' must have a vnum" %
301 raise Errors
.WafError("public library '%s' must have pkg-config file" %
303 if public_headers
is None:
304 raise Errors
.WafError("public library '%s' must have header files" %
309 if bundled_name
is not None:
311 elif target_type
== 'PYTHON' or realname
or not private_library
:
312 bundled_name
= libname
.replace('_', '-')
314 assert (private_library
is True and realname
is None)
315 bundled_name
= PRIVATE_NAME(bld
, libname
.replace('_', '-'))
318 ldflags
= TO_LIST(ldflags
)
319 if bld
.env
['ENABLE_RELRO'] is True:
320 ldflags
.extend(TO_LIST('-Wl,-z,relro,-z,now'))
322 features
= 'c cshlib symlink_lib install_lib'
326 features
+= ' pyembed'
329 features
+= ' abi_check'
331 if pyembed
and bld
.env
['PYTHON_SO_ABI_FLAG']:
332 # For ABI checking, we don't care about the Python version.
333 # Remove the Python ABI tag (e.g. ".cpython-35m")
334 abi_flag
= bld
.env
['PYTHON_SO_ABI_FLAG']
336 version_libname
= libname
.replace(abi_flag
, replacement
)
338 version_libname
= libname
341 if bld
.env
.HAVE_LD_VERSION_SCRIPT
:
342 if force_unversioned
:
344 elif private_library
:
345 version
= bld
.env
.PRIVATE_VERSION
347 version
= "%s_%s" % (libname
, vnum
)
351 vscript
= "%s.vscript" % libname
353 bld
.VSCRIPT_MAP_PRIVATE(version_libname
, orig_vscript_map
, version
, vscript
)
355 bld
.ABI_VSCRIPT(version_libname
, abi_directory
, version
, vscript
,
356 abi_match
, private_library
)
357 fullname
= apply_pattern(bundled_name
, bld
.env
.cshlib_PATTERN
)
358 fullpath
= bld
.path
.find_or_declare(fullname
)
359 vscriptpath
= bld
.path
.find_or_declare(vscript
)
361 raise Errors
.WafError("unable to find fullpath for %s" % fullname
)
363 raise Errors
.WafError("unable to find vscript path for %s" % vscript
)
364 bld
.add_manual_dependency(fullpath
, vscriptpath
)
366 # also make the .inst file depend on the vscript
367 instname
= apply_pattern(bundled_name
+ '.inst', bld
.env
.cshlib_PATTERN
)
368 bld
.add_manual_dependency(bld
.path
.find_or_declare(instname
), bld
.path
.find_or_declare(vscript
))
369 vscript
= os
.path
.join(bld
.path
.abspath(bld
.env
), vscript
)
371 bld
.SET_BUILD_GROUP(group
)
375 target
= bundled_name
,
376 depends_on
= depends_on
,
377 samba_ldflags
= ldflags
,
378 samba_deps
= samba_deps
,
379 samba_includes
= includes
,
380 version_script
= vscript
,
381 version_libname
= version_libname
,
382 local_include
= local_include
,
383 global_include
= global_include
,
387 samba_inst_path
= install_path
,
389 samba_realname
= realname
,
390 samba_install
= install
,
391 abi_directory
= "%s/%s" % (bld
.path
.abspath(), abi_directory
),
392 abi_match
= abi_match
,
394 private_library
= private_library
,
395 grouping_library
=grouping_library
,
396 allow_undefined_symbols
=allow_undefined_symbols
,
397 samba_require_builtin_deps
=False,
398 samba_builtin_subsystem
=builtin_subsystem
,
401 if realname
and not link_name
:
402 link_name
= 'shared/%s' % realname
405 if 'waflib.extras.compat15' in sys
.modules
:
406 link_name
= 'default/' + link_name
407 t
.link_name
= link_name
409 if pc_files
is not None and not private_library
:
411 bld
.PKG_CONFIG_FILES(pc_files
, vnum
=vnum
, extra_name
=bld
.env
['PYTHON_SO_ABI_FLAG'])
413 bld
.PKG_CONFIG_FILES(pc_files
, vnum
=vnum
)
415 if (manpages
is not None and 'XSLTPROC_MANPAGES' in bld
.env
and
416 bld
.env
['XSLTPROC_MANPAGES']):
417 bld
.MANPAGES(manpages
, install
)
420 Build
.BuildContext
.SAMBA_LIBRARY
= SAMBA_LIBRARY
423 #################################################################
424 def SAMBA_BINARY(bld
, binname
, source
,
428 private_headers
=None,
436 use_global_deps
=True,
443 allow_warnings
=False,
452 '''define a Samba binary'''
456 if not bld
.CONFIG_GET('ENABLE_SELFTEST'):
460 SET_TARGET_TYPE(bld
, binname
, 'DISABLED')
463 # Fuzzing builds do not build normal binaries
464 # however we must build asn1compile etc
466 if not use_hostcc
and bld
.env
.enable_fuzzing
!= fuzzer
:
467 SET_TARGET_TYPE(bld
, binname
, 'DISABLED')
473 ldflags
= bld
.env
['FUZZ_TARGET_LDFLAGS']
475 if not SET_TARGET_TYPE(bld
, binname
, 'BINARY'):
478 features
= 'c cprogram symlink_bin install_bin'
480 features
+= ' pyembed'
482 obj_target
= binname
+ '.objlist'
484 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
486 source
= bld
.SUBDIR(subdir
, source
)
487 source
= unique_list(TO_LIST(source
))
489 if group
== 'binaries':
490 subsystem_group
= 'main'
491 elif group
== 'build_compilers':
492 subsystem_group
= 'compiler_libraries'
494 subsystem_group
= group
496 # only specify PIE flags for binaries
497 pie_cflags
= TO_LIST(cflags
)
498 pie_ldflags
= TO_LIST(ldflags
)
499 if bld
.env
['ENABLE_PIE'] is True:
500 pie_cflags
.extend(TO_LIST('-fPIE'))
501 pie_ldflags
.extend(TO_LIST('-pie'))
502 if bld
.env
['ENABLE_RELRO'] is True:
503 pie_ldflags
.extend(TO_LIST('-Wl,-z,relro,-z,now'))
505 # first create a target for building the object files for this binary
506 # by separating in this way, we avoid recompiling the C files
507 # separately for the install binary and the build binary
508 bld
.SAMBA_SUBSYSTEM(obj_target
,
513 cflags_end
= cflags_end
,
514 group
= subsystem_group
,
515 autoproto
= autoproto
,
516 subsystem_name
= subsystem_name
,
517 local_include
= local_include
,
518 global_include
= global_include
,
519 use_hostcc
= use_hostcc
,
521 allow_warnings
= allow_warnings
,
522 use_global_deps
= use_global_deps
)
524 bld
.SET_BUILD_GROUP(group
)
526 # the binary itself will depend on that object target
528 deps
.append(obj_target
)
535 samba_includes
= includes
,
536 local_include
= local_include
,
537 global_include
= global_include
,
538 samba_modules
= modules
,
540 samba_subsystem
= subsystem_name
,
542 samba_inst_path
= install_path
,
543 samba_install
= install
,
544 samba_ldflags
= pie_ldflags
547 if manpages
is not None and 'XSLTPROC_MANPAGES' in bld
.env
and bld
.env
['XSLTPROC_MANPAGES']:
548 bld
.MANPAGES(manpages
, install
)
550 Build
.BuildContext
.SAMBA_BINARY
= SAMBA_BINARY
553 #################################################################
554 def SAMBA_MODULE(bld
, modname
, source
,
559 module_init_name
='samba_init_module',
561 autoproto_extra_source
='',
564 internal_module
=True,
572 allow_undefined_symbols
=False,
573 allow_warnings
=False,
576 '''define a Samba module.'''
578 bld
.ASSERT(subsystem
, "You must specify a subsystem for SAMBA_MODULE(%s)" % modname
)
580 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
582 source
= bld
.SUBDIR(subdir
, source
)
584 if internal_module
or BUILTIN_LIBRARY(bld
, modname
):
585 # Do not create modules for disabled subsystems
586 if GET_TARGET_TYPE(bld
, subsystem
) == 'DISABLED':
588 bld
.SAMBA_SUBSYSTEM(modname
, source
,
592 autoproto_extra_source
=autoproto_extra_source
,
594 cflags_end
=cflags_end
,
595 local_include
=local_include
,
596 global_include
=global_include
,
597 allow_warnings
=allow_warnings
,
600 bld
.ADD_INIT_FUNCTION(subsystem
, modname
, init_function
)
604 SET_TARGET_TYPE(bld
, modname
, 'DISABLED')
607 # Do not create modules for disabled subsystems
608 if GET_TARGET_TYPE(bld
, subsystem
) == 'DISABLED':
612 deps
+= ' ' + subsystem
613 while realname
.startswith("lib"+subsystem
+"_"):
614 realname
= realname
[len("lib"+subsystem
+"_"):]
615 while realname
.startswith(subsystem
+"_"):
616 realname
= realname
[len(subsystem
+"_"):]
618 build_name
= "%s_module_%s" % (subsystem
, realname
)
620 realname
= bld
.make_libname(realname
)
621 while realname
.startswith("lib"):
622 realname
= realname
[len("lib"):]
624 build_link_name
= "modules/%s/%s" % (subsystem
, realname
)
627 cflags
+= " -D%s=%s" % (init_function
, module_init_name
)
629 bld
.SAMBA_LIBRARY(modname
,
634 cflags_end
=cflags_end
,
636 autoproto
= autoproto
,
637 local_include
=local_include
,
638 global_include
=global_include
,
640 bundled_name
=build_name
,
641 link_name
=build_link_name
,
642 install_path
="${MODULESDIR}/%s" % subsystem
,
645 allow_undefined_symbols
=allow_undefined_symbols
,
646 allow_warnings
=allow_warnings
,
647 private_library
=True,
652 Build
.BuildContext
.SAMBA_MODULE
= SAMBA_MODULE
654 #################################################################
655 def SAMBA_PLUGIN(bld
, pluginname
, source
,
668 autoproto_extra_source
='',
672 require_builtin_deps
=True,
673 allow_undefined_symbols
=False,
675 '''define an external plugin.'''
677 bld
.ASSERT(realname
, "You must specify a realname for SAMBA_PLUGIN(%s)" % pluginname
)
679 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
681 source
= bld
.SUBDIR(subdir
, source
)
683 build_name
= "_plugin_%s" % (pluginname
)
684 build_link_name
= "plugins/%s" % (realname
)
686 bld
.SAMBA_LIBRARY(pluginname
,
688 bundled_name
=build_name
,
689 link_name
=build_link_name
,
690 target_type
='PLUGIN',
699 autoproto_extra_source
=autoproto_extra_source
,
700 local_include
=local_include
,
701 global_include
=global_include
,
704 install_path
=install_path
,
707 require_builtin_deps
=require_builtin_deps
,
708 builtin_cflags
=cflags
,
711 public_headers_install
=False,
713 allow_undefined_symbols
=allow_undefined_symbols
,
714 allow_warnings
=False,
716 Build
.BuildContext
.SAMBA_PLUGIN
= SAMBA_PLUGIN
718 def __SAMBA_SUBSYSTEM_BUILTIN(bld
, builtin_target
, source
,
723 public_headers_install
=True,
724 private_headers
=None,
727 builtin_cflags_end
=None,
730 autoproto_extra_source
='',
734 allow_warnings
=False):
736 bld
.ASSERT(builtin_target
.endswith('.builtin.objlist'),
737 "builtin_target[%s] does not end with '.builtin.objlist'" %
739 return bld
.SAMBA_SUBSYSTEM(builtin_target
, source
,
741 public_deps
=public_deps
,
743 public_headers
=public_headers
,
744 public_headers_install
=public_headers_install
,
745 private_headers
=private_headers
,
746 header_path
=header_path
,
747 cflags
=builtin_cflags
,
748 cflags_end
=builtin_cflags_end
,
751 target_type
='BUILTIN',
753 autoproto_extra_source
=autoproto_extra_source
,
754 depends_on
=depends_on
,
755 local_include
=local_include
,
756 global_include
=global_include
,
757 allow_warnings
=allow_warnings
,
758 __require_builtin_deps
=True)
760 #################################################################
761 def SAMBA_SUBSYSTEM(bld
, modname
, source
,
767 public_headers_install
=True,
768 private_headers
=None,
773 target_type
='SUBSYSTEM',
774 init_function_sentinel
=None,
776 autoproto_extra_source
='',
779 local_include_first
=True,
784 use_global_deps
=True,
788 __require_builtin_deps
=False,
789 provide_builtin_linking
=False,
791 allow_warnings
=False,
794 '''define a Samba subsystem'''
797 # - SUBSYSTEM: a normal subsystem from SAMBA_SUBSYSTEM()
798 # - BUILTIN: a hidden subsystem from __SAMBA_SUBSYSTEM_BUILTIN()
799 if target_type
not in ['SUBSYSTEM', 'BUILTIN']:
800 raise Errors
.WafError("target_type[%s] not supported in SAMBA_SUBSYSTEM('%s')" %
801 (target_type
, modname
))
804 SET_TARGET_TYPE(bld
, modname
, 'DISABLED')
807 # remember empty subsystems, so we can strip the dependencies
808 if ((source
== '') or (source
== [])):
809 if not __force_empty
and deps
== '' and public_deps
== '':
810 SET_TARGET_TYPE(bld
, modname
, 'EMPTY')
812 empty_c
= modname
+ '.empty.c'
813 bld
.SAMBA_GENERATOR('%s_empty_c' % modname
,
814 rule
=generate_empty_file
,
818 if not SET_TARGET_TYPE(bld
, modname
, target_type
):
821 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
823 source
= bld
.SUBDIR(subdir
, source
)
824 source
= unique_list(TO_LIST(source
))
826 deps
+= ' ' + public_deps
828 bld
.SET_BUILD_GROUP(group
)
834 features
+= ' pyembed'
840 samba_cflags
= CURRENT_CFLAGS(bld
, modname
, cflags
,
841 allow_warnings
=allow_warnings
,
842 use_hostcc
=use_hostcc
,
843 hide_symbols
=hide_symbols
),
844 depends_on
= depends_on
,
845 samba_deps
= TO_LIST(deps
),
846 samba_includes
= includes
,
847 local_include
= local_include
,
848 local_include_first
= local_include_first
,
849 global_include
= global_include
,
850 samba_subsystem
= subsystem_name
,
851 samba_use_hostcc
= use_hostcc
,
852 samba_use_global_deps
= use_global_deps
,
853 samba_require_builtin_deps
= __require_builtin_deps
,
854 samba_builtin_subsystem
= None,
857 if cflags_end
is not None:
858 t
.samba_cflags
.extend(TO_LIST(cflags_end
))
860 if autoproto
is not None:
861 bld
.SAMBA_AUTOPROTO(autoproto
, source
+ TO_LIST(autoproto_extra_source
))
862 if public_headers
is not None:
863 bld
.PUBLIC_HEADERS(public_headers
, header_path
=header_path
,
864 public_headers_install
=public_headers_install
)
866 if provide_builtin_linking
:
869 raise Errors
.WafError("subsystem[%s] provide_builtin_linking=True " +
870 "not allowed with use_hostcc=True" %
874 raise Errors
.WafError("subsystem[%s] provide_builtin_linking=True " +
875 "not allowed with pyext=True nor pyembed=True" %
878 if __require_builtin_deps
:
879 raise Errors
.WafError("subsystem[%s] provide_builtin_linking=True " +
880 "not allowed with __require_builtin_deps=True" %
883 builtin_target
= modname
+ '.builtin.objlist'
884 tbuiltin
= __SAMBA_SUBSYSTEM_BUILTIN(bld
, builtin_target
, source
,
886 public_deps
=public_deps
,
888 header_path
=header_path
,
889 builtin_cflags
=builtin_cflags
,
890 builtin_cflags_end
='-D_PUBLIC_=_PRIVATE_',
892 depends_on
=depends_on
,
893 local_include
=local_include
,
894 global_include
=global_include
,
895 allow_warnings
=allow_warnings
)
896 t
.samba_builtin_subsystem
= tbuiltin
901 Build
.BuildContext
.SAMBA_SUBSYSTEM
= SAMBA_SUBSYSTEM
904 def SAMBA_GENERATOR(bld
, name
, rule
, source
='', target
='',
905 group
='generators', enabled
=True,
907 public_headers_install
=True,
908 private_headers
=None,
913 '''A generic source generator target'''
917 if not SET_TARGET_TYPE(bld
, name
, 'GENERATOR'):
923 dep_vars
= TO_LIST(dep_vars
)
924 dep_vars
.append('ruledeps')
925 dep_vars
.append('SAMBA_GENERATOR_VARS')
927 shell
=isinstance(rule
, str)
929 # This ensures that if the command (executed in the shell) fails
930 # (returns non-zero), the build fails
932 rule
= "set -e; " + rule
934 bld
.SET_BUILD_GROUP(group
)
937 source
=bld
.EXPAND_VARIABLES(source
, vars=vars),
943 samba_type
='GENERATOR',
949 t
.env
.SAMBA_GENERATOR_VARS
= vars
954 if public_headers
is not None:
955 bld
.PUBLIC_HEADERS(public_headers
, header_path
=header_path
,
956 public_headers_install
=public_headers_install
)
958 Build
.BuildContext
.SAMBA_GENERATOR
= SAMBA_GENERATOR
963 def SETUP_BUILD_GROUPS(bld
):
964 '''setup build groups used to ensure that the different build
965 phases happen consecutively'''
966 bld
.p_ln
= bld
.srcnode
# we do want to see all targets!
967 bld
.env
['USING_BUILD_GROUPS'] = True
968 bld
.add_group('setup')
969 bld
.add_group('generators')
970 bld
.add_group('hostcc_base_build_source')
971 bld
.add_group('hostcc_base_build_main')
972 bld
.add_group('hostcc_build_source')
973 bld
.add_group('hostcc_build_main')
974 bld
.add_group('vscripts')
975 bld
.add_group('base_libraries')
976 bld
.add_group('build_source')
977 bld
.add_group('prototypes')
978 bld
.add_group('headers')
979 bld
.add_group('main')
980 bld
.add_group('symbolcheck')
981 bld
.add_group('syslibcheck')
982 bld
.add_group('final')
983 Build
.BuildContext
.SETUP_BUILD_GROUPS
= SETUP_BUILD_GROUPS
986 def SET_BUILD_GROUP(bld
, group
):
987 '''set the current build group'''
988 if not 'USING_BUILD_GROUPS' in bld
.env
:
991 Build
.BuildContext
.SET_BUILD_GROUP
= SET_BUILD_GROUP
995 def SAMBA_SCRIPT(bld
, name
, pattern
, installdir
, installname
=None):
996 '''used to copy scripts from the source tree into the build directory
997 for use by selftest'''
999 source
= bld
.path
.ant_glob(pattern
, flat
=True)
1001 bld
.SET_BUILD_GROUP('build_source')
1002 for s
in TO_LIST(source
):
1004 if installname
is not None:
1006 target
= os
.path
.join(installdir
, iname
)
1007 tgtdir
= os
.path
.dirname(os
.path
.join(bld
.srcnode
.abspath(bld
.env
), '..', target
))
1009 link_src
= os
.path
.normpath(os
.path
.join(bld
.path
.abspath(), s
))
1010 link_dst
= os
.path
.join(tgtdir
, os
.path
.basename(iname
))
1011 if os
.path
.islink(link_dst
) and os
.readlink(link_dst
) == link_src
:
1013 if os
.path
.islink(link_dst
):
1015 Logs
.info("symlink: %s -> %s/%s" % (s
, installdir
, iname
))
1016 symlink(link_src
, link_dst
)
1017 Build
.BuildContext
.SAMBA_SCRIPT
= SAMBA_SCRIPT
1020 def copy_and_fix_python_path(task
):
1021 pattern
='sys.path.insert(0, "bin/python")'
1022 if task
.env
["PYTHONARCHDIR"] in sys
.path
and task
.env
["PYTHONDIR"] in sys
.path
:
1024 elif task
.env
["PYTHONARCHDIR"] == task
.env
["PYTHONDIR"]:
1025 replacement
="""sys.path.insert(0, "%s")""" % task
.env
["PYTHONDIR"]
1027 replacement
="""sys.path.insert(0, "%s")
1028 sys.path.insert(1, "%s")""" % (task
.env
["PYTHONARCHDIR"], task
.env
["PYTHONDIR"])
1030 if task
.env
["PYTHON"][0].startswith("/"):
1031 replacement_shebang
= "#!%s\n" % task
.env
["PYTHON"][0]
1033 replacement_shebang
= "#!/usr/bin/env %s\n" % task
.env
["PYTHON"][0]
1035 installed_location
=task
.outputs
[0].bldpath(task
.env
)
1036 source_file
= open(task
.inputs
[0].srcpath(task
.env
))
1037 installed_file
= open(installed_location
, 'w')
1039 for line
in source_file
:
1043 newline
= replacement_shebang
1044 elif pattern
in line
:
1045 newline
= line
.replace(pattern
, replacement
)
1046 installed_file
.write(newline
)
1048 installed_file
.close()
1049 os
.chmod(installed_location
, 0o755)
1052 def copy_and_fix_perl_path(task
):
1053 pattern
='use lib "$RealBin/lib";'
1056 if not task
.env
["PERL_LIB_INSTALL_DIR"] in task
.env
["PERL_INC"]:
1057 replacement
= 'use lib "%s";' % task
.env
["PERL_LIB_INSTALL_DIR"]
1059 if task
.env
["PERL"][0] == "/":
1060 replacement_shebang
= "#!%s\n" % task
.env
["PERL"]
1062 replacement_shebang
= "#!/usr/bin/env %s\n" % task
.env
["PERL"]
1064 installed_location
=task
.outputs
[0].bldpath(task
.env
)
1065 source_file
= open(task
.inputs
[0].srcpath(task
.env
))
1066 installed_file
= open(installed_location
, 'w')
1068 for line
in source_file
:
1070 if lineno
== 0 and task
.env
["PERL_SPECIFIED"] is True and line
[:2] == "#!":
1071 newline
= replacement_shebang
1072 elif pattern
in line
:
1073 newline
= line
.replace(pattern
, replacement
)
1074 installed_file
.write(newline
)
1076 installed_file
.close()
1077 os
.chmod(installed_location
, 0o755)
1081 def install_file(bld
, destdir
, file, chmod
=MODE_644
, flat
=False,
1082 python_fixup
=False, perl_fixup
=False,
1083 destname
=None, base_name
=None):
1084 '''install a file'''
1085 if not isinstance(file, str):
1086 file = file.abspath()
1087 destdir
= bld
.EXPAND_VARIABLES(destdir
)
1091 destname
= os
.path
.basename(destname
)
1092 dest
= os
.path
.join(destdir
, destname
)
1094 # fix the path python will use to find Samba modules
1095 inst_file
= file + '.inst'
1096 bld
.SAMBA_GENERATOR('python_%s' % destname
,
1097 rule
=copy_and_fix_python_path
,
1098 dep_vars
=["PYTHON","PYTHON_SPECIFIED","PYTHONDIR","PYTHONARCHDIR"],
1103 # fix the path perl will use to find Samba modules
1104 inst_file
= file + '.inst'
1105 bld
.SAMBA_GENERATOR('perl_%s' % destname
,
1106 rule
=copy_and_fix_perl_path
,
1107 dep_vars
=["PERL","PERL_SPECIFIED","PERL_LIB_INSTALL_DIR"],
1112 file = os
.path
.join(base_name
, file)
1113 bld
.install_as(dest
, file, chmod
=chmod
)
1116 def INSTALL_FILES(bld
, destdir
, files
, chmod
=MODE_644
, flat
=False,
1117 python_fixup
=False, perl_fixup
=False,
1118 destname
=None, base_name
=None):
1119 '''install a set of files'''
1120 for f
in TO_LIST(files
):
1121 install_file(bld
, destdir
, f
, chmod
=chmod
, flat
=flat
,
1122 python_fixup
=python_fixup
, perl_fixup
=perl_fixup
,
1123 destname
=destname
, base_name
=base_name
)
1124 Build
.BuildContext
.INSTALL_FILES
= INSTALL_FILES
1127 def INSTALL_WILDCARD(bld
, destdir
, pattern
, chmod
=MODE_644
, flat
=False,
1128 python_fixup
=False, exclude
=None, trim_path
=None):
1129 '''install a set of files matching a wildcard pattern'''
1130 files
=TO_LIST(bld
.path
.ant_glob(pattern
, flat
=True))
1134 files2
.append(os
.path
.relpath(f
, trim_path
))
1139 if fnmatch
.fnmatch(f
, exclude
):
1141 INSTALL_FILES(bld
, destdir
, files
, chmod
=chmod
, flat
=flat
,
1142 python_fixup
=python_fixup
, base_name
=trim_path
)
1143 Build
.BuildContext
.INSTALL_WILDCARD
= INSTALL_WILDCARD
1145 def INSTALL_DIR(bld
, path
, chmod
=0o755):
1146 """Install a directory if it doesn't exist, always set permissions."""
1151 destpath
= bld
.EXPAND_VARIABLES(path
)
1152 if Options
.options
.destdir
:
1153 destpath
= os
.path
.join(Options
.options
.destdir
, destpath
.lstrip(os
.sep
))
1155 if bld
.is_install
> 0:
1156 if not os
.path
.isdir(destpath
):
1158 Logs
.info('* create %s', destpath
)
1159 os
.makedirs(destpath
)
1160 os
.chmod(destpath
, chmod
)
1161 except OSError as e
:
1162 if not os
.path
.isdir(destpath
):
1163 raise Errors
.WafError("Cannot create the folder '%s' (error: %s)" % (path
, e
))
1164 Build
.BuildContext
.INSTALL_DIR
= INSTALL_DIR
1166 def INSTALL_DIRS(bld
, destdir
, dirs
, chmod
=0o755):
1167 '''install a set of directories'''
1168 destdir
= bld
.EXPAND_VARIABLES(destdir
)
1169 dirs
= bld
.EXPAND_VARIABLES(dirs
)
1170 for d
in TO_LIST(dirs
):
1171 INSTALL_DIR(bld
, os
.path
.join(destdir
, d
), chmod
)
1172 Build
.BuildContext
.INSTALL_DIRS
= INSTALL_DIRS
1175 def MANPAGES(bld
, manpages
, install
):
1176 '''build and install manual pages'''
1177 bld
.env
.MAN_XSL
= 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
1178 for m
in manpages
.split():
1180 bld
.SAMBA_GENERATOR(m
,
1184 rule
='${XSLTPROC} --xinclude -o ${TGT} --nonet ${MAN_XSL} ${SRC}'
1187 bld
.INSTALL_FILES('${MANDIR}/man%s' % m
[-1], m
, flat
=True)
1188 Build
.BuildContext
.MANPAGES
= MANPAGES
1190 def SAMBAMANPAGES(bld
, manpages
, extra_source
=None):
1191 '''build and install manual pages'''
1192 bld
.env
.SAMBA_EXPAND_XSL
= bld
.srcnode
.abspath() + '/docs-xml/xslt/expand-sambadoc.xsl'
1193 bld
.env
.SAMBA_MAN_XSL
= bld
.srcnode
.abspath() + '/docs-xml/xslt/man.xsl'
1194 bld
.env
.SAMBA_CATALOG
= bld
.bldnode
.abspath() + '/docs-xml/build/catalog.xml'
1195 bld
.env
.SAMBA_CATALOGS
= os
.getenv('XML_CATALOG_FILES', 'file:///etc/xml/catalog file:///usr/local/share/xml/catalog') + ' file://' + bld
.env
.SAMBA_CATALOG
1197 for m
in manpages
.split():
1198 source
= [m
+ '.xml']
1199 if extra_source
is not None:
1200 source
= [source
, extra_source
]
1201 # ${SRC[1]}, ${SRC[2]} and ${SRC[3]} are not referenced in the
1202 # SAMBA_GENERATOR but trigger the dependency calculation so
1203 # ensures that manpages are rebuilt when these change.
1204 source
+= ['build/DTD/samba.build.pathconfig', 'build/DTD/samba.entities', 'build/DTD/samba.build.version']
1205 bld
.SAMBA_GENERATOR(m
,
1209 dep_vars
=['SAMBA_MAN_XSL', 'SAMBA_EXPAND_XSL', 'SAMBA_CATALOG'],
1210 rule
='''XML_CATALOG_FILES="${SAMBA_CATALOGS}"
1211 export XML_CATALOG_FILES
1212 ${XSLTPROC} --xinclude --stringparam noreference 0 -o ${TGT}.xml --nonet ${SAMBA_EXPAND_XSL} ${SRC[0].abspath(env)}
1213 ${XSLTPROC} --nonet -o ${TGT} ${SAMBA_MAN_XSL} ${TGT}.xml'''
1215 bld
.INSTALL_FILES('${MANDIR}/man%s' % m
[-1], m
, flat
=True)
1216 Build
.BuildContext
.SAMBAMANPAGES
= SAMBAMANPAGES
1218 @after('apply_link')
1220 def apply_bundle_remove_dynamiclib_patch(self
):
1221 if self
.env
['MACBUNDLE'] or getattr(self
,'mac_bundle',False):
1222 if not getattr(self
,'vnum',None):
1224 self
.env
['LINKFLAGS'].remove('-dynamiclib')
1225 self
.env
['LINKFLAGS'].remove('-single_module')