Skip to content
43 changes: 39 additions & 4 deletions Build/Boot.scons
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import os
import platform
import re

EnsureSConsVersion(0,98,1)

Expand All @@ -16,7 +17,8 @@ PLATFORM_TO_TARGET_MAP = {
'linux2' : 'x86-unknown-linux',
'win32' : 'x86-microsoft-win32',
'cygwin' : 'x86-unknown-cygwin',
'darwin' : 'universal-apple-macosx'
'darwin' : 'universal-apple-macosx',
'raspberry-pi-arm' : 'arm-raspberry-pi-linux'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could you align the : please?

}

# list all target dirs
Expand All @@ -25,17 +27,50 @@ targets_dir = scons_root+'/Build/Targets'
targets_dirs = os.listdir(targets_dir)
TARGET_PLATFORMS = [x for x in targets_dirs if os.path.exists(targets_dir +'/'+x+'/Config.scons')]

def pi_version():
"""Detect the version of the Raspberry Pi. Returns either 1, 2 or
None depending on if it's a Raspberry Pi 1 (model A, B, A+, B+),
Raspberry Pi 2 (model B+), or not a Raspberry Pi.
"""
# Check /proc/cpuinfo for the Hardware field value.
# 2708 is pi 1
# 2709 is pi 2
# 2835 is pi 3 on 4.9.x kernel
# Anything else is not a pi.
with open('/proc/cpuinfo', 'r') as infile:
cpuinfo = infile.read()
# Match a line like 'Hardware : BCM2709'
match = re.search('^Hardware\s+:\s+(\w+)$', cpuinfo,
flags=re.MULTILINE | re.IGNORECASE)
if not match:
# Couldn't find the hardware, assume it isn't a pi.
return None
if match.group(1) == 'BCM2708':
# Pi 1
return 1
elif match.group(1) == 'BCM2709':
# Pi 2
return 2
elif match.group(1) == 'BCM2835':
# Pi 3 / Pi on 4.9.x kernel
return 3
else:
# Something else, not a pi.
return None

def DefaultTarget():
platform_id = sys.platform
if platform.system() == 'Linux':
if (platform.machine() == 'i386' or
if pi_version() is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to hook into platform.machine().startswith('arm') last and differentiate between linux-arm and raspberry-pi-arm instead?
Alternatively, is there anyway to use linux-arm for raspberry?

platform_id = 'raspberry-pi-arm'
elif (platform.machine() == 'i386' or
platform.machine() == 'i486' or
platform.machine() == 'i586'or
platform.machine() == 'i686'):
platform_id = 'linux-i386'
if (platform.machine() == 'x86_64'):
elif (platform.machine() == 'x86_64'):
platform_id = 'linux-x86_64'
if (platform.machine().startswith('arm')):
elif (platform.machine().startswith('arm')):
platform_id = 'linux-arm'

if PLATFORM_TO_TARGET_MAP.has_key(platform_id):
Expand Down
41 changes: 41 additions & 0 deletions Build/Build.scons
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class LibraryModule(Module):

# the product is a library
self.env.AppendUnique(CPPPATH=cpp_path)
self.env.AppendUnique(CCFLAGS='-fPIC')
if shared is False:
self.product = self.env.Library(target=name, source=sources)
else:
Expand Down Expand Up @@ -145,6 +146,42 @@ def Application(name, dir, deps, install = False):
if env['build_config'] == 'Release' and env.has_key('STRIP'):
env.AddPostAction(inst, env['STRIP']+' $TARGETS');

def Swig(name, dir, deps):
DeclareBuildDir(dir)
cpp_path = GetIncludeDirs(deps)

inc = '-I' + ' -I'.join([env.GetBuildPath(x) for x in cpp_path])

def generator(source, target, env, for_signature):
return 'swig -python -py3 -threads -c++ {} -o {} {}'.format(inc, target[0], source[0])

bld = Builder(generator = generator)
env.Append(BUILDERS={'Swig' : bld})

return env.Swig([name + '_wrap.cxx', name + '_wrap.h', name + '.py'], GlobSources(dir, ['*.i']))

def PythonBinding(name, dir, deps):
swig_out = Swig(name, dir, deps)

DeclareBuildDir(dir)
cpp_path = GetIncludeDirs(deps) + [GetDirPath(dir)]
libs = GetLibraries(deps)

# the product is a library
env_ = env.Clone()
env_.AppendUnique(CPPPATH=cpp_path, LIBS=libs)
env_.ParseConfig('pkg-config python3 --cflags --libs')
product = env_.SharedLibrary(target=name,
source=GlobSources(dir, ['*.cxx']) + [swig_out[0]],
SHLIBSUFFIX='.so', SHLIBPREFIX='_')
env_.Alias(name, product)

# copy to Targets folder
inst = env.Install(dir=env.GetBuildPath('#/Targets/'+env['target']+'/'+env['build_config']), source=product)
if env['build_config'] == 'Release' and env.has_key('STRIP'):
env.AddPostAction(inst, env['STRIP']+' $TARGETS');

env.Install(dir=env.GetBuildPath('#/Targets/'+env['target']+'/'+env['build_config']), source=swig_out[2])
#######################################################
# Main Build
#######################################################
Expand Down Expand Up @@ -273,3 +310,7 @@ for tool in ['TextToHeader']:
dir = 'Source/Tools/' + tool,
deps = ['Platinum'],
install = True)

PythonBinding(name = 'media_renderer',
dir = 'binding/python',
deps = ['Platinum', 'PltMediaRenderer'])
7 changes: 7 additions & 0 deletions Build/Targets/arm-raspberry-pi-linux/Config.scons
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
LoadTool('gcc-generic', env, gcc_cross_prefix='')

### Neptune System Files
env['NPT_SYSTEM_SOURCES']={'System/StdC':'*.cpp', 'System/Bsd':'*.cpp', 'System/Posix':'*.cpp', 'System/Null':'NptNullAutoreleasePool.cpp'}
env['NPT_EXTRA_LIBS']=['pthread']

env['STRIP'] = ''
5 changes: 5 additions & 0 deletions Build/Targets/universal-apple-macosx/Config.scons
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LoadTool('gcc-generic', env)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentionally not supported because building iOS/macOS with Scons is unstable and unsupported at the moment.


### Neptune System Files
env['NPT_SYSTEM_SOURCES']={'System/StdC':'*.cpp', 'System/Bsd':'*.cpp', 'System/Posix':'*.cpp', 'System/Null':'NptNullAutoreleasePool.cpp NptNullSerialPort.cpp'}
env['NPT_EXTRA_LIBS']=['pthread']
5 changes: 5 additions & 0 deletions Build/Targets/x86_64-unknown-linux/Config.scons
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LoadTool('gcc-generic', env)

### Neptune System Files
env['NPT_SYSTEM_SOURCES']={'System/StdC':'*.cpp', 'System/Bsd':'*.cpp', 'System/Posix':'*.cpp', 'System/Null':'NptNullAutoreleasePool.cpp NptNullSerialPort.cpp'}
env['NPT_EXTRA_LIBS']=['pthread']
2 changes: 1 addition & 1 deletion Source/Apps/FrameStreamer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ main(int argc, char** argv)
return 1;

char buf[256];
while (gets(buf))
while (fgets(buf,256,stdin))
{
if (*buf == 'q')
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Apps/MediaConnect/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ main(int argc, char** argv)
return 1;

char buf[256];
while (gets(buf))
while (fgets(buf, 256, stdin))
{
if (*buf == 'q')
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Apps/MediaCrawler/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int main(void)
ctrlPoint->Discover(NPT_HttpUrl("255.255.255.255", 1900, "*"), "upnp:rootdevice", 1);

char buf[256];
while (gets(buf)) {
while (fgets(buf, 256, stdin)) {
if (*buf == 'q')
break;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Tests/FileMediaServer/FileMediaServerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ main(int /* argc */, char** argv)
NPT_LOG_INFO("Press 'q' to quit.");

char buf[256];
while (gets(buf)) {
while (fgets(buf, 256, stdin)) {
if (*buf == 'q')
break;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Tests/LightSample/LightSampleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ main(int /* argc */, char** /* argv */)
upnp.Start();

char buf[256];
while (gets(buf)) {
while (fgets(buf, 256, stdin)) {
if (*buf == 'q')
break;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Tests/MediaRenderer/MediaRendererTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ main(int /* argc */, char** argv)
upnp.Start();

char buf[256];
while (gets(buf)) {
while (fgets(buf, 256, stdin)) {
if (*buf == 'q')
break;

Expand Down
Loading