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