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