solve the error "ldb.inst.h does not exist"
[Samba.git] / buildtools / wafsamba / wafsamba.py
blobfd6a5523e99ce4cb33f0391ca68059e07bf57dc2
1 # a waf tool to add autoconf-like macros to the configure section
2 # and for SAMBA_ macros for building libraries, binaries etc
4 import Build, os, 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
9 # bring in the other samba modules
10 from samba_optimisation import *
11 from samba_utils import *
12 from samba_autoconf import *
13 from samba_patterns import *
14 from samba_pidl import *
15 from samba_errtable import *
16 from samba_asn1 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 tru64cc
25 import irixcc
26 import generic_cc
27 import samba_dist
28 import samba_wildcard
30 O644 = 420
32 # some systems have broken threading in python
33 if os.environ.get('WAF_NOTHREADS') == '1':
34 import nothreads
36 LIB_PATH="shared"
38 os.putenv('PYTHONUNBUFFERED', '1')
41 if Constants.HEXVERSION < 0x105016:
42 Logs.error('''
43 Please use the version of waf that comes with Samba, not
44 a system installed version. See http://wiki.samba.org/index.php/Waf
45 for details.
47 Alternatively, please use ./autogen-waf.sh, and then
48 run ./configure and make as usual. That will call the right version of waf.
49 ''')
50 sys.exit(1)
53 @conf
54 def SAMBA_BUILD_ENV(conf):
55 '''create the samba build environment'''
56 conf.env.BUILD_DIRECTORY = conf.blddir
57 mkdir_p(os.path.join(conf.blddir, LIB_PATH))
58 mkdir_p(os.path.join(conf.blddir, 'python/samba/dcerpc'))
59 # this allows all of the bin/shared and bin/python targets
60 # to be expressed in terms of build directory paths
61 mkdir_p(os.path.join(conf.blddir, 'default'))
62 for p in ['python','shared']:
63 link_target = os.path.join(conf.blddir, 'default/' + p)
64 if not os.path.lexists(link_target):
65 os.symlink('../' + p, link_target)
67 # get perl to put the blib files in the build directory
68 blib_bld = os.path.join(conf.blddir, 'default/pidl/blib')
69 blib_src = os.path.join(conf.srcdir, 'pidl/blib')
70 mkdir_p(blib_bld + '/man1')
71 mkdir_p(blib_bld + '/man3')
72 if os.path.islink(blib_src):
73 os.unlink(blib_src)
74 elif os.path.exists(blib_src):
75 shutil.rmtree(blib_src)
78 def ADD_INIT_FUNCTION(bld, subsystem, target, init_function):
79 '''add an init_function to the list for a subsystem'''
80 if init_function is None:
81 return
82 bld.ASSERT(subsystem is not None, "You must specify a subsystem for init_function '%s'" % init_function)
83 cache = LOCAL_CACHE(bld, 'INIT_FUNCTIONS')
84 if not subsystem in cache:
85 cache[subsystem] = []
86 cache[subsystem].append( { 'TARGET':target, 'INIT_FUNCTION':init_function } )
87 Build.BuildContext.ADD_INIT_FUNCTION = ADD_INIT_FUNCTION
91 #################################################################
92 def SAMBA_LIBRARY(bld, libname, source,
93 deps='',
94 public_deps='',
95 includes='',
96 public_headers=None,
97 header_path=None,
98 pc_files=None,
99 vnum=None,
100 cflags='',
101 external_library=False,
102 realname=None,
103 autoproto=None,
104 group='main',
105 depends_on='',
106 local_include=True,
107 vars=None,
108 install_path=None,
109 install=True,
110 needs_python=False,
111 target_type='LIBRARY',
112 bundled_extension=True,
113 link_name=None,
114 abi_file=None,
115 abi_match=None,
116 hide_symbols=False,
117 enabled=True):
118 '''define a Samba library'''
120 if not enabled:
121 SET_TARGET_TYPE(bld, libname, 'DISABLED')
122 return
124 source = bld.EXPAND_VARIABLES(source, vars=vars)
126 # remember empty libraries, so we can strip the dependencies
127 if ((source == '') or (source == [])) and deps == '' and public_deps == '':
128 SET_TARGET_TYPE(bld, libname, 'EMPTY')
129 return
131 if target_type != 'PYTHON' and BUILTIN_LIBRARY(bld, libname):
132 obj_target = libname
133 else:
134 obj_target = libname + '.objlist'
136 # first create a target for building the object files for this library
137 # by separating in this way, we avoid recompiling the C files
138 # separately for the install library and the build library
139 bld.SAMBA_SUBSYSTEM(obj_target,
140 source = source,
141 deps = deps,
142 public_deps = public_deps,
143 includes = includes,
144 public_headers = public_headers,
145 header_path = header_path,
146 cflags = cflags,
147 group = group,
148 autoproto = autoproto,
149 depends_on = depends_on,
150 needs_python = needs_python,
151 hide_symbols = hide_symbols,
152 local_include = local_include)
154 if libname == obj_target:
155 return
157 if not SET_TARGET_TYPE(bld, libname, target_type):
158 return
160 # the library itself will depend on that object target
161 deps += ' ' + public_deps
162 deps = TO_LIST(deps)
163 deps.append(obj_target)
165 if target_type == 'PYTHON' or realname:
166 bundled_name = libname
167 else:
168 bundled_name = BUNDLED_NAME(bld, libname, bundled_extension)
170 features = 'cc cshlib symlink_lib install_lib'
171 if target_type == 'PYTHON':
172 features += ' pyext'
173 elif needs_python:
174 features += ' pyembed'
175 if abi_file:
176 features += ' abi_check'
178 if abi_file:
179 abi_file = os.path.join(bld.curdir, abi_file)
181 bld.SET_BUILD_GROUP(group)
182 t = bld(
183 features = features,
184 source = [],
185 target = bundled_name,
186 samba_cflags = CURRENT_CFLAGS(bld, libname, cflags),
187 depends_on = depends_on,
188 samba_deps = deps,
189 samba_includes = includes,
190 local_include = local_include,
191 vnum = vnum,
192 install_path = None,
193 samba_inst_path = install_path,
194 name = libname,
195 samba_realname = realname,
196 samba_install = install,
197 abi_file = abi_file,
198 abi_match = abi_match
201 if realname and not link_name:
202 link_name = 'shared/%s' % realname
204 if link_name:
205 t.link_name = link_name
207 if pc_files is not None:
208 bld.PKG_CONFIG_FILES(pc_files, vnum=vnum)
210 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
213 #################################################################
214 def SAMBA_BINARY(bld, binname, source,
215 deps='',
216 includes='',
217 public_headers=None,
218 header_path=None,
219 modules=None,
220 ldflags=None,
221 cflags='',
222 autoproto=None,
223 use_hostcc=False,
224 use_global_deps=True,
225 compiler=None,
226 group='binaries',
227 manpages=None,
228 local_include=True,
229 subsystem_name=None,
230 needs_python=False,
231 vars=None,
232 install=True,
233 install_path=None,
234 enabled=True):
235 '''define a Samba binary'''
237 if not enabled:
238 SET_TARGET_TYPE(bld, binname, 'DISABLED')
239 return
241 if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
242 return
244 features = 'cc cprogram symlink_bin install_bin'
245 if needs_python:
246 features += ' pyembed'
248 obj_target = binname + '.objlist'
250 source = bld.EXPAND_VARIABLES(source, vars=vars)
251 source = unique_list(TO_LIST(source))
253 # first create a target for building the object files for this binary
254 # by separating in this way, we avoid recompiling the C files
255 # separately for the install binary and the build binary
256 bld.SAMBA_SUBSYSTEM(obj_target,
257 source = source,
258 deps = deps,
259 includes = includes,
260 cflags = cflags,
261 group = group,
262 autoproto = autoproto,
263 subsystem_name = subsystem_name,
264 needs_python = needs_python,
265 local_include = local_include,
266 use_hostcc = use_hostcc,
267 use_global_deps= use_global_deps)
269 bld.SET_BUILD_GROUP(group)
271 # the binary itself will depend on that object target
272 deps = TO_LIST(deps)
273 deps.append(obj_target)
275 t = bld(
276 features = features,
277 source = [],
278 target = binname,
279 samba_cflags = CURRENT_CFLAGS(bld, binname, cflags),
280 samba_deps = deps,
281 samba_includes = includes,
282 local_include = local_include,
283 samba_modules = modules,
284 top = True,
285 samba_subsystem= subsystem_name,
286 install_path = None,
287 samba_inst_path= install_path,
288 samba_install = install
291 # setup the subsystem_name as an alias for the real
292 # binary name, so it can be found when expanding
293 # subsystem dependencies
294 if subsystem_name is not None:
295 bld.TARGET_ALIAS(subsystem_name, binname)
297 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
300 #################################################################
301 def SAMBA_MODULE(bld, modname, source,
302 deps='',
303 includes='',
304 subsystem=None,
305 init_function=None,
306 autoproto=None,
307 autoproto_extra_source='',
308 aliases=None,
309 cflags='',
310 internal_module=True,
311 local_include=True,
312 vars=None,
313 enabled=True):
314 '''define a Samba module.'''
316 # we add the init function regardless of whether the module
317 # is enabled or not, as we need to generate a null list if
318 # all disabled
319 bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
321 if internal_module or BUILTIN_LIBRARY(bld, modname):
322 # treat internal modules as subsystems for now
323 SAMBA_SUBSYSTEM(bld, modname, source,
324 deps=deps,
325 includes=includes,
326 autoproto=autoproto,
327 autoproto_extra_source=autoproto_extra_source,
328 cflags=cflags,
329 local_include=local_include,
330 enabled=enabled)
331 return
333 if not enabled:
334 SET_TARGET_TYPE(bld, modname, 'DISABLED')
335 return
337 source = bld.EXPAND_VARIABLES(source, vars=vars)
338 source = unique_list(TO_LIST(source))
340 # remember empty modules, so we can strip the dependencies
341 if ((source == '') or (source == [])) and deps == '' and public_deps == '':
342 SET_TARGET_TYPE(bld, modname, 'EMPTY')
343 return
345 if not SET_TARGET_TYPE(bld, modname, 'MODULE'):
346 return
348 if subsystem is not None:
349 deps += ' ' + subsystem
351 bld.SET_BUILD_GROUP('main')
352 bld(
353 features = 'cc',
354 source = source,
355 target = modname,
356 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags),
357 samba_includes = includes,
358 local_include = local_include,
359 samba_deps = TO_LIST(deps)
362 if autoproto is not None:
363 bld.SAMBA_AUTOPROTO(autoproto, source + TO_LIST(autoproto_extra_source))
365 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
368 #################################################################
369 def SAMBA_SUBSYSTEM(bld, modname, source,
370 deps='',
371 public_deps='',
372 includes='',
373 public_headers=None,
374 header_path=None,
375 cflags='',
376 cflags_end=None,
377 group='main',
378 init_function_sentinal=None,
379 heimdal_autoproto=None,
380 heimdal_autoproto_options=None,
381 heimdal_autoproto_private=None,
382 autoproto=None,
383 autoproto_extra_source='',
384 depends_on='',
385 local_include=True,
386 local_include_first=True,
387 subsystem_name=None,
388 enabled=True,
389 use_hostcc=False,
390 use_global_deps=True,
391 vars=None,
392 hide_symbols=False,
393 needs_python=False):
394 '''define a Samba subsystem'''
396 if not enabled:
397 SET_TARGET_TYPE(bld, modname, 'DISABLED')
398 return
400 # remember empty subsystems, so we can strip the dependencies
401 if ((source == '') or (source == [])) and deps == '' and public_deps == '':
402 SET_TARGET_TYPE(bld, modname, 'EMPTY')
403 return
405 if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
406 return
408 source = bld.EXPAND_VARIABLES(source, vars=vars)
409 source = unique_list(TO_LIST(source))
411 deps += ' ' + public_deps
413 bld.SET_BUILD_GROUP(group)
415 features = 'cc'
416 if needs_python:
417 features += ' pyext'
419 t = bld(
420 features = features,
421 source = source,
422 target = modname,
423 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags, hide_symbols=hide_symbols),
424 depends_on = depends_on,
425 samba_deps = TO_LIST(deps),
426 samba_includes = includes,
427 local_include = local_include,
428 local_include_first = local_include_first,
429 samba_subsystem= subsystem_name,
430 samba_use_hostcc = use_hostcc,
431 samba_use_global_deps = use_global_deps
434 if cflags_end is not None:
435 t.samba_cflags.extend(TO_LIST(cflags_end))
437 if heimdal_autoproto is not None:
438 bld.HEIMDAL_AUTOPROTO(heimdal_autoproto, source, options=heimdal_autoproto_options)
439 if heimdal_autoproto_private is not None:
440 bld.HEIMDAL_AUTOPROTO_PRIVATE(heimdal_autoproto_private, source)
441 if autoproto is not None:
442 bld.SAMBA_AUTOPROTO(autoproto, source + TO_LIST(autoproto_extra_source))
443 if public_headers is not None:
444 bld.PUBLIC_HEADERS(public_headers, header_path=header_path)
445 return t
448 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
451 def SAMBA_GENERATOR(bld, name, rule, source='', target='',
452 group='generators', enabled=True,
453 public_headers=None,
454 header_path=None,
455 vars=None):
456 '''A generic source generator target'''
458 if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
459 return
461 if not enabled:
462 return
464 bld.SET_BUILD_GROUP(group)
465 t = bld(
466 rule=rule,
467 source=bld.EXPAND_VARIABLES(source, vars=vars),
468 target=target,
469 shell=isinstance(rule, str),
470 on_results=True,
471 before='cc',
472 ext_out='.c',
473 name=name)
475 if public_headers is not None:
476 bld.PUBLIC_HEADERS(public_headers, header_path=header_path)
477 return t
478 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
482 @runonce
483 def SETUP_BUILD_GROUPS(bld):
484 '''setup build groups used to ensure that the different build
485 phases happen consecutively'''
486 bld.p_ln = bld.srcnode # we do want to see all targets!
487 bld.env['USING_BUILD_GROUPS'] = True
488 bld.add_group('setup')
489 bld.add_group('build_compiler_source')
490 bld.add_group('base_libraries')
491 bld.add_group('generators')
492 bld.add_group('compiler_prototypes')
493 bld.add_group('compiler_libraries')
494 bld.add_group('build_compilers')
495 bld.add_group('build_source')
496 bld.add_group('prototypes')
497 bld.add_group('main')
498 bld.add_group('binaries')
499 bld.add_group('final')
500 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
503 def SET_BUILD_GROUP(bld, group):
504 '''set the current build group'''
505 if not 'USING_BUILD_GROUPS' in bld.env:
506 return
507 bld.set_group(group)
508 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
512 @conf
513 def ENABLE_TIMESTAMP_DEPENDENCIES(conf):
514 """use timestamps instead of file contents for deps
515 this currently doesn't work"""
516 def h_file(filename):
517 import stat
518 st = os.stat(filename)
519 if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
520 m = Utils.md5()
521 m.update(str(st.st_mtime))
522 m.update(str(st.st_size))
523 m.update(filename)
524 return m.digest()
525 Utils.h_file = h_file
529 t = Task.simple_task_type('copy_script', 'rm -f ${LINK_TARGET} && ln -s ${SRC[0].abspath(env)} ${LINK_TARGET}',
530 shell=True, color='PINK', ext_in='.bin')
531 t.quiet = True
533 @feature('copy_script')
534 @before('apply_link')
535 def copy_script(self):
536 tsk = self.create_task('copy_script', self.allnodes[0])
537 tsk.env.TARGET = self.target
539 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
540 '''used to copy scripts from the source tree into the build directory
541 for use by selftest'''
543 source = bld.path.ant_glob(pattern)
545 bld.SET_BUILD_GROUP('build_source')
546 for s in TO_LIST(source):
547 iname = s
548 if installname != None:
549 iname = installname
550 target = os.path.join(installdir, iname)
551 tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
552 mkdir_p(tgtdir)
553 t = bld(features='copy_script',
554 source = s,
555 target = target,
556 always = True,
557 install_path = None)
558 t.env.LINK_TARGET = target
560 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT
563 def install_file(bld, destdir, file, chmod=O644, flat=False,
564 python_fixup=False, destname=None, base_name=None):
565 '''install a file'''
566 destdir = bld.EXPAND_VARIABLES(destdir)
567 if not destname:
568 destname = file
569 if flat:
570 destname = os.path.basename(destname)
571 dest = os.path.join(destdir, destname)
572 if python_fixup:
573 # fixup the python path it will use to find Samba modules
574 inst_file = file + '.inst'
575 bld.SAMBA_GENERATOR('python_%s' % destname,
576 rule="sed 's|\(sys.path.insert.*\)bin/python\(.*\)$|\\1${PYTHONDIR}\\2|g' < ${SRC} > ${TGT}",
577 source=file,
578 target=inst_file)
579 file = inst_file
580 if base_name:
581 file = os.path.join(base_name, file)
582 bld.install_as(dest, file, chmod=chmod)
585 def INSTALL_FILES(bld, destdir, files, chmod=O644, flat=False,
586 python_fixup=False, destname=None, base_name=None):
587 '''install a set of files'''
588 for f in TO_LIST(files):
589 install_file(bld, destdir, f, chmod=chmod, flat=flat,
590 python_fixup=python_fixup, destname=destname,
591 base_name=base_name)
592 Build.BuildContext.INSTALL_FILES = INSTALL_FILES
595 def INSTALL_WILDCARD(bld, destdir, pattern, chmod=O644, flat=False,
596 python_fixup=False, exclude=None, trim_path=None):
597 '''install a set of files matching a wildcard pattern'''
598 files=TO_LIST(bld.path.ant_glob(pattern))
599 if trim_path:
600 files2 = []
601 for f in files:
602 files2.append(os_path_relpath(f, trim_path))
603 files = files2
605 if exclude:
606 for f in files[:]:
607 if fnmatch.fnmatch(f, exclude):
608 files.remove(f)
609 INSTALL_FILES(bld, destdir, files, chmod=chmod, flat=flat,
610 python_fixup=python_fixup, base_name=trim_path)
611 Build.BuildContext.INSTALL_WILDCARD = INSTALL_WILDCARD
614 def INSTALL_DIRS(bld, destdir, dirs):
615 '''install a set of directories'''
616 destdir = bld.EXPAND_VARIABLES(destdir)
617 dirs = bld.EXPAND_VARIABLES(dirs)
618 for d in TO_LIST(dirs):
619 bld.install_dir(os.path.join(destdir, d))
620 Build.BuildContext.INSTALL_DIRS = INSTALL_DIRS
623 re_header = re.compile('#include[ \t]*"([^"]+)"', re.I | re.M)
624 class header_task(Task.Task):
625 name = 'header'
626 color = 'PINK'
627 vars = ['INCLUDEDIR', 'HEADER_DEPS']
628 def run(self):
629 txt = self.inputs[0].read(self.env)
631 txt = txt.replace('#if _SAMBA_BUILD_ == 4', '#if 1\n')
633 themap = self.generator.bld.subst_table
634 def repl(m):
635 if m.group(1):
636 s = m.group(1)
637 return "#include <%s>" % themap.get(s, s)
638 return ''
640 txt = re_header.sub(repl, txt)
642 f = None
643 try:
644 f = open(self.outputs[0].abspath(self.env), 'w')
645 f.write(txt)
646 finally:
647 if f:
648 f.close()
650 def init_subst(bld):
652 initialize the header substitution table
653 for now use the file headermap.txt but in the future we will compute the paths properly
656 if getattr(bld, 'subst_table', None):
657 return bld.subst_table_h
659 node = bld.srcnode.find_resource("source4/headermap.txt")
660 if not node:
661 bld.subst_table = {}
662 bld.subst_table_h = 0
663 return {}
664 lines = node.read(None)
666 lines = [x.strip().split(': ') for x in lines.split('\n') if x.rfind(': ') > -1]
667 bld.subst_table = dict(lines)
669 # pidl file replacement (all of this is temporary, one step at a time)
670 keyz = list(bld.subst_table.keys())
671 for k in keyz:
672 bld.subst_table['bin/default/' + k] = bld.subst_table[k]
674 tp = tuple(bld.subst_table.keys())
675 bld.subst_table_h = hash(tp)
676 return bld.subst_table_h
678 @TaskGen.feature('pubh')
679 def make_public_headers(self):
680 if not self.bld.is_install:
681 # install time only (lazy)
682 return
684 self.env['HEADER_DEPS'] = init_subst(self.bld)
685 # adds a dependency and trigger a rebuild if the dict changes
687 header_path = getattr(self, 'header_path', None) or ''
689 for x in self.to_list(self.headers):
691 # too complicated, but what was the original idea?
692 if isinstance(header_path, list):
693 add_dir = ''
694 for (p1, dir) in header_path:
695 lst = self.to_list(p1)
696 for p2 in lst:
697 if fnmatch.fnmatch(x, p2):
698 add_dir = dir
699 break
700 else:
701 continue
702 break
703 inst_path = add_dir
704 else:
705 inst_path = header_path
707 dest = ''
708 name = x
709 if x.find(':') != -1:
710 s = x.split(':')
711 name = s[0]
712 dest = s[1]
714 inn = self.path.find_resource(name)
715 if not inn:
716 raise ValueError("could not find the public header %r in %r" % (name, self.path))
717 out = inn.change_ext('.inst.h')
718 self.create_task('header', inn, out)
720 if not dest:
721 dest = inn.name
723 if inst_path:
724 inst_path = inst_path + '/'
725 inst_path = inst_path + dest
727 #print("going to install the headers", inst_path, out)
728 self.bld.install_as('${INCLUDEDIR}/%s' % inst_path, out, self.env)
730 def PUBLIC_HEADERS(bld, public_headers, header_path=None):
731 '''install some headers
733 header_path may either be a string that is added to the INCLUDEDIR,
734 or it can be a dictionary of wildcard patterns which map to destination
735 directories relative to INCLUDEDIR
737 bld.SET_BUILD_GROUP('final')
738 ret = bld(features=['pubh'], headers=public_headers, header_path=header_path)
739 return ret
740 Build.BuildContext.PUBLIC_HEADERS = PUBLIC_HEADERS
743 def subst_at_vars(task):
744 '''substiture @VAR@ style variables in a file'''
745 src = task.inputs[0].srcpath(task.env)
746 tgt = task.outputs[0].bldpath(task.env)
748 f = open(src, 'r')
749 s = f.read()
750 f.close()
751 # split on the vars
752 a = re.split('(@\w+@)', s)
753 out = []
754 done_var = {}
755 back_sub = [ ('PREFIX', '${prefix}'), ('EXEC_PREFIX', '${exec_prefix}')]
756 for v in a:
757 if re.match('@\w+@', v):
758 vname = v[1:-1]
759 if not vname in task.env and vname.upper() in task.env:
760 vname = vname.upper()
761 if not vname in task.env:
762 Logs.error("Unknown substitution %s in %s" % (v, task.name))
763 sys.exit(1)
764 v = SUBST_VARS_RECURSIVE(task.env[vname], task.env)
765 # now we back substitute the allowed pc vars
766 for (b, m) in back_sub:
767 s = task.env[b]
768 if s == v[0:len(s)]:
769 if not b in done_var:
770 # we don't want to substitute the first usage
771 done_var[b] = True
772 else:
773 v = m + v[len(s):]
774 break
775 out.append(v)
776 contents = ''.join(out)
777 f = open(tgt, 'w')
778 s = f.write(contents)
779 f.close()
780 return 0
784 def PKG_CONFIG_FILES(bld, pc_files, vnum=None):
785 '''install some pkg_config pc files'''
786 dest = '${PKGCONFIGDIR}'
787 dest = bld.EXPAND_VARIABLES(dest)
788 for f in TO_LIST(pc_files):
789 base=os.path.basename(f)
790 t = bld.SAMBA_GENERATOR('PKGCONFIG_%s' % base,
791 rule=subst_at_vars,
792 source=f+'.in',
793 target=f)
794 if vnum:
795 t.env.PACKAGE_VERSION = vnum
796 INSTALL_FILES(bld, dest, f, flat=True, destname=base)
797 Build.BuildContext.PKG_CONFIG_FILES = PKG_CONFIG_FILES
801 #############################################################
802 # give a nicer display when building different types of files
803 def progress_display(self, msg, fname):
804 col1 = Logs.colors(self.color)
805 col2 = Logs.colors.NORMAL
806 total = self.position[1]
807 n = len(str(total))
808 fs = '[%%%dd/%%%dd] %s %%s%%s%%s\n' % (n, n, msg)
809 return fs % (self.position[0], self.position[1], col1, fname, col2)
811 def link_display(self):
812 if Options.options.progress_bar != 0:
813 return Task.Task.old_display(self)
814 fname = self.outputs[0].bldpath(self.env)
815 return progress_display(self, 'Linking', fname)
816 Task.TaskBase.classes['cc_link'].display = link_display
818 def samba_display(self):
819 if Options.options.progress_bar != 0:
820 return Task.Task.old_display(self)
822 targets = LOCAL_CACHE(self, 'TARGET_TYPE')
823 if self.name in targets:
824 target_type = targets[self.name]
825 type_map = { 'GENERATOR' : 'Generating',
826 'PROTOTYPE' : 'Generating'
828 if target_type in type_map:
829 return progress_display(self, type_map[target_type], self.name)
831 fname = self.inputs[0].bldpath(self.env)
832 if fname[0:3] == '../':
833 fname = fname[3:]
834 ext_loc = fname.rfind('.')
835 if ext_loc == -1:
836 return Task.Task.old_display(self)
837 ext = fname[ext_loc:]
839 ext_map = { '.idl' : 'Compiling IDL',
840 '.et' : 'Compiling ERRTABLE',
841 '.asn1': 'Compiling ASN1',
842 '.c' : 'Compiling' }
843 if ext in ext_map:
844 return progress_display(self, ext_map[ext], fname)
845 return Task.Task.old_display(self)
847 Task.TaskBase.classes['Task'].old_display = Task.TaskBase.classes['Task'].display
848 Task.TaskBase.classes['Task'].display = samba_display