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.6_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 example = file[:-2] 68 examples.append(example) 69 70 # create folder 71 project_folder = projects_path + example + "/" 72 if not os.path.exists(project_folder): 73 os.makedirs(project_folder) 74 75 # check if .gatt file is present 76 gatt_path = examples_embedded + example + ".gatt" 77 gatt_h = "" 78 if os.path.exists(gatt_path): 79 gatt_h = example+'.h' 80 81 # create makefile 82 with open(project_folder + 'Makefile', 'wt') as fout: 83 with open(template_path, 'rt') as fin: 84 for line in fin: 85 if 'PROJECT=spp_and_le_streamer' in line: 86 fout.write('PROJECT=%s\n' % example) 87 continue 88 if 'all: spp_and_le_streamer.h' in line: 89 if len(gatt_h): 90 fout.write("all: %s\n" % gatt_h) 91 continue 92 fout.write(line) 93 94 print("- %s" % example) 95 96with open(projects_path+'Makefile', 'wt') as fout: 97 fout.write(build_all % ' \\\n'.join(examples)) 98 99print("Projects are ready for compile in example folder. See README for details.") 100