wafsamba: Also build libraries with RELRO protection
[Samba.git] / buildtools / wafsamba / wafsamba.py
blobc27241eff8d9c6b41770b87f7ae122f09be1317b
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 Build, os, sys, Options, Task, Utils, cc, TaskGen, fnmatch, re, shutil, Logs, Constants
5 from Configure import conf
6 from Logs import debug
7 from samba_utils import SUBST_VARS_RECURSIVE
8 TaskGen.task_gen.apply_verif = Utils.nada
10 # bring in the other samba modules
11 from samba_optimisation import *
12 from samba_utils import *
13 from samba_version import *
14 from samba_autoconf import *
15 from samba_patterns import *
16 from samba_pidl import *
17 from samba_autoproto import *
18 from samba_python import *
19 from samba_perl import *
20 from samba_deps import *
21 from samba_bundled import *
22 from samba_third_party import *
23 import samba_install
24 import samba_conftests
25 import samba_abi
26 import samba_headers
27 import tru64cc
28 import irixcc
29 import hpuxcc
30 import generic_cc
31 import samba_dist
32 import samba_wildcard
33 import stale_files
34 import symbols
35 import pkgconfig
36 import configure_file
38 # some systems have broken threading in python
39 if os.environ.get('WAF_NOTHREADS') == '1':
40 import nothreads
42 LIB_PATH="shared"
44 os.environ['PYTHONUNBUFFERED'] = '1'
47 if Constants.HEXVERSION < 0x105019:
48 Logs.error('''
49 Please use the version of waf that comes with Samba, not
50 a system installed version. See http://wiki.samba.org/index.php/Waf
51 for details.
53 Alternatively, please run ./configure and make as usual. That will
54 call the right version of waf.''')
55 sys.exit(1)
58 @conf
59 def SAMBA_BUILD_ENV(conf):
60 '''create the samba build environment'''
61 conf.env.BUILD_DIRECTORY = conf.blddir
62 mkdir_p(os.path.join(conf.blddir, LIB_PATH))
63 mkdir_p(os.path.join(conf.blddir, LIB_PATH, "private"))
64 mkdir_p(os.path.join(conf.blddir, "modules"))
65 mkdir_p(os.path.join(conf.blddir, 'python/samba/dcerpc'))
66 # this allows all of the bin/shared and bin/python targets
67 # to be expressed in terms of build directory paths
68 mkdir_p(os.path.join(conf.blddir, 'default'))
69 for (source, target) in [('shared', 'shared'), ('modules', 'modules'), ('python', 'python_modules')]:
70 link_target = os.path.join(conf.blddir, 'default/' + target)
71 if not os.path.lexists(link_target):
72 os.symlink('../' + source, link_target)
74 # get perl to put the blib files in the build directory
75 blib_bld = os.path.join(conf.blddir, 'default/pidl/blib')
76 blib_src = os.path.join(conf.srcdir, 'pidl/blib')
77 mkdir_p(blib_bld + '/man1')
78 mkdir_p(blib_bld + '/man3')
79 if os.path.islink(blib_src):
80 os.unlink(blib_src)
81 elif os.path.exists(blib_src):
82 shutil.rmtree(blib_src)
85 def ADD_INIT_FUNCTION(bld, subsystem, target, init_function):
86 '''add an init_function to the list for a subsystem'''
87 if init_function is None:
88 return
89 bld.ASSERT(subsystem is not None, "You must specify a subsystem for init_function '%s'" % init_function)
90 cache = LOCAL_CACHE(bld, 'INIT_FUNCTIONS')
91 if not subsystem in cache:
92 cache[subsystem] = []
93 cache[subsystem].append( { 'TARGET':target, 'INIT_FUNCTION':init_function } )
94 Build.BuildContext.ADD_INIT_FUNCTION = ADD_INIT_FUNCTION
97 def generate_empty_file(task):
98 target_fname = installed_location=task.outputs[0].bldpath(task.env)
99 target_file = open(installed_location, 'w')
100 target_file.close()
101 return 0
103 #################################################################
104 def SAMBA_LIBRARY(bld, libname, source,
105 deps='',
106 public_deps='',
107 includes='',
108 public_headers=None,
109 public_headers_install=True,
110 header_path=None,
111 pc_files=None,
112 vnum=None,
113 soname=None,
114 cflags='',
115 ldflags='',
116 external_library=False,
117 realname=None,
118 keep_underscore=False,
119 autoproto=None,
120 autoproto_extra_source='',
121 group='main',
122 depends_on='',
123 local_include=True,
124 global_include=True,
125 vars=None,
126 subdir=None,
127 install_path=None,
128 install=True,
129 pyembed=False,
130 pyext=False,
131 target_type='LIBRARY',
132 bundled_extension=False,
133 bundled_name=None,
134 link_name=None,
135 abi_directory=None,
136 abi_match=None,
137 hide_symbols=False,
138 manpages=None,
139 private_library=False,
140 grouping_library=False,
141 allow_undefined_symbols=False,
142 allow_warnings=False,
143 enabled=True):
144 '''define a Samba library'''
146 if pyembed and bld.env['IS_EXTRA_PYTHON']:
147 public_headers = pc_files = None
149 if LIB_MUST_BE_PRIVATE(bld, libname):
150 private_library=True
152 if not enabled:
153 SET_TARGET_TYPE(bld, libname, 'DISABLED')
154 return
156 source = bld.EXPAND_VARIABLES(source, vars=vars)
157 if subdir:
158 source = bld.SUBDIR(subdir, source)
160 # remember empty libraries, so we can strip the dependencies
161 if ((source == '') or (source == [])):
162 if deps == '' and public_deps == '':
163 SET_TARGET_TYPE(bld, libname, 'EMPTY')
164 return
165 empty_c = libname + '.empty.c'
166 bld.SAMBA_GENERATOR('%s_empty_c' % libname,
167 rule=generate_empty_file,
168 target=empty_c)
169 source=empty_c
171 if BUILTIN_LIBRARY(bld, libname):
172 obj_target = libname
173 else:
174 obj_target = libname + '.objlist'
176 if group == 'libraries':
177 subsystem_group = 'main'
178 else:
179 subsystem_group = group
181 # first create a target for building the object files for this library
182 # by separating in this way, we avoid recompiling the C files
183 # separately for the install library and the build library
184 bld.SAMBA_SUBSYSTEM(obj_target,
185 source = source,
186 deps = deps,
187 public_deps = public_deps,
188 includes = includes,
189 public_headers = public_headers,
190 public_headers_install = public_headers_install,
191 header_path = header_path,
192 cflags = cflags,
193 group = subsystem_group,
194 autoproto = autoproto,
195 autoproto_extra_source=autoproto_extra_source,
196 depends_on = depends_on,
197 hide_symbols = hide_symbols,
198 allow_warnings = allow_warnings,
199 pyembed = pyembed,
200 pyext = pyext,
201 local_include = local_include,
202 global_include = global_include)
204 if BUILTIN_LIBRARY(bld, libname):
205 return
207 if not SET_TARGET_TYPE(bld, libname, target_type):
208 return
210 # the library itself will depend on that object target
211 deps += ' ' + public_deps
212 deps = TO_LIST(deps)
213 deps.append(obj_target)
215 realname = bld.map_shlib_extension(realname, python=(target_type=='PYTHON'))
216 link_name = bld.map_shlib_extension(link_name, python=(target_type=='PYTHON'))
218 # we don't want any public libraries without version numbers
219 if (not private_library and target_type != 'PYTHON' and not realname):
220 if vnum is None and soname is None:
221 raise Utils.WafError("public library '%s' must have a vnum" %
222 libname)
223 if pc_files is None and not bld.env['IS_EXTRA_PYTHON']:
224 raise Utils.WafError("public library '%s' must have pkg-config file" %
225 libname)
226 if public_headers is None and not bld.env['IS_EXTRA_PYTHON']:
227 raise Utils.WafError("public library '%s' must have header files" %
228 libname)
230 if bundled_name is not None:
231 pass
232 elif target_type == 'PYTHON' or realname or not private_library:
233 if keep_underscore:
234 bundled_name = libname
235 else:
236 bundled_name = libname.replace('_', '-')
237 else:
238 assert (private_library == True and realname is None)
239 if abi_directory or vnum or soname:
240 bundled_extension=True
241 bundled_name = PRIVATE_NAME(bld, libname.replace('_', '-'),
242 bundled_extension, private_library)
244 ldflags = TO_LIST(ldflags)
245 if bld.env['ENABLE_RELRO'] is True:
246 ldflags.extend(TO_LIST('-Wl,-z,relro,-z,now'))
248 features = 'cc cshlib symlink_lib install_lib'
249 if pyext:
250 features += ' pyext'
251 if pyembed:
252 features += ' pyembed'
254 if abi_directory:
255 features += ' abi_check'
257 vscript = None
258 if bld.env.HAVE_LD_VERSION_SCRIPT:
259 if private_library:
260 version = "%s_%s" % (Utils.g_module.APPNAME, Utils.g_module.VERSION)
261 elif vnum:
262 version = "%s_%s" % (libname, vnum)
263 else:
264 version = None
265 if version:
266 vscript = "%s.vscript" % libname
267 bld.ABI_VSCRIPT(libname, abi_directory, version, vscript,
268 abi_match)
269 fullname = apply_pattern(bundled_name, bld.env.shlib_PATTERN)
270 fullpath = bld.path.find_or_declare(fullname)
271 vscriptpath = bld.path.find_or_declare(vscript)
272 if not fullpath:
273 raise Utils.WafError("unable to find fullpath for %s" % fullname)
274 if not vscriptpath:
275 raise Utils.WafError("unable to find vscript path for %s" % vscript)
276 bld.add_manual_dependency(fullpath, vscriptpath)
277 if Options.is_install:
278 # also make the .inst file depend on the vscript
279 instname = apply_pattern(bundled_name + '.inst', bld.env.shlib_PATTERN)
280 bld.add_manual_dependency(bld.path.find_or_declare(instname), bld.path.find_or_declare(vscript))
281 vscript = os.path.join(bld.path.abspath(bld.env), vscript)
283 bld.SET_BUILD_GROUP(group)
284 t = bld(
285 features = features,
286 source = [],
287 target = bundled_name,
288 depends_on = depends_on,
289 samba_ldflags = ldflags,
290 samba_deps = deps,
291 samba_includes = includes,
292 version_script = vscript,
293 local_include = local_include,
294 global_include = global_include,
295 vnum = vnum,
296 soname = soname,
297 install_path = None,
298 samba_inst_path = install_path,
299 name = libname,
300 samba_realname = realname,
301 samba_install = install,
302 abi_directory = "%s/%s" % (bld.path.abspath(), abi_directory),
303 abi_match = abi_match,
304 private_library = private_library,
305 grouping_library=grouping_library,
306 allow_undefined_symbols=allow_undefined_symbols
309 if realname and not link_name:
310 link_name = 'shared/%s' % realname
312 if link_name:
313 t.link_name = link_name
315 if pc_files is not None and not private_library:
316 bld.PKG_CONFIG_FILES(pc_files, vnum=vnum)
318 if (manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and
319 bld.env['XSLTPROC_MANPAGES']):
320 bld.MANPAGES(manpages, install)
323 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
326 #################################################################
327 def SAMBA_BINARY(bld, binname, source,
328 deps='',
329 includes='',
330 public_headers=None,
331 header_path=None,
332 modules=None,
333 ldflags=None,
334 cflags='',
335 autoproto=None,
336 use_hostcc=False,
337 use_global_deps=True,
338 compiler=None,
339 group='main',
340 manpages=None,
341 local_include=True,
342 global_include=True,
343 subsystem_name=None,
344 pyembed=False,
345 vars=None,
346 subdir=None,
347 install=True,
348 install_path=None,
349 enabled=True):
350 '''define a Samba binary'''
352 if not enabled:
353 SET_TARGET_TYPE(bld, binname, 'DISABLED')
354 return
356 if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
357 return
359 features = 'cc cprogram symlink_bin install_bin'
360 if pyembed:
361 features += ' pyembed'
363 obj_target = binname + '.objlist'
365 source = bld.EXPAND_VARIABLES(source, vars=vars)
366 if subdir:
367 source = bld.SUBDIR(subdir, source)
368 source = unique_list(TO_LIST(source))
370 if group == 'binaries':
371 subsystem_group = 'main'
372 else:
373 subsystem_group = group
375 # only specify PIE flags for binaries
376 pie_cflags = cflags
377 pie_ldflags = TO_LIST(ldflags)
378 if bld.env['ENABLE_PIE'] is True:
379 pie_cflags += ' -fPIE'
380 pie_ldflags.extend(TO_LIST('-pie'))
381 if bld.env['ENABLE_RELRO'] is True:
382 pie_ldflags.extend(TO_LIST('-Wl,-z,relro,-z,now'))
384 # first create a target for building the object files for this binary
385 # by separating in this way, we avoid recompiling the C files
386 # separately for the install binary and the build binary
387 bld.SAMBA_SUBSYSTEM(obj_target,
388 source = source,
389 deps = deps,
390 includes = includes,
391 cflags = pie_cflags,
392 group = subsystem_group,
393 autoproto = autoproto,
394 subsystem_name = subsystem_name,
395 local_include = local_include,
396 global_include = global_include,
397 use_hostcc = use_hostcc,
398 pyext = pyembed,
399 use_global_deps= use_global_deps)
401 bld.SET_BUILD_GROUP(group)
403 # the binary itself will depend on that object target
404 deps = TO_LIST(deps)
405 deps.append(obj_target)
407 t = bld(
408 features = features,
409 source = [],
410 target = binname,
411 samba_deps = deps,
412 samba_includes = includes,
413 local_include = local_include,
414 global_include = global_include,
415 samba_modules = modules,
416 top = True,
417 samba_subsystem= subsystem_name,
418 install_path = None,
419 samba_inst_path= install_path,
420 samba_install = install,
421 samba_ldflags = pie_ldflags
424 if manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and bld.env['XSLTPROC_MANPAGES']:
425 bld.MANPAGES(manpages, install)
427 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
430 #################################################################
431 def SAMBA_MODULE(bld, modname, source,
432 deps='',
433 includes='',
434 subsystem=None,
435 init_function=None,
436 module_init_name='samba_init_module',
437 autoproto=None,
438 autoproto_extra_source='',
439 cflags='',
440 internal_module=True,
441 local_include=True,
442 global_include=True,
443 vars=None,
444 subdir=None,
445 enabled=True,
446 pyembed=False,
447 manpages=None,
448 allow_undefined_symbols=False,
449 allow_warnings=False
451 '''define a Samba module.'''
453 bld.ASSERT(subsystem, "You must specify a subsystem for SAMBA_MODULE(%s)" % modname)
455 source = bld.EXPAND_VARIABLES(source, vars=vars)
456 if subdir:
457 source = bld.SUBDIR(subdir, source)
459 if internal_module or BUILTIN_LIBRARY(bld, modname):
460 # Do not create modules for disabled subsystems
461 if GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
462 return
463 bld.SAMBA_SUBSYSTEM(modname, source,
464 deps=deps,
465 includes=includes,
466 autoproto=autoproto,
467 autoproto_extra_source=autoproto_extra_source,
468 cflags=cflags,
469 local_include=local_include,
470 global_include=global_include,
471 allow_warnings=allow_warnings,
472 enabled=enabled)
474 bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
475 return
477 if not enabled:
478 SET_TARGET_TYPE(bld, modname, 'DISABLED')
479 return
481 # Do not create modules for disabled subsystems
482 if GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
483 return
485 realname = modname
486 deps += ' ' + subsystem
487 while realname.startswith("lib"+subsystem+"_"):
488 realname = realname[len("lib"+subsystem+"_"):]
489 while realname.startswith(subsystem+"_"):
490 realname = realname[len(subsystem+"_"):]
492 build_name = "%s_module_%s" % (subsystem, realname)
494 realname = bld.make_libname(realname)
495 while realname.startswith("lib"):
496 realname = realname[len("lib"):]
498 build_link_name = "modules/%s/%s" % (subsystem, realname)
500 if init_function:
501 cflags += " -D%s=%s" % (init_function, module_init_name)
503 bld.SAMBA_LIBRARY(modname,
504 source,
505 deps=deps,
506 includes=includes,
507 cflags=cflags,
508 realname = realname,
509 autoproto = autoproto,
510 local_include=local_include,
511 global_include=global_include,
512 vars=vars,
513 bundled_name=build_name,
514 link_name=build_link_name,
515 install_path="${MODULESDIR}/%s" % subsystem,
516 pyembed=pyembed,
517 manpages=manpages,
518 allow_undefined_symbols=allow_undefined_symbols,
519 allow_warnings=allow_warnings
523 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
526 #################################################################
527 def SAMBA_SUBSYSTEM(bld, modname, source,
528 deps='',
529 public_deps='',
530 includes='',
531 public_headers=None,
532 public_headers_install=True,
533 header_path=None,
534 cflags='',
535 cflags_end=None,
536 group='main',
537 init_function_sentinel=None,
538 autoproto=None,
539 autoproto_extra_source='',
540 depends_on='',
541 local_include=True,
542 local_include_first=True,
543 global_include=True,
544 subsystem_name=None,
545 enabled=True,
546 use_hostcc=False,
547 use_global_deps=True,
548 vars=None,
549 subdir=None,
550 hide_symbols=False,
551 allow_warnings=False,
552 pyext=False,
553 pyembed=False):
554 '''define a Samba subsystem'''
556 if not enabled:
557 SET_TARGET_TYPE(bld, modname, 'DISABLED')
558 return
560 # remember empty subsystems, so we can strip the dependencies
561 if ((source == '') or (source == [])):
562 if deps == '' and public_deps == '':
563 SET_TARGET_TYPE(bld, modname, 'EMPTY')
564 return
565 empty_c = modname + '.empty.c'
566 bld.SAMBA_GENERATOR('%s_empty_c' % modname,
567 rule=generate_empty_file,
568 target=empty_c)
569 source=empty_c
571 if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
572 return
574 source = bld.EXPAND_VARIABLES(source, vars=vars)
575 if subdir:
576 source = bld.SUBDIR(subdir, source)
577 source = unique_list(TO_LIST(source))
579 deps += ' ' + public_deps
581 bld.SET_BUILD_GROUP(group)
583 features = 'cc'
584 if pyext:
585 features += ' pyext'
586 if pyembed:
587 features += ' pyembed'
589 t = bld(
590 features = features,
591 source = source,
592 target = modname,
593 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags,
594 allow_warnings=allow_warnings,
595 hide_symbols=hide_symbols),
596 depends_on = depends_on,
597 samba_deps = TO_LIST(deps),
598 samba_includes = includes,
599 local_include = local_include,
600 local_include_first = local_include_first,
601 global_include = global_include,
602 samba_subsystem= subsystem_name,
603 samba_use_hostcc = use_hostcc,
604 samba_use_global_deps = use_global_deps,
607 if cflags_end is not None:
608 t.samba_cflags.extend(TO_LIST(cflags_end))
610 if autoproto is not None:
611 bld.SAMBA_AUTOPROTO(autoproto, source + TO_LIST(autoproto_extra_source))
612 if public_headers is not None:
613 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
614 public_headers_install=public_headers_install)
615 return t
618 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
621 def SAMBA_GENERATOR(bld, name, rule, source='', target='',
622 group='generators', enabled=True,
623 public_headers=None,
624 public_headers_install=True,
625 header_path=None,
626 vars=None,
627 dep_vars=[],
628 always=False):
629 '''A generic source generator target'''
631 if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
632 return
634 if not enabled:
635 return
637 dep_vars.append('ruledeps')
638 dep_vars.append('SAMBA_GENERATOR_VARS')
640 bld.SET_BUILD_GROUP(group)
641 t = bld(
642 rule=rule,
643 source=bld.EXPAND_VARIABLES(source, vars=vars),
644 target=target,
645 shell=isinstance(rule, str),
646 update_outputs=True,
647 before='cc',
648 ext_out='.c',
649 samba_type='GENERATOR',
650 dep_vars = dep_vars,
651 name=name)
653 if vars is None:
654 vars = {}
655 t.env.SAMBA_GENERATOR_VARS = vars
657 if always:
658 t.always = True
660 if public_headers is not None:
661 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
662 public_headers_install=public_headers_install)
663 return t
664 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
668 @runonce
669 def SETUP_BUILD_GROUPS(bld):
670 '''setup build groups used to ensure that the different build
671 phases happen consecutively'''
672 bld.p_ln = bld.srcnode # we do want to see all targets!
673 bld.env['USING_BUILD_GROUPS'] = True
674 bld.add_group('setup')
675 bld.add_group('build_compiler_source')
676 bld.add_group('vscripts')
677 bld.add_group('base_libraries')
678 bld.add_group('generators')
679 bld.add_group('compiler_prototypes')
680 bld.add_group('compiler_libraries')
681 bld.add_group('build_compilers')
682 bld.add_group('build_source')
683 bld.add_group('prototypes')
684 bld.add_group('headers')
685 bld.add_group('main')
686 bld.add_group('symbolcheck')
687 bld.add_group('syslibcheck')
688 bld.add_group('final')
689 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
692 def SET_BUILD_GROUP(bld, group):
693 '''set the current build group'''
694 if not 'USING_BUILD_GROUPS' in bld.env:
695 return
696 bld.set_group(group)
697 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
701 @conf
702 def ENABLE_TIMESTAMP_DEPENDENCIES(conf):
703 """use timestamps instead of file contents for deps
704 this currently doesn't work"""
705 def h_file(filename):
706 import stat
707 st = os.stat(filename)
708 if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
709 m = Utils.md5()
710 m.update(str(st.st_mtime))
711 m.update(str(st.st_size))
712 m.update(filename)
713 return m.digest()
714 Utils.h_file = h_file
717 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
718 '''used to copy scripts from the source tree into the build directory
719 for use by selftest'''
721 source = bld.path.ant_glob(pattern)
723 bld.SET_BUILD_GROUP('build_source')
724 for s in TO_LIST(source):
725 iname = s
726 if installname is not None:
727 iname = installname
728 target = os.path.join(installdir, iname)
729 tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
730 mkdir_p(tgtdir)
731 link_src = os.path.normpath(os.path.join(bld.curdir, s))
732 link_dst = os.path.join(tgtdir, os.path.basename(iname))
733 if os.path.islink(link_dst) and os.readlink(link_dst) == link_src:
734 continue
735 if os.path.exists(link_dst):
736 os.unlink(link_dst)
737 Logs.info("symlink: %s -> %s/%s" % (s, installdir, iname))
738 os.symlink(link_src, link_dst)
739 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT
742 def copy_and_fix_python_path(task):
743 pattern='sys.path.insert(0, "bin/python")'
744 if task.env["PYTHONARCHDIR"] in sys.path and task.env["PYTHONDIR"] in sys.path:
745 replacement = ""
746 elif task.env["PYTHONARCHDIR"] == task.env["PYTHONDIR"]:
747 replacement="""sys.path.insert(0, "%s")""" % task.env["PYTHONDIR"]
748 else:
749 replacement="""sys.path.insert(0, "%s")
750 sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"])
752 if task.env["PYTHON"][0] == "/":
753 replacement_shebang = "#!%s\n" % task.env["PYTHON"]
754 else:
755 replacement_shebang = "#!/usr/bin/env %s\n" % task.env["PYTHON"]
757 installed_location=task.outputs[0].bldpath(task.env)
758 source_file = open(task.inputs[0].srcpath(task.env))
759 installed_file = open(installed_location, 'w')
760 lineno = 0
761 for line in source_file:
762 newline = line
763 if (lineno == 0 and task.env["PYTHON_SPECIFIED"] is True and
764 line[:2] == "#!"):
765 newline = replacement_shebang
766 elif pattern in line:
767 newline = line.replace(pattern, replacement)
768 installed_file.write(newline)
769 lineno = lineno + 1
770 installed_file.close()
771 os.chmod(installed_location, 0755)
772 return 0
774 def copy_and_fix_perl_path(task):
775 pattern='use lib "$RealBin/lib";'
777 replacement = ""
778 if not task.env["PERL_LIB_INSTALL_DIR"] in task.env["PERL_INC"]:
779 replacement = 'use lib "%s";' % task.env["PERL_LIB_INSTALL_DIR"]
781 if task.env["PERL"][0] == "/":
782 replacement_shebang = "#!%s\n" % task.env["PERL"]
783 else:
784 replacement_shebang = "#!/usr/bin/env %s\n" % task.env["PERL"]
786 installed_location=task.outputs[0].bldpath(task.env)
787 source_file = open(task.inputs[0].srcpath(task.env))
788 installed_file = open(installed_location, 'w')
789 lineno = 0
790 for line in source_file:
791 newline = line
792 if lineno == 0 and task.env["PERL_SPECIFIED"] == True and line[:2] == "#!":
793 newline = replacement_shebang
794 elif pattern in line:
795 newline = line.replace(pattern, replacement)
796 installed_file.write(newline)
797 lineno = lineno + 1
798 installed_file.close()
799 os.chmod(installed_location, 0755)
800 return 0
803 def install_file(bld, destdir, file, chmod=MODE_644, flat=False,
804 python_fixup=False, perl_fixup=False,
805 destname=None, base_name=None):
806 '''install a file'''
807 destdir = bld.EXPAND_VARIABLES(destdir)
808 if not destname:
809 destname = file
810 if flat:
811 destname = os.path.basename(destname)
812 dest = os.path.join(destdir, destname)
813 if python_fixup:
814 # fix the path python will use to find Samba modules
815 inst_file = file + '.inst'
816 bld.SAMBA_GENERATOR('python_%s' % destname,
817 rule=copy_and_fix_python_path,
818 dep_vars=["PYTHON","PYTHON_SPECIFIED","PYTHONDIR","PYTHONARCHDIR"],
819 source=file,
820 target=inst_file)
821 file = inst_file
822 if perl_fixup:
823 # fix the path perl will use to find Samba modules
824 inst_file = file + '.inst'
825 bld.SAMBA_GENERATOR('perl_%s' % destname,
826 rule=copy_and_fix_perl_path,
827 dep_vars=["PERL","PERL_SPECIFIED","PERL_LIB_INSTALL_DIR"],
828 source=file,
829 target=inst_file)
830 file = inst_file
831 if base_name:
832 file = os.path.join(base_name, file)
833 bld.install_as(dest, file, chmod=chmod)
836 def INSTALL_FILES(bld, destdir, files, chmod=MODE_644, flat=False,
837 python_fixup=False, perl_fixup=False,
838 destname=None, base_name=None):
839 '''install a set of files'''
840 for f in TO_LIST(files):
841 install_file(bld, destdir, f, chmod=chmod, flat=flat,
842 python_fixup=python_fixup, perl_fixup=perl_fixup,
843 destname=destname, base_name=base_name)
844 Build.BuildContext.INSTALL_FILES = INSTALL_FILES
847 def INSTALL_WILDCARD(bld, destdir, pattern, chmod=MODE_644, flat=False,
848 python_fixup=False, exclude=None, trim_path=None):
849 '''install a set of files matching a wildcard pattern'''
850 files=TO_LIST(bld.path.ant_glob(pattern))
851 if trim_path:
852 files2 = []
853 for f in files:
854 files2.append(os_path_relpath(f, trim_path))
855 files = files2
857 if exclude:
858 for f in files[:]:
859 if fnmatch.fnmatch(f, exclude):
860 files.remove(f)
861 INSTALL_FILES(bld, destdir, files, chmod=chmod, flat=flat,
862 python_fixup=python_fixup, base_name=trim_path)
863 Build.BuildContext.INSTALL_WILDCARD = INSTALL_WILDCARD
866 def INSTALL_DIRS(bld, destdir, dirs):
867 '''install a set of directories'''
868 destdir = bld.EXPAND_VARIABLES(destdir)
869 dirs = bld.EXPAND_VARIABLES(dirs)
870 for d in TO_LIST(dirs):
871 bld.install_dir(os.path.join(destdir, d))
872 Build.BuildContext.INSTALL_DIRS = INSTALL_DIRS
875 def MANPAGES(bld, manpages, install):
876 '''build and install manual pages'''
877 bld.env.MAN_XSL = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
878 for m in manpages.split():
879 source = m + '.xml'
880 bld.SAMBA_GENERATOR(m,
881 source=source,
882 target=m,
883 group='final',
884 rule='${XSLTPROC} --xinclude -o ${TGT} --nonet ${MAN_XSL} ${SRC}'
886 if install:
887 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
888 Build.BuildContext.MANPAGES = MANPAGES
890 def SAMBAMANPAGES(bld, manpages, extra_source=None):
891 '''build and install manual pages'''
892 bld.env.SAMBA_EXPAND_XSL = bld.srcnode.abspath() + '/docs-xml/xslt/expand-sambadoc.xsl'
893 bld.env.SAMBA_MAN_XSL = bld.srcnode.abspath() + '/docs-xml/xslt/man.xsl'
894 bld.env.SAMBA_CATALOG = bld.srcnode.abspath() + '/bin/default/docs-xml/build/catalog.xml'
895 bld.env.SAMBA_CATALOGS = 'file:///etc/xml/catalog file:///usr/local/share/xml/catalog file://' + bld.env.SAMBA_CATALOG
897 for m in manpages.split():
898 source = m + '.xml'
899 if extra_source is not None:
900 source = [source, extra_source]
901 bld.SAMBA_GENERATOR(m,
902 source=source,
903 target=m,
904 group='final',
905 dep_vars=['SAMBA_MAN_XSL', 'SAMBA_EXPAND_XSL', 'SAMBA_CATALOG'],
906 rule='''XML_CATALOG_FILES="${SAMBA_CATALOGS}"
907 export XML_CATALOG_FILES
908 ${XSLTPROC} --xinclude --stringparam noreference 0 -o ${TGT}.xml --nonet ${SAMBA_EXPAND_XSL} ${SRC[0].abspath(env)}
909 ${XSLTPROC} --nonet -o ${TGT} ${SAMBA_MAN_XSL} ${TGT}.xml'''
911 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
912 Build.BuildContext.SAMBAMANPAGES = SAMBAMANPAGES
914 #############################################################
915 # give a nicer display when building different types of files
916 def progress_display(self, msg, fname):
917 col1 = Logs.colors(self.color)
918 col2 = Logs.colors.NORMAL
919 total = self.position[1]
920 n = len(str(total))
921 fs = '[%%%dd/%%%dd] %s %%s%%s%%s\n' % (n, n, msg)
922 return fs % (self.position[0], self.position[1], col1, fname, col2)
924 def link_display(self):
925 if Options.options.progress_bar != 0:
926 return Task.Task.old_display(self)
927 fname = self.outputs[0].bldpath(self.env)
928 return progress_display(self, 'Linking', fname)
929 Task.TaskBase.classes['cc_link'].display = link_display
931 def samba_display(self):
932 if Options.options.progress_bar != 0:
933 return Task.Task.old_display(self)
935 targets = LOCAL_CACHE(self, 'TARGET_TYPE')
936 if self.name in targets:
937 target_type = targets[self.name]
938 type_map = { 'GENERATOR' : 'Generating',
939 'PROTOTYPE' : 'Generating'
941 if target_type in type_map:
942 return progress_display(self, type_map[target_type], self.name)
944 if len(self.inputs) == 0:
945 return Task.Task.old_display(self)
947 fname = self.inputs[0].bldpath(self.env)
948 if fname[0:3] == '../':
949 fname = fname[3:]
950 ext_loc = fname.rfind('.')
951 if ext_loc == -1:
952 return Task.Task.old_display(self)
953 ext = fname[ext_loc:]
955 ext_map = { '.idl' : 'Compiling IDL',
956 '.et' : 'Compiling ERRTABLE',
957 '.asn1': 'Compiling ASN1',
958 '.c' : 'Compiling' }
959 if ext in ext_map:
960 return progress_display(self, ext_map[ext], fname)
961 return Task.Task.old_display(self)
963 Task.TaskBase.classes['Task'].old_display = Task.TaskBase.classes['Task'].display
964 Task.TaskBase.classes['Task'].display = samba_display
967 @after('apply_link')
968 @feature('cshlib')
969 def apply_bundle_remove_dynamiclib_patch(self):
970 if self.env['MACBUNDLE'] or getattr(self,'mac_bundle',False):
971 if not getattr(self,'vnum',None):
972 try:
973 self.env['LINKFLAGS'].remove('-dynamiclib')
974 self.env['LINKFLAGS'].remove('-single_module')
975 except ValueError:
976 pass