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 30LITEOSTOPDIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) 31export LITEOSTOPDIR 32 33LITEOS_TARGET = liteos 34HIDE := @ 35KCONFIG_CMDS := $(notdir $(wildcard $(dir $(shell which menuconfig))*config)) 36 37ohos_kernel ?= liteos_m 38$(foreach line,$(shell hb env | sed 's/\[OHOS INFO\]/ohos/g;s/ /_/g;s/:_/=/g' || true),$(eval $(line))) 39ifneq ($(ohos_kernel),liteos_m) 40$(error The selected product ($(ohos_product)) is not a liteos_m kernel type product) 41endif 42 43ifeq ($(PRODUCT_PATH),) 44PRODUCT_PATH:=$(ohos_product_path) 45endif 46 47ifeq ($(DEVICE_PATH),) 48DEVICE_PATH:=$(ohos_device_path) 49endif 50 51ifeq ($(BOARD_COMPANY),) 52BOARD_COMPANY:=$(ohos_device_company) 53endif 54 55ifeq ($(TEE:1=y),y) 56tee = _tee 57endif 58ifeq ($(RELEASE:1=y),y) 59CONFIG ?= $(PRODUCT_PATH)/kernel_configs/release$(tee).config 60else 61CONFIG ?= $(PRODUCT_PATH)/kernel_configs/debug$(tee).config 62endif 63 64KCONFIG_CONFIG ?= $(CONFIG) 65LITEOS_MENUCONFIG_H ?= $(LITEOSTOPDIR)/config.h 66LITEOS_CONFIG_FILE ?= $(LITEOSTOPDIR)/.config 67 68# export los_config.mk related environment variables 69export LITEOS_MENUCONFIG_H 70export LITEOS_CONFIG_FILE 71export BOARD_COMPANY 72export DEVICE_PATH 73export PRODUCT_PATH 74 75# export kconfig related environment variables 76export CONFIG_=LOSCFG_ 77export srctree=$(LITEOSTOPDIR) 78 79-include $(LITEOS_CONFIG_FILE) 80 81define HELP = 82Usage: make [TARGET]... [PARAMETER=VALUE]... 83 84Targets: 85 help: display this help and exit 86 clean: clean compiled objects 87 cleanall: clean all build outputs 88 all: do build (Default target) 89 update_config: update product kernel config (use menuconfig) 90 xxconfig: invoke xxconfig command of kconfiglib (xxconfig is one of $(KCONFIG_CMDS)) 91 92Parameters: 93 TEE: boolean value(1 or y for true), enable tee 94 RELEASE: boolean value(1 or y for true), build release version 95 CONFIG: kernel config file to be use 96 args: arguments for xxconfig command 97endef 98export HELP 99 100all: 101 $(HIDE)hb build -f --gn-args "liteos_kernel_only=true liteos_name=\"$(LITEOS_TARGET)\"" 102 103help: 104 $(HIDE)echo "$$HELP" 105 106$(filter-out menuconfig,$(KCONFIG_CMDS)): 107 $(HIDE)$@ $(args) 108 109$(LITEOS_CONFIG_FILE): $(KCONFIG_CONFIG) 110 $(HIDE)env KCONFIG_CONFIG=$< genconfig --config-out $@ --header-path $(LITEOS_MENUCONFIG_H) 111 112update_config menuconfig: 113 $(HIDE)test -f "$(CONFIG)" && cp -v "$(CONFIG)" .config && menuconfig $(args) && savedefconfig --out "$(CONFIG)" 114 115clean: 116 $(HIDE)hb clean 117 $(HIDE)echo "clean $(LOSCFG_PLATFORM) finish" 118 119cleanall: clean 120 $(HIDE)echo "clean all done" 121 122.PHONY: all clean cleanall help update_config $(KCONFIG_CMDS) $(KCONFIG_CONFIG) 123