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