-
-
Notifications
You must be signed in to change notification settings - Fork 751
/
get_makefile_decls.py
80 lines (64 loc) · 2.46 KB
/
get_makefile_decls.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
# This file is part of Espruino, a JavaScript interpreter for Microcontrollers
#
# Copyright (C) 2013 Gordon Williams <[email protected]>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# ----------------------------------------------------------------------------------------
# Script to extract the correct decls from boards/BOARDNAME.py
# ----------------------------------------------------------------------------------------
import subprocess;
import re;
import json;
import sys;
import os;
import importlib;
scriptdir = os.path.dirname(os.path.realpath(__file__))
basedir = scriptdir+"/../"
sys.path.append(basedir+"scripts");
sys.path.append(basedir+"boards");
import common;
import pinutils;
# -----------------------------------------------------------------------------------------
# Now scan AF file
if len(sys.argv)!=2:
print("ERROR, USAGE: get_makefile_decls.py BOARD_NAME")
exit(1)
boardname = sys.argv[1]
# import the board def
board = importlib.import_module(boardname)
#print(json.dumps(board.info))
print("# Generated with scripts/get_makefile_decls.py "+boardname);
print("BOARD="+boardname)
#allow to override board name so we can build for same board from multiple board files
if "boardname" in board.info:
boardname = board.info["boardname"]
print("# board.info.boardname set to "+boardname)
print("DEFINES+= -D"+boardname)
binaryName=common.get_board_binary_name(board)
if binaryName.find('.bin')>=0:
binaryName = binaryName[:binaryName.find('.bin')]
if binaryName.find('.hex')>=0:
binaryName = binaryName[:binaryName.find('.hex')]
print("PROJ_NAME=$(BINDIR)/"+binaryName)
if board.chip["family"]!="LINUX":
print("EMBEDDED=1")
print("FAMILY="+board.chip['family'])
print("CHIP="+board.chip['part'])
if "optimizeflags" in board.info["build"]:
if board.info["build"]["optimizeflags"]:
print("OPTIMIZEFLAGS+="+board.info["build"]["optimizeflags"])
for lib in board.info["build"]["libraries"]:
print("USE_"+lib+"?=1")
if "makefile" in board.info["build"]:
for mfLine in board.info["build"]["makefile"]:
print(mfLine)
if 'USB' in board.devices:
print("USB:=1")
if 'bootloader' in board.info and board.info['bootloader']==1:
print("USE_BOOTLOADER:=1")
print("BOOTLOADER_PROJ_NAME:=$(BINDIR)/bootloader_"+binaryName)
print("DEFINES+=-DUSE_BOOTLOADER")