添加BUILD.gn 文件 能生成ninja脚本 但编译不过

This commit is contained in:
2025-01-16 15:44:56 +08:00
parent 4536cef906
commit 639024a1a6
21 changed files with 1522 additions and 20 deletions

View File

@@ -3,11 +3,40 @@
# found in the LICENSE file.
config("compiler_defaults") {
if (current_os == "linux") {
if (board_toolchain == "gcc") {
cflags = [
"-fPIC",
"-pthread",
]
} else if (board_toolchain == "riscv-gcc"){
cflags = [
"-mabi=ilp32f",
"-march=rv32imafc",
"-falign-functions=2",
"-msave-restore",
"-fno-optimize-strlen",
"-freorder-blocks-algorithm=simple",
"-fno-schedule-insns",
"-fno-inline-small-functions",
"-mtune=size",
"-mno-small-data-limit=0",
"-fno-aggressive-loop-optimizations",
"-Wpointer-arith",
"-ffunction-sections",
"-fdata-sections",
"-fno-exceptions",
"-fno-short-enums",
"-D__LITEOS__M",
"-nostartfiles",
"-mstrict-align",
"-Wno-error=unused-function",
"-Wno-error=unused-but-set-variable",
"-ffast-math",
]
cflags_cc = cflags
ldflags = cflags
asmflags = cflags
}
}
@@ -19,3 +48,5 @@ config("executable_ldconfig") {
]
}
}

View File

@@ -10,7 +10,7 @@
if (!defined(board_toolchain)){
board_toolchain="gcc"
board_toolchain="riscv-gcc"
}
if (board_toolchain=="riscv-gcc"){

110
build/buildcfg.gni Normal file
View File

@@ -0,0 +1,110 @@
import("//build/config.gni")
template("kernel_module") {
build_gn = rebase_path("BUILD.gn")
# 如果只存在一个kernel_module,则auto_config=true
cmd = "grep -c '^\s*\(kernel_module\|hdf_driver\)\s*(\s*\S*\s*)\s*{\s*\$' $build_gn"
modules_count = exec_script("//build/run_shell_cmd.py", [ cmd ], "value")
if (modules_count == 1) {
auto_config = true
}
# 如果不存在config("public")或者module_group,则创建config("public")
cmd = "if grep -q '^\s*\(config\s*(\s*\"public\"\s*)\|module_group\s*(\s*\"\S*\"\s*)\)\s*{\s*\$' $build_gn; then echo true; else echo false; fi"
has_public_config =
exec_script("//build/run_shell_cmd.py", [ cmd ], "value")
if (!has_public_config && defined(auto_config)) {
config("public") {
configs = []
}
}
# 如果不存在module_group或group,则建立group
current_dir_name = get_path_info(rebase_path("."), "file")
if (target_name != current_dir_name) {
cmd = "if grep -q '^\s*\(module_group\|group\)\s*(\s*\"$current_dir_name\"\s*)\s*{\s*\$' $build_gn; then echo true; else echo false; fi"
has_current_dir_group =
exec_script("//build/run_shell_cmd.py", [ cmd ], "value")
if (!has_current_dir_group && defined(auto_config)) {
module_name = target_name
group(current_dir_name) {
public_deps = [ ":$module_name" ]
}
}
}
if (defined(invoker.module_switch) && !invoker.module_switch) {
group(target_name) {
not_needed(invoker, "*")
}
} else {
source_set(target_name) {
public_configs = []
forward_variables_from(invoker, "*", [ "configs" ])
configs += invoker.configs
if (has_public_config) {
included_public_config = false
foreach(cfg, public_configs) {
what = "label_no_toolchain"
if (get_label_info(cfg, what) == get_label_info(":public", what)) {
included_public_config = true
}
}
if (!included_public_config) {
public_configs += [ ":public" ]
}
}
}
}
not_needed([ "auto_config" ])
}
template("config") {
config(target_name) {
# 如果定义了module_switch 并且 module_switch为false 并且 配置名称为 "public"
if (defined(invoker.module_switch) && !invoker.module_switch &&
target_name == "public") {
# 忽略调用者的所有变量,定义任意变量不会导致错误
not_needed(invoker, "*")
# 将调用者的 configs 变量复制到当前
forward_variables_from(invoker, [ "configs" ])
} else {
forward_variables_from(invoker, "*")
}
}
}
template("module_group") {
assert(defined(invoker.modules), "modules are must")
group(target_name) {
deps = []
foreach(m, invoker.modules) {
deps += [ m ]
}
if (defined(invoker.deps)) {
deps += invoker.deps
}
}
config("public") {
configs = []
foreach(m, invoker.modules) {
configs += [ "$m:public" ]
}
if (defined(invoker.configs)) {
configs += invoker.configs
}
}
}
# 使用这个模板时的默认配置
set_defaults("kernel_module"){
configs = [
]
}

View File

@@ -1,17 +0,0 @@
if (target_cpu == ""){
target_cpu = "x64"
}
if (target_os == ""){
target_os = "linux"
}
if (current_cpu == ""){
current_cpu = target_cpu
}
if (current_os == ""){
current_os = target_os
}
set_default_toolchain(":gcc")

33
build/config.gni Normal file
View File

@@ -0,0 +1,33 @@
fastboot_mode=""
flash_size="4"
psram_enable="1"
psram_size="8"
layout_index="8"
HW_CHIP_ID="HZ"
PROTO_TYPE="p12087"
rf_enable="1"
dual_enable="1"
build_amp_type="0"
sec_cpu_enable="1"
cco="1"
os_type="freertos"
new_type_cco=""
soft_float_enable=""
smart_cco_sta=""
ckb=""
gdb_debug_enable=""
disable_print="0"
hw_platform_ver="2"
gcc="riscv"
target="kunlun3"
ftm_build="0"
opt_build="1"
flash_build="1"
cpu1_build="0"
mpu_enable="0"
release_build="0"
product_line="PLC"
PLATFORM="CHIP"
APP="0"
FLASH_SIZE="4"
kl_ld_script="//startup/ldscripts/riscv3/link_psram_8m_cco_plc_only.ld"

27
build/run_shell_cmd.py Executable file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import subprocess
import sys
def main():
return subprocess.Popen(' '.join(sys.argv[1:]), shell=True).wait()
if __name__ == '__main__':
sys.exit(main())