1*6ccd8248SMilanka Ringwald#!/usr/bin/env python3 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 118f3b3e6cSMatthias Ringwald# build all template 128f3b3e6cSMatthias Ringwaldbuild_all = ''' 138f3b3e6cSMatthias RingwaldSUBDIRS = \\ 148f3b3e6cSMatthias Ringwald%s 158f3b3e6cSMatthias Ringwald 168f3b3e6cSMatthias Ringwaldall: 178f3b3e6cSMatthias Ringwald\techo Building all examples 188f3b3e6cSMatthias Ringwald\tfor dir in $(SUBDIRS); do \\ 198f3b3e6cSMatthias Ringwald\t$(MAKE) -C $$dir || exit 1; \\ 208f3b3e6cSMatthias Ringwald\tdone 218f3b3e6cSMatthias Ringwald 228f3b3e6cSMatthias Ringwaldclean: 238f3b3e6cSMatthias Ringwald\techo Cleaning all ports 248f3b3e6cSMatthias Ringwald\tfor dir in $(SUBDIRS); do \\ 258f3b3e6cSMatthias Ringwald\t$(MAKE) -C $$dir clean; \\ 268f3b3e6cSMatthias Ringwald\tdone 278f3b3e6cSMatthias Ringwald''' 288f3b3e6cSMatthias Ringwald 29c894dca1SMatthias Ringwald# get script path 30c894dca1SMatthias Ringwaldscript_path = os.path.abspath(os.path.dirname(sys.argv[0])) + '/../' 31c894dca1SMatthias Ringwald 32c894dca1SMatthias Ringwald# get btstack root 33c894dca1SMatthias Ringwaldbtstack_root = script_path + '../../' 34c894dca1SMatthias Ringwald 35c894dca1SMatthias Ringwald## pick correct init script based on your hardware 36c894dca1SMatthias Ringwald# - init script for CC2564B 37f2eb0907SMatthias Ringwaldcc256x_init_script = 'bluetooth_init_cc2564B_1.8_BT_Spec_4.1.c' 38c894dca1SMatthias Ringwald 39c894dca1SMatthias Ringwaldsubprocess.call("make -f ../Makefile -C src " + cc256x_init_script, shell=True) 40c894dca1SMatthias Ringwald 41c894dca1SMatthias Ringwald# fetch init script 42c894dca1SMatthias Ringwald# print("Creating init script %s" % cc256x_init_script) 43c894dca1SMatthias Ringwald# make_template = 'make -f {BTSTACK_ROOT}chipset/cc256x/Makefile.inc -C {SCRIPT_PATH}src/ {INIT_SCRIPT} BTSTACK_ROOT={BTSTACK_ROOT}' 44c894dca1SMatthias Ringwald# make_command = make_template.format(BTSTACK_ROOT=btstack_root, SCRIPT_PATH=script_path, INIT_SCRIPT=cc256x_init_script) 45c894dca1SMatthias Ringwald# print(make_command) 46c894dca1SMatthias Ringwald# subprocess.call(make_command) 47c894dca1SMatthias Ringwald 48c894dca1SMatthias Ringwald# path to examples 49c894dca1SMatthias Ringwaldexamples_embedded = btstack_root + 'example/' 50c894dca1SMatthias Ringwald 51c894dca1SMatthias Ringwald# path to generated example projects 526b7adbe5SMatthias Ringwaldprojects_path = script_path + "example/" 53c894dca1SMatthias Ringwald 54c894dca1SMatthias Ringwald# path to template 556b7adbe5SMatthias Ringwaldtemplate_path = script_path + 'example/template/Makefile' 56c894dca1SMatthias Ringwald 57c894dca1SMatthias Ringwaldprint("Creating example projects:") 58c894dca1SMatthias Ringwald 59c894dca1SMatthias Ringwald# iterate over btstack examples 60c894dca1SMatthias Ringwaldexample_files = os.listdir(examples_embedded) 61c894dca1SMatthias Ringwald 628f3b3e6cSMatthias Ringwaldexamples = [] 638f3b3e6cSMatthias Ringwald 64c894dca1SMatthias Ringwaldfor file in example_files: 65c894dca1SMatthias Ringwald if not file.endswith(".c"): 66c894dca1SMatthias Ringwald continue 67df09fcaeSMatthias Ringwald if file in ['panu_demo.c', 'sco_demo_util.c', 'ant_test.c']: 68f39cc24dSMatthias Ringwald continue 69c894dca1SMatthias Ringwald example = file[:-2] 708f3b3e6cSMatthias Ringwald examples.append(example) 71c894dca1SMatthias Ringwald 72c894dca1SMatthias Ringwald # create folder 73c894dca1SMatthias Ringwald project_folder = projects_path + example + "/" 74c894dca1SMatthias Ringwald if not os.path.exists(project_folder): 75c894dca1SMatthias Ringwald os.makedirs(project_folder) 76c894dca1SMatthias Ringwald 77c894dca1SMatthias Ringwald # check if .gatt file is present 78c894dca1SMatthias Ringwald gatt_path = examples_embedded + example + ".gatt" 79c894dca1SMatthias Ringwald gatt_h = "" 80c894dca1SMatthias Ringwald if os.path.exists(gatt_path): 81c894dca1SMatthias Ringwald gatt_h = example+'.h' 82c894dca1SMatthias Ringwald 83c894dca1SMatthias Ringwald # create makefile 84c894dca1SMatthias Ringwald with open(project_folder + 'Makefile', 'wt') as fout: 85c894dca1SMatthias Ringwald with open(template_path, 'rt') as fin: 86c894dca1SMatthias Ringwald for line in fin: 87c894dca1SMatthias Ringwald if 'PROJECT=spp_and_le_streamer' in line: 88c894dca1SMatthias Ringwald fout.write('PROJECT=%s\n' % example) 89c894dca1SMatthias Ringwald continue 90c894dca1SMatthias Ringwald if 'all: spp_and_le_streamer.h' in line: 91c894dca1SMatthias Ringwald if len(gatt_h): 92c894dca1SMatthias Ringwald fout.write("all: %s\n" % gatt_h) 93c894dca1SMatthias Ringwald continue 94c894dca1SMatthias Ringwald fout.write(line) 95c894dca1SMatthias Ringwald 96c894dca1SMatthias Ringwald print("- %s" % example) 97c894dca1SMatthias Ringwald 988f3b3e6cSMatthias Ringwaldwith open(projects_path+'Makefile', 'wt') as fout: 998f3b3e6cSMatthias Ringwald fout.write(build_all % ' \\\n'.join(examples)) 1008f3b3e6cSMatthias Ringwald 1016b7adbe5SMatthias Ringwaldprint("Projects are ready for compile in example folder. See README for details.") 102