wafsamba: add perl_fixup parameter to INSTALL_FILES
[Samba.git] / buildtools / wafsamba / wafsamba.py
blobd26b7b579690678e493eb792405b865e5d8c70a7
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 autoproto=None,
113 autoproto_extra_source='',
114 group='libraries',
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=True,
126 link_name=None,
127 abi_directory=None,
128 abi_match=None,
129 hide_symbols=False,
130 manpages=None,
131 private_library=False,
132 grouping_library=False,
133 allow_undefined_symbols=False,
134 enabled=True):
135 '''define a Samba library'''
137 if LIB_MUST_BE_PRIVATE(bld, libname):
138 private_library=True
140 if not enabled:
141 SET_TARGET_TYPE(bld, libname, 'DISABLED')
142 return
144 source = bld.EXPAND_VARIABLES(source, vars=vars)
145 if subdir:
146 source = bld.SUBDIR(subdir, source)
148 # remember empty libraries, so we can strip the dependencies
149 if ((source == '') or (source == [])) and deps == '' and public_deps == '':
150 SET_TARGET_TYPE(bld, libname, 'EMPTY')
151 return
153 if BUILTIN_LIBRARY(bld, libname):
154 obj_target = libname
155 else:
156 obj_target = libname + '.objlist'
158 if group == 'libraries':
159 subsystem_group = 'main'
160 else:
161 subsystem_group = group
163 # first create a target for building the object files for this library
164 # by separating in this way, we avoid recompiling the C files
165 # separately for the install library and the build library
166 bld.SAMBA_SUBSYSTEM(obj_target,
167 source = source,
168 deps = deps,
169 public_deps = public_deps,
170 includes = includes,
171 public_headers = public_headers,
172 public_headers_install = public_headers_install,
173 header_path = header_path,
174 cflags = cflags,
175 group = subsystem_group,
176 autoproto = autoproto,
177 autoproto_extra_source=autoproto_extra_source,
178 depends_on = depends_on,
179 hide_symbols = hide_symbols,
180 pyembed = pyembed,
181 pyext = pyext,
182 local_include = local_include,
183 global_include = global_include)
185 if BUILTIN_LIBRARY(bld, libname):
186 return
188 if not SET_TARGET_TYPE(bld, libname, target_type):
189 return
191 # the library itself will depend on that object target
192 deps += ' ' + public_deps
193 deps = TO_LIST(deps)
194 deps.append(obj_target)
196 realname = bld.map_shlib_extension(realname, python=(target_type=='PYTHON'))
197 link_name = bld.map_shlib_extension(link_name, python=(target_type=='PYTHON'))
199 # we don't want any public libraries without version numbers
200 if (not private_library and target_type != 'PYTHON' and not realname):
201 if vnum is None and soname is None:
202 raise Utils.WafError("public library '%s' must have a vnum" %
203 libname)
204 if pc_files is None:
205 raise Utils.WafError("public library '%s' must have pkg-config file" %
206 libname)
207 if public_headers is None:
208 raise Utils.WafError("public library '%s' must have header files" %
209 libname)
211 if target_type == 'PYTHON' or realname or not private_library:
212 bundled_name = libname.replace('_', '-')
213 else:
214 bundled_name = PRIVATE_NAME(bld, libname, bundled_extension,
215 private_library)
217 ldflags = TO_LIST(ldflags)
219 features = 'cc cshlib symlink_lib install_lib'
220 if pyext:
221 features += ' pyext'
222 if pyembed:
223 features += ' pyembed'
225 if abi_directory:
226 features += ' abi_check'
228 vscript = None
229 if bld.env.HAVE_LD_VERSION_SCRIPT:
230 if private_library:
231 version = "%s_%s" % (Utils.g_module.APPNAME, Utils.g_module.VERSION)
232 elif vnum:
233 version = "%s_%s" % (libname, vnum)
234 else:
235 version = None
236 if version:
237 vscript = "%s.vscript" % libname
238 bld.ABI_VSCRIPT(libname, abi_directory, version, vscript,
239 abi_match)
240 fullname = apply_pattern(bundled_name, bld.env.shlib_PATTERN)
241 fullpath = bld.path.find_or_declare(fullname)
242 vscriptpath = bld.path.find_or_declare(vscript)
243 if not fullpath:
244 raise Utils.WafError("unable to find fullpath for %s" % fullname)
245 if not vscriptpath:
246 raise Utils.WafError("unable to find vscript path for %s" % vscript)
247 bld.add_manual_dependency(fullpath, vscriptpath)
248 if Options.is_install:
249 # also make the .inst file depend on the vscript
250 instname = apply_pattern(bundled_name + '.inst', bld.env.shlib_PATTERN)
251 bld.add_manual_dependency(bld.path.find_or_declare(instname), bld.path.find_or_declare(vscript))
252 vscript = os.path.join(bld.path.abspath(bld.env), vscript)
254 bld.SET_BUILD_GROUP(group)
255 t = bld(
256 features = features,
257 source = [],
258 target = bundled_name,
259 depends_on = depends_on,
260 samba_ldflags = ldflags,
261 samba_deps = deps,
262 samba_includes = includes,
263 version_script = vscript,
264 local_include = local_include,
265 global_include = global_include,
266 vnum = vnum,
267 soname = soname,
268 install_path = None,
269 samba_inst_path = install_path,
270 name = libname,
271 samba_realname = realname,
272 samba_install = install,
273 abi_directory = "%s/%s" % (bld.path.abspath(), abi_directory),
274 abi_match = abi_match,
275 private_library = private_library,
276 grouping_library=grouping_library,
277 allow_undefined_symbols=allow_undefined_symbols
280 if realname and not link_name:
281 link_name = 'shared/%s' % realname
283 if link_name:
284 t.link_name = link_name
286 if pc_files is not None and not private_library:
287 bld.PKG_CONFIG_FILES(pc_files, vnum=vnum)
289 if (manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and
290 bld.env['XSLTPROC_MANPAGES']):
291 bld.MANPAGES(manpages, install)
294 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
297 #################################################################
298 def SAMBA_BINARY(bld, binname, source,
299 deps='',
300 includes='',
301 public_headers=None,
302 header_path=None,
303 modules=None,
304 ldflags=None,
305 cflags='',
306 autoproto=None,
307 use_hostcc=False,
308 use_global_deps=True,
309 compiler=None,
310 group='binaries',
311 manpages=None,
312 local_include=True,
313 global_include=True,
314 subsystem_name=None,
315 pyembed=False,
316 vars=None,
317 subdir=None,
318 install=True,
319 install_path=None,
320 enabled=True):
321 '''define a Samba binary'''
323 if not enabled:
324 SET_TARGET_TYPE(bld, binname, 'DISABLED')
325 return
327 if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
328 return
330 features = 'cc cprogram symlink_bin install_bin'
331 if pyembed:
332 features += ' pyembed'
334 obj_target = binname + '.objlist'
336 source = bld.EXPAND_VARIABLES(source, vars=vars)
337 if subdir:
338 source = bld.SUBDIR(subdir, source)
339 source = unique_list(TO_LIST(source))
341 if group == 'binaries':
342 subsystem_group = 'main'
343 else:
344 subsystem_group = group
346 # only specify PIE flags for binaries
347 pie_cflags = cflags
348 pie_ldflags = TO_LIST(ldflags)
349 if bld.env['ENABLE_PIE'] == True:
350 pie_cflags += ' -fPIE'
351 pie_ldflags.extend(TO_LIST('-pie'))
353 # first create a target for building the object files for this binary
354 # by separating in this way, we avoid recompiling the C files
355 # separately for the install binary and the build binary
356 bld.SAMBA_SUBSYSTEM(obj_target,
357 source = source,
358 deps = deps,
359 includes = includes,
360 cflags = pie_cflags,
361 group = subsystem_group,
362 autoproto = autoproto,
363 subsystem_name = subsystem_name,
364 local_include = local_include,
365 global_include = global_include,
366 use_hostcc = use_hostcc,
367 pyext = pyembed,
368 use_global_deps= use_global_deps)
370 bld.SET_BUILD_GROUP(group)
372 # the binary itself will depend on that object target
373 deps = TO_LIST(deps)
374 deps.append(obj_target)
376 t = bld(
377 features = features,
378 source = [],
379 target = binname,
380 samba_deps = deps,
381 samba_includes = includes,
382 local_include = local_include,
383 global_include = global_include,
384 samba_modules = modules,
385 top = True,
386 samba_subsystem= subsystem_name,
387 install_path = None,
388 samba_inst_path= install_path,
389 samba_install = install,
390 samba_ldflags = pie_ldflags
393 if manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and bld.env['XSLTPROC_MANPAGES']:
394 bld.MANPAGES(manpages, install)
396 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
399 #################################################################
400 def SAMBA_MODULE(bld, modname, source,
401 deps='',
402 includes='',
403 subsystem=None,
404 init_function=None,
405 module_init_name='samba_init_module',
406 autoproto=None,
407 autoproto_extra_source='',
408 cflags='',
409 internal_module=True,
410 local_include=True,
411 global_include=True,
412 vars=None,
413 subdir=None,
414 enabled=True,
415 pyembed=False,
416 manpages=None,
417 allow_undefined_symbols=False
419 '''define a Samba module.'''
421 source = bld.EXPAND_VARIABLES(source, vars=vars)
422 if subdir:
423 source = bld.SUBDIR(subdir, source)
425 if internal_module or BUILTIN_LIBRARY(bld, modname):
426 # Do not create modules for disabled subsystems
427 if subsystem and GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
428 return
429 bld.SAMBA_SUBSYSTEM(modname, source,
430 deps=deps,
431 includes=includes,
432 autoproto=autoproto,
433 autoproto_extra_source=autoproto_extra_source,
434 cflags=cflags,
435 local_include=local_include,
436 global_include=global_include,
437 enabled=enabled)
439 bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
440 return
442 if not enabled:
443 SET_TARGET_TYPE(bld, modname, 'DISABLED')
444 return
446 # Do not create modules for disabled subsystems
447 if subsystem and GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
448 return
450 obj_target = modname + '.objlist'
452 realname = modname
453 if subsystem is not None:
454 deps += ' ' + subsystem
455 while realname.startswith("lib"+subsystem+"_"):
456 realname = realname[len("lib"+subsystem+"_"):]
457 while realname.startswith(subsystem+"_"):
458 realname = realname[len(subsystem+"_"):]
460 realname = bld.make_libname(realname)
461 while realname.startswith("lib"):
462 realname = realname[len("lib"):]
464 build_link_name = "modules/%s/%s" % (subsystem, realname)
466 if init_function:
467 cflags += " -D%s=%s" % (init_function, module_init_name)
469 bld.SAMBA_LIBRARY(modname,
470 source,
471 deps=deps,
472 includes=includes,
473 cflags=cflags,
474 realname = realname,
475 autoproto = autoproto,
476 local_include=local_include,
477 global_include=global_include,
478 vars=vars,
479 link_name=build_link_name,
480 install_path="${MODULESDIR}/%s" % subsystem,
481 pyembed=pyembed,
482 manpages=manpages,
483 allow_undefined_symbols=allow_undefined_symbols
487 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
490 #################################################################
491 def SAMBA_SUBSYSTEM(bld, modname, source,
492 deps='',
493 public_deps='',
494 includes='',
495 public_headers=None,
496 public_headers_install=True,
497 header_path=None,
498 cflags='',
499 cflags_end=None,
500 group='main',
501 init_function_sentinel=None,
502 autoproto=None,
503 autoproto_extra_source='',
504 depends_on='',
505 local_include=True,
506 local_include_first=True,
507 global_include=True,
508 subsystem_name=None,
509 enabled=True,
510 use_hostcc=False,
511 use_global_deps=True,
512 vars=None,
513 subdir=None,
514 hide_symbols=False,
515 pyext=False,
516 pyembed=False):
517 '''define a Samba subsystem'''
519 if not enabled:
520 SET_TARGET_TYPE(bld, modname, 'DISABLED')
521 return
523 # remember empty subsystems, so we can strip the dependencies
524 if ((source == '') or (source == [])) and deps == '' and public_deps == '':
525 SET_TARGET_TYPE(bld, modname, 'EMPTY')
526 return
528 if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
529 return
531 source = bld.EXPAND_VARIABLES(source, vars=vars)
532 if subdir:
533 source = bld.SUBDIR(subdir, source)
534 source = unique_list(TO_LIST(source))
536 deps += ' ' + public_deps
538 bld.SET_BUILD_GROUP(group)
540 features = 'cc'
541 if pyext:
542 features += ' pyext'
543 if pyembed:
544 features += ' pyembed'
546 t = bld(
547 features = features,
548 source = source,
549 target = modname,
550 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags, hide_symbols=hide_symbols),
551 depends_on = depends_on,
552 samba_deps = TO_LIST(deps),
553 samba_includes = includes,
554 local_include = local_include,
555 local_include_first = local_include_first,
556 global_include = global_include,
557 samba_subsystem= subsystem_name,
558 samba_use_hostcc = use_hostcc,
559 samba_use_global_deps = use_global_deps,
562 if cflags_end is not None:
563 t.samba_cflags.extend(TO_LIST(cflags_end))
565 if autoproto is not None:
566 bld.SAMBA_AUTOPROTO(autoproto, source + TO_LIST(autoproto_extra_source))
567 if public_headers is not None:
568 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
569 public_headers_install=public_headers_install)
570 return t
573 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
576 def SAMBA_GENERATOR(bld, name, rule, source='', target='',
577 group='generators', enabled=True,
578 public_headers=None,
579 public_headers_install=True,
580 header_path=None,
581 vars=None,
582 dep_vars=[],
583 always=False):
584 '''A generic source generator target'''
586 if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
587 return
589 if not enabled:
590 return
592 dep_vars.append('ruledeps')
593 dep_vars.append('SAMBA_GENERATOR_VARS')
595 bld.SET_BUILD_GROUP(group)
596 t = bld(
597 rule=rule,
598 source=bld.EXPAND_VARIABLES(source, vars=vars),
599 target=target,
600 shell=isinstance(rule, str),
601 on_results=True,
602 before='cc',
603 ext_out='.c',
604 samba_type='GENERATOR',
605 dep_vars = dep_vars,
606 name=name)
608 if vars is None:
609 vars = {}
610 t.env.SAMBA_GENERATOR_VARS = vars
612 if always:
613 t.always = True
615 if public_headers is not None:
616 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
617 public_headers_install=public_headers_install)
618 return t
619 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
623 @runonce
624 def SETUP_BUILD_GROUPS(bld):
625 '''setup build groups used to ensure that the different build
626 phases happen consecutively'''
627 bld.p_ln = bld.srcnode # we do want to see all targets!
628 bld.env['USING_BUILD_GROUPS'] = True
629 bld.add_group('setup')
630 bld.add_group('build_compiler_source')
631 bld.add_group('vscripts')
632 bld.add_group('base_libraries')
633 bld.add_group('generators')
634 bld.add_group('compiler_prototypes')
635 bld.add_group('compiler_libraries')
636 bld.add_group('build_compilers')
637 bld.add_group('build_source')
638 bld.add_group('prototypes')
639 bld.add_group('headers')
640 bld.add_group('main')
641 bld.add_group('symbolcheck')
642 bld.add_group('libraries')
643 bld.add_group('binaries')
644 bld.add_group('syslibcheck')
645 bld.add_group('final')
646 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
649 def SET_BUILD_GROUP(bld, group):
650 '''set the current build group'''
651 if not 'USING_BUILD_GROUPS' in bld.env:
652 return
653 bld.set_group(group)
654 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
658 @conf
659 def ENABLE_TIMESTAMP_DEPENDENCIES(conf):
660 """use timestamps instead of file contents for deps
661 this currently doesn't work"""
662 def h_file(filename):
663 import stat
664 st = os.stat(filename)
665 if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
666 m = Utils.md5()
667 m.update(str(st.st_mtime))
668 m.update(str(st.st_size))
669 m.update(filename)
670 return m.digest()
671 Utils.h_file = h_file
674 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
675 '''used to copy scripts from the source tree into the build directory
676 for use by selftest'''
678 source = bld.path.ant_glob(pattern)
680 bld.SET_BUILD_GROUP('build_source')
681 for s in TO_LIST(source):
682 iname = s
683 if installname is not None:
684 iname = installname
685 target = os.path.join(installdir, iname)
686 tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
687 mkdir_p(tgtdir)
688 link_src = os.path.normpath(os.path.join(bld.curdir, s))
689 link_dst = os.path.join(tgtdir, os.path.basename(iname))
690 if os.path.islink(link_dst) and os.readlink(link_dst) == link_src:
691 continue
692 if os.path.exists(link_dst):
693 os.unlink(link_dst)
694 Logs.info("symlink: %s -> %s/%s" % (s, installdir, iname))
695 os.symlink(link_src, link_dst)
696 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT
699 def copy_and_fix_python_path(task):
700 pattern='sys.path.insert(0, "bin/python")'
701 if task.env["PYTHONARCHDIR"] in sys.path and task.env["PYTHONDIR"] in sys.path:
702 replacement = ""
703 elif task.env["PYTHONARCHDIR"] == task.env["PYTHONDIR"]:
704 replacement="""sys.path.insert(0, "%s")""" % task.env["PYTHONDIR"]
705 else:
706 replacement="""sys.path.insert(0, "%s")
707 sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"])
709 if task.env["PYTHON"][0] == "/":
710 replacement_shebang = "#!%s\n" % task.env["PYTHON"]
711 else:
712 replacement_shebang = "#!/usr/bin/env %s\n" % task.env["PYTHON"]
714 installed_location=task.outputs[0].bldpath(task.env)
715 source_file = open(task.inputs[0].srcpath(task.env))
716 installed_file = open(installed_location, 'w')
717 lineno = 0
718 for line in source_file:
719 newline = line
720 if lineno == 0 and task.env["PYTHON_SPECIFIED"] == True and line[:2] == "#!":
721 newline = replacement_shebang
722 elif pattern in line:
723 newline = line.replace(pattern, replacement)
724 installed_file.write(newline)
725 lineno = lineno + 1
726 installed_file.close()
727 os.chmod(installed_location, 0755)
728 return 0
730 def copy_and_fix_perl_path(task):
731 pattern='use lib "$RealBin/lib";'
733 replacement = ""
734 if not task.env["PERL_LIB_INSTALL_DIR"] in task.env["PERL_INC"]:
735 replacement = 'use lib "%s";' % task.env["PERL_LIB_INSTALL_DIR"]
737 if task.env["PERL"][0] == "/":
738 replacement_shebang = "#!%s\n" % task.env["PERL"]
739 else:
740 replacement_shebang = "#!/usr/bin/env %s\n" % task.env["PERL"]
742 installed_location=task.outputs[0].bldpath(task.env)
743 source_file = open(task.inputs[0].srcpath(task.env))
744 installed_file = open(installed_location, 'w')
745 lineno = 0
746 for line in source_file:
747 newline = line
748 if lineno == 0 and task.env["PERL_SPECIFIED"] == True and line[:2] == "#!":
749 newline = replacement_shebang
750 elif pattern in line:
751 newline = line.replace(pattern, replacement)
752 installed_file.write(newline)
753 lineno = lineno + 1
754 installed_file.close()
755 os.chmod(installed_location, 0755)
756 return 0
759 def install_file(bld, destdir, file, chmod=MODE_644, flat=False,
760 python_fixup=False, perl_fixup=False,
761 destname=None, base_name=None):
762 '''install a file'''
763 destdir = bld.EXPAND_VARIABLES(destdir)
764 if not destname:
765 destname = file
766 if flat:
767 destname = os.path.basename(destname)
768 dest = os.path.join(destdir, destname)
769 if python_fixup:
770 # fix the path python will use to find Samba modules
771 inst_file = file + '.inst'
772 bld.SAMBA_GENERATOR('python_%s' % destname,
773 rule=copy_and_fix_python_path,
774 dep_vars=["PYTHON","PYTHON_SPECIFIED","PYTHONDIR","PYTHONARCHDIR"],
775 source=file,
776 target=inst_file)
777 file = inst_file
778 if perl_fixup:
779 # fix the path perl will use to find Samba modules
780 inst_file = file + '.inst'
781 bld.SAMBA_GENERATOR('perl_%s' % destname,
782 rule=copy_and_fix_perl_path,
783 dep_vars=["PERL","PERL_SPECIFIED","PERL_LIB_INSTALL_DIR"],
784 source=file,
785 target=inst_file)
786 file = inst_file
787 if base_name:
788 file = os.path.join(base_name, file)
789 bld.install_as(dest, file, chmod=chmod)
792 def INSTALL_FILES(bld, destdir, files, chmod=MODE_644, flat=False,
793 python_fixup=False, perl_fixup=False,
794 destname=None, base_name=None):
795 '''install a set of files'''
796 for f in TO_LIST(files):
797 install_file(bld, destdir, f, chmod=chmod, flat=flat,
798 python_fixup=python_fixup, perl_fixup=perl_fixup,
799 destname=destname, base_name=base_name)
800 Build.BuildContext.INSTALL_FILES = INSTALL_FILES
803 def INSTALL_WILDCARD(bld, destdir, pattern, chmod=MODE_644, flat=False,
804 python_fixup=False, exclude=None, trim_path=None):
805 '''install a set of files matching a wildcard pattern'''
806 files=TO_LIST(bld.path.ant_glob(pattern))
807 if trim_path:
808 files2 = []
809 for f in files:
810 files2.append(os_path_relpath(f, trim_path))
811 files = files2
813 if exclude:
814 for f in files[:]:
815 if fnmatch.fnmatch(f, exclude):
816 files.remove(f)
817 INSTALL_FILES(bld, destdir, files, chmod=chmod, flat=flat,
818 python_fixup=python_fixup, base_name=trim_path)
819 Build.BuildContext.INSTALL_WILDCARD = INSTALL_WILDCARD
822 def INSTALL_DIRS(bld, destdir, dirs):
823 '''install a set of directories'''
824 destdir = bld.EXPAND_VARIABLES(destdir)
825 dirs = bld.EXPAND_VARIABLES(dirs)
826 for d in TO_LIST(dirs):
827 bld.install_dir(os.path.join(destdir, d))
828 Build.BuildContext.INSTALL_DIRS = INSTALL_DIRS
831 def MANPAGES(bld, manpages, install):
832 '''build and install manual pages'''
833 bld.env.MAN_XSL = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
834 for m in manpages.split():
835 source = m + '.xml'
836 bld.SAMBA_GENERATOR(m,
837 source=source,
838 target=m,
839 group='final',
840 rule='${XSLTPROC} --xinclude -o ${TGT} --nonet ${MAN_XSL} ${SRC}'
842 if install:
843 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
844 Build.BuildContext.MANPAGES = MANPAGES
846 def SAMBAMANPAGES(bld, manpages, extra_source=None):
847 '''build and install manual pages'''
848 bld.env.SAMBA_EXPAND_XSL = bld.srcnode.abspath() + '/docs-xml/xslt/expand-sambadoc.xsl'
849 bld.env.SAMBA_MAN_XSL = bld.srcnode.abspath() + '/docs-xml/xslt/man.xsl'
850 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'
852 for m in manpages.split():
853 source = m + '.xml'
854 if extra_source is not None:
855 source = [source, extra_source]
856 bld.SAMBA_GENERATOR(m,
857 source=source,
858 target=m,
859 group='final',
860 rule='''XML_CATALOG_FILES="${SAMBA_CATALOGS}"
861 export XML_CATALOG_FILES
862 ${XSLTPROC} --xinclude --stringparam noreference 0 -o ${TGT}.xml --nonet ${SAMBA_EXPAND_XSL} ${SRC[0].abspath(env)}
863 ${XSLTPROC} --nonet -o ${TGT} ${SAMBA_MAN_XSL} ${TGT}.xml'''
865 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
866 Build.BuildContext.SAMBAMANPAGES = SAMBAMANPAGES
868 #############################################################
869 # give a nicer display when building different types of files
870 def progress_display(self, msg, fname):
871 col1 = Logs.colors(self.color)
872 col2 = Logs.colors.NORMAL
873 total = self.position[1]
874 n = len(str(total))
875 fs = '[%%%dd/%%%dd] %s %%s%%s%%s\n' % (n, n, msg)
876 return fs % (self.position[0], self.position[1], col1, fname, col2)
878 def link_display(self):
879 if Options.options.progress_bar != 0:
880 return Task.Task.old_display(self)
881 fname = self.outputs[0].bldpath(self.env)
882 return progress_display(self, 'Linking', fname)
883 Task.TaskBase.classes['cc_link'].display = link_display
885 def samba_display(self):
886 if Options.options.progress_bar != 0:
887 return Task.Task.old_display(self)
889 targets = LOCAL_CACHE(self, 'TARGET_TYPE')
890 if self.name in targets:
891 target_type = targets[self.name]
892 type_map = { 'GENERATOR' : 'Generating',
893 'PROTOTYPE' : 'Generating'
895 if target_type in type_map:
896 return progress_display(self, type_map[target_type], self.name)
898 if len(self.inputs) == 0:
899 return Task.Task.old_display(self)
901 fname = self.inputs[0].bldpath(self.env)
902 if fname[0:3] == '../':
903 fname = fname[3:]
904 ext_loc = fname.rfind('.')
905 if ext_loc == -1:
906 return Task.Task.old_display(self)
907 ext = fname[ext_loc:]
909 ext_map = { '.idl' : 'Compiling IDL',
910 '.et' : 'Compiling ERRTABLE',
911 '.asn1': 'Compiling ASN1',
912 '.c' : 'Compiling' }
913 if ext in ext_map:
914 return progress_display(self, ext_map[ext], fname)
915 return Task.Task.old_display(self)
917 Task.TaskBase.classes['Task'].old_display = Task.TaskBase.classes['Task'].display
918 Task.TaskBase.classes['Task'].display = samba_display
921 @after('apply_link')
922 @feature('cshlib')
923 def apply_bundle_remove_dynamiclib_patch(self):
924 if self.env['MACBUNDLE'] or getattr(self,'mac_bundle',False):
925 if not getattr(self,'vnum',None):
926 try:
927 self.env['LINKFLAGS'].remove('-dynamiclib')
928 self.env['LINKFLAGS'].remove('-single_module')
929 except ValueError:
930 pass