1# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 2# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without modification, 5# are permitted provided that the following conditions are met: 6# 7# 1. Redistributions of source code must retain the above copyright notice, this list of 8# conditions and the following disclaimer. 9# 10# 2. Redistributions in binary form must reproduce the above copyright notice, this list 11# of conditions and the following disclaimer in the documentation and/or other materials 12# provided with the distribution. 13# 14# 3. Neither the name of the copyright holder nor the names of its contributors may be used 15# to endorse or promote products derived from this software without specific prior written 16# permission. 17# 18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30import("//build/lite/config/component/lite_component.gni") 31 32LITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h") 33 34liteos_config_file = "${ohos_build_type}.config" 35 36liteos_config_file = 37 rebase_path(liteos_config_file, "", "$product_path/kernel_configs") 38print("liteos_config_file:", liteos_config_file) 39 40exec_script("//build/lite/run_shell_cmd.py", 41 [ "env" + " CONFIG_=LOSCFG_" + " KCONFIG_CONFIG_HEADER='y=true'" + 42 " KCONFIG_CONFIG=$liteos_config_file" + 43 " BOARD_COMPANY=$device_company" + 44 " DEVICE_PATH=$device_path" + " srctree=" + rebase_path(".") + 45 " genconfig" + " --header-path $LITEOS_MENUCONFIG_H" + 46 " --file-list kconfig_files.txt" + 47 " --env-list kconfig_env.txt" + " --config-out config.gni" ], 48 "", 49 [ liteos_config_file ]) 50 51import("$root_out_dir/config.gni") 52 53LITEOSTOPDIR = "//kernel/liteos_m" 54HDFTOPDIR = "//drivers/hdf_core/adapter/khdf/liteos_m" 55THIRDPARTY_BOUNDS_CHECKING_FUNCTION_DIR = 56 "//third_party/bounds_checking_function" 57LITEOSTHIRDPARTY = "//third_party" 58THIRDPARTY_FATFS_DIR = "//third_party/FatFs" 59THIRDPARTY_MUSL_DIR = "//third_party/musl" 60THIRDPARTY_LITTLEFS_DIR = "//third_party/littlefs" 61THIRDPARTY_CMSIS_DIR = "//third_party/cmsis" 62THIRDPARTY_LWIP_DIR = "//third_party/lwip" 63DEVICE_BOARD_DIR = "//device/board" 64DEVICE_SOC_DIR = "//device/soc" 65COMMONLIBRARY_UTILS_LITE_DIR = "//commonlibrary/utils_lite" 66TEST_XTS_TOOLS_DIR = "//test/xts/tools" 67 68ARCH = "" 69if (defined(LOSCFG_ARCH_ARM_AARCH32)) { 70 ARCH = "arm" 71} else if (defined(LOSCFG_ARCH_ARM_AARCH64)) { 72 ARCH = "aarch64" 73} else if (defined(LOSCFG_ARCH_RISCV32)) { 74 ARCH = "rv32imac" 75} else if (defined(LOSCFG_ARCH_CSKY)) { 76 ARCH = "csky" 77} else if (defined(LOSCFG_ARCH_XTENSA)) { 78 ARCH = "xtensa" 79} 80 81template("kernel_module") { 82 build_gn = rebase_path("BUILD.gn") 83 cmd = "grep -c '^\s*\(kernel_module\|hdf_driver\)\s*(\s*\S*\s*)\s*{\s*\$' $build_gn" 84 modules_count = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") 85 if (modules_count == 1) { 86 auto_config = true 87 } 88 89 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" 90 has_public_config = 91 exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") 92 if (!has_public_config && defined(auto_config)) { 93 config("public") { 94 configs = [] 95 } 96 } 97 98 current_dir_name = get_path_info(rebase_path("."), "file") 99 if (target_name != current_dir_name) { 100 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" 101 has_current_dir_group = 102 exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") 103 if (!has_current_dir_group && defined(auto_config)) { 104 module_name = target_name 105 group(current_dir_name) { 106 public_deps = [ ":$module_name" ] 107 } 108 } 109 } 110 111 if (defined(invoker.module_switch) && !invoker.module_switch) { 112 group(target_name) { 113 not_needed(invoker, "*") 114 } 115 } else { 116 source_set(target_name) { 117 public_configs = [] 118 forward_variables_from(invoker, "*", [ "configs" ]) 119 configs += invoker.configs 120 if (has_public_config) { 121 included_public_config = false 122 foreach(cfg, public_configs) { 123 what = "label_no_toolchain" 124 if (get_label_info(cfg, what) == get_label_info(":public", what)) { 125 included_public_config = true 126 } 127 } 128 if (!included_public_config) { 129 public_configs += [ ":public" ] 130 } 131 } 132 } 133 } 134 not_needed([ "auto_config" ]) 135} 136 137template("config") { 138 config(target_name) { 139 if (defined(invoker.module_switch) && !invoker.module_switch && 140 target_name == "public") { 141 not_needed(invoker, "*") 142 forward_variables_from(invoker, [ "configs" ]) 143 } else { 144 forward_variables_from(invoker, "*") 145 } 146 } 147} 148 149template("module_group") { 150 assert(defined(invoker.modules), "modules are must") 151 group(target_name) { 152 deps = [] 153 foreach(m, invoker.modules) { 154 deps += [ m ] 155 } 156 if (defined(invoker.deps)) { 157 deps += invoker.deps 158 } 159 } 160 config("public") { 161 configs = [] 162 foreach(m, invoker.modules) { 163 configs += [ "$m:public" ] 164 } 165 if (defined(invoker.configs)) { 166 configs += invoker.configs 167 } 168 } 169} 170 171set_defaults("kernel_module") { 172 configs = [ 173 "$LITEOSTOPDIR:public", 174 "$LITEOSTOPDIR:los_config", 175 ] 176 visibility = [ 177 ":*", 178 "$LITEOSTOPDIR:*", 179 "..:*", 180 "../..:*", 181 ] 182} 183