wafsamba: add optional keep_underscore=True to SAMBA_LIBRARY()
[Samba.git] / buildtools / wafsamba / wafsamba.py
blob6f0e11bb6d559c4207b7b56037cbaa89a10daa67
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 import samba_install
23 import samba_conftests
24 import samba_abi
25 import samba_headers
26 import tru64cc
27 import irixcc
28 import hpuxcc
29 import generic_cc
30 import samba_dist
31 import samba_wildcard
32 import stale_files
33 import symbols
34 import pkgconfig
35 import configure_file
37 # some systems have broken threading in python
38 if os.environ.get('WAF_NOTHREADS') == '1':
39 import nothreads
41 LIB_PATH="shared"
43 os.environ['PYTHONUNBUFFERED'] = '1'
46 if Constants.HEXVERSION < 0x105019:
47 Logs.error('''
48 Please use the version of waf that comes with Samba, not
49 a system installed version. See http://wiki.samba.org/index.php/Waf
50 for details.
52 Alternatively, please run ./configure and make as usual. That will
53 call the right version of waf.''')
54 sys.exit(1)
57 @conf
58 def SAMBA_BUILD_ENV(conf):
59 '''create the samba build environment'''
60 conf.env.BUILD_DIRECTORY = conf.blddir
61 mkdir_p(os.path.join(conf.blddir, LIB_PATH))
62 mkdir_p(os.path.join(conf.blddir, LIB_PATH, "private"))
63 mkdir_p(os.path.join(conf.blddir, "modules"))
64 mkdir_p(os.path.join(conf.blddir, 'python/samba/dcerpc'))
65 # this allows all of the bin/shared and bin/python targets
66 # to be expressed in terms of build directory paths
67 mkdir_p(os.path.join(conf.blddir, 'default'))
68 for (source, target) in [('shared', 'shared'), ('modules', 'modules'), ('python', 'python_modules')]:
69 link_target = os.path.join(conf.blddir, 'default/' + target)
70 if not os.path.lexists(link_target):
71 os.symlink('../' + source, link_target)
73 # get perl to put the blib files in the build directory
74 blib_bld = os.path.join(conf.blddir, 'default/pidl/blib')
75 blib_src = os.path.join(conf.srcdir, 'pidl/blib')
76 mkdir_p(blib_bld + '/man1')
77 mkdir_p(blib_bld + '/man3')
78 if os.path.islink(blib_src):
79 os.unlink(blib_src)
80 elif os.path.exists(blib_src):
81 shutil.rmtree(blib_src)
84 def ADD_INIT_FUNCTION(bld, subsystem, target, init_function):
85 '''add an init_function to the list for a subsystem'''
86 if init_function is None:
87 return
88 bld.ASSERT(subsystem is not None, "You must specify a subsystem for init_function '%s'" % init_function)
89 cache = LOCAL_CACHE(bld, 'INIT_FUNCTIONS')
90 if not subsystem in cache:
91 cache[subsystem] = []
92 cache[subsystem].append( { 'TARGET':target, 'INIT_FUNCTION':init_function } )
93 Build.BuildContext.ADD_INIT_FUNCTION = ADD_INIT_FUNCTION
97 #################################################################
98 def SAMBA_LIBRARY(bld, libname, source,
99 deps='',
100 public_deps='',
101 includes='',
102 public_headers=None,
103 public_headers_install=True,
104 header_path=None,
105 pc_files=None,
106 vnum=None,
107 soname=None,
108 cflags='',
109 ldflags='',
110 external_library=False,
111 realname=None,
112 keep_underscore=False,
113 autoproto=None,
114 autoproto_extra_source='',
115 group='main',
116 depends_on='',
117 local_include=True,
118 global_include=True,
119 vars=None,
120 subdir=None,
121 install_path=None,
122 install=True,
123 pyembed=False,
124 pyext=False,
125 target_type='LIBRARY',
126 bundled_extension=True,
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 enabled=True):
136 '''define a Samba library'''
138 if LIB_MUST_BE_PRIVATE(bld, libname):
139 private_library=True
141 if not enabled:
142 SET_TARGET_TYPE(bld, libname, 'DISABLED')
143 return
145 source = bld.EXPAND_VARIABLES(source, vars=vars)
146 if subdir:
147 source = bld.SUBDIR(subdir, source)
149 # remember empty libraries, so we can strip the dependencies
150 if ((source == '') or (source == [])) and deps == '' and public_deps == '':
151 SET_TARGET_TYPE(bld, libname, 'EMPTY')
152 return
154 if BUILTIN_LIBRARY(bld, libname):
155 obj_target = libname
156 else:
157 obj_target = libname + '.objlist'
159 if group == 'libraries':
160 subsystem_group = 'main'
161 else:
162 subsystem_group = group
164 # first create a target for building the object files for this library
165 # by separating in this way, we avoid recompiling the C files
166 # separately for the install library and the build library
167 bld.SAMBA_SUBSYSTEM(obj_target,
168 source = source,
169 deps = deps,
170 public_deps = public_deps,
171 includes = includes,
172 public_headers = public_headers,
173 public_headers_install = public_headers_install,
174 header_path = header_path,
175 cflags = cflags,
176 group = subsystem_group,
177 autoproto = autoproto,
178 autoproto_extra_source=autoproto_extra_source,
179 depends_on = depends_on,
180 hide_symbols = hide_symbols,
181 pyembed = pyembed,
182 pyext = pyext,
183 local_include = local_include,
184 global_include = global_include)
186 if BUILTIN_LIBRARY(bld, libname):
187 return
189 if not SET_TARGET_TYPE(bld, libname, target_type):
190 return
192 # the library itself will depend on that object target
193 deps += ' ' + public_deps
194 deps = TO_LIST(deps)
195 deps.append(obj_target)
197 realname = bld.map_shlib_extension(realname, python=(target_type=='PYTHON'))
198 link_name = bld.map_shlib_extension(link_name, python=(target_type=='PYTHON'))
200 # we don't want any public libraries without version numbers
201 if (not private_library and target_type != 'PYTHON' and not realname):
202 if vnum is None and soname is None:
203 raise Utils.WafError("public library '%s' must have a vnum" %
204 libname)
205 if pc_files is None:
206 raise Utils.WafError("public library '%s' must have pkg-config file" %
207 libname)
208 if public_headers is None:
209 raise Utils.WafError("public library '%s' must have header files" %
210 libname)
212 if target_type == 'PYTHON' or realname or not private_library:
213 if keep_underscore:
214 bundled_name = libname
215 else:
216 bundled_name = libname.replace('_', '-')
217 else:
218 bundled_name = PRIVATE_NAME(bld, libname, bundled_extension,
219 private_library)
221 ldflags = TO_LIST(ldflags)
223 features = 'cc cshlib symlink_lib install_lib'
224 if pyext:
225 features += ' pyext'
226 if pyembed:
227 features += ' pyembed'
229 if abi_directory:
230 features += ' abi_check'
232 vscript = None
233 if bld.env.HAVE_LD_VERSION_SCRIPT:
234 if private_library:
235 version = "%s_%s" % (Utils.g_module.APPNAME, Utils.g_module.VERSION)
236 elif vnum:
237 version = "%s_%s" % (libname, vnum)
238 else:
239 version = None
240 if version:
241 vscript = "%s.vscript" % libname
242 bld.ABI_VSCRIPT(libname, abi_directory, version, vscript,
243 abi_match)
244 fullname = apply_pattern(bundled_name, bld.env.shlib_PATTERN)
245 fullpath = bld.path.find_or_declare(fullname)
246 vscriptpath = bld.path.find_or_declare(vscript)
247 if not fullpath:
248 raise Utils.WafError("unable to find fullpath for %s" % fullname)
249 if not vscriptpath:
250 raise Utils.WafError("unable to find vscript path for %s" % vscript)
251 bld.add_manual_dependency(fullpath, vscriptpath)
252 if Options.is_install:
253 # also make the .inst file depend on the vscript
254 instname = apply_pattern(bundled_name + '.inst', bld.env.shlib_PATTERN)
255 bld.add_manual_dependency(bld.path.find_or_declare(instname), bld.path.find_or_declare(vscript))
256 vscript = os.path.join(bld.path.abspath(bld.env), vscript)
258 bld.SET_BUILD_GROUP(group)
259 t = bld(
260 features = features,
261 source = [],
262 target = bundled_name,
263 depends_on = depends_on,
264 samba_ldflags = ldflags,
265 samba_deps = deps,
266 samba_includes = includes,
267 version_script = vscript,
268 local_include = local_include,
269 global_include = global_include,
270 vnum = vnum,
271 soname = soname,
272 install_path = None,
273 samba_inst_path = install_path,
274 name = libname,
275 samba_realname = realname,
276 samba_install = install,
277 abi_directory = "%s/%s" % (bld.path.abspath(), abi_directory),
278 abi_match = abi_match,
279 private_library = private_library,
280 grouping_library=grouping_library,
281 allow_undefined_symbols=allow_undefined_symbols
284 if realname and not link_name:
285 link_name = 'shared/%s' % realname
287 if link_name:
288 t.link_name = link_name
290 if pc_files is not None and not private_library:
291 bld.PKG_CONFIG_FILES(pc_files, vnum=vnum)
293 if (manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and
294 bld.env['XSLTPROC_MANPAGES']):
295 bld.MANPAGES(manpages, install)
298 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
301 #################################################################
302 def SAMBA_BINARY(bld, binname, source,
303 deps='',
304 includes='',
305 public_headers=None,
306 header_path=None,
307 modules=None,
308 ldflags=None,
309 cflags='',
310 autoproto=None,
311 use_hostcc=False,
312 use_global_deps=True,
313 compiler=None,
314 group='main',
315 manpages=None,
316 local_include=True,
317 global_include=True,
318 subsystem_name=None,
319 pyembed=False,
320 vars=None,
321 subdir=None,
322 install=True,
323 install_path=None,
324 enabled=True):
325 '''define a Samba binary'''
327 if not enabled:
328 SET_TARGET_TYPE(bld, binname, 'DISABLED')
329 return
331 if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
332 return
334 features = 'cc cprogram symlink_bin install_bin'
335 if pyembed:
336 features += ' pyembed'
338 obj_target = binname + '.objlist'
340 source = bld.EXPAND_VARIABLES(source, vars=vars)
341 if subdir:
342 source = bld.SUBDIR(subdir, source)
343 source = unique_list(TO_LIST(source))
345 if group == 'binaries':
346 subsystem_group = 'main'
347 else:
348 subsystem_group = group
350 # only specify PIE flags for binaries
351 pie_cflags = cflags
352 pie_ldflags = TO_LIST(ldflags)
353 if bld.env['ENABLE_PIE'] == True:
354 pie_cflags += ' -fPIE'
355 pie_ldflags.extend(TO_LIST('-pie'))
357 # first create a target for building the object files for this binary
358 # by separating in this way, we avoid recompiling the C files
359 # separately for the install binary and the build binary
360 bld.SAMBA_SUBSYSTEM(obj_target,
361 source = source,
362 deps = deps,
363 includes = includes,
364 cflags = pie_cflags,
365 group = subsystem_group,
366 autoproto = autoproto,
367 subsystem_name = subsystem_name,
368 local_include = local_include,
369 global_include = global_include,
370 use_hostcc = use_hostcc,
371 pyext = pyembed,
372 use_global_deps= use_global_deps)
374 bld.SET_BUILD_GROUP(group)
376 # the binary itself will depend on that object target
377 deps = TO_LIST(deps)
378 deps.append(obj_target)
380 t = bld(
381 features = features,
382 source = [],
383 target = binname,
384 samba_deps = deps,
385 samba_includes = includes,
386 local_include = local_include,
387 global_include = global_include,
388 samba_modules = modules,
389 top = True,
390 samba_subsystem= subsystem_name,
391 install_path = None,
392 samba_inst_path= install_path,
393 samba_install = install,
394 samba_ldflags = pie_ldflags
397 if manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and bld.env['XSLTPROC_MANPAGES']:
398 bld.MANPAGES(manpages, install)
400 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
403 #################################################################
404 def SAMBA_MODULE(bld, modname, source,
405 deps='',
406 includes='',
407 subsystem=None,
408 init_function=None,
409 module_init_name='samba_init_module',
410 autoproto=None,
411 autoproto_extra_source='',
412 cflags='',
413 internal_module=True,
414 local_include=True,
415 global_include=True,
416 vars=None,
417 subdir=None,
418 enabled=True,
419 pyembed=False,
420 manpages=None,
421 allow_undefined_symbols=False
423 '''define a Samba module.'''
425 source = bld.EXPAND_VARIABLES(source, vars=vars)
426 if subdir:
427 source = bld.SUBDIR(subdir, source)
429 if internal_module or BUILTIN_LIBRARY(bld, modname):
430 # Do not create modules for disabled subsystems
431 if subsystem and GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
432 return
433 bld.SAMBA_SUBSYSTEM(modname, source,
434 deps=deps,
435 includes=includes,
436 autoproto=autoproto,
437 autoproto_extra_source=autoproto_extra_source,
438 cflags=cflags,
439 local_include=local_include,
440 global_include=global_include,
441 enabled=enabled)
443 bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
444 return
446 if not enabled:
447 SET_TARGET_TYPE(bld, modname, 'DISABLED')
448 return
450 # Do not create modules for disabled subsystems
451 if subsystem and GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
452 return
454 obj_target = modname + '.objlist'
456 realname = modname
457 if subsystem is not None:
458 deps += ' ' + subsystem
459 while realname.startswith("lib"+subsystem+"_"):
460 realname = realname[len("lib"+subsystem+"_"):]
461 while realname.startswith(subsystem+"_"):
462 realname = realname[len(subsystem+"_"):]
464 realname = bld.make_libname(realname)
465 while realname.startswith("lib"):
466 realname = realname[len("lib"):]
468 build_link_name = "modules/%s/%s" % (subsystem, realname)
470 if init_function:
471 cflags += " -D%s=%s" % (init_function, module_init_name)
473 bld.SAMBA_LIBRARY(modname,
474 source,
475 deps=deps,
476 includes=includes,
477 cflags=cflags,
478 realname = realname,
479 autoproto = autoproto,
480 local_include=local_include,
481 global_include=global_include,
482 vars=vars,
483 link_name=build_link_name,
484 install_path="${MODULESDIR}/%s" % subsystem,
485 pyembed=pyembed,
486 manpages=manpages,
487 allow_undefined_symbols=allow_undefined_symbols
491 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
494 #################################################################
495 def SAMBA_SUBSYSTEM(bld, modname, source,
496 deps='',
497 public_deps='',
498 includes='',
499 public_headers=None,
500 public_headers_install=True,
501 header_path=None,
502 cflags='',
503 cflags_end=None,
504 group='main',
505 init_function_sentinel=None,
506 autoproto=None,
507 autoproto_extra_source='',
508 depends_on='',
509 local_include=True,
510 local_include_first=True,
511 global_include=True,
512 subsystem_name=None,
513 enabled=True,
514 use_hostcc=False,
515 use_global_deps=True,
516 vars=None,
517 subdir=None,
518 hide_symbols=False,
519 pyext=False,
520 pyembed=False):
521 '''define a Samba subsystem'''
523 if not enabled:
524 SET_TARGET_TYPE(bld, modname, 'DISABLED')
525 return
527 # remember empty subsystems, so we can strip the dependencies
528 if ((source == '') or (source == [])) and deps == '' and public_deps == '':
529 SET_TARGET_TYPE(bld, modname, 'EMPTY')
530 return
532 if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
533 return
535 source = bld.EXPAND_VARIABLES(source, vars=vars)
536 if subdir:
537 source = bld.SUBDIR(subdir, source)
538 source = unique_list(TO_LIST(source))
540 deps += ' ' + public_deps
542 bld.SET_BUILD_GROUP(group)
544 features = 'cc'
545 if pyext:
546 features += ' pyext'
547 if pyembed:
548 features += ' pyembed'
550 t = bld(
551 features = features,
552 source = source,
553 target = modname,
554 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags, hide_symbols=hide_symbols),
555 depends_on = depends_on,
556 samba_deps = TO_LIST(deps),
557 samba_includes = includes,
558 local_include = local_include,
559 local_include_first = local_include_first,
560 global_include = global_include,
561 samba_subsystem= subsystem_name,
562 samba_use_hostcc = use_hostcc,
563 samba_use_global_deps = use_global_deps,
566 if cflags_end is not None:
567 t.samba_cflags.extend(TO_LIST(cflags_end))
569 if autoproto is not None:
570 bld.SAMBA_AUTOPROTO(autoproto, source + TO_LIST(autoproto_extra_source))
571 if public_headers is not None:
572 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
573 public_headers_install=public_headers_install)
574 return t
577 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
580 def SAMBA_GENERATOR(bld, name, rule, source='', target='',
581 group='generators', enabled=True,
582 public_headers=None,
583 public_headers_install=True,
584 header_path=None,
585 vars=None,
586 dep_vars=[],
587 always=False):
588 '''A generic source generator target'''
590 if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
591 return
593 if not enabled:
594 return
596 dep_vars.append('ruledeps')
597 dep_vars.append('SAMBA_GENERATOR_VARS')
599 bld.SET_BUILD_GROUP(group)
600 t = bld(
601 rule=rule,
602 source=bld.EXPAND_VARIABLES(source, vars=vars),
603 target=target,
604 shell=isinstance(rule, str),
605 on_results=True,
606 before='cc',
607 ext_out='.c',
608 samba_type='GENERATOR',
609 dep_vars = dep_vars,
610 name=name)
612 if vars is None:
613 vars = {}
614 t.env.SAMBA_GENERATOR_VARS = vars
616 if always:
617 t.always = True
619 if public_headers is not None:
620 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
621 public_headers_install=public_headers_install)
622 return t
623 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
627 @runonce
628 def SETUP_BUILD_GROUPS(bld):
629 '''setup build groups used to ensure that the different build
630 phases happen consecutively'''
631 bld.p_ln = bld.srcnode # we do want to see all targets!
632 bld.env['USING_BUILD_GROUPS'] = True
633 bld.add_group('setup')
634 bld.add_group('build_compiler_source')
635 bld.add_group('vscripts')
636 bld.add_group('base_libraries')
637 bld.add_group('generators')
638 bld.add_group('compiler_prototypes')
639 bld.add_group('compiler_libraries')
640 bld.add_group('build_compilers')
641 bld.add_group('build_source')
642 bld.add_group('prototypes')
643 bld.add_group('headers')
644 bld.add_group('main')
645 bld.add_group('symbolcheck')
646 bld.add_group('syslibcheck')
647 bld.add_group('final')
648 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
651 def SET_BUILD_GROUP(bld, group):
652 '''set the current build group'''
653 if not 'USING_BUILD_GROUPS' in bld.env:
654 return
655 bld.set_group(group)
656 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
660 @conf
661 def ENABLE_TIMESTAMP_DEPENDENCIES(conf):
662 """use timestamps instead of file contents for deps
663 this currently doesn't work"""
664 def h_file(filename):
665 import stat
666 st = os.stat(filename)
667 if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
668 m = Utils.md5()
669 m.update(str(st.st_mtime))
670 m.update(str(st.st_size))
671 m.update(filename)
672 return m.digest()
673 Utils.h_file = h_file
676 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
677 '''used to copy scripts from the source tree into the build directory
678 for use by selftest'''
680 source = bld.path.ant_glob(pattern)
682 bld.SET_BUILD_GROUP('build_source')
683 for s in TO_LIST(source):
684 iname = s
685 if installname is not None:
686 iname = installname
687 target = os.path.join(installdir, iname)
688 tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
689 mkdir_p(tgtdir)
690 link_src = os.path.normpath(os.path.join(bld.curdir, s))
691 link_dst = os.path.join(tgtdir, os.path.basename(iname))
692 if os.path.islink(link_dst) and os.readlink(link_dst) == link_src:
693 continue
694 if os.path.exists(link_dst):
695 os.unlink(link_dst)
696 Logs.info("symlink: %s -> %s/%s" % (s, installdir, iname))
697 os.symlink(link_src, link_dst)
698 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT
701 def copy_and_fix_python_path(task):
702 pattern='sys.path.insert(0, "bin/python")'
703 if task.env["PYTHONARCHDIR"] in sys.path and task.env["PYTHONDIR"] in sys.path:
704 replacement = ""
705 elif task.env["PYTHONARCHDIR"] == task.env["PYTHONDIR"]:
706 replacement="""sys.path.insert(0, "%s")""" % task.env["PYTHONDIR"]
707 else:
708 replacement="""sys.path.insert(0, "%s")
709 sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"])
711 if task.env["PYTHON"][0] == "/":
712 replacement_shebang = "#!%s\n" % task.env["PYTHON"]
713 else:
714 replacement_shebang = "#!/usr/bin/env %s\n" % task.env["PYTHON"]
716 installed_location=task.outputs[0].bldpath(task.env)
717 source_file = open(task.inputs[0].srcpath(task.env))
718 installed_file = open(installed_location, 'w')
719 lineno = 0
720 for line in source_file:
721 newline = line
722 if lineno == 0 and task.env["PYTHON_SPECIFIED"] == True and line[:2] == "#!":
723 newline = replacement_shebang
724 elif pattern in line:
725 newline = line.replace(pattern, replacement)
726 installed_file.write(newline)
727 lineno = lineno + 1
728 installed_file.close()
729 os.chmod(installed_location, 0755)
730 return 0
732 def copy_and_fix_perl_path(task):
733 pattern='use lib "$RealBin/lib";'
735 replacement = ""
736 if not task.env["PERL_LIB_INSTALL_DIR"] in task.env["PERL_INC"]:
737 replacement = 'use lib "%s";' % task.env["PERL_LIB_INSTALL_DIR"]
739 if task.env["PERL"][0] == "/":
740 replacement_shebang = "#!%s\n" % task.env["PERL"]
741 else:
742 replacement_shebang = "#!/usr/bin/env %s\n" % task.env["PERL"]
744 installed_location=task.outputs[0].bldpath(task.env)
745 source_file = open(task.inputs[0].srcpath(task.env))
746 installed_file = open(installed_location, 'w')
747 lineno = 0
748 for line in source_file:
749 newline = line
750 if lineno == 0 and task.env["PERL_SPECIFIED"] == True and line[:2] == "#!":
751 newline = replacement_shebang
752 elif pattern in line:
753 newline = line.replace(pattern, replacement)
754 installed_file.write(newline)
755 lineno = lineno + 1
756 installed_file.close()
757 os.chmod(installed_location, 0755)
758 return 0
761 def install_file(bld, destdir, file, chmod=MODE_644, flat=False,
762 python_fixup=False, perl_fixup=False,
763 destname=None, base_name=None):
764 '''install a file'''
765 destdir = bld.EXPAND_VARIABLES(destdir)
766 if not destname:
767 destname = file
768 if flat:
769 destname = os.path.basename(destname)
770 dest = os.path.join(destdir, destname)
771 if python_fixup:
772 # fix the path python will use to find Samba modules
773 inst_file = file + '.inst'
774 bld.SAMBA_GENERATOR('python_%s' % destname,
775 rule=copy_and_fix_python_path,
776 dep_vars=["PYTHON","PYTHON_SPECIFIED","PYTHONDIR","PYTHONARCHDIR"],
777 source=file,
778 target=inst_file)
779 file = inst_file
780 if perl_fixup:
781 # fix the path perl will use to find Samba modules
782 inst_file = file + '.inst'
783 bld.SAMBA_GENERATOR('perl_%s' % destname,
784 rule=copy_and_fix_perl_path,
785 dep_vars=["PERL","PERL_SPECIFIED","PERL_LIB_INSTALL_DIR"],
786 source=file,
787 target=inst_file)
788 file = inst_file
789 if base_name:
790 file = os.path.join(base_name, file)
791 bld.install_as(dest, file, chmod=chmod)
794 def INSTALL_FILES(bld, destdir, files, chmod=MODE_644, flat=False,
795 python_fixup=False, perl_fixup=False,
796 destname=None, base_name=None):
797 '''install a set of files'''
798 for f in TO_LIST(files):
799 install_file(bld, destdir, f, chmod=chmod, flat=flat,
800 python_fixup=python_fixup, perl_fixup=perl_fixup,
801 destname=destname, base_name=base_name)
802 Build.BuildContext.INSTALL_FILES = INSTALL_FILES
805 def INSTALL_WILDCARD(bld, destdir, pattern, chmod=MODE_644, flat=False,
806 python_fixup=False, exclude=None, trim_path=None):
807 '''install a set of files matching a wildcard pattern'''
808 files=TO_LIST(bld.path.ant_glob(pattern))
809 if trim_path:
810 files2 = []
811 for f in files:
812 files2.append(os_path_relpath(f, trim_path))
813 files = files2
815 if exclude:
816 for f in files[:]:
817 if fnmatch.fnmatch(f, exclude):
818 files.remove(f)
819 INSTALL_FILES(bld, destdir, files, chmod=chmod, flat=flat,
820 python_fixup=python_fixup, base_name=trim_path)
821 Build.BuildContext.INSTALL_WILDCARD = INSTALL_WILDCARD
824 def INSTALL_DIRS(bld, destdir, dirs):
825 '''install a set of directories'''
826 destdir = bld.EXPAND_VARIABLES(destdir)
827 dirs = bld.EXPAND_VARIABLES(dirs)
828 for d in TO_LIST(dirs):
829 bld.install_dir(os.path.join(destdir, d))
830 Build.BuildContext.INSTALL_DIRS = INSTALL_DIRS
833 def MANPAGES(bld, manpages, install):
834 '''build and install manual pages'''
835 bld.env.MAN_XSL = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
836 for m in manpages.split():
837 source = m + '.xml'
838 bld.SAMBA_GENERATOR(m,
839 source=source,
840 target=m,
841 group='final',
842 rule='${XSLTPROC} --xinclude -o ${TGT} --nonet ${MAN_XSL} ${SRC}'
844 if install:
845 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
846 Build.BuildContext.MANPAGES = MANPAGES
848 def SAMBAMANPAGES(bld, manpages, extra_source=None):
849 '''build and install manual pages'''
850 bld.env.SAMBA_EXPAND_XSL = bld.srcnode.abspath() + '/docs-xml/xslt/expand-sambadoc.xsl'
851 bld.env.SAMBA_MAN_XSL = bld.srcnode.abspath() + '/docs-xml/xslt/man.xsl'
852 bld.env.SAMBA_CATALOGS = 'file:///etc/xml/catalog file:///usr/local/share/xml/catalog file://' + bld.srcnode.abspath() + '/bin/default/docs-xml/build/catalog.xml'
854 for m in manpages.split():
855 source = m + '.xml'
856 if extra_source is not None:
857 source = [source, extra_source]
858 bld.SAMBA_GENERATOR(m,
859 source=source,
860 target=m,
861 group='final',
862 rule='''XML_CATALOG_FILES="${SAMBA_CATALOGS}"
863 export XML_CATALOG_FILES
864 ${XSLTPROC} --xinclude --stringparam noreference 0 -o ${TGT}.xml --nonet ${SAMBA_EXPAND_XSL} ${SRC[0].abspath(env)}
865 ${XSLTPROC} --nonet -o ${TGT} ${SAMBA_MAN_XSL} ${TGT}.xml'''
867 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
868 Build.BuildContext.SAMBAMANPAGES = SAMBAMANPAGES
870 #############################################################
871 # give a nicer display when building different types of files
872 def progress_display(self, msg, fname):
873 col1 = Logs.colors(self.color)
874 col2 = Logs.colors.NORMAL
875 total = self.position[1]
876 n = len(str(total))
877 fs = '[%%%dd/%%%dd] %s %%s%%s%%s\n' % (n, n, msg)
878 return fs % (self.position[0], self.position[1], col1, fname, col2)
880 def link_display(self):
881 if Options.options.progress_bar != 0:
882 return Task.Task.old_display(self)
883 fname = self.outputs[0].bldpath(self.env)
884 return progress_display(self, 'Linking', fname)
885 Task.TaskBase.classes['cc_link'].display = link_display
887 def samba_display(self):
888 if Options.options.progress_bar != 0:
889 return Task.Task.old_display(self)
891 targets = LOCAL_CACHE(self, 'TARGET_TYPE')
892 if self.name in targets:
893 target_type = targets[self.name]
894 type_map = { 'GENERATOR' : 'Generating',
895 'PROTOTYPE' : 'Generating'
897 if target_type in type_map:
898 return progress_display(self, type_map[target_type], self.name)
900 if len(self.inputs) == 0:
901 return Task.Task.old_display(self)
903 fname = self.inputs[0].bldpath(self.env)
904 if fname[0:3] == '../':
905 fname = fname[3:]
906 ext_loc = fname.rfind('.')
907 if ext_loc == -1:
908 return Task.Task.old_display(self)
909 ext = fname[ext_loc:]
911 ext_map = { '.idl' : 'Compiling IDL',
912 '.et' : 'Compiling ERRTABLE',
913 '.asn1': 'Compiling ASN1',
914 '.c' : 'Compiling' }
915 if ext in ext_map:
916 return progress_display(self, ext_map[ext], fname)
917 return Task.Task.old_display(self)
919 Task.TaskBase.classes['Task'].old_display = Task.TaskBase.classes['Task'].display
920 Task.TaskBase.classes['Task'].display = samba_display
923 @after('apply_link')
924 @feature('cshlib')
925 def apply_bundle_remove_dynamiclib_patch(self):
926 if self.env['MACBUNDLE'] or getattr(self,'mac_bundle',False):
927 if not getattr(self,'vnum',None):
928 try:
929 self.env['LINKFLAGS'].remove('-dynamiclib')
930 self.env['LINKFLAGS'].remove('-single_module')
931 except ValueError:
932 pass