xref: /btstack/port/max32630-fthr/scripts/create_examples.py (revision 8613e0eb5b9621b90c6c50e3d739bfa544af1c63)
1#!/usr/bin/env python
2#
3# Create project files for all BTstack embedded examples in WICED/apps/btstack
4
5import os
6import re
7import shutil
8import subprocess
9import sys
10
11# build all template
12build_all = '''
13SUBDIRS =  \\
14%s
15
16all:
17\techo Building all examples
18\tfor dir in $(SUBDIRS); do \\
19\t$(MAKE) -C $$dir || exit 1; \\
20\tdone
21
22clean:
23\techo Cleaning all ports
24\tfor dir in $(SUBDIRS); do \\
25\t$(MAKE) -C $$dir clean; \\
26\tdone
27'''
28
29# get script path
30script_path = os.path.abspath(os.path.dirname(sys.argv[0])) + '/../'
31
32# get btstack root
33btstack_root = script_path + '../../'
34
35## pick correct init script based on your hardware
36# - init script for CC2564B
37cc256x_init_script = 'bluetooth_init_cc2564B_1.8_BT_Spec_4.1.c'
38
39subprocess.call("make -f ../Makefile -C src " + cc256x_init_script, shell=True)
40
41# fetch init script
42# print("Creating init script %s" % cc256x_init_script)
43# make_template = 'make -f {BTSTACK_ROOT}chipset/cc256x/Makefile.inc -C {SCRIPT_PATH}src/ {INIT_SCRIPT} BTSTACK_ROOT={BTSTACK_ROOT}'
44# make_command = make_template.format(BTSTACK_ROOT=btstack_root, SCRIPT_PATH=script_path, INIT_SCRIPT=cc256x_init_script)
45# print(make_command)
46# subprocess.call(make_command)
47
48# path to examples
49examples_embedded = btstack_root + 'example/'
50
51# path to generated example projects
52projects_path = script_path + "example/"
53
54# path to template
55template_path = script_path + 'example/template/Makefile'
56
57print("Creating example projects:")
58
59# iterate over btstack examples
60example_files = os.listdir(examples_embedded)
61
62examples = []
63
64for file in example_files:
65    if not file.endswith(".c"):
66        continue
67    if file in ['panu_demo.c', 'sco_demo_util.c', 'ant_test.c']:
68        continue
69    example = file[:-2]
70    examples.append(example)
71
72    # create folder
73    project_folder = projects_path + example + "/"
74    if not os.path.exists(project_folder):
75        os.makedirs(project_folder)
76
77    # check if .gatt file is present
78    gatt_path = examples_embedded + example + ".gatt"
79    gatt_h = ""
80    if os.path.exists(gatt_path):
81        gatt_h = example+'.h'
82
83    # create makefile
84    with open(project_folder + 'Makefile', 'wt') as fout:
85        with open(template_path, 'rt') as fin:
86            for line in fin:
87                if 'PROJECT=spp_and_le_streamer' in line:
88                    fout.write('PROJECT=%s\n' % example)
89                    continue
90                if 'all: spp_and_le_streamer.h' in line:
91                    if len(gatt_h):
92                        fout.write("all: %s\n" % gatt_h)
93                    continue
94                fout.write(line)
95
96    print("- %s" % example)
97
98with open(projects_path+'Makefile', 'wt') as fout:
99    fout.write(build_all % ' \\\n'.join(examples))
100
101print("Projects are ready for compile in example folder. See README for details.")
102