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