Skip to content

Commit

Permalink
OTHER: Simplify compiler flag checks.
Browse files Browse the repository at this point in the history
Based on patch by Sergei Trofimovich, slyfox@gentoo.org
  • Loading branch information
dsvensson committed Apr 28, 2011
1 parent f5e9fa4 commit 1cd38a5
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/clients/lib/ruby/wscript
Expand Up @@ -15,7 +15,7 @@ def build(bld):
rb_result.c
""".split()
obj.uselib_local = 'xmmsclient'
obj.uselib = 'NOSTRICTPROTOTYPES'
obj.uselib = 'DISABLE_STRICTPROTOTYPES'
obj.mac_bundle = True
obj.install_path = '${ARCHDIR_RUBY}'

Expand All @@ -29,7 +29,7 @@ def build(bld):
obj.includes = '../../../.. ../../../include ../../../includepriv'
obj.source = ['rb_xmmsclient_glib.c']
obj.uselib_local = 'xmmsclient-glib xmmsclient'
obj.uselib = 'glib2 NOSTRICTPROTOTYPES'
obj.uselib = 'glib2 DISABLE_STRICTPROTOTYPES'
obj.mac_bundle = True
obj.install_path = '${ARCHDIR_RUBY}'

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/mp4/wscript
Expand Up @@ -20,4 +20,4 @@ def plugin_build(bld, obj):
obj.find_sources_in_dirs("mp4ff")

configure, build = plugin("mp4", configure=plugin_configure, build=plugin_build,
libs=["mp4", "math", "NOMISSINGPROTOTYPES"])
libs=["mp4", "math", "DISABLE_MISSINGPROTOTYPES"])
4 changes: 2 additions & 2 deletions tests/wscript
Expand Up @@ -21,15 +21,15 @@ def build(bld):
obj.source = ['runner/main.c', 'runner/valgrind.c'] + types_suite
obj.includes = '. ../ runner/ ../src ../src/include'
obj.uselib_local = 'xmmstypes'
obj.uselib = 'cunit ncurses valgrind NOWRITESTRINGS'
obj.uselib = 'cunit ncurses valgrind DISABLE_WRITESTRINGS'
obj.install_path = None

obj = bld.new_task_gen('cc', 'program')
obj.target = "test_server"
obj.source = ['runner/main.c', 'runner/valgrind.c', '../src/xmms/streamtype.c', '../src/xmms/object.c'] + server_suite
obj.includes = '. ../ runner/ ../src ../src/includepriv ../src/include'
obj.uselib_local = 'xmmstypes'
obj.uselib = 'cunit ncurses valgrind glib2 gthread2 NOWRITESTRINGS'
obj.uselib = 'cunit ncurses valgrind glib2 gthread2 DISABLE_WRITESTRINGS'
obj.install_path = None


Expand Down
65 changes: 65 additions & 0 deletions waftools/compiler_flags.py
@@ -0,0 +1,65 @@
class compiler_flags(object):
def __init__(self, conf):
self.conf = conf

def _check(self, func, key, enable_prefix, disable_prefix, name):
enable_flag = enable_prefix + name
disable_flag = disable_prefix + name
if not func(cflags=enable_flag):
return False, False

uselib = name.replace("-", "").replace("=", "").upper()
self.conf.env.append_unique("%s_ENABLE_%s" % (key, uselib), [enable_flag])
self.conf.env.append_unique("%s_DISABLE_%s" % (key, uselib), [disable_flag])

return enable_flag, disable_flag

def check_cc(self, *args):
return self._check(self.conf.check_cc, "CCFLAGS", *args)

def check_cxx(self, *args):
return self._check(self.conf.check_cxx, "CXXFLAGS", *args)

def enable_c_error(self, error_name):
enable, disable = self.check_cc("-Werror=", "-Wno-error=", error_name)
if enable:
self.conf.env.append_unique("CCFLAGS", [enable])

def disable_c_error(self, error_name):
enable, disable = self.check_cc("-Werror=", "-Wno-error=", error_name)
if disable:
self.conf.env.append_unique("CCFLAGS", [disable])

def enable_c_warning(self, warn_name):
enable, disable = self.check_cc("-W", "-Wno-", warn_name)
if enable:
self.conf.env.append_unique("CCFLAGS", [enable])

def disable_c_warning(self, warn_name):
enable, disable = self.check_cc("-W", "-Wno-", warn_name)
if disable:
self.conf.env.append_unique("CCFLAGS", [disable])

def enable_c_feature(self, feature_name):
enable, disable = self.check_cc("-f", "-fno-", feature_name)
if enable:
self.conf.env.append_unique("CCFLAGS", [enable])

def disable_c_feature(self, feature_name):
enable, disable = self.check_cc("-f", "-fno-", feature_name)
if disable:
self.conf.env.append_unique("CCFLAGS", [disable])

def enable_cxx_feature(self, feature_name):
enable, disable = self.check_cxx("-f", "-fno-", feature_name)
if enable:
self.conf.env.append_unique("CXXFLAGS", [enable])

def disable_cxx_feature(self, feature_name):
enable, disable = self.check_cxx("-f", "-fno-", feature_name)
if disable:
self.conf.env.append_unique("CXXFLAGS", [disable])

def enable_feature(self, feature_name):
self.enable_c_feature(feature_name)
self.enable_cxx_feature(feature_name)
42 changes: 21 additions & 21 deletions wscript
Expand Up @@ -17,6 +17,7 @@ import imp
sys.path.insert(0,os.getcwd())

from waftools import gittools
from waftools.compiler_flags import compiler_flags

import Options
import Utils
Expand Down Expand Up @@ -247,6 +248,7 @@ def _output_summary(enabled_plugins, disabled_plugins,
Utils.pprint('Normal', "Disabled:")
Utils.pprint('BLUE', ", ".join(sorted(disabled_plugins)))


def configure(conf):
if os.environ.has_key('PKG_CONFIG_PREFIX'):
prefix = os.environ['PKG_CONFIG_PREFIX']
Expand All @@ -265,7 +267,6 @@ def configure(conf):
conf.check_tool('gcc')
conf.check_tool('g++')


if Options.options.target_platform:
Options.platform = Options.options.target_platform

Expand All @@ -280,26 +281,25 @@ def configure(conf):
conf.check_message("uncommitted changes", "", bool(changed))
conf.env["VERSION"] = BASEVERSION + " (git commit: %s%s)" % (nam, dirty)

conf.env["CCFLAGS"] = Utils.to_list(conf.env["CCFLAGS"]) + ['-g', '-O0']
for name in ('all',
'no-format-extra-args',
'no-format-zero-length',
'format-nonliteral',
'format-security',
'format=2',
"missing-prototypes",
"strict-prototypes",
"empty-body",
"ignored-qualifiers",
"type-limits",
"write-strings"):
warnflag = "-W%s" % name
if conf.check_cc(cflags=warnflag):
conf.env["CCFLAGS"].append(warnflag)
# autogenerate uselib definitions to disable warnings
conf.env["CCFLAGS_NO%s" % name.replace("-","").upper()] = ["-Wno-%s" % name]

conf.env["CXXFLAGS"] = Utils.to_list(conf.env["CXXFLAGS"]) + ['-g', '-O0']
conf.env.append_unique("CCFLAGS", ["-g", "-O0"])
conf.env.append_unique("CXXFLAGS", ["-g", "-O0"])

flags = compiler_flags(conf)

flags.enable_c_warning('all')
flags.enable_c_warning('empty-body')
flags.enable_c_warning('format=2')
flags.enable_c_warning('format-nonliteral')
flags.enable_c_warning('format-security')
flags.enable_c_warning('ignored-qualifiers')
flags.enable_c_warning('missing-prototypes')
flags.enable_c_warning('strict-prototypes')
flags.enable_c_warning('type-limits')
flags.enable_c_warning('write-strings')

flags.disable_c_warning('format-extra-args')
flags.disable_c_warning('format-zero-length')

conf.env['XMMS_PKGCONF_FILES'] = []
conf.env['XMMS_OUTPUT_PLUGINS'] = [(-1, "NONE")]

Expand Down

0 comments on commit 1cd38a5

Please sign in to comment.