xref: /btstack/tool/create_makefile_inc.py (revision 5c54401929043df982e040eba652f5fd7763ce15)
1#!/usr/bin/env python3
2#
3# Create Makefile.inc file for all source folders
4# Copyright 2017 BlueKitchen GmbH
5
6import sys
7import os
8
9makefile_inc_header = '''# Makefile to collect all C source files of {folder}
10
11{var_name} = \\
12'''
13
14folders = [
15'src',
16'src/ble',
17'src/ble/gatt-service',
18'src/classic',
19]
20
21# get btstack root
22btstack_root = os.path.abspath(os.path.dirname(sys.argv[0]) + '/..')
23
24def create_makefile_inc(path):
25    global btstack_root
26
27    folder_path = btstack_root + '/' + path + '/'
28
29    # write makefile based on header and list
30    with open(folder_path + "Makefile.inc", "wt") as fout:
31        var_name = path.upper().replace('/','_').replace('-','_')+'_FILES'
32        fout.write(makefile_inc_header.format(var_name=var_name,folder=path))
33
34        # get all .c files in folder
35        for file in sorted(os.listdir(folder_path)):
36            if not file.endswith(".c"):
37                continue
38            fout.write('    %s \\\n' % file)
39
40        fout.write('\n')
41
42# create all makefile.inc
43if (len(sys.argv) > 1):
44    path = sys.argv[1]
45    print('Creating Makefile.inc for %s' % path)
46    create_makefile_inc(path)
47else:
48    for path in folders:
49        print('Creating Makefile.inc for %s' % path)
50        create_makefile_inc(path)
51