-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmake_libraries.py
138 lines (110 loc) · 4.91 KB
/
make_libraries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
import sys
import os
# this function reads the library.properties file
def get_library_properties():
properties = {}
with open('library.properties') as f:
for line in f:
if '=' in line:
key, value = line.split('=', 1)
properties[key] = value.strip()
return properties
properties = get_library_properties()
name = properties['name'].split(' ')[0].lower()
name += '_library-' + properties['version']
name_lib2 = properties['name'].split(' ')[0].lower()
name_lib2 += '_lib'
if len(name) < 3:
print('Error, library name is not present or is too short in library.properties')
sys.exit(1)
print(f'This script will build an Arduino library file called ../{name}.zip')
print(f'and a library for CMake projects called ../{name_lib2}.zip')
print('If this is incorrect, you should abort and check your library.properties file')
response = input('Do you wish to proceed? [y/n]: ')
if response != 'y':
print('Aborted.')
sys.exit(1)
print(f'creating folder ../{name}')
if os.path.exists('../' + name):
os.system('rm -rf ../' + name)
os.makedirs('../' + name)
print(f'creating folder ../{name}/src')
if os.path.exists('../' + name + '/src'):
os.system('rm -rf ../' + name + '/src')
os.makedirs('../' + name + '/src')
print(f'creating folder ../{name}/examples')
if os.path.exists('../' + name + '/examples'):
os.system('rm -rf ../' + name + '/examples')
os.makedirs('../' + name + '/examples')
print('copying library.properties..')
os.system('cp -r library.properties ../' + name)
print('copying src folder contents..')
os.system('cp -r src/* ../' + name + '/src')
print('copying examples folder contents..')
os.system('cp -r examples/* ../' + name + '/examples')
print('removing StarmapLinuxTest folder since it is not required for Arduino..')
if os.path.exists('../' + name + '/examples/StarmapLinuxTest'):
os.system('rm -rf ../' + name + '/examples/StarmapLinuxTest')
print('removing any main.cpp and CMakeLists.txt file..')
if os.path.exists('../' + name + '/src/main.cpp'):
os.system('rm ../' + name + '/src/main.cpp')
if os.path.exists('../' + name + '/src/CMakeLists.txt'):
os.system('rm ../' + name + '/src/CMakeLists.txt')
print('removing any CMakeLists.txt_lib2 file..')
if os.path.exists('../' + name + '/src/CMakeLists.txt_lib2'):
os.system('rm ../' + name + '/src/CMakeLists.txt_lib2')
print('removing any dummy Arduino .cpp/.h file..')
if os.path.exists('../' + name + '/src/Arduino.h'):
os.system('rm ../' + name + '/src/Arduino.h')
if os.path.exists('../' + name + '/src/Arduino.cpp'):
os.system('rm ../' + name + '/src/Arduino.cpp')
print('removing any build folder..')
if os.path.exists('../' + name + '/src/build'):
os.system('rm -rf ../' + name + '/src/build')
print('removing any existing zip file of the target name..')
if os.path.exists('../' + name + '.zip'):
os.system('rm ../' + name + '.zip')
print('creating zip file..')
os.system('cd ../ && zip -r ' + name + '.zip ' + name)
# library for use with Pico C SDK
print(f'creating folder ../{name_lib2}')
if os.path.exists('../' + name_lib2):
os.system('rm -rf ../' + name_lib2)
os.makedirs('../' + name_lib2)
print('copying files into the folder..')
os.system('cp -r src/* ../' + name_lib2)
if os.path.exists('examples/StarmapLinuxTest/CMakeLists.txt_lib2'):
os.system('cp examples/StarmapLinuxTest/CMakeLists.txt_lib2 ../' + name_lib2)
print('removing any main.cpp and CMakeLists.txt file..')
if os.path.exists('../' + name_lib2 + '/main.cpp'):
os.system('rm ../' + name_lib2 + '/main.cpp')
if os.path.exists('../' + name_lib2 + '/CMakeLists.txt'):
os.system('rm ../' + name_lib2 + '/CMakeLists.txt')
print('renaming CMakeLists.txt_lib2 to CMakeLists.txt')
if os.path.exists('../' + name_lib2 + '/CMakeLists.txt_lib2'):
os.system('mv ../' + name_lib2 + '/CMakeLists.txt_lib2 ../' + name_lib2 + '/CMakeLists.txt')
print('removing any dummy Arduino .cpp file..')
if os.path.exists('../' + name_lib2 + '/Arduino.cpp'):
os.system('rm ../' + name_lib2 + '/Arduino.cpp')
print('removing any build folder..')
if os.path.exists('../' + name_lib2 + '/build'):
os.system('rm -rf ../' + name_lib2 + '/build')
print('removing any existing zip file of the target name..')
if os.path.exists('../' + name_lib2 + '.zip'):
os.system('rm ../' + name_lib2 + '.zip')
print('creating zip file..')
os.system('cd ../ && zip -r ' + name_lib2 + '.zip ' + name_lib2)
print('Done!')
print(' ')
print(f'**** CMake projects zip file: {name_lib2}.zip *****')
print('Place the extracted folder as a sub-folder into your project')
print('Then, add the following into the top-level CMakeLists.txt file:')
print(f'add_subdirectory({name_lib2})')
print(f'include_directories(./{name_lib2})')
print(f'Add the following into target_link_libraries: {name_lib2}')
print(' ')
print(f'**** Arduino library zip file: {name}.zip *****')
print('Using the Arduino IDE, click on')
print(' Sketch->Include Library->Add .ZIP file')
print(' ')