xref: /btstack/port/max32630-fthr/scripts/create_examples.py (revision 6b7adbe5dd4b0af3c7d33d07ce150d2f4a3a18e0)
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# get script path
12script_path = os.path.abspath(os.path.dirname(sys.argv[0])) + '/../'
13
14# get btstack root
15btstack_root = script_path + '../../'
16
17## pick correct init script based on your hardware
18# - init script for CC2564B
19cc256x_init_script = 'bluetooth_init_cc2564B_1.6_BT_Spec_4.1.c'
20
21subprocess.call("make -f ../Makefile -C src " + cc256x_init_script, shell=True)
22
23# fetch init script
24# print("Creating init script %s" % cc256x_init_script)
25# make_template = 'make -f {BTSTACK_ROOT}chipset/cc256x/Makefile.inc -C {SCRIPT_PATH}src/ {INIT_SCRIPT} BTSTACK_ROOT={BTSTACK_ROOT}'
26# make_command = make_template.format(BTSTACK_ROOT=btstack_root, SCRIPT_PATH=script_path, INIT_SCRIPT=cc256x_init_script)
27# print(make_command)
28# subprocess.call(make_command)
29
30# path to examples
31examples_embedded = btstack_root + 'example/'
32
33# path to generated example projects
34projects_path = script_path + "example/"
35
36# path to template
37template_path = script_path + 'example/template/Makefile'
38
39print("Creating example projects:")
40
41# iterate over btstack examples
42example_files = os.listdir(examples_embedded)
43
44for file in example_files:
45    if not file.endswith(".c"):
46        continue
47    example = file[:-2]
48
49    # create folder
50    project_folder = projects_path + example + "/"
51    if not os.path.exists(project_folder):
52        os.makedirs(project_folder)
53
54    # check if .gatt file is present
55    gatt_path = examples_embedded + example + ".gatt"
56    gatt_h = ""
57    if os.path.exists(gatt_path):
58        gatt_h = example+'.h'
59
60    # create makefile
61    with open(project_folder + 'Makefile', 'wt') as fout:
62        with open(template_path, 'rt') as fin:
63            for line in fin:
64                if 'PROJECT=spp_and_le_streamer' in line:
65                    fout.write('PROJECT=%s\n' % example)
66                    continue
67                if 'all: spp_and_le_streamer.h' in line:
68                    if len(gatt_h):
69                        fout.write("all: %s\n" % gatt_h)
70                    continue
71                fout.write(line)
72
73    print("- %s" % example)
74
75print("Projects are ready for compile in example folder. See README for details.")
76