Skip to content

Commit

Permalink
Adapted SConscript to allow for OpenWRT cross-compilation (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
ereOn committed Apr 19, 2015
1 parent 11af1db commit cb80ca9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
2 changes: 1 addition & 1 deletion BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ To build everything in the directory (including samples), type instead:
To build then install everything into a specific directory, type instead:

> scons install --prefix=/usr/local/
> scons install prefix=/usr/local/
### Debugging

Expand Down
69 changes: 38 additions & 31 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ from fnmatch import fnmatch
# This file is local.
from defines import Defines


AddOption(
'--prefix',
dest='prefix',
default='./install',
type='string',
nargs=1,
action='store',
metavar='DIR',
help='The installation prefix.',
)

AddOption(
'--mode',
dest='mode',
Expand All @@ -49,29 +37,52 @@ class FreelanEnvironment(Environment):
"""
super(FreelanEnvironment, self).__init__(**kwargs)

# Inherit the environment from the context.
self['ENV'] = os.environ

self.defines = Defines()
self.defines.register_into(self)

for flag in [
'CXX',
'CC',
'CXX',
'AR',
'LINK',
]:
if flag in os.environ:
self[flag] = os.environ[flag]

for flag in [
'CFLAGS',
'CXXFLAGS',
'CCFLAGS',
'CPPFLAGS',
'ARFLAGS',
'LDFLAGS',
'LINKFLAGS',
'LIBS',
]:
if flag in os.environ:
self[flag] = Split(os.environ[flag])

#TODO: Remove these lines
print '#####################'
print '\n'.join("%s: %s" % x for x in os.environ.iteritems())
print '#####################'

self.mode = mode
self.prefix = prefix
self.destdir = self['ENV'].get('DESTDIR', '')

if self.destdir:
self.install_prefix = os.path.normpath(
os.path.abspath(self.destdir),
) + self.prefix
else:
self.install_prefix = self.prefix

print self.prefix
print self.destdir
print self.install_prefix

if os.path.basename(self['CXX']) == 'clang++':
self.Append(CXXFLAGS=['-Qunused-arguments'])
Expand All @@ -87,21 +98,17 @@ class FreelanEnvironment(Environment):
self.Append(CXXFLAGS=['-Wshadow'])
self.Append(LDFLAGS=['--std=c++11'])

if 'OPENWRT_BUILD' in os.environ:
self['ENV'] = os.environ
self.arch = os.environ['ARCH']
if sys.platform.startswith('darwin'):
self.Append(CXXFLAGS=['-arch', 'x86_64'])
self.Append(CXXFLAGS=['-DBOOST_ASIO_DISABLE_KQUEUE'])
self.Append(CXXFLAGS=['--stdlib=libc++'])
self.Append(LDFLAGS=['--stdlib=libc++'])

if self.mode == 'debug':
self.Append(CXXFLAGS=['-g'])
self.Append(CXXFLAGS='-DFREELAN_DEBUG=1')
else:
if sys.platform.startswith('darwin'):
self.Append(CXXFLAGS=['-arch', 'x86_64'])
self.Append(CXXFLAGS=['-DBOOST_ASIO_DISABLE_KQUEUE'])
self.Append(CXXFLAGS=['--stdlib=libc++'])
self.Append(LDFLAGS=['--stdlib=libc++'])

if self.mode == 'debug':
self.Append(CXXFLAGS=['-g'])
self.Append(CXXFLAGS='-DFREELAN_DEBUG=1')
else:
self.Append(CXXFLAGS='-O3')
self.Append(CXXFLAGS='-O3')

self.Append(CPPDEFINES=r'FREELAN_INSTALL_PREFIX="\"%s\""' % self.prefix)

Expand Down Expand Up @@ -147,13 +154,13 @@ class FreelanEnvironment(Environment):


mode = GetOption('mode')
prefix = os.path.abspath(GetOption('prefix'))
prefix = os.path.normpath(os.path.abspath(ARGUMENTS.get('prefix', './install')))

if mode in ('all', 'release'):
env = FreelanEnvironment(mode='release', prefix=prefix)
libraries, includes, apps, samples, configurations = SConscript('SConscript', exports='env', variant_dir=os.path.join('build', env.mode))
install = env.Install(os.path.join(prefix, 'bin'), apps)
install.extend(env.Install(os.path.join(prefix, 'etc', 'freelan'), configurations))
install = env.Install(os.path.join(env.install_prefix, 'bin'), apps)
install.extend(env.Install(os.path.join(env.install_prefix, 'etc', 'freelan'), configurations))

Alias('install', install)
Alias('apps', apps)
Expand Down
2 changes: 1 addition & 1 deletion apps/freelan/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ elif sys.platform.startswith('darwin'):
])

env = env.Clone()
env.Append(LIBS=libraries)
env.Prepend(LIBS=libraries)

sources = list(sorted(set(env.RGlob('src', '*.cpp')) - set(env.RGlob(os.path.join('src', 'windows'), '*.cpp'))))
app = env.Program(target=os.path.join(str(dirs['bin']), name), source=sources)
Expand Down

0 comments on commit cb80ca9

Please sign in to comment.