waf: moved header file handling into its own module
[kai/samba.git] / buildtools / wafsamba / wafsamba.py
1 # a waf tool to add autoconf-like macros to the configure section
2 # and for SAMBA_ macros for building libraries, binaries etc
3
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
9
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_deps import *
20 from samba_bundled import *
21 import samba_install
22 import samba_conftests
23 import samba_abi
24 import samba_headers
25 import tru64cc
26 import irixcc
27 import hpuxcc
28 import generic_cc
29 import samba_dist
30 import samba_wildcard
31 import stale_files
32 import symbols
33 import pkgconfig
34
35 # some systems have broken threading in python
36 if os.environ.get('WAF_NOTHREADS') == '1':
37     import nothreads
38
39 LIB_PATH="shared"
40
41 os.environ['PYTHONUNBUFFERED'] = '1'
42
43
44 if Constants.HEXVERSION < 0x105019:
45     Logs.error('''
46 Please use the version of waf that comes with Samba, not
47 a system installed version. See http://wiki.samba.org/index.php/Waf
48 for details.
49
50 Alternatively, please run ./configure and make as usual. That will
51 call the right version of waf.''')
52     sys.exit(1)
53
54
55 @conf
56 def SAMBA_BUILD_ENV(conf):
57     '''create the samba build environment'''
58     conf.env.BUILD_DIRECTORY = conf.blddir
59     mkdir_p(os.path.join(conf.blddir, LIB_PATH))
60     mkdir_p(os.path.join(conf.blddir, LIB_PATH, "private"))
61     mkdir_p(os.path.join(conf.blddir, "modules"))
62     mkdir_p(os.path.join(conf.blddir, 'python/samba/dcerpc'))
63     # this allows all of the bin/shared and bin/python targets
64     # to be expressed in terms of build directory paths
65     mkdir_p(os.path.join(conf.blddir, 'default'))
66     for p in ['python','shared', 'modules']:
67         link_target = os.path.join(conf.blddir, 'default/' + p)
68         if not os.path.lexists(link_target):
69             os.symlink('../' + p, link_target)
70
71     # get perl to put the blib files in the build directory
72     blib_bld = os.path.join(conf.blddir, 'default/pidl/blib')
73     blib_src = os.path.join(conf.srcdir, 'pidl/blib')
74     mkdir_p(blib_bld + '/man1')
75     mkdir_p(blib_bld + '/man3')
76     if os.path.islink(blib_src):
77         os.unlink(blib_src)
78     elif os.path.exists(blib_src):
79         shutil.rmtree(blib_src)
80
81
82 def ADD_INIT_FUNCTION(bld, subsystem, target, init_function):
83     '''add an init_function to the list for a subsystem'''
84     if init_function is None:
85         return
86     bld.ASSERT(subsystem is not None, "You must specify a subsystem for init_function '%s'" % init_function)
87     cache = LOCAL_CACHE(bld, 'INIT_FUNCTIONS')
88     if not subsystem in cache:
89         cache[subsystem] = []
90     cache[subsystem].append( { 'TARGET':target, 'INIT_FUNCTION':init_function } )
91 Build.BuildContext.ADD_INIT_FUNCTION = ADD_INIT_FUNCTION
92
93
94
95 #################################################################
96 def SAMBA_LIBRARY(bld, libname, source,
97                   deps='',
98                   public_deps='',
99                   includes='',
100                   public_headers=None,
101                   header_path=None,
102                   pc_files=None,
103                   vnum=None,
104                   soname=None,
105                   cflags='',
106                   ldflags='',
107                   external_library=False,
108                   realname=None,
109                   autoproto=None,
110                   group='libraries',
111                   depends_on='',
112                   local_include=True,
113                   global_include=True,
114                   vars=None,
115                   subdir=None,
116                   install_path=None,
117                   install=True,
118                   pyembed=False,
119                   pyext=False,
120                   target_type='LIBRARY',
121                   bundled_extension=True,
122                   link_name=None,
123                   abi_directory=None,
124                   abi_match=None,
125                   hide_symbols=False,
126                   manpages=None,
127                   private_library=False,
128                   grouping_library=False,
129                   allow_undefined_symbols=False,
130                   enabled=True):
131     '''define a Samba library'''
132
133     if not enabled:
134         SET_TARGET_TYPE(bld, libname, 'DISABLED')
135         return
136
137     source = bld.EXPAND_VARIABLES(source, vars=vars)
138     if subdir:
139         source = bld.SUBDIR(subdir, source)
140
141     # remember empty libraries, so we can strip the dependencies
142     if ((source == '') or (source == [])) and deps == '' and public_deps == '':
143         SET_TARGET_TYPE(bld, libname, 'EMPTY')
144         return
145
146     if BUILTIN_LIBRARY(bld, libname):
147         obj_target = libname
148     else:
149         obj_target = libname + '.objlist'
150
151     if group == 'libraries':
152         subsystem_group = 'main'
153     else:
154         subsystem_group = group
155
156     # first create a target for building the object files for this library
157     # by separating in this way, we avoid recompiling the C files
158     # separately for the install library and the build library
159     bld.SAMBA_SUBSYSTEM(obj_target,
160                         source         = source,
161                         deps           = deps,
162                         public_deps    = public_deps,
163                         includes       = includes,
164                         public_headers = public_headers,
165                         header_path    = header_path,
166                         cflags         = cflags,
167                         group          = subsystem_group,
168                         autoproto      = autoproto,
169                         depends_on     = depends_on,
170                         hide_symbols   = hide_symbols,
171                         pyext          = pyext or (target_type == "PYTHON"),
172                         local_include  = local_include,
173                         global_include = global_include)
174
175     if BUILTIN_LIBRARY(bld, libname):
176         return
177
178     if not SET_TARGET_TYPE(bld, libname, target_type):
179         return
180
181     # the library itself will depend on that object target
182     deps += ' ' + public_deps
183     deps = TO_LIST(deps)
184     deps.append(obj_target)
185
186     realname = bld.map_shlib_extension(realname, python=(target_type=='PYTHON'))
187     link_name = bld.map_shlib_extension(link_name, python=(target_type=='PYTHON'))
188
189     # we don't want any public libraries without version numbers
190     if not private_library and vnum is None and soname is None and target_type != 'PYTHON' and not realname:
191         raise Utils.WafError("public library '%s' must have a vnum" % libname)
192
193     if target_type == 'PYTHON' or realname or not private_library:
194         bundled_name = libname.replace('_', '-')
195     else:
196         bundled_name = PRIVATE_NAME(bld, libname, bundled_extension, private_library)
197
198     ldflags = TO_LIST(ldflags)
199
200     features = 'cc cshlib symlink_lib install_lib'
201     if target_type == 'PYTHON':
202         features += ' pyext'
203     if pyext or pyembed:
204         # this is quite strange. we should add pyext feature for pyext
205         # but that breaks the build. This may be a bug in the waf python tool
206         features += ' pyembed'
207
208     if abi_directory:
209         features += ' abi_check'
210
211     vscript = None
212     if bld.env.HAVE_LD_VERSION_SCRIPT:
213         if private_library:
214             version = "%s_%s" % (Utils.g_module.APPNAME, Utils.g_module.VERSION)
215         elif vnum:
216             version = "%s_%s" % (libname, vnum)
217         else:
218             version = None
219         if version:
220             vscript = "%s.vscript" % libname
221             bld.ABI_VSCRIPT(libname, abi_directory, version, vscript,
222                             abi_match)
223             fullname = apply_pattern(bundled_name, bld.env.shlib_PATTERN)
224             fullpath = bld.path.find_or_declare(fullname)
225             vscriptpath = bld.path.find_or_declare(vscript)
226             if not fullpath:
227                 raise Utils.WafError("unable to find fullpath for %s" % fullname)
228             if not vscriptpath:
229                 raise Utils.WafError("unable to find vscript path for %s" % vscript)
230             bld.add_manual_dependency(fullpath, vscriptpath)
231             if Options.is_install:
232                 # also make the .inst file depend on the vscript
233                 instname = apply_pattern(bundled_name + '.inst', bld.env.shlib_PATTERN)
234                 bld.add_manual_dependency(bld.path.find_or_declare(instname), bld.path.find_or_declare(vscript))
235             vscript = os.path.join(bld.path.abspath(bld.env), vscript)
236
237     bld.SET_BUILD_GROUP(group)
238     t = bld(
239         features        = features,
240         source          = [],
241         target          = bundled_name,
242         depends_on      = depends_on,
243         samba_ldflags   = ldflags,
244         samba_deps      = deps,
245         samba_includes  = includes,
246         version_script  = vscript,
247         local_include   = local_include,
248         global_include  = global_include,
249         vnum            = vnum,
250         soname          = soname,
251         install_path    = None,
252         samba_inst_path = install_path,
253         name            = libname,
254         samba_realname  = realname,
255         samba_install   = install,
256         abi_directory   = "%s/%s" % (bld.path.abspath(), abi_directory),
257         abi_match       = abi_match,
258         private_library = private_library,
259         grouping_library=grouping_library,
260         allow_undefined_symbols=allow_undefined_symbols
261         )
262
263     if realname and not link_name:
264         link_name = 'shared/%s' % realname
265
266     if link_name:
267         t.link_name = link_name
268
269     if pc_files is not None:
270         bld.PKG_CONFIG_FILES(pc_files, vnum=vnum)
271
272     if manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and bld.env['XSLTPROC_MANPAGES']:
273         bld.MANPAGES(manpages)
274
275
276 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
277
278
279 #################################################################
280 def SAMBA_BINARY(bld, binname, source,
281                  deps='',
282                  includes='',
283                  public_headers=None,
284                  header_path=None,
285                  modules=None,
286                  ldflags=None,
287                  cflags='',
288                  autoproto=None,
289                  use_hostcc=False,
290                  use_global_deps=True,
291                  compiler=None,
292                  group='binaries',
293                  manpages=None,
294                  local_include=True,
295                  global_include=True,
296                  subsystem_name=None,
297                  pyembed=False,
298                  vars=None,
299                  subdir=None,
300                  install=True,
301                  install_path=None,
302                  enabled=True):
303     '''define a Samba binary'''
304
305     if not enabled:
306         SET_TARGET_TYPE(bld, binname, 'DISABLED')
307         return
308
309     if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
310         return
311
312     features = 'cc cprogram symlink_bin install_bin'
313     if pyembed:
314         features += ' pyembed'
315
316     obj_target = binname + '.objlist'
317
318     source = bld.EXPAND_VARIABLES(source, vars=vars)
319     if subdir:
320         source = bld.SUBDIR(subdir, source)
321     source = unique_list(TO_LIST(source))
322
323     if group == 'binaries':
324         subsystem_group = 'main'
325     else:
326         subsystem_group = group
327
328     # first create a target for building the object files for this binary
329     # by separating in this way, we avoid recompiling the C files
330     # separately for the install binary and the build binary
331     bld.SAMBA_SUBSYSTEM(obj_target,
332                         source         = source,
333                         deps           = deps,
334                         includes       = includes,
335                         cflags         = cflags,
336                         group          = subsystem_group,
337                         autoproto      = autoproto,
338                         subsystem_name = subsystem_name,
339                         local_include  = local_include,
340                         global_include = global_include,
341                         use_hostcc     = use_hostcc,
342                         pyext          = pyembed,
343                         use_global_deps= use_global_deps)
344
345     bld.SET_BUILD_GROUP(group)
346
347     # the binary itself will depend on that object target
348     deps = TO_LIST(deps)
349     deps.append(obj_target)
350
351     t = bld(
352         features       = features,
353         source         = [],
354         target         = binname,
355         samba_deps     = deps,
356         samba_includes = includes,
357         local_include  = local_include,
358         global_include = global_include,
359         samba_modules  = modules,
360         top            = True,
361         samba_subsystem= subsystem_name,
362         install_path   = None,
363         samba_inst_path= install_path,
364         samba_install  = install,
365         samba_ldflags  = TO_LIST(ldflags)
366         )
367
368     if manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and bld.env['XSLTPROC_MANPAGES']:
369         bld.MANPAGES(manpages)
370
371 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
372
373
374 #################################################################
375 def SAMBA_MODULE(bld, modname, source,
376                  deps='',
377                  includes='',
378                  subsystem=None,
379                  init_function=None,
380                  module_init_name='samba_init_module',
381                  autoproto=None,
382                  autoproto_extra_source='',
383                  cflags='',
384                  internal_module=True,
385                  local_include=True,
386                  global_include=True,
387                  vars=None,
388                  subdir=None,
389                  enabled=True,
390                  pyembed=False,
391                  allow_undefined_symbols=False
392                  ):
393     '''define a Samba module.'''
394
395     source = bld.EXPAND_VARIABLES(source, vars=vars)
396     if subdir:
397         source = bld.SUBDIR(subdir, source)
398
399     if internal_module or BUILTIN_LIBRARY(bld, modname):
400         bld.SAMBA_SUBSYSTEM(modname, source,
401                     deps=deps,
402                     includes=includes,
403                     autoproto=autoproto,
404                     autoproto_extra_source=autoproto_extra_source,
405                     cflags=cflags,
406                     local_include=local_include,
407                     global_include=global_include,
408                     enabled=enabled)
409
410         bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
411         return
412
413     if not enabled:
414         SET_TARGET_TYPE(bld, modname, 'DISABLED')
415         return
416
417     obj_target = modname + '.objlist'
418
419     realname = modname
420     if subsystem is not None:
421         deps += ' ' + subsystem
422         while realname.startswith("lib"+subsystem+"_"):
423             realname = realname[len("lib"+subsystem+"_"):]
424         while realname.startswith(subsystem+"_"):
425             realname = realname[len(subsystem+"_"):]
426
427     realname = bld.make_libname(realname)
428     while realname.startswith("lib"):
429         realname = realname[len("lib"):]
430
431     build_link_name = "modules/%s/%s" % (subsystem, realname)
432
433     if init_function:
434         cflags += " -D%s=%s" % (init_function, module_init_name)
435
436     bld.SAMBA_LIBRARY(modname,
437                       source,
438                       deps=deps,
439                       includes=includes,
440                       cflags=cflags,
441                       realname = realname,
442                       autoproto = autoproto,
443                       local_include=local_include,
444                       global_include=global_include,
445                       vars=vars,
446                       link_name=build_link_name,
447                       install_path="${MODULESDIR}/%s" % subsystem,
448                       pyembed=pyembed,
449                       allow_undefined_symbols=allow_undefined_symbols
450                       )
451
452
453 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
454
455
456 #################################################################
457 def SAMBA_SUBSYSTEM(bld, modname, source,
458                     deps='',
459                     public_deps='',
460                     includes='',
461                     public_headers=None,
462                     header_path=None,
463                     cflags='',
464                     cflags_end=None,
465                     group='main',
466                     init_function_sentinal=None,
467                     autoproto=None,
468                     autoproto_extra_source='',
469                     depends_on='',
470                     local_include=True,
471                     local_include_first=True,
472                     global_include=True,
473                     subsystem_name=None,
474                     enabled=True,
475                     use_hostcc=False,
476                     use_global_deps=True,
477                     vars=None,
478                     subdir=None,
479                     hide_symbols=False,
480                     pyext=False):
481     '''define a Samba subsystem'''
482
483     if not enabled:
484         SET_TARGET_TYPE(bld, modname, 'DISABLED')
485         return
486
487     # remember empty subsystems, so we can strip the dependencies
488     if ((source == '') or (source == [])) and deps == '' and public_deps == '':
489         SET_TARGET_TYPE(bld, modname, 'EMPTY')
490         return
491
492     if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
493         return
494
495     source = bld.EXPAND_VARIABLES(source, vars=vars)
496     if subdir:
497         source = bld.SUBDIR(subdir, source)
498     source = unique_list(TO_LIST(source))
499
500     deps += ' ' + public_deps
501
502     bld.SET_BUILD_GROUP(group)
503
504     features = 'cc'
505     if pyext:
506         features += ' pyext'
507
508     t = bld(
509         features       = features,
510         source         = source,
511         target         = modname,
512         samba_cflags   = CURRENT_CFLAGS(bld, modname, cflags, hide_symbols=hide_symbols),
513         depends_on     = depends_on,
514         samba_deps     = TO_LIST(deps),
515         samba_includes = includes,
516         local_include  = local_include,
517         local_include_first  = local_include_first,
518         global_include = global_include,
519         samba_subsystem= subsystem_name,
520         samba_use_hostcc = use_hostcc,
521         samba_use_global_deps = use_global_deps
522         )
523
524     if cflags_end is not None:
525         t.samba_cflags.extend(TO_LIST(cflags_end))
526
527     if autoproto is not None:
528         bld.SAMBA_AUTOPROTO(autoproto, source + TO_LIST(autoproto_extra_source))
529     if public_headers is not None:
530         bld.PUBLIC_HEADERS(public_headers, header_path=header_path)
531     return t
532
533
534 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
535
536
537 def SAMBA_GENERATOR(bld, name, rule, source='', target='',
538                     group='generators', enabled=True,
539                     public_headers=None,
540                     header_path=None,
541                     vars=None,
542                     always=False):
543     '''A generic source generator target'''
544
545     if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
546         return
547
548     if not enabled:
549         return
550
551     bld.SET_BUILD_GROUP(group)
552     t = bld(
553         rule=rule,
554         source=bld.EXPAND_VARIABLES(source, vars=vars),
555         target=target,
556         shell=isinstance(rule, str),
557         on_results=True,
558         before='cc',
559         ext_out='.c',
560         samba_type='GENERATOR',
561         dep_vars = [rule] + (vars or []),
562         name=name)
563
564     if always:
565         t.always = True
566
567     if public_headers is not None:
568         bld.PUBLIC_HEADERS(public_headers, header_path=header_path)
569     return t
570 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
571
572
573
574 @runonce
575 def SETUP_BUILD_GROUPS(bld):
576     '''setup build groups used to ensure that the different build
577     phases happen consecutively'''
578     bld.p_ln = bld.srcnode # we do want to see all targets!
579     bld.env['USING_BUILD_GROUPS'] = True
580     bld.add_group('setup')
581     bld.add_group('build_compiler_source')
582     bld.add_group('vscripts')
583     bld.add_group('base_libraries')
584     bld.add_group('generators')
585     bld.add_group('compiler_prototypes')
586     bld.add_group('compiler_libraries')
587     bld.add_group('build_compilers')
588     bld.add_group('build_source')
589     bld.add_group('prototypes')
590     bld.add_group('main')
591     bld.add_group('symbolcheck')
592     bld.add_group('libraries')
593     bld.add_group('binaries')
594     bld.add_group('syslibcheck')
595     bld.add_group('final')
596 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
597
598
599 def SET_BUILD_GROUP(bld, group):
600     '''set the current build group'''
601     if not 'USING_BUILD_GROUPS' in bld.env:
602         return
603     bld.set_group(group)
604 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
605
606
607
608 @conf
609 def ENABLE_TIMESTAMP_DEPENDENCIES(conf):
610     """use timestamps instead of file contents for deps
611     this currently doesn't work"""
612     def h_file(filename):
613         import stat
614         st = os.stat(filename)
615         if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
616         m = Utils.md5()
617         m.update(str(st.st_mtime))
618         m.update(str(st.st_size))
619         m.update(filename)
620         return m.digest()
621     Utils.h_file = h_file
622
623
624
625 t = Task.simple_task_type('copy_script', 'rm -f "${LINK_TARGET}" && ln -s "${SRC[0].abspath(env)}" ${LINK_TARGET}',
626                           shell=True, color='PINK', ext_in='.bin')
627 t.quiet = True
628
629 @feature('copy_script')
630 @before('apply_link')
631 def copy_script(self):
632     tsk = self.create_task('copy_script', self.allnodes[0])
633     tsk.env.TARGET = self.target
634
635 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
636     '''used to copy scripts from the source tree into the build directory
637        for use by selftest'''
638
639     source = bld.path.ant_glob(pattern)
640
641     bld.SET_BUILD_GROUP('build_source')
642     for s in TO_LIST(source):
643         iname = s
644         if installname != None:
645             iname = installname
646         target = os.path.join(installdir, iname)
647         tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
648         mkdir_p(tgtdir)
649         t = bld(features='copy_script',
650                 source       = s,
651                 target       = target,
652                 always       = True,
653                 install_path = None)
654         t.env.LINK_TARGET = target
655
656 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT
657
658 def copy_and_fix_python_path(task):
659     pattern='sys.path.insert(0, "bin/python")'
660     if task.env["PYTHONARCHDIR"] in sys.path and task.env["PYTHONDIR"] in sys.path:
661         replacement = ""
662     elif task.env["PYTHONARCHDIR"] == task.env["PYTHONDIR"]:
663         replacement="""sys.path.insert(0, "%s")""" % task.env["PYTHONDIR"]
664     else:
665         replacement="""sys.path.insert(0, "%s")
666 sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"])
667
668     installed_location=task.outputs[0].bldpath(task.env)
669     source_file = open(task.inputs[0].srcpath(task.env))
670     installed_file = open(installed_location, 'w')
671     for line in source_file:
672         newline = line
673         if pattern in line:
674             newline = line.replace(pattern, replacement)
675         installed_file.write(newline)
676     installed_file.close()
677     os.chmod(installed_location, 0755)
678     return 0
679
680
681 def install_file(bld, destdir, file, chmod=MODE_644, flat=False,
682                  python_fixup=False, destname=None, base_name=None):
683     '''install a file'''
684     destdir = bld.EXPAND_VARIABLES(destdir)
685     if not destname:
686         destname = file
687         if flat:
688             destname = os.path.basename(destname)
689     dest = os.path.join(destdir, destname)
690     if python_fixup:
691         # fixup the python path it will use to find Samba modules
692         inst_file = file + '.inst'
693         bld.SAMBA_GENERATOR('python_%s' % destname,
694                             rule=copy_and_fix_python_path,
695                             source=file,
696                             target=inst_file)
697         file = inst_file
698     if base_name:
699         file = os.path.join(base_name, file)
700     bld.install_as(dest, file, chmod=chmod)
701
702
703 def INSTALL_FILES(bld, destdir, files, chmod=MODE_644, flat=False,
704                   python_fixup=False, destname=None, base_name=None):
705     '''install a set of files'''
706     for f in TO_LIST(files):
707         install_file(bld, destdir, f, chmod=chmod, flat=flat,
708                      python_fixup=python_fixup, destname=destname,
709                      base_name=base_name)
710 Build.BuildContext.INSTALL_FILES = INSTALL_FILES
711
712
713 def INSTALL_WILDCARD(bld, destdir, pattern, chmod=MODE_644, flat=False,
714                      python_fixup=False, exclude=None, trim_path=None):
715     '''install a set of files matching a wildcard pattern'''
716     files=TO_LIST(bld.path.ant_glob(pattern))
717     if trim_path:
718         files2 = []
719         for f in files:
720             files2.append(os_path_relpath(f, trim_path))
721         files = files2
722
723     if exclude:
724         for f in files[:]:
725             if fnmatch.fnmatch(f, exclude):
726                 files.remove(f)
727     INSTALL_FILES(bld, destdir, files, chmod=chmod, flat=flat,
728                   python_fixup=python_fixup, base_name=trim_path)
729 Build.BuildContext.INSTALL_WILDCARD = INSTALL_WILDCARD
730
731
732 def INSTALL_DIRS(bld, destdir, dirs):
733     '''install a set of directories'''
734     destdir = bld.EXPAND_VARIABLES(destdir)
735     dirs = bld.EXPAND_VARIABLES(dirs)
736     for d in TO_LIST(dirs):
737         bld.install_dir(os.path.join(destdir, d))
738 Build.BuildContext.INSTALL_DIRS = INSTALL_DIRS
739
740
741 def MANPAGES(bld, manpages):
742     '''build and install manual pages'''
743     bld.env.MAN_XSL = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
744     for m in manpages.split():
745         source = m + '.xml'
746         bld.SAMBA_GENERATOR(m,
747                             source=source,
748                             target=m,
749                             group='final',
750                             rule='${XSLTPROC} -o ${TGT} --nonet ${MAN_XSL} ${SRC}'
751                             )
752         bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
753 Build.BuildContext.MANPAGES = MANPAGES
754
755
756 #############################################################
757 # give a nicer display when building different types of files
758 def progress_display(self, msg, fname):
759     col1 = Logs.colors(self.color)
760     col2 = Logs.colors.NORMAL
761     total = self.position[1]
762     n = len(str(total))
763     fs = '[%%%dd/%%%dd] %s %%s%%s%%s\n' % (n, n, msg)
764     return fs % (self.position[0], self.position[1], col1, fname, col2)
765
766 def link_display(self):
767     if Options.options.progress_bar != 0:
768         return Task.Task.old_display(self)
769     fname = self.outputs[0].bldpath(self.env)
770     return progress_display(self, 'Linking', fname)
771 Task.TaskBase.classes['cc_link'].display = link_display
772
773 def samba_display(self):
774     if Options.options.progress_bar != 0:
775         return Task.Task.old_display(self)
776
777     targets    = LOCAL_CACHE(self, 'TARGET_TYPE')
778     if self.name in targets:
779         target_type = targets[self.name]
780         type_map = { 'GENERATOR' : 'Generating',
781                      'PROTOTYPE' : 'Generating'
782                      }
783         if target_type in type_map:
784             return progress_display(self, type_map[target_type], self.name)
785
786     if len(self.inputs) == 0:
787         return Task.Task.old_display(self)
788
789     fname = self.inputs[0].bldpath(self.env)
790     if fname[0:3] == '../':
791         fname = fname[3:]
792     ext_loc = fname.rfind('.')
793     if ext_loc == -1:
794         return Task.Task.old_display(self)
795     ext = fname[ext_loc:]
796
797     ext_map = { '.idl' : 'Compiling IDL',
798                 '.et'  : 'Compiling ERRTABLE',
799                 '.asn1': 'Compiling ASN1',
800                 '.c'   : 'Compiling' }
801     if ext in ext_map:
802         return progress_display(self, ext_map[ext], fname)
803     return Task.Task.old_display(self)
804
805 Task.TaskBase.classes['Task'].old_display = Task.TaskBase.classes['Task'].display
806 Task.TaskBase.classes['Task'].display = samba_display
807
808
809 @after('apply_link')
810 @feature('cshlib')
811 def apply_bundle_remove_dynamiclib_patch(self):
812     if self.env['MACBUNDLE'] or getattr(self,'mac_bundle',False):
813         if not getattr(self,'vnum',None):
814             try:
815                 self.env['LINKFLAGS'].remove('-dynamiclib')
816                 self.env['LINKFLAGS'].remove('-single_module')
817             except ValueError:
818                 pass