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