Beispiel #1
0
def read_assembly(self, assembly, install_path = None):
    """
    Read a foreign .net assembly that was validated via check_assembl
    """
    env = self.env
    uselib = Utils.quote_define_name(assembly)

    if not uselib in getattr(env, 'ext_csshlib', []):
        self.fatal('Assembly %s not registered as a C sharp assembly' % assembly)

    name = getattr(env, '%s_NAME' % uselib, None)
    path = getattr(env, '%s_LIBPATH' % uselib, None)

    tg = self(name=name,
              features='fake_lib',
              lib_paths=[path],
              lib_type='csshlib')

    if install_path:
        d = self.root.find_node(path)
        if not d:
            self.fatal('Can\'t find assembly path')
        f = d.find_node(name)
        self.install_files(install_path, f)

    return tg
Beispiel #2
0
def check_extlib(self, *k, **kw):

    env = self.env

    if not 'package' in kw:
        kw['package'] = k[0]

    if not 'msg' in kw:
        kw['msg'] = 'Checking for %s' % kw['package']

    paths = ['.']
    if "path_list" in kw:
        for p in Utils.to_list(kw['path_list']):
            if p:
                paths.append(p)

    if not 'lib_type' in kw:
        kw['lib_type'] = 'shlib'

    names = [x % kw['package'] for x in ccroot.lib_patterns[kw['lib_type']]]
    ret = self.find_file(names, path_list=paths)

    if ret:
        uselib = Utils.quote_define_name(kw.get('uselib_store', kw['package']))

        env.append_value('ext_%s' % kw['lib_type'], uselib)
        setattr(env, '%s_NAME' % uselib, os.path.basename(ret))
        setattr(env, '%s_LIBPATH' % uselib, os.path.dirname(ret))

        self.define(self.have_define(kw.get('uselib_store', kw['package'])), 1, 0)

    self.msg(kw['msg'], ret, "GREEN")
Beispiel #3
0
def write_config_header(self, configfile='', guard='', top=False, env=None, remove=True):
	"""
	save the defines into a file
	with configfile=foo/bar.h and a script in folder xyz
	top -> build/foo/bar.h
	!top -> build/xyz/foo/bar.h

	by default, reset env.DEFINES to []
	"""
	if not configfile: configfile = WAF_CONFIG_H
	waf_guard = guard or '_%s_WAF' % Utils.quote_define_name(configfile)

	node = top and self.bldnode or self.path.get_bld()
	node = node.make_node(configfile)
	node.parent.mkdir()

	lst = []
	lst.append('/* Configuration header created by Waf - do not edit */\n')
	lst.append('#ifndef %s\n#define %s\n' % (waf_guard, waf_guard))
	lst.append(self.get_config_header())
	lst.append('\n#endif /* %s */\n' % waf_guard)

	node.write('\n'.join(lst))

	env = env or self.env

	# config files are not removed on "waf clean"
	env.append_unique(Build.CFG_FILES, [node.path_from(self.bldnode)])

	if remove:
		for key in self.env[DEFKEYS]:
			self.undefine(key)
		self.env[DEFKEYS] = []
Beispiel #4
0
def validate_cfg(self,kw):
	if not'path'in kw:
		if not self.env.PKGCONFIG:
			self.find_program('pkg-config',var='PKGCONFIG')
		kw['path']=self.env.PKGCONFIG
	s=('atleast_pkgconfig_version'in kw)+('modversion'in kw)+('package'in kw)
	if s!=1:
		raise ValueError('exactly one of atleast_pkgconfig_version, modversion and package must be set')
	if not'msg'in kw:
		if'atleast_pkgconfig_version'in kw:
			kw['msg']='Checking for pkg-config version >= %r'%kw['atleast_pkgconfig_version']
		elif'modversion'in kw:
			kw['msg']='Checking for %r version'%kw['modversion']
		else:
			kw['msg']='Checking for %r'%(kw['package'])
	if not'okmsg'in kw and not'modversion'in kw:
		kw['okmsg']='yes'
	if not'errmsg'in kw:
		kw['errmsg']='not found'
	if'atleast_pkgconfig_version'in kw:
		pass
	elif'modversion'in kw:
		if not'uselib_store'in kw:
			kw['uselib_store']=kw['modversion']
		if not'define_name'in kw:
			kw['define_name']='%s_VERSION'%Utils.quote_define_name(kw['uselib_store'])
	else:
		if not'uselib_store'in kw:
			kw['uselib_store']=Utils.to_list(kw['package'])[0].upper()
		if not'define_name'in kw:
			kw['define_name']=self.have_define(kw['uselib_store'])
Beispiel #5
0
def write_config_header(self, configfile='', guard='', top=False, env=None, defines=True, headers=False, remove=True):
	"""
	save the defines into a file
	with configfile=foo/bar.h and a script in folder xyz
	top -> build/foo/bar.h
	!top -> build/xyz/foo/bar.h

	defines: add the defines or not (yes by default)
	headers: add #include in the file (if headers are defined by env.INCKEYS)
	remove: remove the defines added to the configuration header (yes by default)
	"""
	if not configfile: configfile = WAF_CONFIG_H
	waf_guard = guard or '_%s_WAF' % Utils.quote_define_name(configfile)

	node = top and self.bldnode or self.path.get_bld()
	node = node.make_node(configfile)
	node.parent.mkdir()

	lst = ['/* WARNING! All changes made to this file will be lost! */\n']
	lst.append('#ifndef %s\n#define %s\n' % (waf_guard, waf_guard))
	lst.append(self.get_config_header(defines, headers))
	lst.append('\n#endif /* %s */\n' % waf_guard)

	node.write('\n'.join(lst))

	env = env or self.env

	# config files are not removed on "waf clean"
	env.append_unique(Build.CFG_FILES, [node.abspath()])

	if remove:
		for key in self.env[DEFKEYS]:
			self.undefine(key)
		self.env[DEFKEYS] = []
Beispiel #6
0
def exec_cfg(self, kw):

	# pkg-config version
	if 'atleast_pkgconfig_version' in kw:
		cmd = [kw['path'], '--atleast-pkgconfig-version=%s' % kw['atleast_pkgconfig_version']]
		self.cmd_and_log(cmd)
		if not 'okmsg' in kw:
			kw['okmsg'] = 'yes'
		return

	# checking for the version of a module
	for x in cfg_ver:
		y = x.replace('-', '_')
		if y in kw:
			self.cmd_and_log([kw['path'], '--%s=%s' % (x, kw[y]), kw['package']])
			if not 'okmsg' in kw:
				kw['okmsg'] = 'yes'
			self.define(self.have_define(kw.get('uselib_store', kw['package'])), 1, 0)
			break

	# retrieving the version of a module
	if 'modversion' in kw:
		version = self.cmd_and_log([kw['path'], '--modversion', kw['modversion']]).strip()
		self.define('%s_VERSION' % Utils.quote_define_name(kw.get('uselib_store', kw['modversion'])), version)
		return version

	lst = [kw['path']]

	defi = kw.get('define_variable', None)
	if not defi:
		defi = self.env.PKG_CONFIG_DEFINES or {}
	for key, val in defi.items():
		lst.append('--define-variable=%s=%s' % (key, val))

	if kw['package']:
		lst.extend(Utils.to_list(kw['package']))

	# retrieving variables of a module
	if 'variables' in kw:
		env = kw.get('env', self.env)
		uselib = kw.get('uselib_store', kw['package'].upper())
		vars = Utils.to_list(kw['variables'])
		for v in vars:
			val = self.cmd_and_log(lst + ['--variable=' + v]).strip()
			var = '%s_%s' % (uselib, v)
			env[var] = val
		if not 'okmsg' in kw:
			kw['okmsg'] = 'yes'
		return

	if 'args' in kw:
		lst += Utils.to_list(kw['args'])
	# so we assume the command-line will output flags to be parsed afterwards
	ret = self.cmd_and_log(lst)
	if not 'okmsg' in kw:
		kw['okmsg'] = 'yes'

	self.define(self.have_define(kw.get('uselib_store', kw['package'])), 1, 0)
	self.parse_flags(ret, kw.get('uselib_store', kw['package'].upper()), kw.get('env', self.env))
	return ret
Beispiel #7
0
def write_config_header(self,
                        configfile='',
                        guard='',
                        top=False,
                        env=None,
                        defines=True,
                        headers=False,
                        remove=True,
                        define_prefix=''):
    if env:
        Logs.warn('Cannot pass env to write_config_header')
    if not configfile: configfile = WAF_CONFIG_H
    waf_guard = guard or 'W_%s_WAF' % Utils.quote_define_name(configfile)
    node = top and self.bldnode or self.path.get_bld()
    node = node.make_node(configfile)
    node.parent.mkdir()
    lst = ['/* WARNING! All changes made to this file will be lost! */\n']
    lst.append('#ifndef %s\n#define %s\n' % (waf_guard, waf_guard))
    lst.append(
        self.get_config_header(defines, headers, define_prefix=define_prefix))
    lst.append('\n#endif /* %s */\n' % waf_guard)
    node.write('\n'.join(lst))
    self.env.append_unique(Build.CFG_FILES, [node.abspath()])
    if remove:
        for key in self.env[DEFKEYS]:
            self.undefine(key)
        self.env[DEFKEYS] = []
Beispiel #8
0
def have_define(self, key):
	"""
	:param key: define name
	:type key: string
	:return: the input key prefixed by *HAVE_* and substitute any invalid characters.
	:rtype: string
	"""
	return self.__dict__.get('HAVE_PAT', 'HAVE_%s') % Utils.quote_define_name(key)
Beispiel #9
0
def have_define(self, key):
    """
	:param key: define name
	:type key: string
	:return: the input key prefixed by *HAVE_* and substitute any invalid characters.
	:rtype: string
	"""
    return (self.env.HAVE_PAT or 'HAVE_%s') % Utils.quote_define_name(key)
Beispiel #10
0
def have_define(self, key):
    """
	:param key: define name
	:type key: string
	:return: the input key prefixed by *HAVE_* and substitute any invalid characters.
	:rtype: string
	"""
    return (self.env.HAVE_PAT or "HAVE_%s") % Utils.quote_define_name(key)
Beispiel #11
0
def write_config_header(
    self,
    configfile="",
    guard="",
    top=False,
    defines=True,
    headers=False,
    remove=True,
    define_prefix="",
):
    """
    Writes a configuration header containing defines and includes::

            def configure(cnf):
                    cnf.define('A', 1)
                    cnf.write_config_header('config.h')

    This function only adds include guards (if necessary), consult
    :py:func:`waflib.Tools.c_config.get_config_header` for details on the body.

    :param configfile: path to the file to create (relative or absolute)
    :type configfile: string
    :param guard: include guard name to add, by default it is computed from the file name
    :type guard: string
    :param top: write the configuration header from the build directory (default is from the current path)
    :type top: bool
    :param defines: add the defines (yes by default)
    :type defines: bool
    :param headers: add #include in the file
    :type headers: bool
    :param remove: remove the defines after they are added (yes by default, works like in autoconf)
    :type remove: bool
    :type define_prefix: string
    :param define_prefix: prefix all the defines in the file with a particular prefix
    """
    if not configfile:
        configfile = WAF_CONFIG_H
    waf_guard = guard or "W_%s_WAF" % Utils.quote_define_name(configfile)

    node = top and self.bldnode or self.path.get_bld()
    node = node.make_node(configfile)
    node.parent.mkdir()

    lst = ["/* WARNING! All changes made to this file will be lost! */\n"]
    lst.append(f"#ifndef {waf_guard}\n#define {waf_guard}\n")
    lst.append(
        self.get_config_header(defines, headers, define_prefix=define_prefix))
    lst.append("\n#endif /* %s */\n" % waf_guard)

    node.write("\n".join(lst))

    # config files must not be removed on "waf clean"
    self.env.append_unique(Build.CFG_FILES, [node.abspath()])

    if remove:
        for key in self.env[DEFKEYS]:
            self.undefine(key)
        self.env[DEFKEYS] = []
def exec_cfg(self,kw):
	path=Utils.to_list(kw['path'])
	env=self.env.env or None
	def define_it():
		pkgname=kw.get('uselib_store',kw['package'].upper())
		if kw.get('global_define'):
			self.define(self.have_define(kw['package']),1,False)
		else:
			self.env.append_unique('DEFINES_%s'%pkgname,"%s=1"%self.have_define(pkgname))
		self.env[self.have_define(pkgname)]=1
	if'atleast_pkgconfig_version'in kw:
		cmd=path+['--atleast-pkgconfig-version=%s'%kw['atleast_pkgconfig_version']]
		self.cmd_and_log(cmd,env=env)
		if not'okmsg'in kw:
			kw['okmsg']='yes'
		return
	for x in cfg_ver:
		y=x.replace('-','_')
		if y in kw:
			self.cmd_and_log(path+['--%s=%s'%(x,kw[y]),kw['package']],env=env)
			if not'okmsg'in kw:
				kw['okmsg']='yes'
			define_it()
			break
	if'modversion'in kw:
		version=self.cmd_and_log(path+['--modversion',kw['modversion']],env=env).strip()
		self.define('%s_VERSION'%Utils.quote_define_name(kw.get('uselib_store',kw['modversion'])),version)
		return version
	lst=[]+path
	defi=kw.get('define_variable',None)
	if not defi:
		defi=self.env.PKG_CONFIG_DEFINES or{}
	for key,val in defi.items():
		lst.append('--define-variable=%s=%s'%(key,val))
	static=kw.get('force_static',False)
	if'args'in kw:
		args=Utils.to_list(kw['args'])
		if'--static'in args or'--static-libs'in args:
			static=True
		lst+=args
	lst.extend(Utils.to_list(kw['package']))
	if'variables'in kw:
		v_env=kw.get('env',self.env)
		uselib=kw.get('uselib_store',kw['package'].upper())
		vars=Utils.to_list(kw['variables'])
		for v in vars:
			val=self.cmd_and_log(lst+['--variable='+v],env=env).strip()
			var='%s_%s'%(uselib,v)
			v_env[var]=val
		if not'okmsg'in kw:
			kw['okmsg']='yes'
		return
	ret=self.cmd_and_log(lst,env=env)
	if not'okmsg'in kw:
		kw['okmsg']='yes'
	define_it()
	self.parse_flags(ret,kw.get('uselib_store',kw['package'].upper()),kw.get('env',self.env),force_static=static,posix=kw.get('posix',None))
	return ret
Beispiel #13
0
def write_config_header(self,
                        configfile='',
                        guard='',
                        top=False,
                        env=None,
                        defines=True,
                        headers=False,
                        remove=True,
                        define_prefix=''):
    """
	Write a configuration header containing defines and includes::

		def configure(cnf):
			cnf.define('A', 1)
			cnf.write_config_header('config.h')

	:param configfile: relative path to the file to create
	:type configfile: string
	:param guard: include guard name to add, by default it is computed from the file name
	:type guard: string
	:param top: write the configuration header from the build directory (default is from the current path)
	:type top: bool
	:param defines: add the defines (yes by default)
	:type defines: bool
	:param headers: add #include in the file
	:type headers: bool
	:param remove: remove the defines after they are added (yes by default, works like in autoconf)
	:type remove: bool
	:type define_prefix: string
	:param define_prefix: prefix all the defines in the file with a particular prefix
	"""
    # TODO waf 1.8: the parameter env is not used
    if env:
        Logs.warn('Cannot pass env to write_config_header')

    if not configfile: configfile = WAF_CONFIG_H
    waf_guard = guard or 'W_%s_WAF' % Utils.quote_define_name(configfile)

    node = top and self.bldnode or self.path.get_bld()
    node = node.make_node(configfile)
    node.parent.mkdir()

    lst = ['/* WARNING! All changes made to this file will be lost! */\n']
    lst.append('#ifndef %s\n#define %s\n' % (waf_guard, waf_guard))
    lst.append(
        self.get_config_header(defines, headers, define_prefix=define_prefix))
    lst.append('\n#endif /* %s */\n' % waf_guard)

    node.write('\n'.join(lst))

    # config files are not removed on "waf clean"
    self.env.append_unique(Build.CFG_FILES, [node.abspath()])

    if remove:
        for key in self.env[DEFKEYS]:
            self.undefine(key)
        self.env[DEFKEYS] = []
def validate_cfg(self, kw):
    """
    Searches for the program *pkg-config* if missing, and validates the
    parameters to pass to :py:func:`waflib.Tools.c_config.exec_cfg`.

    :param path: the **-config program to use** (default is *pkg-config*)
    :type path: list of string
    :param msg: message to display to describe the test executed
    :type msg: string
    :param okmsg: message to display when the test is successful
    :type okmsg: string
    :param errmsg: message to display in case of error
    :type errmsg: string
    """
    if not "path" in kw:
        if not self.env.PKGCONFIG:
            self.find_program("pkg-config", var="PKGCONFIG")
        kw["path"] = self.env.PKGCONFIG

    # verify that exactly one action is requested
    s = ("atleast_pkgconfig_version" in kw) + ("modversion" in kw) + ("package" in kw)
    if s != 1:
        raise ValueError(
            "exactly one of atleast_pkgconfig_version, modversion and package must be set"
        )
    if not "msg" in kw:
        if "atleast_pkgconfig_version" in kw:
            kw["msg"] = (
                "Checking for pkg-config version >= %r"
                % kw["atleast_pkgconfig_version"]
            )
        elif "modversion" in kw:
            kw["msg"] = "Checking for %r version" % kw["modversion"]
        else:
            kw["msg"] = "Checking for %r" % (kw["package"])

    # let the modversion check set the okmsg to the detected version
    if not "okmsg" in kw and not "modversion" in kw:
        kw["okmsg"] = "yes"
    if not "errmsg" in kw:
        kw["errmsg"] = "not found"

    # pkg-config version
    if "atleast_pkgconfig_version" in kw:
        pass
    elif "modversion" in kw:
        if not "uselib_store" in kw:
            kw["uselib_store"] = kw["modversion"]
        if not "define_name" in kw:
            kw["define_name"] = "%s_VERSION" % Utils.quote_define_name(
                kw["uselib_store"]
            )
    else:
        if not "uselib_store" in kw:
            kw["uselib_store"] = Utils.to_list(kw["package"])[0].upper()
        if not "define_name" in kw:
            kw["define_name"] = self.have_define(kw["uselib_store"])
Beispiel #15
0
def exec_cfg(self, kw):
    if 'atleast_pkgconfig_version' in kw:
        cmd = [
            kw['path'],
            '--atleast-pkgconfig-version=%s' % kw['atleast_pkgconfig_version']
        ]
        self.cmd_and_log(cmd)
        if not 'okmsg' in kw:
            kw['okmsg'] = 'yes'
        return
    for x in cfg_ver:
        y = x.replace('-', '_')
        if y in kw:
            self.cmd_and_log(
                [kw['path'], '--%s=%s' % (x, kw[y]), kw['package']])
            if not 'okmsg' in kw:
                kw['okmsg'] = 'yes'
            self.define(
                self.have_define(kw.get('uselib_store', kw['package'])), 1, 0)
            break
    if 'modversion' in kw:
        version = self.cmd_and_log(
            [kw['path'], '--modversion', kw['modversion']]).strip()
        self.define(
            '%s_VERSION' %
            Utils.quote_define_name(kw.get('uselib_store', kw['modversion'])),
            version)
        return version
    lst = [kw['path']]
    defi = kw.get('define_variable', None)
    if not defi:
        defi = self.env.PKG_CONFIG_DEFINES or {}
    for key, val in defi.items():
        lst.append('--define-variable=%s=%s' % (key, val))
    if kw['package']:
        lst.extend(Utils.to_list(kw['package']))
    if 'variables' in kw:
        env = kw.get('env', self.env)
        uselib = kw.get('uselib_store', kw['package'].upper())
        vars = Utils.to_list(kw['variables'])
        for v in vars:
            val = self.cmd_and_log(lst + ['--variable=' + v]).strip()
            var = '%s_%s' % (uselib, v)
            env[var] = val
        if not 'okmsg' in kw:
            kw['okmsg'] = 'yes'
        return
    if 'args' in kw:
        lst += Utils.to_list(kw['args'])
    ret = self.cmd_and_log(lst)
    if not 'okmsg' in kw:
        kw['okmsg'] = 'yes'
    self.define(self.have_define(kw.get('uselib_store', kw['package'])), 1, 0)
    self.parse_flags(ret, kw.get('uselib_store', kw['package'].upper()),
                     kw.get('env', self.env))
    return ret
Beispiel #16
0
def validate_cfg(self, kw):
    """
	Searches for the program *pkg-config* if missing, and validates the
	parameters to pass to :py:func:`waflib.Tools.c_config.exec_cfg`.

	:param path: the **-config program to use** (default is *pkg-config*)
	:type path: list of string
	:param msg: message to display to describe the test executed
	:type msg: string
	:param okmsg: message to display when the test is successful
	:type okmsg: string
	:param errmsg: message to display in case of error
	:type errmsg: string
	"""
    if not 'path' in kw:
        if not self.env.PKGCONFIG:
            self.find_program('pkg-config', var='PKGCONFIG')
        kw['path'] = self.env.PKGCONFIG

    # verify that exactly one action is requested
    s = ('atleast_pkgconfig_version' in kw) + ('modversion' in kw) + ('package'
                                                                      in kw)
    if s != 1:
        raise ValueError(
            'exactly one of atleast_pkgconfig_version, modversion and package must be set'
        )
    if not 'msg' in kw:
        if 'atleast_pkgconfig_version' in kw:
            kw['msg'] = 'Checking for pkg-config version >= %r' % kw[
                'atleast_pkgconfig_version']
        elif 'modversion' in kw:
            kw['msg'] = 'Checking for %r version' % kw['modversion']
        else:
            kw['msg'] = 'Checking for %r' % (kw['package'])

    # let the modversion check set the okmsg to the detected version
    if not 'okmsg' in kw and not 'modversion' in kw:
        kw['okmsg'] = 'yes'
    if not 'errmsg' in kw:
        kw['errmsg'] = 'not found'

    # pkg-config version
    if 'atleast_pkgconfig_version' in kw:
        pass
    elif 'modversion' in kw:
        if not 'uselib_store' in kw:
            kw['uselib_store'] = kw['modversion']
        if not 'define_name' in kw:
            kw['define_name'] = '%s_VERSION' % Utils.quote_define_name(
                kw['uselib_store'])
    else:
        if not 'uselib_store' in kw:
            kw['uselib_store'] = Utils.to_list(kw['package'])[0].upper()
        if not 'define_name' in kw:
            kw['define_name'] = self.have_define(kw['uselib_store'])
Beispiel #17
0
def have_define(self, key):
	"""
	Returns a variable suitable for command-line or header use by removing invalid characters
	and prefixing it with ``HAVE_``

	:param key: define name
	:type key: string
	:return: the input key prefixed by *HAVE_* and substitute any invalid characters.
	:rtype: string
	"""
	return (self.env.HAVE_PAT or 'HAVE_%s') % Utils.quote_define_name(key)
Beispiel #18
0
def have_define(self, key):
    """
	Returns a variable suitable for command-line or header use by removing invalid characters
	and prefixing it with ``HAVE_``

	:param key: define name
	:type key: string
	:return: the input key prefixed by *HAVE_* and substitute any invalid characters.
	:rtype: string
	"""
    return (self.env.HAVE_PAT or 'HAVE_%s') % Utils.quote_define_name(key)
Beispiel #19
0
def pkg_cs(self):
    names = self.to_list(getattr(self, 'use', []))
    use = names[:]

    for x in names:
        pkg = 'PKG_%s' % Utils.quote_define_name(x)
        if  pkg in getattr(self.env, 'packages', []):
            self.env.append_value('CSFLAGS', '/pkg:%s' % x)
            use.remove(x)

    self.use = ' '.join(use)
Beispiel #20
0
def check_assembly(self, *k, **kw):
    path_list = []
    if "path_list" in kw:
        for path in kw['path_list']:
            if path:
                path_list.append(path)
        kw['path_list'] = path_list
    ret = self.find_file(*k, **kw)

    self.msg("Checking for %s" % k[0], ret, "GREEN")
    self.env.append_value(Utils.quote_define_name(k[0]), os.path.dirname(ret))
    self.define(self.have_define(k[0]), 1, 0)
Beispiel #21
0
def exec_cfg(self,kw):
	def define_it():
		self.define(self.have_define(kw.get('uselib_store',kw['package'])),1,0)
	env=kw.get('env',self.env)
	run_env=env.env or os.environ
	if'atleast_pkgconfig_version'in kw:
		cmd=[kw['path'],'--atleast-pkgconfig-version=%s'%kw['atleast_pkgconfig_version']]
		self.cmd_and_log(cmd,env=run_env)
		if not'okmsg'in kw:
			kw['okmsg']='yes'
		return
	for x in cfg_ver:
		y=x.replace('-','_')
		if y in kw:
			self.cmd_and_log([kw['path'],'--%s=%s'%(x,kw[y]),kw['package']],env=run_env)
			if not'okmsg'in kw:
				kw['okmsg']='yes'
			define_it()
			break
	if'modversion'in kw:
		version=self.cmd_and_log([kw['path'],'--modversion',kw['modversion']],env=run_env).strip()
		self.define('%s_VERSION'%Utils.quote_define_name(kw.get('uselib_store',kw['modversion'])),version)
		return version
	lst=[kw['path']]
	defi=kw.get('define_variable',None)
	if not defi:
		defi=self.env.PKG_CONFIG_DEFINES or{}
	for key,val in defi.items():
		lst.append('--define-variable=%s=%s'%(key,val))
	if'variables'in kw:
		uselib=kw.get('uselib_store',kw['package'].upper())
		vars=Utils.to_list(kw['variables'])
		for v in vars:
			val=self.cmd_and_log(lst+['--variable='+v],env=run_env).strip()
			var='%s_%s'%(uselib,v)
			env[var]=val
		if not'okmsg'in kw:
			kw['okmsg']='yes'
		return
	static=False
	if'args'in kw:
		args=Utils.to_list(kw['args'])
		if'--static'in args or'--static-libs'in args:
			static=True
		lst+=args
	lst.extend(Utils.to_list(kw['package']))
	ret=self.cmd_and_log(lst,env=run_env)
	if not'okmsg'in kw:
		kw['okmsg']='yes'
	define_it()
	self.parse_flags(ret,kw.get('uselib_store',kw['package'].upper()),kw.get('env',self.env),force_static=static)
	return ret
Beispiel #22
0
def filter_flags(conf, flags, required_flags, features, checkarg, compiler):

    check_flags = required_flags + (['-Werror'] if compiler != 'msvc' else [])
    tests = map(
        lambda x: {
            'features': features,
            'compiler': compiler,
            'msg': '... ' + x,
            'define_name': Utils.quote_define_name(x),
            checkarg: [x] + check_flags
        }, flags)

    conf.env.stash()
    conf.multicheck(*tests,
                    msg='Checking supported flags for %s in parallel' %
                    compiler,
                    mandatory=False)
    supported_flags = [
        f for f in flags if conf.env[Utils.quote_define_name(f)]
    ]
    conf.env.revert()
    return supported_flags
Beispiel #23
0
def write_config_header(self,
                        configfile='',
                        guard='',
                        top=False,
                        env=None,
                        defines=True,
                        headers=False,
                        remove=True):
    """
	Write a configuration header containing defines and includes::

		def configure(cnf):
			cnf.define('A', 1)
			cnf.write_config_header('config.h')

	:param configfile: relative path to the file to create
	:type configfile: string
	:param env: config set to read the definitions from (default is conf.env)
	:type env: :py:class:`waflib.ConfigSet.ConfigSet`
	:param top: write the configuration header from the build directory (default is from the current path)
	:type top: bool
	:param defines: add the defines (yes by default)
	:type defines: bool
	:param headers: add #include in the file
	:type headers: bool
	:param remove: remove the defines after they are added (yes by default)
	:type remove: bool
	"""
    if not configfile: configfile = WAF_CONFIG_H
    waf_guard = guard or '_%s_WAF' % Utils.quote_define_name(configfile)

    node = top and self.bldnode or self.path.get_bld()
    node = node.make_node(configfile)
    node.parent.mkdir()

    lst = ['/* WARNING! All changes made to this file will be lost! */\n']
    lst.append('#ifndef %s\n#define %s\n' % (waf_guard, waf_guard))
    lst.append(self.get_config_header(defines, headers))
    lst.append('\n#endif /* %s */\n' % waf_guard)

    node.write('\n'.join(lst))

    env = env or self.env

    # config files are not removed on "waf clean"
    env.append_unique(Build.CFG_FILES, [node.abspath()])

    if remove:
        for key in self.env[DEFKEYS]:
            self.undefine(key)
        self.env[DEFKEYS] = []
Beispiel #24
0
def check_header(self, h, **kw):

	if isinstance(h, str):
		code = '#include <%s>' % h
	else:
		code = '\n'.join(map(lambda x: '#include <%s>' % x, h))

	if 'msg' not in kw:
		kw['msg'] = 'Checking for %r' % h
	if 'errmsg' not in kw:
		kw['errmsg'] = 'not found'
	if 'define_name' not in kw:
		kw['define_name'] = 'HAVE_%s' % Utils.quote_define_name(h)
	self.check_cpp(fragment = code, **kw)
Beispiel #25
0
def write_config_header(
    self, configfile="", guard="", top=False, defines=True, headers=False, remove=True, define_prefix=""
):
    """
	Writes a configuration header containing defines and includes::

		def configure(cnf):
			cnf.define('A', 1)
			cnf.write_config_header('config.h')

	This function only adds include guards (if necessary), consult
	:py:func:`waflib.Tools.c_config.get_config_header` for details on the body.

	:param configfile: path to the file to create (relative or absolute)
	:type configfile: string
	:param guard: include guard name to add, by default it is computed from the file name
	:type guard: string
	:param top: write the configuration header from the build directory (default is from the current path)
	:type top: bool
	:param defines: add the defines (yes by default)
	:type defines: bool
	:param headers: add #include in the file
	:type headers: bool
	:param remove: remove the defines after they are added (yes by default, works like in autoconf)
	:type remove: bool
	:type define_prefix: string
	:param define_prefix: prefix all the defines in the file with a particular prefix
	"""
    if not configfile:
        configfile = WAF_CONFIG_H
    waf_guard = guard or "W_%s_WAF" % Utils.quote_define_name(configfile)

    node = top and self.bldnode or self.path.get_bld()
    node = node.make_node(configfile)
    node.parent.mkdir()

    lst = ["/* WARNING! All changes made to this file will be lost! */\n"]
    lst.append("#ifndef %s\n#define %s\n" % (waf_guard, waf_guard))
    lst.append(self.get_config_header(defines, headers, define_prefix=define_prefix))
    lst.append("\n#endif /* %s */\n" % waf_guard)

    node.write("\n".join(lst))

    # config files must not be removed on "waf clean"
    self.env.append_unique(Build.CFG_FILES, [node.abspath()])

    if remove:
        for key in self.env[DEFKEYS]:
            self.undefine(key)
        self.env[DEFKEYS] = []
Beispiel #26
0
def validate_cfg(self, kw):
	"""
	Searches for the program *pkg-config* if missing, and validates the
	parameters to pass to :py:func:`waflib.Tools.c_config.exec_cfg`.

	:param path: the **-config program to use** (default is *pkg-config*)
	:type path: list of string
	:param msg: message to display to describe the test executed
	:type msg: string
	:param okmsg: message to display when the test is successful
	:type okmsg: string
	:param errmsg: message to display in case of error
	:type errmsg: string
	"""
	if not 'path' in kw:
		if not self.env.PKGCONFIG:
			self.find_program('pkg-config', var='PKGCONFIG')
		kw['path'] = self.env.PKGCONFIG

	# verify that exactly one action is requested
	s = ('atleast_pkgconfig_version' in kw) + ('modversion' in kw) + ('package' in kw)
	if s != 1:
		raise ValueError('exactly one of atleast_pkgconfig_version, modversion and package must be set')
	if not 'msg' in kw:
		if 'atleast_pkgconfig_version' in kw:
			kw['msg'] = 'Checking for pkg-config version >= %r' % kw['atleast_pkgconfig_version']
		elif 'modversion' in kw:
			kw['msg'] = 'Checking for %r version' % kw['modversion']
		else:
			kw['msg'] = 'Checking for %r' %(kw['package'])

	# let the modversion check set the okmsg to the detected version
	if not 'okmsg' in kw and not 'modversion' in kw:
		kw['okmsg'] = 'yes'
	if not 'errmsg' in kw:
		kw['errmsg'] = 'not found'

	# pkg-config version
	if 'atleast_pkgconfig_version' in kw:
		pass
	elif 'modversion' in kw:
		if not 'uselib_store' in kw:
			kw['uselib_store'] = kw['modversion']
		if not 'define_name' in kw:
			kw['define_name'] = '%s_VERSION' % Utils.quote_define_name(kw['uselib_store'])
	else:
		if not 'uselib_store' in kw:
			kw['uselib_store'] = Utils.to_list(kw['package'])[0].upper()
		if not 'define_name' in kw:
			kw['define_name'] = self.have_define(kw['uselib_store'])
Beispiel #27
0
def write_config_header(self, configfile='', guard='', top=False, env=None, defines=True, headers=False, remove=True, define_prefix=''):
	"""
	Write a configuration header containing defines and includes::

		def configure(cnf):
			cnf.define('A', 1)
			cnf.write_config_header('config.h')

	:param configfile: relative path to the file to create
	:type configfile: string
	:param guard: include guard name to add, by default it is computed from the file name
	:type guard: string
	:param top: write the configuration header from the build directory (default is from the current path)
	:type top: bool
	:param defines: add the defines (yes by default)
	:type defines: bool
	:param headers: add #include in the file
	:type headers: bool
	:param remove: remove the defines after they are added (yes by default, works like in autoconf)
	:type remove: bool
	:type define_prefix: string
	:param define_prefix: prefix all the defines in the file with a particular prefix
	"""
	# TODO waf 1.8: the parameter env is not used
	if env:
		Logs.warn('Cannot pass env to write_config_header')

	if not configfile: configfile = WAF_CONFIG_H
	waf_guard = guard or 'W_%s_WAF' % Utils.quote_define_name(configfile)

	node = top and self.bldnode or self.path.get_bld()
	node = node.make_node(configfile)
	node.parent.mkdir()

	lst = ['/* WARNING! All changes made to this file will be lost! */\n']
	lst.append('#ifndef %s\n#define %s\n' % (waf_guard, waf_guard))
	lst.append(self.get_config_header(defines, headers, define_prefix=define_prefix))
	lst.append('\n#endif /* %s */\n' % waf_guard)

	node.write('\n'.join(lst))

	# config files are not removed on "waf clean"
	self.env.append_unique(Build.CFG_FILES, [node.abspath()])

	if remove:
		for key in self.env[DEFKEYS]:
			self.undefine(key)
		self.env[DEFKEYS] = []
Beispiel #28
0
def write_config_header(self,configfile='',guard='',top=False,defines=True,headers=False,remove=True,define_prefix=''):
	if not configfile:configfile=WAF_CONFIG_H
	waf_guard=guard or'W_%s_WAF'%Utils.quote_define_name(configfile)
	node=top and self.bldnode or self.path.get_bld()
	node=node.make_node(configfile)
	node.parent.mkdir()
	lst=['/* WARNING! All changes made to this file will be lost! */\n']
	lst.append('#ifndef %s\n#define %s\n'%(waf_guard,waf_guard))
	lst.append(self.get_config_header(defines,headers,define_prefix=define_prefix))
	lst.append('\n#endif /* %s */\n'%waf_guard)
	node.write('\n'.join(lst))
	self.env.append_unique(Build.CFG_FILES,[node.abspath()])
	if remove:
		for key in self.env[DEFKEYS]:
			self.undefine(key)
		self.env[DEFKEYS]=[]
Beispiel #29
0
def exec_cfg(self, kw):
    if "atleast_pkgconfig_version" in kw:
        cmd = [kw["path"], "--atleast-pkgconfig-version=%s" % kw["atleast_pkgconfig_version"]]
        self.cmd_and_log(cmd)
        if not "okmsg" in kw:
            kw["okmsg"] = "yes"
        return
    for x in cfg_ver:
        y = x.replace("-", "_")
        if y in kw:
            self.cmd_and_log([kw["path"], "--%s=%s" % (x, kw[y]), kw["package"]])
            if not "okmsg" in kw:
                kw["okmsg"] = "yes"
            self.define(self.have_define(kw.get("uselib_store", kw["package"])), 1, 0)
            break
    if "modversion" in kw:
        version = self.cmd_and_log([kw["path"], "--modversion", kw["modversion"]]).strip()
        self.define("%s_VERSION" % Utils.quote_define_name(kw.get("uselib_store", kw["modversion"])), version)
        return version
    lst = [kw["path"]]
    defi = kw.get("define_variable", None)
    if not defi:
        defi = self.env.PKG_CONFIG_DEFINES or {}
    for key, val in defi.items():
        lst.append("--define-variable=%s=%s" % (key, val))
    if kw["package"]:
        lst.extend(Utils.to_list(kw["package"]))
    if "variables" in kw:
        env = kw.get("env", self.env)
        uselib = kw.get("uselib_store", kw["package"].upper())
        vars = Utils.to_list(kw["variables"])
        for v in vars:
            val = self.cmd_and_log(lst + ["--variable=" + v]).strip()
            var = "%s_%s" % (uselib, v)
            env[var] = val
        if not "okmsg" in kw:
            kw["okmsg"] = "yes"
        return
    if "args" in kw:
        lst += Utils.to_list(kw["args"])
    ret = self.cmd_and_log(lst)
    if not "okmsg" in kw:
        kw["okmsg"] = "yes"
    self.define(self.have_define(kw.get("uselib_store", kw["package"])), 1, 0)
    self.parse_flags(ret, kw.get("uselib_store", kw["package"].upper()), kw.get("env", self.env))
    return ret
Beispiel #30
0
def use_extlib(self):
    names = self.to_list(getattr(self, 'use', []))
    use = names[:]

    for x in names:
        lib_name = Utils.quote_define_name(x)

        for lib_type in ccroot.lib_patterns.keys():
            if lib_name in getattr(self.env, 'ext_%s' % lib_type, []):
                name = getattr(self.env, '%s_NAME' % lib_name, None)

                # replace uselib with real assembly name
                if name:
                    use.remove(x)
                    use.append(name);

    self.use = ' '.join(use)
Beispiel #31
0
def validate_cfg(self, kw):
    if not 'path' in kw:
        if not self.env.PKGCONFIG:
            self.find_program('pkg-config', var='PKGCONFIG')
        kw['path'] = self.env.PKGCONFIG
    if 'atleast_pkgconfig_version' in kw:
        if not 'msg' in kw:
            kw['msg'] = 'Checking for pkg-config version >= %r' % kw[
                'atleast_pkgconfig_version']
        return
    if not 'okmsg' in kw:
        kw['okmsg'] = 'yes'
    if not 'errmsg' in kw:
        kw['errmsg'] = 'not found'
    if 'modversion' in kw:
        if not 'msg' in kw:
            kw['msg'] = 'Checking for %r version' % kw['modversion']
        if not 'uselib_store' in kw:
            kw['uselib_store'] = kw['modversion']
        if not 'define_name' in kw:
            kw['define_name'] = '%s_VERSION' % Utils.quote_define_name(
                kw['uselib_store'])
        return
    if not 'package' in kw:
        raise ValueError('a package name is required')
    if not 'uselib_store' in kw:
        kw['uselib_store'] = kw['package'].upper()
    if not 'define_name' in kw:
        kw['define_name'] = self.have_define(kw['uselib_store'])
    if not 'msg' in kw:
        kw['msg'] = 'Checking for %r' % (kw['package'] or kw['path'])
    for x in cfg_ver:
        y = x.replace('-', '_')
        if y in kw:
            package = kw['package']
            if Logs.verbose:
                Logs.warn(
                    'Passing %r to conf.check_cfg() is obsolete, pass parameters directly, eg:',
                    y)
                Logs.warn(
                    " conf.check_cfg(package='%s', args=['--libs', '--cflags', '%s >= 1.6'])",
                    package, package)
            if not 'msg' in kw:
                kw['msg'] = 'Checking for %r %s %s' % (package, cfg_ver[x],
                                                       kw[y])
            break
Beispiel #32
0
def write_config_header(self, configfile='', guard='', top=False, env=None, defines=True, headers=False, remove=True):
    """
    Write a configuration header containing defines and includes::

        def configure(cnf):
            cnf.define('A', 1)
            cnf.write_config_header('config.h')

    :param configfile: relative path to the file to create
    :type configfile: string
    :param env: config set to read the definitions from (default is conf.env)
    :type env: :py:class:`waflib.ConfigSet.ConfigSet`
    :param top: write the configuration header from the build directory (default is from the current path)
    :type top: bool
    :param defines: add the defines (yes by default)
    :type defines: bool
    :param headers: add #include in the file
    :type headers: bool
    :param remove: remove the defines after they are added (yes by default)
    :type remove: bool
    """
    if not configfile:
        configfile = WAF_CONFIG_H
    waf_guard = guard or '_%s_WAF' % Utils.quote_define_name(configfile)

    node = top and self.bldnode or self.path.get_bld()
    node = node.make_node(configfile)
    node.parent.mkdir()

    lst = ['/* WARNING! All changes made to this file will be lost! */\n']
    lst.append('#ifndef %s\n#define %s\n' % (waf_guard, waf_guard))
    lst.append(self.get_config_header(defines, headers))
    lst.append('\n#endif /* %s */\n' % waf_guard)

    node.write('\n'.join(lst))

    env = env or self.env

    # config files are not removed on "waf clean"
    env.append_unique(Build.CFG_FILES, [node.abspath()])

    if remove:
        for key in self.env[DEFKEYS]:
            self.undefine(key)
        self.env[DEFKEYS] = []
Beispiel #33
0
def write_config_header(self, configfile="", guard="", top=False, env=None, defines=True, headers=False, remove=True):
    if not configfile:
        configfile = WAF_CONFIG_H
    waf_guard = guard or "_%s_WAF" % Utils.quote_define_name(configfile)
    node = top and self.bldnode or self.path.get_bld()
    node = node.make_node(configfile)
    node.parent.mkdir()
    lst = ["/* WARNING! All changes made to this file will be lost! */\n"]
    lst.append("#ifndef %s\n#define %s\n" % (waf_guard, waf_guard))
    lst.append(self.get_config_header(defines, headers))
    lst.append("\n#endif /* %s */\n" % waf_guard)
    node.write("\n".join(lst))
    env = env or self.env
    env.append_unique(Build.CFG_FILES, [node.abspath()])
    if remove:
        for key in self.env[DEFKEYS]:
            self.undefine(key)
        self.env[DEFKEYS] = []
Beispiel #34
0
def exec_cfg(self, kw):

	# pkg-config version
	if 'atleast_pkgconfig_version' in kw:
		cmd = '%s --atleast-pkgconfig-version=%s' % (kw['path'], kw['atleast_pkgconfig_version'])
		self.cmd_and_log(cmd)
		if not 'okmsg' in kw:
			kw['okmsg'] = 'yes'
		return

	# checking for the version of a module
	for x in cfg_ver:
		y = x.replace('-', '_')
		if y in kw:
			self.cmd_and_log('%s --%s=%s %s' % (kw['path'], x, kw[y], kw['package']))
			if not 'okmsg' in kw:
				kw['okmsg'] = 'yes'
			self.define(self.have_define(kw.get('uselib_store', kw['package'])), 1, 0)
			break

	# retrieving the version of a module
	if 'modversion' in kw:
		version = self.cmd_and_log('%s --modversion %s' % (kw['path'], kw['modversion'])).strip()
		self.define('%s_VERSION' % Utils.quote_define_name(kw.get('uselib_store', kw['modversion'])), version)
		return version

	lst = [kw['path']]
	for key, val in kw.get('define_variable', {}).items():
		lst.append('--define-variable=%s=%s' % (key, val))

	lst.append(kw.get('args', ''))
	lst.append(kw['package'])

	# so we assume the command-line will output flags to be parsed afterwards
	cmd = ' '.join(lst)
	ret = self.cmd_and_log(cmd)
	if not 'okmsg' in kw:
		kw['okmsg'] = 'yes'

	self.define(self.have_define(kw.get('uselib_store', kw['package'])), 1, 0)
	parse_flags(ret, kw.get('uselib_store', kw['package'].upper()), kw.get('env', self.env))
	return ret
Beispiel #35
0
def validate_cfg(self,kw):
	if not'path'in kw:
		if not self.env.PKGCONFIG:
			self.find_program('pkg-config',var='PKGCONFIG')
		kw['path']=self.env.PKGCONFIG
	if'atleast_pkgconfig_version'in kw:
		if not'msg'in kw:
			kw['msg']='Checking for pkg-config version >= %r'%kw['atleast_pkgconfig_version']
		return
	if not'okmsg'in kw:
		kw['okmsg']='yes'
	if not'errmsg'in kw:
		kw['errmsg']='not found'
	if'modversion'in kw:
		if not'msg'in kw:
			kw['msg']='Checking for %r version'%kw['modversion']
		if not'uselib_store'in kw:
			kw['uselib_store']=kw['modversion']
		if not'define_name'in kw:
			kw['define_name']='%s_VERSION'%Utils.quote_define_name(kw['uselib_store'])
		return
	if not'package'in kw:
		raise ValueError('a package name is required')
	if not'uselib_store'in kw:
		kw['uselib_store']=kw['package'].upper()
	if not'define_name'in kw:
		kw['define_name']=self.have_define(kw['uselib_store'])
	if not'msg'in kw:
		kw['msg']='Checking for %r'%(kw['package']or kw['path'])
	for x in cfg_ver:
		y=x.replace('-','_')
		if y in kw:
			package=kw['package']
			if Logs.verbose:
				Logs.warn('Passing %r to conf.check_cfg() is obsolete, pass parameters directly, eg:',y)
				Logs.warn(" conf.check_cfg(package='%s', args=['--libs', '--cflags', '%s >= 1.6'])",package,package)
			if not'msg'in kw:
				kw['msg']='Checking for %r %s %s'%(package,cfg_ver[x],kw[y])
			break
Beispiel #36
0
def have_define(self, key):
    return (self.env.HAVE_PAT or 'HAVE_%s') % Utils.quote_define_name(key)
Beispiel #37
0
def validate_cfg(self, kw):
    """
	Searches for the program *pkg-config* if missing, and validates the
	parameters to pass to :py:func:`waflib.Tools.c_config.exec_cfg`.

	:param path: the **-config program to use** (default is *pkg-config*)
	:type path: list of string
	:param msg: message to display to describe the test executed
	:type msg: string
	:param okmsg: message to display when the test is successful
	:type okmsg: string
	:param errmsg: message to display in case of error
	:type errmsg: string
	"""
    if not 'path' in kw:
        if not self.env.PKGCONFIG:
            self.find_program('pkg-config', var='PKGCONFIG')
        kw['path'] = self.env.PKGCONFIG

    # pkg-config version
    if 'atleast_pkgconfig_version' in kw:
        if not 'msg' in kw:
            kw['msg'] = 'Checking for pkg-config version >= %r' % kw[
                'atleast_pkgconfig_version']
        return

    if not 'okmsg' in kw:
        kw['okmsg'] = 'yes'
    if not 'errmsg' in kw:
        kw['errmsg'] = 'not found'

    if 'modversion' in kw:
        if not 'msg' in kw:
            kw['msg'] = 'Checking for %r version' % kw['modversion']
        if not 'uselib_store' in kw:
            kw['uselib_store'] = kw['modversion']
        if not 'define_name' in kw:
            kw['define_name'] = '%s_VERSION' % Utils.quote_define_name(
                kw['uselib_store'])
        return

    if not 'package' in kw:
        raise ValueError('a package name is required')

    if not 'uselib_store' in kw:
        kw['uselib_store'] = kw['package'].upper()

    if not 'define_name' in kw:
        kw['define_name'] = self.have_define(kw['uselib_store'])

    if not 'msg' in kw:
        kw['msg'] = 'Checking for %r' % (kw['package'] or kw['path'])

    for x in cfg_ver:
        # Gotcha: only one predicate is allowed at a time
        # TODO remove in waf 2.0
        y = x.replace('-', '_')
        if y in kw:
            package = kw['package']
            if Logs.verbose:
                Logs.warn(
                    'Passing %r to conf.check_cfg() is obsolete, pass parameters directly, eg:',
                    y)
                Logs.warn(
                    " conf.check_cfg(package='%s', args=['--libs', '--cflags', '%s >= 1.6'])",
                    package, package)
            if not 'msg' in kw:
                kw['msg'] = 'Checking for %r %s %s' % (package, cfg_ver[x],
                                                       kw[y])
            break
Beispiel #38
0
    def __init__(self,
                 opt,
                 name,
                 help=None,
                 default=True,
                 conf_dest=None,
                 define=None,
                 style=None):
        """
        Class initializing method.

        Arguments:
            opt       OptionsContext
            name      name of the option, e.g. alsa
            help      help text that will be displayed in --help output
            conf_dest conf.env variable to define to the result
            define    the preprocessor symbol to define with the result
            style     the option style to use; see below for options
        """

        # The dependencies to check for. The elements are on the form
        # (func, k, kw) where func is the function or function name that
        # is used for the check and k and kw are the arguments and
        # options to give the function.
        self.deps = []

        # Whether or not the option should be enabled. None indicates
        # that the checks have not been performed yet.
        self.enable = None

        self.help = help
        if help:
            if default:
                help_comment = ' (enabled by default if possible)'
            else:
                help_comment = ' (disabled by default)'
            option_help = help + help_comment
            no_option_help = None
        else:
            option_help = no_option_help = optparse.SUPPRESS_HELP

        self.dest = 'auto_option_' + name

        self.default = default

        safe_name = Utils.quote_define_name(name)
        self.conf_dest = conf_dest or safe_name

        default_define = opt.get_auto_options_define()
        self.define = define or default_define % safe_name

        if not style:
            style = opt.get_auto_options_style()
        self.style = style

        # plain (default):
        #   --foo | --no-foo
        # yesno:
        #   --foo=yes | --foo=no
        # yesno_and_hack:
        #  --foo[=yes] | --foo=no or --no-foo
        # enable:
        #  --enable-foo | --disble-foo
        # with:
        #  --with-foo | --without-foo
        if style in ['plain', 'yesno', 'yesno_and_hack']:
            self.no_option = '--no-' + name
            self.yes_option = '--' + name
        elif style == 'enable':
            self.no_option = '--disable-' + name
            self.yes_option = '--enable-' + name
        elif style == 'with':
            self.no_option = '--without-' + name
            self.yes_option = '--with-' + name
        else:
            opt.fatal('invalid style')

        if style in ['yesno', 'yesno_and_hack']:
            opt.add_option(self.yes_option,
                           dest=self.dest,
                           action='store',
                           choices=['auto', 'no', 'yes'],
                           default='auto',
                           help=option_help,
                           metavar='no|yes')
        else:
            opt.add_option(self.yes_option,
                           dest=self.dest,
                           action='store_const',
                           const='yes',
                           default='auto',
                           help=option_help)
            opt.add_option(self.no_option,
                           dest=self.dest,
                           action='store_const',
                           const='no',
                           default='auto',
                           help=no_option_help)
Beispiel #39
0
def have_define(self,key):
	return self.__dict__.get('HAVE_PAT','HAVE_%s')%Utils.quote_define_name(key)
Beispiel #40
0
def have_define(self,key):
	return(self.env.HAVE_PAT or'HAVE_%s')%Utils.quote_define_name(key)
Beispiel #41
0
def validate_cfg(self, kw):
	"""
	Searches for the program *pkg-config* if missing, and validates the
	parameters to pass to :py:func:`waflib.Tools.c_config.exec_cfg`.

	:param path: the **-config program to use** (default is *pkg-config*)
	:type path: list of string
	:param msg: message to display to describe the test executed
	:type msg: string
	:param okmsg: message to display when the test is successful
	:type okmsg: string
	:param errmsg: message to display in case of error
	:type errmsg: string
	"""
	if not 'path' in kw:
		if not self.env.PKGCONFIG:
			self.find_program('pkg-config', var='PKGCONFIG')
		kw['path'] = self.env.PKGCONFIG

	# pkg-config version
	if 'atleast_pkgconfig_version' in kw:
		if not 'msg' in kw:
			kw['msg'] = 'Checking for pkg-config version >= %r' % kw['atleast_pkgconfig_version']
		return

	if not 'okmsg' in kw:
		kw['okmsg'] = 'yes'
	if not 'errmsg' in kw:
		kw['errmsg'] = 'not found'

	if 'modversion' in kw:
		if not 'msg' in kw:
			kw['msg'] = 'Checking for %r version' % kw['modversion']
		if not 'uselib_store' in kw:
			kw['uselib_store'] = kw['modversion']
		if not 'define_name' in kw:
			kw['define_name'] = '%s_VERSION' % Utils.quote_define_name(kw['uselib_store'])
		return

	if not 'package' in kw:
		raise ValueError('a package name is required')

	if not 'uselib_store' in kw:
		kw['uselib_store'] = kw['package'].upper()

	if not 'define_name' in kw:
		kw['define_name'] = self.have_define(kw['uselib_store'])

	if not 'msg' in kw:
		kw['msg'] = 'Checking for %r' % (kw['package'] or kw['path'])

	for x in cfg_ver:
		# Gotcha: only one predicate is allowed at a time
		# TODO remove in waf 2.0
		y = x.replace('-', '_')
		if y in kw:
			package = kw['package']
			if Logs.verbose:
				Logs.warn('Passing %r to conf.check_cfg() is obsolete, pass parameters directly, eg:', y)
				Logs.warn(" conf.check_cfg(package='%s', args=['--libs', '--cflags', '%s >= 1.6'])", package, package)
			if not 'msg' in kw:
				kw['msg'] = 'Checking for %r %s %s' % (package, cfg_ver[x], kw[y])
			break
Beispiel #42
0
def have_define(self, key):
	"prefix the define with 'HAVE_' and make sure it has valid characters."
	return self.__dict__.get('HAVE_PAT', 'HAVE_%s') % Utils.quote_define_name(key)
Beispiel #43
0
def exec_cfg(self, kw):
	"""
	Execute the program *pkg-config*:

	* if atleast_pkgconfig_version is given, check that pkg-config has the version n and return
	* if modversion is given, then return the module version
	* else, execute the *-config* program with the *args* and *variables* given, and set the flags on the *conf.env.FLAGS_name* variable

	:param atleast_pkgconfig_version: minimum pkg-config version to use (disable other tests)
	:type atleast_pkgconfig_version: string
	:param package: package name, for example *gtk+-2.0*
	:type package: string
	:param uselib_store: if the test is successful, define HAVE\_*name*. It is also used to define *conf.env.FLAGS_name* variables.
	:type uselib_store: string
	:param modversion: if provided, return the version of the given module and define *name*\_VERSION
	:type modversion: string
	:param args: arguments to give to *package* when retrieving flags
	:type args: list of string
	:param variables: return the values of particular variables
	:type variables: list of string
	:param define_variable: additional variables to define (also in conf.env.PKG_CONFIG_DEFINES)
	:type define_variable: dict(string: string)
	"""

	# pkg-config version
	if 'atleast_pkgconfig_version' in kw:
		cmd = [kw['path'], '--atleast-pkgconfig-version=%s' % kw['atleast_pkgconfig_version']]
		self.cmd_and_log(cmd)
		if not 'okmsg' in kw:
			kw['okmsg'] = 'yes'
		return

	# checking for the version of a module
	for x in cfg_ver:
		y = x.replace('-', '_')
		if y in kw:
			self.cmd_and_log([kw['path'], '--%s=%s' % (x, kw[y]), kw['package']])
			if not 'okmsg' in kw:
				kw['okmsg'] = 'yes'
			self.define(self.have_define(kw.get('uselib_store', kw['package'])), 1, 0)
			break

	# retrieving the version of a module
	if 'modversion' in kw:
		version = self.cmd_and_log([kw['path'], '--modversion', kw['modversion']]).strip()
		self.define('%s_VERSION' % Utils.quote_define_name(kw.get('uselib_store', kw['modversion'])), version)
		return version

	lst = [kw['path']]

	defi = kw.get('define_variable', None)
	if not defi:
		defi = self.env.PKG_CONFIG_DEFINES or {}
	for key, val in defi.items():
		lst.append('--define-variable=%s=%s' % (key, val))

	if kw['package']:
		lst.extend(Utils.to_list(kw['package']))

	# retrieving variables of a module
	if 'variables' in kw:
		env = kw.get('env', self.env)
		uselib = kw.get('uselib_store', kw['package'].upper())
		vars = Utils.to_list(kw['variables'])
		for v in vars:
			val = self.cmd_and_log(lst + ['--variable=' + v]).strip()
			var = '%s_%s' % (uselib, v)
			env[var] = val
		if not 'okmsg' in kw:
			kw['okmsg'] = 'yes'
		return

	static = False
	if 'args' in kw:
		args = Utils.to_list(kw['args'])
		if '--static' in args or '--static-libs' in args:
			static = True
		lst += args
	# so we assume the command-line will output flags to be parsed afterwards
	ret = self.cmd_and_log(lst)
	if not 'okmsg' in kw:
		kw['okmsg'] = 'yes'

	self.define(self.have_define(kw.get('uselib_store', kw['package'])), 1, 0)
	self.parse_flags(ret, kw.get('uselib_store', kw['package'].upper()), kw.get('env', self.env), force_static=static)
	return ret
Beispiel #44
0
def have_define(self,key):
	return self.__dict__.get('HAVE_PAT','HAVE_%s')%Utils.quote_define_name(key)
Beispiel #45
0
def exec_cfg(self, kw):
    """
	Execute the program *pkg-config*:

	* if atleast_pkgconfig_version is given, check that pkg-config has the version n and return
	* if modversion is given, then return the module version
	* else, execute the *-config* program with the *args* and *variables* given, and set the flags on the *conf.env.FLAGS_name* variable

	:param atleast_pkgconfig_version: minimum pkg-config version to use (disable other tests)
	:type atleast_pkgconfig_version: string
	:param package: package name, for example *gtk+-2.0*
	:type package: string
	:param uselib_store: if the test is successful, define HAVE\_*name*. It is also used to define *conf.env.FLAGS_name* variables.
	:type uselib_store: string
	:param modversion: if provided, return the version of the given module and define *name*\_VERSION
	:type modversion: string
	:param args: arguments to give to *package* when retrieving flags
	:type args: list of string
	:param variables: return the values of particular variables
	:type variables: list of string
	:param define_variable: additional variables to define (also in conf.env.PKG_CONFIG_DEFINES)
	:type define_variable: dict(string: string)
	"""

    # pkg-config version
    if 'atleast_pkgconfig_version' in kw:
        cmd = [
            kw['path'],
            '--atleast-pkgconfig-version=%s' % kw['atleast_pkgconfig_version']
        ]
        self.cmd_and_log(cmd)
        if not 'okmsg' in kw:
            kw['okmsg'] = 'yes'
        return

    # checking for the version of a module
    for x in cfg_ver:
        y = x.replace('-', '_')
        if y in kw:
            self.cmd_and_log(
                [kw['path'], '--%s=%s' % (x, kw[y]), kw['package']])
            if not 'okmsg' in kw:
                kw['okmsg'] = 'yes'
            self.define(
                self.have_define(kw.get('uselib_store', kw['package'])), 1, 0)
            break

    # retrieving the version of a module
    if 'modversion' in kw:
        version = self.cmd_and_log(
            [kw['path'], '--modversion', kw['modversion']]).strip()
        self.define(
            '%s_VERSION' %
            Utils.quote_define_name(kw.get('uselib_store', kw['modversion'])),
            version)
        return version

    lst = [kw['path']]

    defi = kw.get('define_variable', None)
    if not defi:
        defi = self.env.PKG_CONFIG_DEFINES or {}
    for key, val in defi.items():
        lst.append('--define-variable=%s=%s' % (key, val))

    if kw['package']:
        lst.extend(Utils.to_list(kw['package']))

    # retrieving variables of a module
    if 'variables' in kw:
        env = kw.get('env', self.env)
        uselib = kw.get('uselib_store', kw['package'].upper())
        vars = Utils.to_list(kw['variables'])
        for v in vars:
            val = self.cmd_and_log(lst + ['--variable=' + v]).strip()
            var = '%s_%s' % (uselib, v)
            env[var] = val
        if not 'okmsg' in kw:
            kw['okmsg'] = 'yes'
        return

    if 'args' in kw:
        lst += Utils.to_list(kw['args'])
    # so we assume the command-line will output flags to be parsed afterwards
    ret = self.cmd_and_log(lst)
    if not 'okmsg' in kw:
        kw['okmsg'] = 'yes'

    self.define(self.have_define(kw.get('uselib_store', kw['package'])), 1, 0)
    self.parse_flags(ret, kw.get('uselib_store', kw['package'].upper()),
                     kw.get('env', self.env))
    return ret
Beispiel #46
0
    def __init__(self, opt, name, help=None, default=True,
            conf_dest=None, define=None, style=None):
        """
        Class initializing method.

        Arguments:
            opt       OptionsContext
            name      name of the option, e.g. alsa
            help      help text that will be displayed in --help output
            conf_dest conf.env variable to define to the result
            define    the preprocessor symbol to define with the result
            style     the option style to use; see below for options
        """

        # The dependencies to check for. The elements are on the form
        # (func, k, kw) where func is the function or function name that
        # is used for the check and k and kw are the arguments and
        # options to give the function.
        self.deps = []

        # Whether or not the option should be enabled. None indicates
        # that the checks have not been performed yet.
        self.enable = None

        self.help = help
        if help:
            if default:
                help_comment = ' (enabled by default if possible)'
            else:
                help_comment = ' (disabled by default)'
            option_help = help + help_comment
            no_option_help = None
        else:
            option_help = no_option_help = optparse.SUPPRESS_HELP

        self.dest = 'auto_option_' + name

        self.default = default

        safe_name = Utils.quote_define_name(name)
        self.conf_dest = conf_dest or safe_name

        default_define = opt.get_auto_options_define()
        self.define = define or default_define % safe_name

        if not style:
            style = opt.get_auto_options_style()
        self.style = style

        # plain (default):
        #   --foo | --no-foo
        # yesno:
        #   --foo=yes | --foo=no
        # yesno_and_hack:
        #  --foo[=yes] | --foo=no or --no-foo
        # enable:
        #  --enable-foo | --disble-foo
        # with:
        #  --with-foo | --without-foo
        if style in ['plain', 'yesno', 'yesno_and_hack']:
            self.no_option = '--no-' + name
            self.yes_option = '--' + name
        elif style == 'enable':
            self.no_option = '--disable-' + name
            self.yes_option = '--enable-' + name
        elif style == 'with':
            self.no_option = '--without-' + name
            self.yes_option = '--with-' + name
        else:
            opt.fatal('invalid style')

        if style in ['yesno', 'yesno_and_hack']:
            opt.add_option(
                    self.yes_option,
                    dest=self.dest,
                    action='store',
                    choices=['auto', 'no', 'yes'],
                    default='auto',
                    help=option_help,
                    metavar='no|yes')
        else:
            opt.add_option(
                    self.yes_option,
                    dest=self.dest,
                    action='store_const',
                    const='yes',
                    default='auto',
                    help=option_help)
            opt.add_option(
                    self.no_option,
                    dest=self.dest,
                    action='store_const',
                    const='no',
                    default='auto',
                    help=no_option_help)
Beispiel #47
0
def exec_cfg(self, kw):
    """
	Execute the program *pkg-config*:

	* if atleast_pkgconfig_version is given, check that pkg-config has the version n and return
	* if modversion is given, then return the module version
	* else, execute the *-config* program with the *args* and *variables* given, and set the flags on the *conf.env.FLAGS_name* variable

	:param atleast_pkgconfig_version: minimum pkg-config version to use (disable other tests)
	:type atleast_pkgconfig_version: string
	:param package: package name, for example *gtk+-2.0*
	:type package: string
	:param uselib_store: if the test is successful, define HAVE\_*name*. It is also used to define *conf.env.FLAGS_name* variables.
	:type uselib_store: string
	:param modversion: if provided, return the version of the given module and define *name*\_VERSION
	:type modversion: string
	:param args: arguments to give to *package* when retrieving flags
	:type args: list of string
	:param variables: return the values of particular variables
	:type variables: list of string
	:param define_variable: additional variables to define (also in conf.env.PKG_CONFIG_DEFINES)
	:type define_variable: dict(string: string)
	"""

    path = Utils.to_list(kw['path'])
    env = self.env.env or None

    def define_it():
        pkgname = kw.get('uselib_store', kw['package'].upper())
        if kw.get('global_define'):
            # compatibility, replace by pkgname in WAF 1.9?
            self.define(self.have_define(kw['package']), 1, False)
        else:
            self.env.append_unique('DEFINES_%s' % pkgname,
                                   "%s=1" % self.have_define(pkgname))
        self.env[self.have_define(pkgname)] = 1

    # pkg-config version
    if 'atleast_pkgconfig_version' in kw:
        cmd = path + [
            '--atleast-pkgconfig-version=%s' % kw['atleast_pkgconfig_version']
        ]
        self.cmd_and_log(cmd, env=env)
        if not 'okmsg' in kw:
            kw['okmsg'] = 'yes'
        return

    # checking for the version of a module
    for x in cfg_ver:
        y = x.replace('-', '_')
        if y in kw:
            self.cmd_and_log(path + ['--%s=%s' % (x, kw[y]), kw['package']],
                             env=env)
            if not 'okmsg' in kw:
                kw['okmsg'] = 'yes'
            define_it()
            break

    # retrieving the version of a module
    if 'modversion' in kw:
        version = self.cmd_and_log(path + ['--modversion', kw['modversion']],
                                   env=env).strip()
        self.define(
            '%s_VERSION' %
            Utils.quote_define_name(kw.get('uselib_store', kw['modversion'])),
            version)
        return version

    lst = [] + path

    defi = kw.get('define_variable', None)
    if not defi:
        defi = self.env.PKG_CONFIG_DEFINES or {}
    for key, val in defi.items():
        lst.append('--define-variable=%s=%s' % (key, val))

    static = kw.get('force_static', False)
    if 'args' in kw:
        args = Utils.to_list(kw['args'])
        if '--static' in args or '--static-libs' in args:
            static = True
        lst += args

    # tools like pkgconf expect the package argument after the -- ones -_-
    lst.extend(Utils.to_list(kw['package']))

    # retrieving variables of a module
    if 'variables' in kw:
        v_env = kw.get('env', self.env)
        uselib = kw.get('uselib_store', kw['package'].upper())
        vars = Utils.to_list(kw['variables'])
        for v in vars:
            val = self.cmd_and_log(lst + ['--variable=' + v], env=env).strip()
            var = '%s_%s' % (uselib, v)
            v_env[var] = val
        if not 'okmsg' in kw:
            kw['okmsg'] = 'yes'
        return

    # so we assume the command-line will output flags to be parsed afterwards
    ret = self.cmd_and_log(lst, env=env)
    if not 'okmsg' in kw:
        kw['okmsg'] = 'yes'

    define_it()
    self.parse_flags(ret,
                     kw.get('uselib_store', kw['package'].upper()),
                     kw.get('env', self.env),
                     force_static=static,
                     posix=kw.get('posix', None))
    return ret
Beispiel #48
0
def validate_cfg(self, kw):
    """
	Searches for the program *pkg-config* if missing, and validates the
	parameters to pass to :py:func:`waflib.Tools.c_config.exec_cfg`.

	:param path: the **-config program to use** (default is *pkg-config*)
	:type path: list of string
	:param msg: message to display to describe the test executed
	:type msg: string
	:param okmsg: message to display when the test is successful
	:type okmsg: string
	:param errmsg: message to display in case of error
	:type errmsg: string
	"""
    if not "path" in kw:
        if not self.env.PKGCONFIG:
            self.find_program("pkg-config", var="PKGCONFIG")
        kw["path"] = self.env.PKGCONFIG

        # pkg-config version
    if "atleast_pkgconfig_version" in kw:
        if not "msg" in kw:
            kw["msg"] = "Checking for pkg-config version >= %r" % kw["atleast_pkgconfig_version"]
        return

    if not "okmsg" in kw:
        kw["okmsg"] = "yes"
    if not "errmsg" in kw:
        kw["errmsg"] = "not found"

    if "modversion" in kw:
        if not "msg" in kw:
            kw["msg"] = "Checking for %r version" % kw["modversion"]
        if not "uselib_store" in kw:
            kw["uselib_store"] = kw["modversion"]
        if not "define_name" in kw:
            kw["define_name"] = "%s_VERSION" % Utils.quote_define_name(kw["uselib_store"])
        return

    if not "package" in kw:
        raise ValueError("a package name is required")

    if not "uselib_store" in kw:
        kw["uselib_store"] = kw["package"].upper()

    if not "define_name" in kw:
        kw["define_name"] = self.have_define(kw["uselib_store"])

    if not "msg" in kw:
        kw["msg"] = "Checking for %r" % (kw["package"] or kw["path"])

    for x in cfg_ver:
        # Gotcha: only one predicate is allowed at a time
        # TODO remove in waf 2.0
        y = x.replace("-", "_")
        if y in kw:
            package = kw["package"]
            if Logs.verbose:
                Logs.warn("Passing %r to conf.check_cfg() is obsolete, pass parameters directly, eg:", y)
                Logs.warn(" conf.check_cfg(package='%s', args=['--libs', '--cflags', '%s >= 1.6'])", package, package)
            if not "msg" in kw:
                kw["msg"] = "Checking for %r %s %s" % (package, cfg_ver[x], kw[y])
            break