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