-
Notifications
You must be signed in to change notification settings - Fork 689
Expand file tree
/
Copy pathcreate_examples.py
More file actions
executable file
·90 lines (69 loc) · 2.14 KB
/
create_examples.py
File metadata and controls
executable file
·90 lines (69 loc) · 2.14 KB
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
#!/usr/bin/env python3
#
# Create project files for all BTstack embedded examples in WICED/apps/btstack
import os
import re
import shutil
import subprocess
import sys
# build all template
build_all = '''
SUBDIRS = \\
%s
all:
\techo Building all examples
\tfor dir in $(SUBDIRS); do \\
\t$(MAKE) -C $$dir || exit 1; \\
\tdone
clean:
\techo Cleaning all ports
\tfor dir in $(SUBDIRS); do \\
\t$(MAKE) -C $$dir clean; \\
\tdone
'''
# get script path
script_path = os.path.abspath(os.path.dirname(sys.argv[0])) + '/../'
# get btstack root
btstack_root = script_path + '../../'
# path to examples
examples_embedded = btstack_root + 'example/'
# path to generated example projects
projects_path = script_path + "example/"
# path to template
template_path = script_path + 'template/Makefile'
print("Creating example projects:")
# iterate over btstack examples
example_files = os.listdir(examples_embedded)
examples = []
for file in example_files:
if not file.endswith(".c"):
continue
if file in ['panu_demo.c', 'sco_demo_util.c', 'ant_test.c']:
continue
example = file[:-2]
examples.append(example)
# create folder
project_folder = projects_path + example + "/"
if not os.path.exists(project_folder):
os.makedirs(project_folder)
# check if .gatt file is present
gatt_path = examples_embedded + example + ".gatt"
gatt_h = ""
if os.path.exists(gatt_path):
gatt_h = example+'.h'
# create makefile
with open(project_folder + 'Makefile', 'wt') as fout:
with open(template_path, 'rt') as fin:
for line in fin:
if 'PROJECT=spp_and_le_streamer' in line:
fout.write('PROJECT=%s\n' % example)
continue
if 'all: spp_and_le_streamer.h' in line:
if len(gatt_h):
fout.write("all: %s\n" % gatt_h)
continue
fout.write(line)
print("- %s" % example)
with open(projects_path+'Makefile', 'wt') as fout:
fout.write(build_all % ' \\\n'.join(examples))
print("Projects are ready for compile in example folder. See README for details.")