1#!/usr/bin/env python3 2 3#encoding=utf-8 4__author__ = 'addy.ke@rock-chips.com' 5 6import traceback 7import os 8import sys 9import threading 10import time 11import math 12import getopt 13import fnmatch 14 15module = "hardware" 16chips = ['Pisces', 'Koala', 'koala', 'Swallow', 'swallow', 'pisces', 'rv1126', 'rv1108', 'rk2108', 'rk2106', 'rk2206', 'rk3568', "rk1808"] 17 18class BuildGn: 19 def __init__(self, chip, board): 20 self.chip = chip 21 self.board = board 22 self.fp = open("BUILD.gn", 'w+', encoding='utf-8') 23 24 def head(self): 25 head = "# Copyright (c) 2020-2021 Lockzhiner Electronics Co., Ltd.\n" 26 head +="# limitations under the License.\n" 27 head +="# Licensed under the Apache License, Version 2.0 (the \"License\");\n" 28 head +="# you may not use this file except in compliance with the License.\n" 29 head +="# You may obtain a copy of the License at\n" 30 head +="#\n" 31 head +="# http://www.apache.org/licenses/LICENSE-2.0\n" 32 head +="#\n" 33 head +="# Unless required by applicable law or agreed to in writing, software\n" 34 head +="# distributed under the License is distributed on an \"AS IS\" BASIS,\n" 35 head +="# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" 36 head +="# See the License for the specific language governing permissions and\n" 37 head +="#\n\n" 38 head += "import(\"//drivers/adapter/khdf/liteos_m/hdf.gni\")\n" 39 head += "import(\"//device/rockchip/%s/sdk_liteos/board.gni\")\n" % self.chip 40 head += "\n" 41 head += "static_library(\"%s\") {\n" % module 42 self.fp.write(head) 43 44 def include(self): 45 inc = " include_dirs = [\n" 46 inc += " \"./include\",\n" 47 inc += " \"./lib/hal/inc\",\n" 48 inc += " \"./lib/CMSIS/Device/%s/Include\",\n" % self.chip.upper() 49 inc += " \"./lib/CMSIS/Core/Include\",\n" 50 inc += " \"./lib/bsp/%s\",\n" % self.chip.upper() 51 inc += " \"./project/%s/src\",\n" % self.chip 52 inc += " \"$adapter_path/include\",\n" 53 inc += " \"$sdk_path/include\",\n" 54 inc += " \"$kernel_path/kernel/arch/include\",\n" 55 inc += " \"$hal_path/include\",\n" 56 inc += " \"./lz_hardware/wifi/include\",\n" 57 inc += " \"//third_party/musl/porting/liteos_m/kernel/include\",\n" 58 inc += " ]\n" 59 self.fp.write(inc) 60 61 def tail(self): 62 tail = "}\n" 63 self.fp.write(tail) 64 65 def source(self, path, init): 66 search = ['*.c'] 67 if init == 0: 68 source = " sources = [\n" 69 else: 70 source = " sources += [\n" 71 for root, dirnames, filenames in os.walk(path): 72 for extension in search: 73 for filename in fnmatch.filter(filenames, extension): 74 src = os.path.join(root, filename) 75 found = 1 76 for chip in chips: 77 if src.find(chip) >= 0 and chip != self.chip: 78 found = 0 79 if src.find(chip.upper()) >= 0 and chip != self.chip: 80 found = 0 81 if found == 1: 82 source += " \"%s\",\n" % src 83 84 source += " ]\n" 85 self.fp.write(source) 86gn = BuildGn("rk2206", "TB-RK2206H0-A") 87 88gn.head() 89gn.source('./lib/hal', 0) 90gn.source('./lib/bsp', 1) 91gn.source('./lib/CMSIS/Device', 1) 92gn.source('./driver', 1) 93gn.source('./lz_hardware', 1) 94gn.include() 95gn.tail() 96