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