samba-tool: implement user getgroups command
[Samba.git] / buildtools / wafsamba / wafsamba.py
blob7827d3746545988d16e9ddd05f41e67e67dc09d1
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 *
24 import samba_cross
25 import samba_install
26 import samba_conftests
27 import samba_abi
28 import samba_headers
29 import generic_cc
30 import samba_dist
31 import samba_wildcard
32 import symbols
33 import pkgconfig
34 import configure_file
35 import samba_waf18
37 LIB_PATH="shared"
39 os.environ['PYTHONUNBUFFERED'] = '1'
41 if Context.HEXVERSION not in (0x2001200,):
42 Logs.error('''
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
45 for details.
47 Alternatively, please run ./configure and make as usual. That will
48 call the right version of waf.''')
49 sys.exit(1)
51 @conf
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, 'python/samba/dcerpc'))
59 # this allows all of the bin/shared and bin/python targets
60 # to be expressed in terms of build directory paths
61 mkdir_p(os.path.join(conf.env.BUILD_DIRECTORY, 'default'))
62 for (source, target) in [('shared', 'shared'), ('modules', 'modules'), ('python', 'python')]:
63 link_target = os.path.join(conf.env.BUILD_DIRECTORY, 'default/' + target)
64 if not os.path.lexists(link_target):
65 symlink('../' + source, link_target)
67 # get perl to put the blib files in the build directory
68 blib_bld = os.path.join(conf.env.BUILD_DIRECTORY, 'default/pidl/blib')
69 blib_src = os.path.join(conf.srcnode.abspath(), 'pidl/blib')
70 mkdir_p(blib_bld + '/man1')
71 mkdir_p(blib_bld + '/man3')
72 if os.path.islink(blib_src):
73 os.unlink(blib_src)
74 elif os.path.exists(blib_src):
75 shutil.rmtree(blib_src)
78 def ADD_INIT_FUNCTION(bld, subsystem, target, init_function):
79 '''add an init_function to the list for a subsystem'''
80 if init_function is None:
81 return
82 bld.ASSERT(subsystem is not None, "You must specify a subsystem for init_function '%s'" % init_function)
83 cache = LOCAL_CACHE(bld, 'INIT_FUNCTIONS')
84 if not subsystem in cache:
85 cache[subsystem] = []
86 cache[subsystem].append( { 'TARGET':target, 'INIT_FUNCTION':init_function } )
87 Build.BuildContext.ADD_INIT_FUNCTION = ADD_INIT_FUNCTION
90 def generate_empty_file(task):
91 task.outputs[0].write('')
92 return 0
94 #################################################################
95 def SAMBA_LIBRARY(bld, libname, source,
96 deps='',
97 public_deps='',
98 includes='',
99 public_headers=None,
100 public_headers_install=True,
101 private_headers=None,
102 header_path=None,
103 pc_files=None,
104 vnum=None,
105 soname=None,
106 cflags='',
107 cflags_end=None,
108 ldflags='',
109 external_library=False,
110 realname=None,
111 keep_underscore=False,
112 autoproto=None,
113 autoproto_extra_source='',
114 group='main',
115 depends_on='',
116 local_include=True,
117 global_include=True,
118 vars=None,
119 subdir=None,
120 install_path=None,
121 install=True,
122 pyembed=False,
123 pyext=False,
124 target_type='LIBRARY',
125 bundled_extension=False,
126 bundled_name=None,
127 link_name=None,
128 abi_directory=None,
129 abi_match=None,
130 hide_symbols=False,
131 manpages=None,
132 private_library=False,
133 grouping_library=False,
134 allow_undefined_symbols=False,
135 allow_warnings=False,
136 enabled=True):
137 '''define a Samba library'''
139 if private_library and public_headers:
140 raise Errors.WafError("private library '%s' must not have public header files" %
141 libname)
143 if LIB_MUST_BE_PRIVATE(bld, libname):
144 private_library = True
146 if not enabled:
147 SET_TARGET_TYPE(bld, libname, 'DISABLED')
148 return
150 source = bld.EXPAND_VARIABLES(source, vars=vars)
151 if subdir:
152 source = bld.SUBDIR(subdir, source)
154 # remember empty libraries, so we can strip the dependencies
155 if ((source == '') or (source == [])):
156 if deps == '' and public_deps == '':
157 SET_TARGET_TYPE(bld, libname, 'EMPTY')
158 return
159 empty_c = libname + '.empty.c'
160 bld.SAMBA_GENERATOR('%s_empty_c' % libname,
161 rule=generate_empty_file,
162 target=empty_c)
163 source=empty_c
165 if BUILTIN_LIBRARY(bld, libname):
166 obj_target = libname
167 else:
168 obj_target = libname + '.objlist'
170 if group == 'libraries':
171 subsystem_group = 'main'
172 else:
173 subsystem_group = group
175 # first create a target for building the object files for this library
176 # by separating in this way, we avoid recompiling the C files
177 # separately for the install library and the build library
178 bld.SAMBA_SUBSYSTEM(obj_target,
179 source = source,
180 deps = deps,
181 public_deps = public_deps,
182 includes = includes,
183 public_headers = public_headers,
184 public_headers_install = public_headers_install,
185 private_headers= private_headers,
186 header_path = header_path,
187 cflags = cflags,
188 cflags_end = cflags_end,
189 group = subsystem_group,
190 autoproto = autoproto,
191 autoproto_extra_source=autoproto_extra_source,
192 depends_on = depends_on,
193 hide_symbols = hide_symbols,
194 allow_warnings = allow_warnings,
195 pyembed = pyembed,
196 pyext = pyext,
197 local_include = local_include,
198 global_include = global_include)
200 if BUILTIN_LIBRARY(bld, libname):
201 return
203 if not SET_TARGET_TYPE(bld, libname, target_type):
204 return
206 # the library itself will depend on that object target
207 deps += ' ' + public_deps
208 deps = TO_LIST(deps)
209 deps.append(obj_target)
211 realname = bld.map_shlib_extension(realname, python=(target_type=='PYTHON'))
212 link_name = bld.map_shlib_extension(link_name, python=(target_type=='PYTHON'))
214 # we don't want any public libraries without version numbers
215 if (not private_library and target_type != 'PYTHON' and not realname):
216 if vnum is None and soname is None:
217 raise Errors.WafError("public library '%s' must have a vnum" %
218 libname)
219 if pc_files is None:
220 raise Errors.WafError("public library '%s' must have pkg-config file" %
221 libname)
222 if public_headers is None:
223 raise Errors.WafError("public library '%s' must have header files" %
224 libname)
226 if bundled_name is not None:
227 pass
228 elif target_type == 'PYTHON' or realname or not private_library:
229 if keep_underscore:
230 bundled_name = libname
231 else:
232 bundled_name = libname.replace('_', '-')
233 else:
234 assert (private_library == True and realname is None)
235 if abi_directory or vnum or soname:
236 bundled_extension=True
237 bundled_name = PRIVATE_NAME(bld, libname.replace('_', '-'),
238 bundled_extension, private_library)
240 ldflags = TO_LIST(ldflags)
241 if bld.env['ENABLE_RELRO'] is True:
242 ldflags.extend(TO_LIST('-Wl,-z,relro,-z,now'))
244 features = 'c cshlib symlink_lib install_lib'
245 if pyext:
246 features += ' pyext'
247 if pyembed:
248 features += ' pyembed'
250 if abi_directory:
251 features += ' abi_check'
253 if pyembed and bld.env['PYTHON_SO_ABI_FLAG']:
254 # For ABI checking, we don't care about the Python version.
255 # Remove the Python ABI tag (e.g. ".cpython-35m")
256 abi_flag = bld.env['PYTHON_SO_ABI_FLAG']
257 replacement = ''
258 version_libname = libname.replace(abi_flag, replacement)
259 else:
260 version_libname = libname
262 vscript = None
263 if bld.env.HAVE_LD_VERSION_SCRIPT:
264 if private_library:
265 version = "%s_%s" % (Context.g_module.APPNAME, Context.g_module.VERSION)
266 elif vnum:
267 version = "%s_%s" % (libname, vnum)
268 else:
269 version = None
270 if version:
271 vscript = "%s.vscript" % libname
272 bld.ABI_VSCRIPT(version_libname, abi_directory, version, vscript,
273 abi_match)
274 fullname = apply_pattern(bundled_name, bld.env.cshlib_PATTERN)
275 fullpath = bld.path.find_or_declare(fullname)
276 vscriptpath = bld.path.find_or_declare(vscript)
277 if not fullpath:
278 raise Errors.WafError("unable to find fullpath for %s" % fullname)
279 if not vscriptpath:
280 raise Errors.WafError("unable to find vscript path for %s" % vscript)
281 bld.add_manual_dependency(fullpath, vscriptpath)
282 if bld.is_install:
283 # also make the .inst file depend on the vscript
284 instname = apply_pattern(bundled_name + '.inst', bld.env.cshlib_PATTERN)
285 bld.add_manual_dependency(bld.path.find_or_declare(instname), bld.path.find_or_declare(vscript))
286 vscript = os.path.join(bld.path.abspath(bld.env), vscript)
288 bld.SET_BUILD_GROUP(group)
289 t = bld(
290 features = features,
291 source = [],
292 target = bundled_name,
293 depends_on = depends_on,
294 samba_ldflags = ldflags,
295 samba_deps = deps,
296 samba_includes = includes,
297 version_script = vscript,
298 version_libname = version_libname,
299 local_include = local_include,
300 global_include = global_include,
301 vnum = vnum,
302 soname = soname,
303 install_path = None,
304 samba_inst_path = install_path,
305 name = libname,
306 samba_realname = realname,
307 samba_install = install,
308 abi_directory = "%s/%s" % (bld.path.abspath(), abi_directory),
309 abi_match = abi_match,
310 private_library = private_library,
311 grouping_library=grouping_library,
312 allow_undefined_symbols=allow_undefined_symbols
315 if realname and not link_name:
316 link_name = 'shared/%s' % realname
318 if link_name:
319 if 'waflib.extras.compat15' in sys.modules:
320 link_name = 'default/' + link_name
321 t.link_name = link_name
323 if pc_files is not None and not private_library:
324 if pyembed:
325 bld.PKG_CONFIG_FILES(pc_files, vnum=vnum, extra_name=bld.env['PYTHON_SO_ABI_FLAG'])
326 else:
327 bld.PKG_CONFIG_FILES(pc_files, vnum=vnum)
329 if (manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and
330 bld.env['XSLTPROC_MANPAGES']):
331 bld.MANPAGES(manpages, install)
334 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
337 #################################################################
338 def SAMBA_BINARY(bld, binname, source,
339 deps='',
340 includes='',
341 public_headers=None,
342 private_headers=None,
343 header_path=None,
344 modules=None,
345 ldflags=None,
346 cflags='',
347 cflags_end=None,
348 autoproto=None,
349 use_hostcc=False,
350 use_global_deps=True,
351 compiler=None,
352 group='main',
353 manpages=None,
354 local_include=True,
355 global_include=True,
356 subsystem_name=None,
357 allow_warnings=False,
358 pyembed=False,
359 vars=None,
360 subdir=None,
361 install=True,
362 install_path=None,
363 enabled=True,
364 fuzzer=False,
365 for_selftest=False):
366 '''define a Samba binary'''
368 if for_selftest and not bld.CONFIG_GET('ENABLE_SELFTEST'):
369 enabled=False
371 if not enabled:
372 SET_TARGET_TYPE(bld, binname, 'DISABLED')
373 return
375 # Fuzzing builds do not build normal binaries
376 # however we must build asn1compile etc
378 if not use_hostcc and bld.env.enable_fuzzing != fuzzer:
379 SET_TARGET_TYPE(bld, binname, 'DISABLED')
380 return
382 if fuzzer:
383 install = False
384 if ldflags is None:
385 ldflags = bld.env['FUZZ_TARGET_LDFLAGS']
387 if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
388 return
390 features = 'c cprogram symlink_bin install_bin'
391 if pyembed:
392 features += ' pyembed'
394 obj_target = binname + '.objlist'
396 source = bld.EXPAND_VARIABLES(source, vars=vars)
397 if subdir:
398 source = bld.SUBDIR(subdir, source)
399 source = unique_list(TO_LIST(source))
401 if group == 'binaries':
402 subsystem_group = 'main'
403 elif group == 'build_compilers':
404 subsystem_group = 'compiler_libraries'
405 else:
406 subsystem_group = group
408 # only specify PIE flags for binaries
409 pie_cflags = cflags
410 pie_ldflags = TO_LIST(ldflags)
411 if bld.env['ENABLE_PIE'] is True:
412 pie_cflags += ' -fPIE'
413 pie_ldflags.extend(TO_LIST('-pie'))
414 if bld.env['ENABLE_RELRO'] is True:
415 pie_ldflags.extend(TO_LIST('-Wl,-z,relro,-z,now'))
417 # first create a target for building the object files for this binary
418 # by separating in this way, we avoid recompiling the C files
419 # separately for the install binary and the build binary
420 bld.SAMBA_SUBSYSTEM(obj_target,
421 source = source,
422 deps = deps,
423 includes = includes,
424 cflags = pie_cflags,
425 cflags_end = cflags_end,
426 group = subsystem_group,
427 autoproto = autoproto,
428 subsystem_name = subsystem_name,
429 local_include = local_include,
430 global_include = global_include,
431 use_hostcc = use_hostcc,
432 pyext = pyembed,
433 allow_warnings = allow_warnings,
434 use_global_deps= use_global_deps)
436 bld.SET_BUILD_GROUP(group)
438 # the binary itself will depend on that object target
439 deps = TO_LIST(deps)
440 deps.append(obj_target)
442 t = bld(
443 features = features,
444 source = [],
445 target = binname,
446 samba_deps = deps,
447 samba_includes = includes,
448 local_include = local_include,
449 global_include = global_include,
450 samba_modules = modules,
451 top = True,
452 samba_subsystem= subsystem_name,
453 install_path = None,
454 samba_inst_path= install_path,
455 samba_install = install,
456 samba_ldflags = pie_ldflags
459 if manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and bld.env['XSLTPROC_MANPAGES']:
460 bld.MANPAGES(manpages, install)
462 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
465 #################################################################
466 def SAMBA_MODULE(bld, modname, source,
467 deps='',
468 includes='',
469 subsystem=None,
470 init_function=None,
471 module_init_name='samba_init_module',
472 autoproto=None,
473 autoproto_extra_source='',
474 cflags='',
475 cflags_end=None,
476 internal_module=True,
477 local_include=True,
478 global_include=True,
479 vars=None,
480 subdir=None,
481 enabled=True,
482 pyembed=False,
483 manpages=None,
484 allow_undefined_symbols=False,
485 allow_warnings=False,
486 install=True
488 '''define a Samba module.'''
490 bld.ASSERT(subsystem, "You must specify a subsystem for SAMBA_MODULE(%s)" % modname)
492 source = bld.EXPAND_VARIABLES(source, vars=vars)
493 if subdir:
494 source = bld.SUBDIR(subdir, source)
496 if internal_module or BUILTIN_LIBRARY(bld, modname):
497 # Do not create modules for disabled subsystems
498 if GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
499 return
500 bld.SAMBA_SUBSYSTEM(modname, source,
501 deps=deps,
502 includes=includes,
503 autoproto=autoproto,
504 autoproto_extra_source=autoproto_extra_source,
505 cflags=cflags,
506 cflags_end=cflags_end,
507 local_include=local_include,
508 global_include=global_include,
509 allow_warnings=allow_warnings,
510 enabled=enabled)
512 bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
513 return
515 if not enabled:
516 SET_TARGET_TYPE(bld, modname, 'DISABLED')
517 return
519 # Do not create modules for disabled subsystems
520 if GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
521 return
523 realname = modname
524 deps += ' ' + subsystem
525 while realname.startswith("lib"+subsystem+"_"):
526 realname = realname[len("lib"+subsystem+"_"):]
527 while realname.startswith(subsystem+"_"):
528 realname = realname[len(subsystem+"_"):]
530 build_name = "%s_module_%s" % (subsystem, realname)
532 realname = bld.make_libname(realname)
533 while realname.startswith("lib"):
534 realname = realname[len("lib"):]
536 build_link_name = "modules/%s/%s" % (subsystem, realname)
538 if init_function:
539 cflags += " -D%s=%s" % (init_function, module_init_name)
541 bld.SAMBA_LIBRARY(modname,
542 source,
543 deps=deps,
544 includes=includes,
545 cflags=cflags,
546 cflags_end=cflags_end,
547 realname = realname,
548 autoproto = autoproto,
549 local_include=local_include,
550 global_include=global_include,
551 vars=vars,
552 bundled_name=build_name,
553 link_name=build_link_name,
554 install_path="${MODULESDIR}/%s" % subsystem,
555 pyembed=pyembed,
556 manpages=manpages,
557 allow_undefined_symbols=allow_undefined_symbols,
558 allow_warnings=allow_warnings,
559 install=install
563 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
566 #################################################################
567 def SAMBA_SUBSYSTEM(bld, modname, source,
568 deps='',
569 public_deps='',
570 includes='',
571 public_headers=None,
572 public_headers_install=True,
573 private_headers=None,
574 header_path=None,
575 cflags='',
576 cflags_end=None,
577 group='main',
578 init_function_sentinel=None,
579 autoproto=None,
580 autoproto_extra_source='',
581 depends_on='',
582 local_include=True,
583 local_include_first=True,
584 global_include=True,
585 subsystem_name=None,
586 enabled=True,
587 use_hostcc=False,
588 use_global_deps=True,
589 vars=None,
590 subdir=None,
591 hide_symbols=False,
592 allow_warnings=False,
593 pyext=False,
594 pyembed=False):
595 '''define a Samba subsystem'''
597 if not enabled:
598 SET_TARGET_TYPE(bld, modname, 'DISABLED')
599 return
601 # remember empty subsystems, so we can strip the dependencies
602 if ((source == '') or (source == [])):
603 if deps == '' and public_deps == '':
604 SET_TARGET_TYPE(bld, modname, 'EMPTY')
605 return
606 empty_c = modname + '.empty.c'
607 bld.SAMBA_GENERATOR('%s_empty_c' % modname,
608 rule=generate_empty_file,
609 target=empty_c)
610 source=empty_c
612 if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
613 return
615 source = bld.EXPAND_VARIABLES(source, vars=vars)
616 if subdir:
617 source = bld.SUBDIR(subdir, source)
618 source = unique_list(TO_LIST(source))
620 deps += ' ' + public_deps
622 bld.SET_BUILD_GROUP(group)
624 features = 'c'
625 if pyext:
626 features += ' pyext'
627 if pyembed:
628 features += ' pyembed'
630 t = bld(
631 features = features,
632 source = source,
633 target = modname,
634 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags,
635 allow_warnings=allow_warnings,
636 hide_symbols=hide_symbols),
637 depends_on = depends_on,
638 samba_deps = TO_LIST(deps),
639 samba_includes = includes,
640 local_include = local_include,
641 local_include_first = local_include_first,
642 global_include = global_include,
643 samba_subsystem= subsystem_name,
644 samba_use_hostcc = use_hostcc,
645 samba_use_global_deps = use_global_deps,
648 if cflags_end is not None:
649 t.samba_cflags.extend(TO_LIST(cflags_end))
651 if autoproto is not None:
652 bld.SAMBA_AUTOPROTO(autoproto, source + TO_LIST(autoproto_extra_source))
653 if public_headers is not None:
654 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
655 public_headers_install=public_headers_install)
656 return t
659 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
662 def SAMBA_GENERATOR(bld, name, rule, source='', target='',
663 group='generators', enabled=True,
664 public_headers=None,
665 public_headers_install=True,
666 private_headers=None,
667 header_path=None,
668 vars=None,
669 dep_vars=[],
670 always=False):
671 '''A generic source generator target'''
673 if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
674 return
676 if not enabled:
677 return
679 dep_vars.append('ruledeps')
680 dep_vars.append('SAMBA_GENERATOR_VARS')
682 bld.SET_BUILD_GROUP(group)
683 t = bld(
684 rule=rule,
685 source=bld.EXPAND_VARIABLES(source, vars=vars),
686 target=target,
687 shell=isinstance(rule, str),
688 update_outputs=True,
689 before='c',
690 ext_out='.c',
691 samba_type='GENERATOR',
692 dep_vars = dep_vars,
693 name=name)
695 if vars is None:
696 vars = {}
697 t.env.SAMBA_GENERATOR_VARS = vars
699 if always:
700 t.always = True
702 if public_headers is not None:
703 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
704 public_headers_install=public_headers_install)
705 return t
706 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
710 @Utils.run_once
711 def SETUP_BUILD_GROUPS(bld):
712 '''setup build groups used to ensure that the different build
713 phases happen consecutively'''
714 bld.p_ln = bld.srcnode # we do want to see all targets!
715 bld.env['USING_BUILD_GROUPS'] = True
716 bld.add_group('setup')
717 bld.add_group('build_compiler_source')
718 bld.add_group('vscripts')
719 bld.add_group('base_libraries')
720 bld.add_group('generators')
721 bld.add_group('compiler_prototypes')
722 bld.add_group('compiler_libraries')
723 bld.add_group('build_compilers')
724 bld.add_group('build_source')
725 bld.add_group('prototypes')
726 bld.add_group('headers')
727 bld.add_group('main')
728 bld.add_group('symbolcheck')
729 bld.add_group('syslibcheck')
730 bld.add_group('final')
731 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
734 def SET_BUILD_GROUP(bld, group):
735 '''set the current build group'''
736 if not 'USING_BUILD_GROUPS' in bld.env:
737 return
738 bld.set_group(group)
739 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
743 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
744 '''used to copy scripts from the source tree into the build directory
745 for use by selftest'''
747 source = bld.path.ant_glob(pattern, flat=True)
749 bld.SET_BUILD_GROUP('build_source')
750 for s in TO_LIST(source):
751 iname = s
752 if installname is not None:
753 iname = installname
754 target = os.path.join(installdir, iname)
755 tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
756 mkdir_p(tgtdir)
757 link_src = os.path.normpath(os.path.join(bld.path.abspath(), s))
758 link_dst = os.path.join(tgtdir, os.path.basename(iname))
759 if os.path.islink(link_dst) and os.readlink(link_dst) == link_src:
760 continue
761 if os.path.islink(link_dst):
762 os.unlink(link_dst)
763 Logs.info("symlink: %s -> %s/%s" % (s, installdir, iname))
764 symlink(link_src, link_dst)
765 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT
768 def copy_and_fix_python_path(task):
769 pattern='sys.path.insert(0, "bin/python")'
770 if task.env["PYTHONARCHDIR"] in sys.path and task.env["PYTHONDIR"] in sys.path:
771 replacement = ""
772 elif task.env["PYTHONARCHDIR"] == task.env["PYTHONDIR"]:
773 replacement="""sys.path.insert(0, "%s")""" % task.env["PYTHONDIR"]
774 else:
775 replacement="""sys.path.insert(0, "%s")
776 sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"])
778 if task.env["PYTHON"][0].startswith("/"):
779 replacement_shebang = "#!%s\n" % task.env["PYTHON"][0]
780 else:
781 replacement_shebang = "#!/usr/bin/env %s\n" % task.env["PYTHON"][0]
783 installed_location=task.outputs[0].bldpath(task.env)
784 source_file = open(task.inputs[0].srcpath(task.env))
785 installed_file = open(installed_location, 'w')
786 lineno = 0
787 for line in source_file:
788 newline = line
789 if (lineno == 0 and
790 line[:2] == "#!"):
791 newline = replacement_shebang
792 elif pattern in line:
793 newline = line.replace(pattern, replacement)
794 installed_file.write(newline)
795 lineno = lineno + 1
796 installed_file.close()
797 os.chmod(installed_location, 0o755)
798 return 0
800 def copy_and_fix_perl_path(task):
801 pattern='use lib "$RealBin/lib";'
803 replacement = ""
804 if not task.env["PERL_LIB_INSTALL_DIR"] in task.env["PERL_INC"]:
805 replacement = 'use lib "%s";' % task.env["PERL_LIB_INSTALL_DIR"]
807 if task.env["PERL"][0] == "/":
808 replacement_shebang = "#!%s\n" % task.env["PERL"]
809 else:
810 replacement_shebang = "#!/usr/bin/env %s\n" % task.env["PERL"]
812 installed_location=task.outputs[0].bldpath(task.env)
813 source_file = open(task.inputs[0].srcpath(task.env))
814 installed_file = open(installed_location, 'w')
815 lineno = 0
816 for line in source_file:
817 newline = line
818 if lineno == 0 and task.env["PERL_SPECIFIED"] == True and line[:2] == "#!":
819 newline = replacement_shebang
820 elif pattern in line:
821 newline = line.replace(pattern, replacement)
822 installed_file.write(newline)
823 lineno = lineno + 1
824 installed_file.close()
825 os.chmod(installed_location, 0o755)
826 return 0
829 def install_file(bld, destdir, file, chmod=MODE_644, flat=False,
830 python_fixup=False, perl_fixup=False,
831 destname=None, base_name=None):
832 '''install a file'''
833 if not isinstance(file, str):
834 file = file.abspath()
835 destdir = bld.EXPAND_VARIABLES(destdir)
836 if not destname:
837 destname = file
838 if flat:
839 destname = os.path.basename(destname)
840 dest = os.path.join(destdir, destname)
841 if python_fixup:
842 # fix the path python will use to find Samba modules
843 inst_file = file + '.inst'
844 bld.SAMBA_GENERATOR('python_%s' % destname,
845 rule=copy_and_fix_python_path,
846 dep_vars=["PYTHON","PYTHON_SPECIFIED","PYTHONDIR","PYTHONARCHDIR"],
847 source=file,
848 target=inst_file)
849 file = inst_file
850 if perl_fixup:
851 # fix the path perl will use to find Samba modules
852 inst_file = file + '.inst'
853 bld.SAMBA_GENERATOR('perl_%s' % destname,
854 rule=copy_and_fix_perl_path,
855 dep_vars=["PERL","PERL_SPECIFIED","PERL_LIB_INSTALL_DIR"],
856 source=file,
857 target=inst_file)
858 file = inst_file
859 if base_name:
860 file = os.path.join(base_name, file)
861 bld.install_as(dest, file, chmod=chmod)
864 def INSTALL_FILES(bld, destdir, files, chmod=MODE_644, flat=False,
865 python_fixup=False, perl_fixup=False,
866 destname=None, base_name=None):
867 '''install a set of files'''
868 for f in TO_LIST(files):
869 install_file(bld, destdir, f, chmod=chmod, flat=flat,
870 python_fixup=python_fixup, perl_fixup=perl_fixup,
871 destname=destname, base_name=base_name)
872 Build.BuildContext.INSTALL_FILES = INSTALL_FILES
875 def INSTALL_WILDCARD(bld, destdir, pattern, chmod=MODE_644, flat=False,
876 python_fixup=False, exclude=None, trim_path=None):
877 '''install a set of files matching a wildcard pattern'''
878 files=TO_LIST(bld.path.ant_glob(pattern, flat=True))
879 if trim_path:
880 files2 = []
881 for f in files:
882 files2.append(os.path.relpath(f, trim_path))
883 files = files2
885 if exclude:
886 for f in files[:]:
887 if fnmatch.fnmatch(f, exclude):
888 files.remove(f)
889 INSTALL_FILES(bld, destdir, files, chmod=chmod, flat=flat,
890 python_fixup=python_fixup, base_name=trim_path)
891 Build.BuildContext.INSTALL_WILDCARD = INSTALL_WILDCARD
893 def INSTALL_DIR(bld, path, chmod=0o755, env=None):
894 """Install a directory if it doesn't exist, always set permissions."""
896 if not path:
897 return []
899 destpath = bld.EXPAND_VARIABLES(path)
900 if Options.options.destdir:
901 destpath = os.path.join(Options.options.destdir, destpath.lstrip(os.sep))
903 if bld.is_install > 0:
904 if not os.path.isdir(destpath):
905 try:
906 Logs.info('* create %s', destpath)
907 os.makedirs(destpath)
908 os.chmod(destpath, chmod)
909 except OSError as e:
910 if not os.path.isdir(destpath):
911 raise Errors.WafError("Cannot create the folder '%s' (error: %s)" % (path, e))
912 Build.BuildContext.INSTALL_DIR = INSTALL_DIR
914 def INSTALL_DIRS(bld, destdir, dirs, chmod=0o755, env=None):
915 '''install a set of directories'''
916 destdir = bld.EXPAND_VARIABLES(destdir)
917 dirs = bld.EXPAND_VARIABLES(dirs)
918 for d in TO_LIST(dirs):
919 INSTALL_DIR(bld, os.path.join(destdir, d), chmod, env)
920 Build.BuildContext.INSTALL_DIRS = INSTALL_DIRS
923 def MANPAGES(bld, manpages, install):
924 '''build and install manual pages'''
925 bld.env.MAN_XSL = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
926 for m in manpages.split():
927 source = m + '.xml'
928 bld.SAMBA_GENERATOR(m,
929 source=source,
930 target=m,
931 group='final',
932 rule='${XSLTPROC} --xinclude -o ${TGT} --nonet ${MAN_XSL} ${SRC}'
934 if install:
935 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
936 Build.BuildContext.MANPAGES = MANPAGES
938 def SAMBAMANPAGES(bld, manpages, extra_source=None):
939 '''build and install manual pages'''
940 bld.env.SAMBA_EXPAND_XSL = bld.srcnode.abspath() + '/docs-xml/xslt/expand-sambadoc.xsl'
941 bld.env.SAMBA_MAN_XSL = bld.srcnode.abspath() + '/docs-xml/xslt/man.xsl'
942 bld.env.SAMBA_CATALOG = bld.bldnode.abspath() + '/docs-xml/build/catalog.xml'
943 bld.env.SAMBA_CATALOGS = 'file:///etc/xml/catalog file:///usr/local/share/xml/catalog file://' + bld.env.SAMBA_CATALOG
945 for m in manpages.split():
946 source = m + '.xml'
947 if extra_source is not None:
948 source = [source, extra_source]
949 bld.SAMBA_GENERATOR(m,
950 source=source,
951 target=m,
952 group='final',
953 dep_vars=['SAMBA_MAN_XSL', 'SAMBA_EXPAND_XSL', 'SAMBA_CATALOG'],
954 rule='''XML_CATALOG_FILES="${SAMBA_CATALOGS}"
955 export XML_CATALOG_FILES
956 ${XSLTPROC} --xinclude --stringparam noreference 0 -o ${TGT}.xml --nonet ${SAMBA_EXPAND_XSL} ${SRC[0].abspath(env)}
957 ${XSLTPROC} --nonet -o ${TGT} ${SAMBA_MAN_XSL} ${TGT}.xml'''
959 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
960 Build.BuildContext.SAMBAMANPAGES = SAMBAMANPAGES
962 @after('apply_link')
963 @feature('cshlib')
964 def apply_bundle_remove_dynamiclib_patch(self):
965 if self.env['MACBUNDLE'] or getattr(self,'mac_bundle',False):
966 if not getattr(self,'vnum',None):
967 try:
968 self.env['LINKFLAGS'].remove('-dynamiclib')
969 self.env['LINKFLAGS'].remove('-single_module')
970 except ValueError:
971 pass