Merge "Broke out build script into variability.. Added support to build either in...
[platform/upstream/iotivity.git] / build_common / arduino / SConscript
1 ##
2 # This script includes arduino specific config
3 ##
4 import os
5 import platform
6
7 Import('env', 'RELEASE_BUILD', 'TARGET_CPU_ARCH', 'ARDUINO_HOME')
8
9 if not ARDUINO_HOME:
10         print '''
11 ************************************* Error ***********************************
12 *   Arduino root directory (ARDUINO_HOME) isn't set, you can set enviornment  *
13 * variable ARDUINO_HOME or add it in command line as:                         *
14 *      # scons ARDUINO_HOME=<path to arduino root directory> ...              *
15 *******************************************************************************
16 '''
17         Exit(1)
18
19 # Overwrite suffixes and prefixes
20 if env['HOST_OS'] == 'win32':
21         env['OBJSUFFIX'] = '.o'
22         env['SHOBJSUFFIX'] = '.os'
23         env['LIBPREFIX'] = 'lib'
24         env['LIBSUFFIX'] = '.a'
25         env['SHLIBPREFIX'] = 'lib'
26         env['SHLIBSUFFIX'] = '.so'
27         env['LIBPREFIXES'] = ['lib']
28         env['LIBSUFFIXES'] = ['.a', '.so']
29         env['PROGSUFFIX'] = ''
30 elif platform.system().lower() == 'darwin':
31         env['SHLIBSUFFIX'] = '.so'
32         env['LIBSUFFIXES'] = ['.a', '.so']
33         env['PROGSUFFIX'] = ''
34
35 # Set toolchain
36 def find_toolchain(dir, tc):
37         for root, dirs, files in os.walk(dir, True, None, False):
38                 for f in files:
39                         lf = f.lower()
40                         if lf == tc:
41                                 return root
42         return None
43
44 if TARGET_CPU_ARCH == 'arm':
45         prefix = 'arm-none-eabi-'
46 else:
47         prefix = 'avr-'
48
49 tc_path = find_toolchain(ARDUINO_HOME + '/hardware/tools/', prefix + 'g++')
50 if not tc_path:
51         print '''
52 ************************************* Error ***********************************
53 *   Arduino toolchain isn't detected. Please specify the toolchain prefix and *
54 * path, you can do it by setting enviornment variable TC_PREFIX and TC_PATH or*
55 * add it in command line as:                                                  *
56 *     # scons TC_PREFIX=<prefix> TC_PATH=<path to toolchain> ...              *
57 * e.g. scons TC_PREFIX=avr- TC_PATH=/opt/arduino-1.5.7/hardware/tools/avr/bin *                                                                         *
58 * Note: TC_PREFIX shouldn't include path                                      *
59 *******************************************************************************
60 '''
61         Exit(1)
62
63 env.PrependENVPath('PATH', tc_path)
64 env.Replace(CC = prefix + 'gcc')
65 env.Replace(CXX = prefix + 'g++')
66 env.Replace(AR = prefix + 'ar')
67 env.Replace(AS = prefix + 'as')
68 env.Replace(LINK = prefix + 'ld')
69 env.Replace(RANLIB = prefix + 'ranlib')
70
71 sys_root = os.path.abspath(os.path.join(tc_path, '..'))
72 env.AppendUnique(CFLAGS = ['--sysroot=' + sys_root])
73 env.AppendUnique(CXXFLAGS = ['--sysroot=' + sys_root])
74 env.AppendUnique(LINKFLAGS = ['--sysroot=' + sys_root])
75
76 # Debug/release relative flags
77 if RELEASE_BUILD:
78         env.AppendUnique(CFLAGS = ['-Os'])
79         env.AppendUnique(CXXFLAGS = ['-Os'])
80         env.AppendUnique(CPPDEFINES = ['NDEBUG'])
81         env.AppendUnique(LINKFLAGS = ['-s'])
82 else:
83         env.AppendUnique(CFLAGS = ['-g'])
84         env.AppendUnique(CXXFLAGS = ['-g'])