f1e7affbefe85c212bed005edda73b2fc81820c3
[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                  allow_undefined_symbols=False
408                  ):
409     '''define a Samba module.'''
410
411     source = bld.EXPAND_VARIABLES(source, vars=vars)
412     if subdir:
413         source = bld.SUBDIR(subdir, source)
414
415     if internal_module or BUILTIN_LIBRARY(bld, modname):
416         # Do not create modules for disabled subsystems
417         if subsystem and GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
418             return
419         bld.SAMBA_SUBSYSTEM(modname, source,
420                     deps=deps,
421                     includes=includes,
422                     autoproto=autoproto,
423                     autoproto_extra_source=autoproto_extra_source,
424                     cflags=cflags,
425                     local_include=local_include,
426                     global_include=global_include,
427                     enabled=enabled)
428
429         bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
430         return
431
432     if not enabled:
433         SET_TARGET_TYPE(bld, modname, 'DISABLED')
434         return
435
436     # Do not create modules for disabled subsystems
437     if subsystem and GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
438         return
439
440     obj_target = modname + '.objlist'
441
442     realname = modname
443     if subsystem is not None:
444         deps += ' ' + subsystem
445         while realname.startswith("lib"+subsystem+"_"):
446             realname = realname[len("lib"+subsystem+"_"):]
447         while realname.startswith(subsystem+"_"):
448             realname = realname[len(subsystem+"_"):]
449
450     realname = bld.make_libname(realname)
451     while realname.startswith("lib"):
452         realname = realname[len("lib"):]
453
454     build_link_name = "modules/%s/%s" % (subsystem, realname)
455
456     if init_function:
457         cflags += " -D%s=%s" % (init_function, module_init_name)
458
459     bld.SAMBA_LIBRARY(modname,
460                       source,
461                       deps=deps,
462                       includes=includes,
463                       cflags=cflags,
464                       realname = realname,
465                       autoproto = autoproto,
466                       local_include=local_include,
467                       global_include=global_include,
468                       vars=vars,
469                       link_name=build_link_name,
470                       install_path="${MODULESDIR}/%s" % subsystem,
471                       pyembed=pyembed,
472                       allow_undefined_symbols=allow_undefined_symbols
473                       )
474
475
476 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
477
478
479 #################################################################
480 def SAMBA_SUBSYSTEM(bld, modname, source,
481                     deps='',
482                     public_deps='',
483                     includes='',
484                     public_headers=None,
485                     public_headers_install=True,
486                     header_path=None,
487                     cflags='',
488                     cflags_end=None,
489                     group='main',
490                     init_function_sentinel=None,
491                     autoproto=None,
492                     autoproto_extra_source='',
493                     depends_on='',
494                     local_include=True,
495                     local_include_first=True,
496                     global_include=True,
497                     subsystem_name=None,
498                     enabled=True,
499                     use_hostcc=False,
500                     use_global_deps=True,
501                     vars=None,
502                     subdir=None,
503                     hide_symbols=False,
504                     pyext=False,
505                     pyembed=False):
506     '''define a Samba subsystem'''
507
508     if not enabled:
509         SET_TARGET_TYPE(bld, modname, 'DISABLED')
510         return
511
512     # remember empty subsystems, so we can strip the dependencies
513     if ((source == '') or (source == [])) and deps == '' and public_deps == '':
514         SET_TARGET_TYPE(bld, modname, 'EMPTY')
515         return
516
517     if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
518         return
519
520     source = bld.EXPAND_VARIABLES(source, vars=vars)
521     if subdir:
522         source = bld.SUBDIR(subdir, source)
523     source = unique_list(TO_LIST(source))
524
525     deps += ' ' + public_deps
526
527     bld.SET_BUILD_GROUP(group)
528
529     features = 'cc'
530     if pyext:
531         features += ' pyext'
532     if pyembed:
533         features += ' pyembed'
534
535     t = bld(
536         features       = features,
537         source         = source,
538         target         = modname,
539         samba_cflags   = CURRENT_CFLAGS(bld, modname, cflags, hide_symbols=hide_symbols),
540         depends_on     = depends_on,
541         samba_deps     = TO_LIST(deps),
542         samba_includes = includes,
543         local_include  = local_include,
544         local_include_first  = local_include_first,
545         global_include = global_include,
546         samba_subsystem= subsystem_name,
547         samba_use_hostcc = use_hostcc,
548         samba_use_global_deps = use_global_deps,
549         )
550
551     if cflags_end is not None:
552         t.samba_cflags.extend(TO_LIST(cflags_end))
553
554     if autoproto is not None:
555         bld.SAMBA_AUTOPROTO(autoproto, source + TO_LIST(autoproto_extra_source))
556     if public_headers is not None:
557         bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
558                            public_headers_install=public_headers_install)
559     return t
560
561
562 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
563
564
565 def SAMBA_GENERATOR(bld, name, rule, source='', target='',
566                     group='generators', enabled=True,
567                     public_headers=None,
568                     public_headers_install=True,
569                     header_path=None,
570                     vars=None,
571                     always=False):
572     '''A generic source generator target'''
573
574     if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
575         return
576
577     if not enabled:
578         return
579
580     bld.SET_BUILD_GROUP(group)
581     t = bld(
582         rule=rule,
583         source=bld.EXPAND_VARIABLES(source, vars=vars),
584         target=target,
585         shell=isinstance(rule, str),
586         on_results=True,
587         before='cc',
588         ext_out='.c',
589         samba_type='GENERATOR',
590         dep_vars = [rule] + (vars or []),
591         name=name)
592
593     if always:
594         t.always = True
595
596     if public_headers is not None:
597         bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
598                            public_headers_install=public_headers_install)
599     return t
600 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
601
602
603
604 @runonce
605 def SETUP_BUILD_GROUPS(bld):
606     '''setup build groups used to ensure that the different build
607     phases happen consecutively'''
608     bld.p_ln = bld.srcnode # we do want to see all targets!
609     bld.env['USING_BUILD_GROUPS'] = True
610     bld.add_group('setup')
611     bld.add_group('build_compiler_source')
612     bld.add_group('vscripts')
613     bld.add_group('base_libraries')
614     bld.add_group('generators')
615     bld.add_group('compiler_prototypes')
616     bld.add_group('compiler_libraries')
617     bld.add_group('build_compilers')
618     bld.add_group('build_source')
619     bld.add_group('prototypes')
620     bld.add_group('headers')
621     bld.add_group('main')
622     bld.add_group('symbolcheck')
623     bld.add_group('libraries')
624     bld.add_group('binaries')
625     bld.add_group('syslibcheck')
626     bld.add_group('final')
627 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
628
629
630 def SET_BUILD_GROUP(bld, group):
631     '''set the current build group'''
632     if not 'USING_BUILD_GROUPS' in bld.env:
633         return
634     bld.set_group(group)
635 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
636
637
638
639 @conf
640 def ENABLE_TIMESTAMP_DEPENDENCIES(conf):
641     """use timestamps instead of file contents for deps
642     this currently doesn't work"""
643     def h_file(filename):
644         import stat
645         st = os.stat(filename)
646         if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
647         m = Utils.md5()
648         m.update(str(st.st_mtime))
649         m.update(str(st.st_size))
650         m.update(filename)
651         return m.digest()
652     Utils.h_file = h_file
653
654
655 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
656     '''used to copy scripts from the source tree into the build directory
657        for use by selftest'''
658
659     source = bld.path.ant_glob(pattern)
660
661     bld.SET_BUILD_GROUP('build_source')
662     for s in TO_LIST(source):
663         iname = s
664         if installname != None:
665             iname = installname
666         target = os.path.join(installdir, iname)
667         tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
668         mkdir_p(tgtdir)
669         link_src = os.path.normpath(os.path.join(bld.curdir, s))
670         link_dst = os.path.join(tgtdir, os.path.basename(iname))
671         if os.path.islink(link_dst) and os.readlink(link_dst) == link_src:
672             continue
673         if os.path.exists(link_dst):
674             os.unlink(link_dst)
675         Logs.info("symlink: %s -> %s/%s" % (s, installdir, iname))
676         os.symlink(link_src, link_dst)
677 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT
678
679
680 def copy_and_fix_python_path(task):
681     pattern='sys.path.insert(0, "bin/python")'
682     if task.env["PYTHONARCHDIR"] in sys.path and task.env["PYTHONDIR"] in sys.path:
683         replacement = ""
684     elif task.env["PYTHONARCHDIR"] == task.env["PYTHONDIR"]:
685         replacement="""sys.path.insert(0, "%s")""" % task.env["PYTHONDIR"]
686     else:
687         replacement="""sys.path.insert(0, "%s")
688 sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"])
689
690     installed_location=task.outputs[0].bldpath(task.env)
691     source_file = open(task.inputs[0].srcpath(task.env))
692     installed_file = open(installed_location, 'w')
693     for line in source_file:
694         newline = line
695         if pattern in line:
696             newline = line.replace(pattern, replacement)
697         installed_file.write(newline)
698     installed_file.close()
699     os.chmod(installed_location, 0755)
700     return 0
701
702
703 def install_file(bld, destdir, file, chmod=MODE_644, flat=False,
704                  python_fixup=False, destname=None, base_name=None):
705     '''install a file'''
706     destdir = bld.EXPAND_VARIABLES(destdir)
707     if not destname:
708         destname = file
709         if flat:
710             destname = os.path.basename(destname)
711     dest = os.path.join(destdir, destname)
712     if python_fixup:
713         # fixup the python path it will use to find Samba modules
714         inst_file = file + '.inst'
715         bld.SAMBA_GENERATOR('python_%s' % destname,
716                             rule=copy_and_fix_python_path,
717                             source=file,
718                             target=inst_file)
719         bld.add_manual_dependency(bld.path.find_or_declare(inst_file), bld.env["PYTHONARCHDIR"])
720         bld.add_manual_dependency(bld.path.find_or_declare(inst_file), bld.env["PYTHONDIR"])
721         file = inst_file
722     if base_name:
723         file = os.path.join(base_name, file)
724     bld.install_as(dest, file, chmod=chmod)
725
726
727 def INSTALL_FILES(bld, destdir, files, chmod=MODE_644, flat=False,
728                   python_fixup=False, destname=None, base_name=None):
729     '''install a set of files'''
730     for f in TO_LIST(files):
731         install_file(bld, destdir, f, chmod=chmod, flat=flat,
732                      python_fixup=python_fixup, destname=destname,
733                      base_name=base_name)
734 Build.BuildContext.INSTALL_FILES = INSTALL_FILES
735
736
737 def INSTALL_WILDCARD(bld, destdir, pattern, chmod=MODE_644, flat=False,
738                      python_fixup=False, exclude=None, trim_path=None):
739     '''install a set of files matching a wildcard pattern'''
740     files=TO_LIST(bld.path.ant_glob(pattern))
741     if trim_path:
742         files2 = []
743         for f in files:
744             files2.append(os_path_relpath(f, trim_path))
745         files = files2
746
747     if exclude:
748         for f in files[:]:
749             if fnmatch.fnmatch(f, exclude):
750                 files.remove(f)
751     INSTALL_FILES(bld, destdir, files, chmod=chmod, flat=flat,
752                   python_fixup=python_fixup, base_name=trim_path)
753 Build.BuildContext.INSTALL_WILDCARD = INSTALL_WILDCARD
754
755
756 def INSTALL_DIRS(bld, destdir, dirs):
757     '''install a set of directories'''
758     destdir = bld.EXPAND_VARIABLES(destdir)
759     dirs = bld.EXPAND_VARIABLES(dirs)
760     for d in TO_LIST(dirs):
761         bld.install_dir(os.path.join(destdir, d))
762 Build.BuildContext.INSTALL_DIRS = INSTALL_DIRS
763
764
765 def MANPAGES(bld, manpages):
766     '''build and install manual pages'''
767     bld.env.MAN_XSL = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
768     for m in manpages.split():
769         source = m + '.xml'
770         bld.SAMBA_GENERATOR(m,
771                             source=source,
772                             target=m,
773                             group='final',
774                             rule='${XSLTPROC} -o ${TGT} --nonet ${MAN_XSL} ${SRC}'
775                             )
776         bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
777 Build.BuildContext.MANPAGES = MANPAGES
778
779
780 #############################################################
781 # give a nicer display when building different types of files
782 def progress_display(self, msg, fname):
783     col1 = Logs.colors(self.color)
784     col2 = Logs.colors.NORMAL
785     total = self.position[1]
786     n = len(str(total))
787     fs = '[%%%dd/%%%dd] %s %%s%%s%%s\n' % (n, n, msg)
788     return fs % (self.position[0], self.position[1], col1, fname, col2)
789
790 def link_display(self):
791     if Options.options.progress_bar != 0:
792         return Task.Task.old_display(self)
793     fname = self.outputs[0].bldpath(self.env)
794     return progress_display(self, 'Linking', fname)
795 Task.TaskBase.classes['cc_link'].display = link_display
796
797 def samba_display(self):
798     if Options.options.progress_bar != 0:
799         return Task.Task.old_display(self)
800
801     targets    = LOCAL_CACHE(self, 'TARGET_TYPE')
802     if self.name in targets:
803         target_type = targets[self.name]
804         type_map = { 'GENERATOR' : 'Generating',
805                      'PROTOTYPE' : 'Generating'
806                      }
807         if target_type in type_map:
808             return progress_display(self, type_map[target_type], self.name)
809
810     if len(self.inputs) == 0:
811         return Task.Task.old_display(self)
812
813     fname = self.inputs[0].bldpath(self.env)
814     if fname[0:3] == '../':
815         fname = fname[3:]
816     ext_loc = fname.rfind('.')
817     if ext_loc == -1:
818         return Task.Task.old_display(self)
819     ext = fname[ext_loc:]
820
821     ext_map = { '.idl' : 'Compiling IDL',
822                 '.et'  : 'Compiling ERRTABLE',
823                 '.asn1': 'Compiling ASN1',
824                 '.c'   : 'Compiling' }
825     if ext in ext_map:
826         return progress_display(self, ext_map[ext], fname)
827     return Task.Task.old_display(self)
828
829 Task.TaskBase.classes['Task'].old_display = Task.TaskBase.classes['Task'].display
830 Task.TaskBase.classes['Task'].display = samba_display
831
832
833 @after('apply_link')
834 @feature('cshlib')
835 def apply_bundle_remove_dynamiclib_patch(self):
836     if self.env['MACBUNDLE'] or getattr(self,'mac_bundle',False):
837         if not getattr(self,'vnum',None):
838             try:
839                 self.env['LINKFLAGS'].remove('-dynamiclib')
840                 self.env['LINKFLAGS'].remove('-single_module')
841             except ValueError:
842                 pass