Skip to content

Commit

Permalink
Build script changes / fixes.
Browse files Browse the repository at this point in the history
- Fix build on 64bit machines using GCC.
- Add clang tool to silently use clang compiler when present.
- Closes #7
  • Loading branch information
Jamie Kirkpatrick committed Aug 30, 2010
1 parent 8857990 commit 0282472
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 16 deletions.
54 changes: 54 additions & 0 deletions build/clang.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#############################################################################
## Copyright (c) 2009-2010 Alan Wright. All rights reserved.
## Distributable under the terms of either the Apache License (Version 2.0)
## or the GNU Lesser General Public License.
#############################################################################

from TaskGen import feature
import Options
import sys


@feature('cc')
def apply_clang(self):
'''
Replaced the default compiler with clang if required.
'''
if not getattr(self, 'clang', True) or Options.options.disable_clang:
return
self.env['CC'] = self.env['CLANG'] or self.env['CC']
if sys.platform == "darwin":
# workaround problems with non-static inline functions
# http://clang.llvm.org/compatibility.html
self.env['CCFLAGS'] += ['-std=gnu89']


@feature('cc')
def apply_clang_cpp(self):
'''
Replaced the default compiler with clang if required.
'''
if not getattr(self, 'clang', True) or Options.options.disable_clang:
return
self.env['CPP'] = self.env['CLANGPP'] or self.env['CXX']
self.env['CXX'] = self.env['CLANGPP'] or self.env['CXX']
if sys.platform == "darwin":
self.env['shlib_CXXFLAGS'] = ['-fPIC']


def set_options(opt):
"""
Add options specific the codehash tool
"""
opt.add_option('--noclang',
dest = 'disable_clang',
action = 'store_true',
default = False,
help = 'disable the clang compiler if it is available')


def detect(conf):
search_paths = ['/Xcode4/usr/bin/'] if sys.platform == "darwin" else []
conf.find_program('clang', var='CLANG')
conf.find_program('clang++', var='CLANGPP', path_list = search_paths)

63 changes: 63 additions & 0 deletions build/gch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#############################################################################
## Copyright (c) 2009-2010 Alan Wright. All rights reserved.
## Distributable under the terms of either the Apache License (Version 2.0)
## or the GNU Lesser General Public License.
#############################################################################

from TaskGen import feature, after
from copy import copy
import Task, ccroot
import os

cmd = '${CXX} ${CXXFLAGS} ${_CXXINCFLAGS} ${_CXXDEFFLAGS} ${SRC} -o ${TGT}'
cls = Task.simple_task_type('gch', cmd, before='cc cxx', shell = False)
cls.scan = ccroot.scan


def requires_pch(task, pch_name):
"""
Determines if a task requires a PCH prefix header
Assume that missing source files equate to "generated" sources
and will require a PCH header.
"""
def is_include_line(line):
line = line.strip()
return line.startswith("#include") or line.startswith("#import")
generated_sources = False
for source_file in task.inputs:
if not os.path.isfile(source_file.abspath()):
generated_sources = True
continue
source_path = source_file.abspath()
if source_file.suffix() not in ["cpp", "c"]:
continue
for line in open(source_path):
if is_include_line(line):
return line.find(pch_name)
return generated_sources


@feature('cxx')
@after('apply_link', 'apply_incpaths')
def process_pch(self):
"""
Routine to add PCH generation if a pch header was specified
for a target.
"""
if not getattr(self, 'pch', None):
return
node = self.path.find_resource(self.pch)
if not node:
print "Invalid PCH specified for %s" % self
return
output = node.parent.find_or_declare(node.name + '.gch')
pch_task = self.create_task('gch')
pch_task.set_inputs(node)
pch_task.set_outputs(output)
altered_envs = []
for task in self.compiled_tasks:
if not requires_pch(task, self.pch):
continue
task.env = task.env.copy()
task.env.append_unique("CXXFLAGS", "-include%s"
% output.abspath(self.env).replace(".gch", ""))
35 changes: 19 additions & 16 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ tester_include_dirs = [
def set_options(opt):
opt.tool_options("boost")
opt.tool_options('compiler_cxx')

opt.tool_options('clang', tooldir = 'build')
opt.add_option(
'--debug',
default = False,
Expand All @@ -92,18 +92,21 @@ def configure(conf):
conf.check_tool('gcc')
conf.check_cc(lib = 'pthread', mandatory = True)
conf.check_tool('boost')
conf.check_tool('clang', 'build')
conf.check_boost(
static = 'onlystatic',
lib = ['filesystem', 'thread', 'regex', 'system', 'date_time', 'iostreams', 'unit_test_framework']
)


def build(bld):

target_type = 'cstaticlib' if Options.options.static else 'cshlib'
compile_flags = ['-O0', '-g'] if Options.options.debug else ['-O2']
debug_define = '_DEBUG' if Options.options.debug else 'NDEBUG'

link_flags = ['-m32']
if Options.options.debug:
compile_flags = ['-O0', '-g', '-m32']
else:
compile_flags = ['-O2', '-m32']
debug_define = '_DEBUG' if Options.options.debug else 'NDEBUG'
lucene_sources = []
for source_dir in lucene_source_dirs:
for source_file in bld.path.ant_glob(source_dir + '/*.c*').split():
Expand All @@ -119,9 +122,10 @@ def build(bld):
includes = lucene_include_dirs + [bld.env["CPPPATH_BOOST"]],
ccflags = compile_flags,
cxxflags = compile_flags,
linkflags = link_flags,
defines = ['LPP_BUILDING_LIB', 'LPP_HAVE_GXXCLASSVISIBILITY'] + [debug_define],
uselib = 'BOOST_FILESYSTEM BOOST_THREAD BOOST_REGEX BOOST_SYSTEM BOOST_DATE_TIME BOOST_IOSTREAMS',
lib = 'pthread'
uselib = 'BOOST_FILESYSTEM BOOST_THREAD BOOST_REGEX BOOST_SYSTEM BOOST_DATE_TIME BOOST_IOSTREAM PTHREAD',

)

tester_sources = []
Expand All @@ -138,10 +142,10 @@ def build(bld):
includes = tester_include_dirs + [bld.env["CPPPATH_BOOST"]],
ccflags = compile_flags,
cxxflags = compile_flags,
linkflags = link_flags,
defines = ['LPP_HAVE_GXXCLASSVISIBILITY'] + [debug_define],
uselib = 'BOOST_FILESYSTEM BOOST_THREAD BOOST_REGEX BOOST_SYSTEM BOOST_DATE_TIME BOOST_IOSTREAMS BOOST_UNIT_TEST_FRAMEWORK',
uselib = 'BOOST_FILESYSTEM BOOST_THREAD BOOST_REGEX BOOST_SYSTEM BOOST_DATE_TIME BOOST_IOSTREAMS BOOST_UNIT_TEST_FRAMEWORK PTHREAD',
uselib_local = 'lucene++',
lib = 'pthread'
)

bld(
Expand All @@ -153,9 +157,8 @@ def build(bld):
ccflags = compile_flags,
cxxflags = compile_flags,
defines = ['LPP_HAVE_GXXCLASSVISIBILITY'] + [debug_define],
uselib = 'BOOST_FILESYSTEM BOOST_THREAD BOOST_REGEX BOOST_SYSTEM BOOST_DATE_TIME BOOST_IOSTREAMS',
uselib = 'BOOST_FILESYSTEM BOOST_THREAD BOOST_REGEX BOOST_SYSTEM BOOST_DATE_TIME BOOST_IOSTREAMS PTHREAD',
uselib_local = 'lucene++',
lib = 'pthread'
)

bld(
Expand All @@ -166,10 +169,10 @@ def build(bld):
includes = ['include'] + [bld.env["CPPPATH_BOOST"]],
ccflags = compile_flags,
cxxflags = compile_flags,
linkflags = link_flags,
defines = ['LPP_HAVE_GXXCLASSVISIBILITY'] + [debug_define],
uselib = 'BOOST_FILESYSTEM BOOST_THREAD BOOST_REGEX BOOST_SYSTEM BOOST_DATE_TIME BOOST_IOSTREAMS',
uselib = 'BOOST_FILESYSTEM BOOST_THREAD BOOST_REGEX BOOST_SYSTEM BOOST_DATE_TIME BOOST_IOSTREAMS PTHREAD',
uselib_local = 'lucene++',
lib = 'pthread'
)

bld(
Expand All @@ -180,9 +183,9 @@ def build(bld):
includes = ['include'] + [bld.env["CPPPATH_BOOST"]],
ccflags = compile_flags,
cxxflags = compile_flags,
linkflags = link_flags,
defines = ['LPP_HAVE_GXXCLASSVISIBILITY'] + [debug_define],
uselib = 'BOOST_FILESYSTEM BOOST_THREAD BOOST_REGEX BOOST_SYSTEM BOOST_DATE_TIME BOOST_IOSTREAMS',
uselib_local = 'lucene++',
lib = 'pthread'
uselib = 'BOOST_FILESYSTEM BOOST_THREAD BOOST_REGEX BOOST_SYSTEM BOOST_DATE_TIME BOOST_IOSTREAMS PTHREAD',
uselib_local = 'lucene++'
)

0 comments on commit 0282472

Please sign in to comment.