2 # Script to install (if they do not exist) the Arduino library, Time library,
3 # Red Bear Library, and Nordic library.
6 import os, subprocess, struct
7 import urllib2, urlparse
13 target_os = env.get('TARGET_OS')
14 src_dir = env.get('SRC_DIR')
16 SConscript(src_dir + '/build_common/tools/UnpackAll.py')
17 SConscript(src_dir + '/build_common/external_libs.scons')
20 if target_os == 'arduino':
21 arduino_home = env.get('ARDUINO_HOME')
23 print 'Creating ARDUINO_HOME for Arduino lib'
25 *******************************************************************************
26 * Arduino root directory isn't set, you can set enviornment variable *
27 * ARDUINO_HOME or add it in command line as follows (Only set if your *
28 * version has fixes applied as depicted below. Press ctrl+c now if you *
29 * wish to manually set ARDUINO_HOME.): *
30 * # scons ARDUINO_HOME=<path to arduino root directory> ... *
31 *******************************************************************************
33 arduinolib_dir = src_dir + '/extlibs/arduino/arduino-1.5.8'
35 if not os.path.exists(arduinolib_dir):
36 from sys import platform as _platform
37 if _platform == "linux" or _platform == "linux2":
38 archType = 8 * struct.calcsize("P")
39 print 'On %s-bit machine.' % (archType)
41 arduinolib_zip_file = src_dir + '/extlibs/arduino/arduino-1.5.8-linux32.tgz'
42 arduinolib_url = 'http://arduino.cc/download.php?f=/arduino-1.5.8-linux32.tgz'
44 arduinolib_zip_file = src_dir + '/extlibs/arduino/arduino-1.5.8-linux64.tgz'
45 arduinolib_url = 'http://arduino.cc/download.php?f=/arduino-1.5.8-linux64.tgz'
46 elif _platform == "darwin":
47 arduinolib_zip_file = src_dir + '/extlibs/arduino/arduino-1.5.8-macosx.zip'
48 arduinolib_url = 'http://arduino.cc/download.php?f=/arduino-1.5.8-macosx.zip'
49 elif _platform == "win32":
50 arduinolib_zip_file = src_dir + '/extlibs/arduino/arduino-1.5.8-windows.zip'
51 arduinolib_url = src_dir + 'http://arduino.cc/download.php?f=/arduino-1.5.8-windows.zip'
53 # If the zip file is not already present, download it
54 if not os.path.exists(arduinolib_zip_file):
55 arduinolib_zip = env.Download(arduinolib_zip_file, arduinolib_url)
57 arduinolib_zip = arduinolib_zip_file
60 print 'Unzipping arduino lib...'
61 env.UnpackAll(arduinolib_dir, arduinolib_zip)
62 print 'Unzipping arduino lib complete'
64 # Remove downloaded file
65 os.remove(arduinolib_zip_file)
67 arduinolib_dir = env.get('ARDUINO_HOME')
69 timelib_dir = arduinolib_dir + '/libraries/Time'
71 if not os.path.exists(timelib_dir):
72 if WhereIs('dos2unix') is not None:
73 timelib_zip_file = src_dir + '/extlibs/arduino/Time.zip'
74 timelib_url = 'http://playground.arduino.cc/uploads/Code/Time.zip'
75 # Install Arduino Time library
76 # If the zip file is not already present, download it
79 if not os.path.exists(timelib_zip_file):
80 timelib_zip = env.Download(timelib_zip_file, timelib_url)
82 timelib_zip = timelib_zip_file
85 print 'Unzipping Arduino Time lib...'
86 env.UnpackAll(timelib_dir + '/Time', timelib_zip)
88 # Apply patches to ARDUINO_HOME directory.
89 os.chdir(arduinolib_dir)
90 print 'Patching Arduino libraries...'
92 os.system("find ./libraries/Time/Time/DateStrings.cpp -type f -exec dos2unix {} \;")
93 os.system("patch -p1 < " + src_dir + "/resource/csdk/connectivity/lib/arduino/arduino_libraries.patch --directory=" + arduinolib_dir)
95 # Remove downloaded file
96 os.remove(timelib_zip_file)
98 print 'Please manually install package dos2unix. The build process will end now. Your Action Required: Install package manually, then restart build process.'
99 print 'You may likely retrieve this package as follows:'
100 print ' sudo apt-get install dos2unix'
102 print ' sudo yum install dos2unix'
105 redbearlib_dir = arduinolib_dir + '/libraries/RBL_nRF8001'
107 if not os.path.exists(redbearlib_dir):
108 if WhereIs('dos2unix') is not None:
109 redbearlib_zip_file = src_dir + '/extlibs/arduino/25643e7b1b7da3740406325a471e3faa4b948747.zip'
110 redbearlib_url = 'https://github.com/RedBearLab/nRF8001/archive/25643e7b1b7da3740406325a471e3faa4b948747.zip'
111 if not os.path.exists(redbearlib_zip_file):
112 redbearlib_zip = env.Download(redbearlib_zip_file, redbearlib_url)
114 redbearlib_zip = redbearlib_zip_file
117 print 'Unzipping Red Bear lib...'
118 os.chdir(arduinolib_dir + '/libraries')
119 env.UnpackAll(redbearlib_dir, redbearlib_zip)
121 # Because the way Red Bear lib is distributed... All Red Bear source files must be moved up a few directories.
122 shutil.move('nRF8001-25643e7b1b7da3740406325a471e3faa4b948747/Arduino/libraries/RBL_nRF8001/', '.')
123 shutil.rmtree('nRF8001-25643e7b1b7da3740406325a471e3faa4b948747')
125 # Apply Red Bear patches
126 print 'Patching Red Bear library...'
127 os.chdir(arduinolib_dir + '/libraries/RBL_nRF8001/')
129 os.system("find . -type f -exec dos2unix {} \;")
130 os.system("patch -p1 < " + src_dir + "/resource/csdk/connectivity/lib/arduino/RBL_nRF8001.patch")
132 # Remove downloaded file
133 os.remove(redbearlib_zip_file)
135 print 'Please manually install package dos2unix. The build process will end now. Your Action Required: Install package manually, then restart build process.'
136 print 'You may likely retrieve this package as follows:'
137 print ' sudo apt-get install dos2unix'
139 print ' sudo yum install dos2unix'
142 nordiclib_dir = arduinolib_dir + '/libraries/BLE'
144 if not os.path.exists(nordiclib_dir):
145 if WhereIs('dos2unix') is not None:
146 nordiclib_zip_file = src_dir + '/extlibs/arduino/ble-sdk-arduino-0.9.5.beta.zip'
147 nordiclib_url = 'https://github.com/NordicSemiconductor/ble-sdk-arduino/archive/0.9.5.beta.zip'
148 if not os.path.exists(nordiclib_zip_file):
149 nordiclib_zip = env.Download(nordiclib_zip_file, nordiclib_url)
151 nordiclib_zip = nordiclib_zip_file
154 print 'Unzipping Nordic lib...'
155 os.chdir(arduinolib_dir + '/libraries')
156 env.UnpackAll(nordiclib_dir, nordiclib_zip)
158 # Because the way Nordic lib is distributed... All Nordic source files must be moved up a few directories.
159 shutil.move('ble-sdk-arduino-0.9.5.beta/libraries/BLE/', '.')
160 shutil.rmtree('ble-sdk-arduino-0.9.5.beta')
162 # Apply Nordic lib patches
163 print 'Patching Nordic library...'
164 os.chdir(arduinolib_dir + '/libraries/BLE/')
166 os.system("find . -type f -exec dos2unix {} \;")
167 os.system("patch -p1 < " + src_dir + "/resource/csdk/connectivity/lib/arduino/arduino_due_ble.patch")
169 # Remove downloaded file
170 os.remove(nordiclib_zip_file)
172 print 'Please manually install package dos2unix. The build process will end now. Your Action Required: Install package manually, then restart build process.'
173 print 'You may likely retrieve this package as follows:'
174 print ' sudo apt-get install dos2unix'
176 print ' sudo yum install dos2unix'
179 # Set the ARDUINO_HOME
180 env.Replace(ARDUINO_HOME = arduinolib_dir)
181 print 'ARDUINO_HOME = ' + env.get('ARDUINO_HOME')