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
, sys
, Options
, Task
, Utils
, cc
, TaskGen
, fnmatch
, re
, shutil
, Logs
, Constants
5 from Configure
import conf
7 from samba_utils
import SUBST_VARS_RECURSIVE
8 TaskGen
.task_gen
.apply_verif
= Utils
.nada
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 *
22 import samba_conftests
35 # some systems have broken threading in python
36 if os
.environ
.get('WAF_NOTHREADS') == '1':
41 os
.environ
['PYTHONUNBUFFERED'] = '1'
44 if Constants
.HEXVERSION
< 0x105019:
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
50 Alternatively, please run ./configure and make as usual. That will
51 call the right version of waf.''')
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
)
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
):
78 elif os
.path
.exists(blib_src
):
79 shutil
.rmtree(blib_src
)
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:
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
:
90 cache
[subsystem
].append( { 'TARGET':target
, 'INIT_FUNCTION':init_function
} )
91 Build
.BuildContext
.ADD_INIT_FUNCTION
= ADD_INIT_FUNCTION
95 #################################################################
96 def SAMBA_LIBRARY(bld
, libname
, source
,
101 public_headers_install
=True,
108 external_library
=False,
121 target_type
='LIBRARY',
122 bundled_extension
=True,
128 private_library
=False,
129 grouping_library
=False,
130 allow_undefined_symbols
=False,
132 '''define a Samba library'''
135 SET_TARGET_TYPE(bld
, libname
, 'DISABLED')
138 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
140 source
= bld
.SUBDIR(subdir
, source
)
142 # remember empty libraries, so we can strip the dependencies
143 if ((source
== '') or (source
== [])) and deps
== '' and public_deps
== '':
144 SET_TARGET_TYPE(bld
, libname
, 'EMPTY')
147 if BUILTIN_LIBRARY(bld
, libname
):
150 obj_target
= libname
+ '.objlist'
152 if group
== 'libraries':
153 subsystem_group
= 'main'
155 subsystem_group
= group
157 # first create a target for building the object files for this library
158 # by separating in this way, we avoid recompiling the C files
159 # separately for the install library and the build library
160 bld
.SAMBA_SUBSYSTEM(obj_target
,
163 public_deps
= public_deps
,
165 public_headers
= public_headers
,
166 public_headers_install
= public_headers_install
,
167 header_path
= header_path
,
169 group
= subsystem_group
,
170 autoproto
= autoproto
,
171 depends_on
= depends_on
,
172 hide_symbols
= hide_symbols
,
173 pyext
= pyext
or (target_type
== "PYTHON"),
174 local_include
= local_include
,
175 global_include
= global_include
)
177 if BUILTIN_LIBRARY(bld
, libname
):
180 if not SET_TARGET_TYPE(bld
, libname
, target_type
):
183 # the library itself will depend on that object target
184 deps
+= ' ' + public_deps
186 deps
.append(obj_target
)
188 realname
= bld
.map_shlib_extension(realname
, python
=(target_type
=='PYTHON'))
189 link_name
= bld
.map_shlib_extension(link_name
, python
=(target_type
=='PYTHON'))
191 # we don't want any public libraries without version numbers
192 if not private_library
and vnum
is None and soname
is None and target_type
!= 'PYTHON' and not realname
:
193 raise Utils
.WafError("public library '%s' must have a vnum" % libname
)
195 if target_type
== 'PYTHON' or realname
or not private_library
:
196 bundled_name
= libname
.replace('_', '-')
198 bundled_name
= PRIVATE_NAME(bld
, libname
, bundled_extension
, private_library
)
200 ldflags
= TO_LIST(ldflags
)
202 features
= 'cc cshlib symlink_lib install_lib'
203 if target_type
== 'PYTHON':
206 # this is quite strange. we should add pyext feature for pyext
207 # but that breaks the build. This may be a bug in the waf python tool
208 features
+= ' pyembed'
211 features
+= ' abi_check'
214 if bld
.env
.HAVE_LD_VERSION_SCRIPT
:
216 version
= "%s_%s" % (Utils
.g_module
.APPNAME
, Utils
.g_module
.VERSION
)
218 version
= "%s_%s" % (libname
, vnum
)
222 vscript
= "%s.vscript" % libname
223 bld
.ABI_VSCRIPT(libname
, abi_directory
, version
, vscript
,
225 fullname
= apply_pattern(bundled_name
, bld
.env
.shlib_PATTERN
)
226 fullpath
= bld
.path
.find_or_declare(fullname
)
227 vscriptpath
= bld
.path
.find_or_declare(vscript
)
229 raise Utils
.WafError("unable to find fullpath for %s" % fullname
)
231 raise Utils
.WafError("unable to find vscript path for %s" % vscript
)
232 bld
.add_manual_dependency(fullpath
, vscriptpath
)
233 if Options
.is_install
:
234 # also make the .inst file depend on the vscript
235 instname
= apply_pattern(bundled_name
+ '.inst', bld
.env
.shlib_PATTERN
)
236 bld
.add_manual_dependency(bld
.path
.find_or_declare(instname
), bld
.path
.find_or_declare(vscript
))
237 vscript
= os
.path
.join(bld
.path
.abspath(bld
.env
), vscript
)
239 bld
.SET_BUILD_GROUP(group
)
243 target
= bundled_name
,
244 depends_on
= depends_on
,
245 samba_ldflags
= ldflags
,
247 samba_includes
= includes
,
248 version_script
= vscript
,
249 local_include
= local_include
,
250 global_include
= global_include
,
254 samba_inst_path
= install_path
,
256 samba_realname
= realname
,
257 samba_install
= install
,
258 abi_directory
= "%s/%s" % (bld
.path
.abspath(), abi_directory
),
259 abi_match
= abi_match
,
260 private_library
= private_library
,
261 grouping_library
=grouping_library
,
262 allow_undefined_symbols
=allow_undefined_symbols
265 if realname
and not link_name
:
266 link_name
= 'shared/%s' % realname
269 t
.link_name
= link_name
271 if pc_files
is not None:
272 bld
.PKG_CONFIG_FILES(pc_files
, vnum
=vnum
)
274 if manpages
is not None and 'XSLTPROC_MANPAGES' in bld
.env
and bld
.env
['XSLTPROC_MANPAGES']:
275 bld
.MANPAGES(manpages
)
278 Build
.BuildContext
.SAMBA_LIBRARY
= SAMBA_LIBRARY
281 #################################################################
282 def SAMBA_BINARY(bld
, binname
, source
,
292 use_global_deps
=True,
305 '''define a Samba binary'''
308 SET_TARGET_TYPE(bld
, binname
, 'DISABLED')
311 if not SET_TARGET_TYPE(bld
, binname
, 'BINARY'):
314 features
= 'cc cprogram symlink_bin install_bin'
316 features
+= ' pyembed'
318 obj_target
= binname
+ '.objlist'
320 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
322 source
= bld
.SUBDIR(subdir
, source
)
323 source
= unique_list(TO_LIST(source
))
325 if group
== 'binaries':
326 subsystem_group
= 'main'
328 subsystem_group
= group
330 # first create a target for building the object files for this binary
331 # by separating in this way, we avoid recompiling the C files
332 # separately for the install binary and the build binary
333 bld
.SAMBA_SUBSYSTEM(obj_target
,
338 group
= subsystem_group
,
339 autoproto
= autoproto
,
340 subsystem_name
= subsystem_name
,
341 local_include
= local_include
,
342 global_include
= global_include
,
343 use_hostcc
= use_hostcc
,
345 use_global_deps
= use_global_deps
)
347 bld
.SET_BUILD_GROUP(group
)
349 # the binary itself will depend on that object target
351 deps
.append(obj_target
)
358 samba_includes
= includes
,
359 local_include
= local_include
,
360 global_include
= global_include
,
361 samba_modules
= modules
,
363 samba_subsystem
= subsystem_name
,
365 samba_inst_path
= install_path
,
366 samba_install
= install
,
367 samba_ldflags
= TO_LIST(ldflags
)
370 if manpages
is not None and 'XSLTPROC_MANPAGES' in bld
.env
and bld
.env
['XSLTPROC_MANPAGES']:
371 bld
.MANPAGES(manpages
)
373 Build
.BuildContext
.SAMBA_BINARY
= SAMBA_BINARY
376 #################################################################
377 def SAMBA_MODULE(bld
, modname
, source
,
382 module_init_name
='samba_init_module',
384 autoproto_extra_source
='',
386 internal_module
=True,
393 allow_undefined_symbols
=False
395 '''define a Samba module.'''
397 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
399 source
= bld
.SUBDIR(subdir
, source
)
401 if internal_module
or BUILTIN_LIBRARY(bld
, modname
):
402 bld
.SAMBA_SUBSYSTEM(modname
, source
,
406 autoproto_extra_source
=autoproto_extra_source
,
408 local_include
=local_include
,
409 global_include
=global_include
,
412 bld
.ADD_INIT_FUNCTION(subsystem
, modname
, init_function
)
416 SET_TARGET_TYPE(bld
, modname
, 'DISABLED')
419 obj_target
= modname
+ '.objlist'
422 if subsystem
is not None:
423 deps
+= ' ' + subsystem
424 while realname
.startswith("lib"+subsystem
+"_"):
425 realname
= realname
[len("lib"+subsystem
+"_"):]
426 while realname
.startswith(subsystem
+"_"):
427 realname
= realname
[len(subsystem
+"_"):]
429 realname
= bld
.make_libname(realname
)
430 while realname
.startswith("lib"):
431 realname
= realname
[len("lib"):]
433 build_link_name
= "modules/%s/%s" % (subsystem
, realname
)
436 cflags
+= " -D%s=%s" % (init_function
, module_init_name
)
438 bld
.SAMBA_LIBRARY(modname
,
444 autoproto
= autoproto
,
445 local_include
=local_include
,
446 global_include
=global_include
,
448 link_name
=build_link_name
,
449 install_path
="${MODULESDIR}/%s" % subsystem
,
451 allow_undefined_symbols
=allow_undefined_symbols
455 Build
.BuildContext
.SAMBA_MODULE
= SAMBA_MODULE
458 #################################################################
459 def SAMBA_SUBSYSTEM(bld
, modname
, source
,
464 public_headers_install
=True,
469 init_function_sentinal
=None,
471 autoproto_extra_source
='',
474 local_include_first
=True,
479 use_global_deps
=True,
484 '''define a Samba subsystem'''
487 SET_TARGET_TYPE(bld
, modname
, 'DISABLED')
490 # remember empty subsystems, so we can strip the dependencies
491 if ((source
== '') or (source
== [])) and deps
== '' and public_deps
== '':
492 SET_TARGET_TYPE(bld
, modname
, 'EMPTY')
495 if not SET_TARGET_TYPE(bld
, modname
, 'SUBSYSTEM'):
498 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
500 source
= bld
.SUBDIR(subdir
, source
)
501 source
= unique_list(TO_LIST(source
))
503 deps
+= ' ' + public_deps
505 bld
.SET_BUILD_GROUP(group
)
515 samba_cflags
= CURRENT_CFLAGS(bld
, modname
, cflags
, hide_symbols
=hide_symbols
),
516 depends_on
= depends_on
,
517 samba_deps
= TO_LIST(deps
),
518 samba_includes
= includes
,
519 local_include
= local_include
,
520 local_include_first
= local_include_first
,
521 global_include
= global_include
,
522 samba_subsystem
= subsystem_name
,
523 samba_use_hostcc
= use_hostcc
,
524 samba_use_global_deps
= use_global_deps
527 if cflags_end
is not None:
528 t
.samba_cflags
.extend(TO_LIST(cflags_end
))
530 if autoproto
is not None:
531 bld
.SAMBA_AUTOPROTO(autoproto
, source
+ TO_LIST(autoproto_extra_source
))
532 if public_headers
is not None:
533 bld
.PUBLIC_HEADERS(public_headers
, header_path
=header_path
,
534 public_headers_install
=public_headers_install
)
538 Build
.BuildContext
.SAMBA_SUBSYSTEM
= SAMBA_SUBSYSTEM
541 def SAMBA_GENERATOR(bld
, name
, rule
, source
='', target
='',
542 group
='generators', enabled
=True,
544 public_headers_install
=True,
548 '''A generic source generator target'''
550 if not SET_TARGET_TYPE(bld
, name
, 'GENERATOR'):
556 bld
.SET_BUILD_GROUP(group
)
559 source
=bld
.EXPAND_VARIABLES(source
, vars=vars),
561 shell
=isinstance(rule
, str),
565 samba_type
='GENERATOR',
566 dep_vars
= [rule
] + (vars or []),
572 if public_headers
is not None:
573 bld
.PUBLIC_HEADERS(public_headers
, header_path
=header_path
,
574 public_headers_install
=public_headers_install
)
576 Build
.BuildContext
.SAMBA_GENERATOR
= SAMBA_GENERATOR
581 def SETUP_BUILD_GROUPS(bld
):
582 '''setup build groups used to ensure that the different build
583 phases happen consecutively'''
584 bld
.p_ln
= bld
.srcnode
# we do want to see all targets!
585 bld
.env
['USING_BUILD_GROUPS'] = True
586 bld
.add_group('setup')
587 bld
.add_group('build_compiler_source')
588 bld
.add_group('vscripts')
589 bld
.add_group('base_libraries')
590 bld
.add_group('generators')
591 bld
.add_group('compiler_prototypes')
592 bld
.add_group('compiler_libraries')
593 bld
.add_group('build_compilers')
594 bld
.add_group('build_source')
595 bld
.add_group('prototypes')
596 bld
.add_group('headers')
597 bld
.add_group('main')
598 bld
.add_group('symbolcheck')
599 bld
.add_group('libraries')
600 bld
.add_group('binaries')
601 bld
.add_group('syslibcheck')
602 bld
.add_group('final')
603 Build
.BuildContext
.SETUP_BUILD_GROUPS
= SETUP_BUILD_GROUPS
606 def SET_BUILD_GROUP(bld
, group
):
607 '''set the current build group'''
608 if not 'USING_BUILD_GROUPS' in bld
.env
:
611 Build
.BuildContext
.SET_BUILD_GROUP
= SET_BUILD_GROUP
616 def ENABLE_TIMESTAMP_DEPENDENCIES(conf
):
617 """use timestamps instead of file contents for deps
618 this currently doesn't work"""
619 def h_file(filename
):
621 st
= os
.stat(filename
)
622 if stat
.S_ISDIR(st
[stat
.ST_MODE
]): raise IOError('not a file')
624 m
.update(str(st
.st_mtime
))
625 m
.update(str(st
.st_size
))
628 Utils
.h_file
= h_file
632 t
= Task
.simple_task_type('copy_script', 'rm -f "${LINK_TARGET}" && ln -s "${SRC[0].abspath(env)}" ${LINK_TARGET}',
633 shell
=True, color
='PINK', ext_in
='.bin')
636 @feature('copy_script')
637 @before('apply_link')
638 def copy_script(self
):
639 tsk
= self
.create_task('copy_script', self
.allnodes
[0])
640 tsk
.env
.TARGET
= self
.target
642 def SAMBA_SCRIPT(bld
, name
, pattern
, installdir
, installname
=None):
643 '''used to copy scripts from the source tree into the build directory
644 for use by selftest'''
646 source
= bld
.path
.ant_glob(pattern
)
648 bld
.SET_BUILD_GROUP('build_source')
649 for s
in TO_LIST(source
):
651 if installname
!= None:
653 target
= os
.path
.join(installdir
, iname
)
654 tgtdir
= os
.path
.dirname(os
.path
.join(bld
.srcnode
.abspath(bld
.env
), '..', target
))
656 t
= bld(features
='copy_script',
661 t
.env
.LINK_TARGET
= target
663 Build
.BuildContext
.SAMBA_SCRIPT
= SAMBA_SCRIPT
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
:
669 elif task
.env
["PYTHONARCHDIR"] == task
.env
["PYTHONDIR"]:
670 replacement
="""sys.path.insert(0, "%s")""" % task
.env
["PYTHONDIR"]
672 replacement
="""sys.path.insert(0, "%s")
673 sys.path.insert(1, "%s")""" % (task
.env
["PYTHONARCHDIR"], task
.env
["PYTHONDIR"])
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
:
681 newline
= line
.replace(pattern
, replacement
)
682 installed_file
.write(newline
)
683 installed_file
.close()
684 os
.chmod(installed_location
, 0755)
688 def install_file(bld
, destdir
, file, chmod
=MODE_644
, flat
=False,
689 python_fixup
=False, destname
=None, base_name
=None):
691 destdir
= bld
.EXPAND_VARIABLES(destdir
)
695 destname
= os
.path
.basename(destname
)
696 dest
= os
.path
.join(destdir
, destname
)
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
,
706 file = os
.path
.join(base_name
, file)
707 bld
.install_as(dest
, file, chmod
=chmod
)
710 def INSTALL_FILES(bld
, destdir
, files
, chmod
=MODE_644
, flat
=False,
711 python_fixup
=False, destname
=None, base_name
=None):
712 '''install a set of files'''
713 for f
in TO_LIST(files
):
714 install_file(bld
, destdir
, f
, chmod
=chmod
, flat
=flat
,
715 python_fixup
=python_fixup
, destname
=destname
,
717 Build
.BuildContext
.INSTALL_FILES
= INSTALL_FILES
720 def INSTALL_WILDCARD(bld
, destdir
, pattern
, chmod
=MODE_644
, flat
=False,
721 python_fixup
=False, exclude
=None, trim_path
=None):
722 '''install a set of files matching a wildcard pattern'''
723 files
=TO_LIST(bld
.path
.ant_glob(pattern
))
727 files2
.append(os_path_relpath(f
, trim_path
))
732 if fnmatch
.fnmatch(f
, exclude
):
734 INSTALL_FILES(bld
, destdir
, files
, chmod
=chmod
, flat
=flat
,
735 python_fixup
=python_fixup
, base_name
=trim_path
)
736 Build
.BuildContext
.INSTALL_WILDCARD
= INSTALL_WILDCARD
739 def INSTALL_DIRS(bld
, destdir
, dirs
):
740 '''install a set of directories'''
741 destdir
= bld
.EXPAND_VARIABLES(destdir
)
742 dirs
= bld
.EXPAND_VARIABLES(dirs
)
743 for d
in TO_LIST(dirs
):
744 bld
.install_dir(os
.path
.join(destdir
, d
))
745 Build
.BuildContext
.INSTALL_DIRS
= INSTALL_DIRS
748 def MANPAGES(bld
, manpages
):
749 '''build and install manual pages'''
750 bld
.env
.MAN_XSL
= 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
751 for m
in manpages
.split():
753 bld
.SAMBA_GENERATOR(m
,
757 rule
='${XSLTPROC} -o ${TGT} --nonet ${MAN_XSL} ${SRC}'
759 bld
.INSTALL_FILES('${MANDIR}/man%s' % m
[-1], m
, flat
=True)
760 Build
.BuildContext
.MANPAGES
= MANPAGES
763 #############################################################
764 # give a nicer display when building different types of files
765 def progress_display(self
, msg
, fname
):
766 col1
= Logs
.colors(self
.color
)
767 col2
= Logs
.colors
.NORMAL
768 total
= self
.position
[1]
770 fs
= '[%%%dd/%%%dd] %s %%s%%s%%s\n' % (n
, n
, msg
)
771 return fs
% (self
.position
[0], self
.position
[1], col1
, fname
, col2
)
773 def link_display(self
):
774 if Options
.options
.progress_bar
!= 0:
775 return Task
.Task
.old_display(self
)
776 fname
= self
.outputs
[0].bldpath(self
.env
)
777 return progress_display(self
, 'Linking', fname
)
778 Task
.TaskBase
.classes
['cc_link'].display
= link_display
780 def samba_display(self
):
781 if Options
.options
.progress_bar
!= 0:
782 return Task
.Task
.old_display(self
)
784 targets
= LOCAL_CACHE(self
, 'TARGET_TYPE')
785 if self
.name
in targets
:
786 target_type
= targets
[self
.name
]
787 type_map
= { 'GENERATOR' : 'Generating',
788 'PROTOTYPE' : 'Generating'
790 if target_type
in type_map
:
791 return progress_display(self
, type_map
[target_type
], self
.name
)
793 if len(self
.inputs
) == 0:
794 return Task
.Task
.old_display(self
)
796 fname
= self
.inputs
[0].bldpath(self
.env
)
797 if fname
[0:3] == '../':
799 ext_loc
= fname
.rfind('.')
801 return Task
.Task
.old_display(self
)
802 ext
= fname
[ext_loc
:]
804 ext_map
= { '.idl' : 'Compiling IDL',
805 '.et' : 'Compiling ERRTABLE',
806 '.asn1': 'Compiling ASN1',
809 return progress_display(self
, ext_map
[ext
], fname
)
810 return Task
.Task
.old_display(self
)
812 Task
.TaskBase
.classes
['Task'].old_display
= Task
.TaskBase
.classes
['Task'].display
813 Task
.TaskBase
.classes
['Task'].display
= samba_display
818 def apply_bundle_remove_dynamiclib_patch(self
):
819 if self
.env
['MACBUNDLE'] or getattr(self
,'mac_bundle',False):
820 if not getattr(self
,'vnum',None):
822 self
.env
['LINKFLAGS'].remove('-dynamiclib')
823 self
.env
['LINKFLAGS'].remove('-single_module')