Makefile: parameters check for board and scenario

When user use make parameters to specify BOARD and SCENARIO, there might
be some conflict because parameter of KCONFIG_FILE/BOARD_FILE/SCENARIO_FILE
also includes BOARD/SCENARIO info. To simplify, we only alow below valid
usages:

 1. make <target>
 2. make <target> KCONFIG_FILE=xxx
 3. make <target> BOARD=xxx SCENARIO=xxx
 4. make <target> BOARD_FILE=xxx SCENARIO_FILE=xxx
 5. make <target> KCONFIG_FILE=xxx BOARD_FILE=xxx SCENARIO_FILE=xxx

Especially for case 1 that no any parameters are specified:
    a. If hypervisor/build/.config file which generated by "make menuconfig"
       exist, the .config file will be loaded as KCONFIG_FILE:
       i.e. equal: make <target> KCONFIG_FILE=hypervisor/build/.config

    b. If hypervisor/build/.config file does not exist,
       the default BOARD/SCENARIO will be loaded:
       i.e. equal: make <target> BOARD=$(BOARD) SCENARIO=$(SCENARIO)

Tracked-On: #4517

Signed-off-by: Victor Sun <victor.sun@intel.com>
This commit is contained in:
Victor Sun
2020-03-16 23:53:05 +08:00
committed by wenlingz
parent 2db5ae08d1
commit 471f7e5b28
3 changed files with 113 additions and 68 deletions

104
Makefile
View File

@@ -3,6 +3,27 @@
# global helper variables
T := $(CURDIR)
# BOARD/SCENARIO/BOARD_FILE/SCENARIO_FILE/KCONFIG_FILE parameters sanity check:
#
# Only below usages are VALID: (target = all | hypervisor)
# 1. make <target>
# 2. make <target> KCONFIG_FILE=xxx
# 3. make <target> BOARD=xxx SCENARIO=xxx
# 4. make <target> BOARD_FILE=xxx SCENARIO_FILE=xxx
# 5. make <target> KCONFIG_FILE=xxx BOARD_FILE=xxx SCENARIO_FILE=xxx
#
# Especially for case 1 that no any parameters are specified:
# a. If hypervisor/build/.config file which generated by "make menuconfig" exist,
# the .config file will be loaded as KCONFIG_FILE:
# i.e. equal: make <target> KCONFIG_FILE=hypervisor/build/.config
#
# b. If hypervisor/build/.config file does not exist,
# the default BOARD/SCENARIO will be loaded:
# i.e. equal: make <target> BOARD=$(BOARD) SCENARIO=$(SCENARIO)
#
# The grep process did not handle corner case when '#' is manually put right after config value as comments,
# i.e. it will be failed in the case of "CONFIG_XXX=y # some comments here "
ifneq ($(KCONFIG_FILE),)
ifneq ($(KCONFIG_FILE), $(wildcard $(KCONFIG_FILE)))
$(error KCONFIG_FILE: $(KCONFIG_FILE) does not exist)
@@ -12,6 +33,50 @@ else
override KCONFIG_FILE := $(T)/hypervisor/build/.config
endif
ifneq ($(BOARD)$(SCENARIO),)
ifneq ($(BOARD_FILE)$(SCENARIO_FILE),)
$(error BOARD/SCENARIO parameter could not coexist with BOARD_FILE/SCENARIO_FILE)
endif
endif
ifneq ($(BOARD_FILE)$(SCENARIO_FILE),)
ifneq ($(BOARD_FILE), $(wildcard $(BOARD_FILE)))
$(error BOARD_FILE: $(BOARD_FILE) does not exist)
endif
ifneq ($(SCENARIO_FILE), $(wildcard $(SCENARIO_FILE)))
$(error SCENARIO_FILE: $(SCENARIO_FILE) does not exist)
endif
override BOARD_FILE := $(realpath $(BOARD_FILE))
override SCENARIO_FILE := $(realpath $(SCENARIO_FILE))
endif
ifeq ($(KCONFIG_FILE), $(wildcard $(KCONFIG_FILE)))
ifneq ($(BOARD)$(SCENARIO),)
$(error BOARD/SCENARIO parameter could not coexist with KCONFIG_FILE)
endif
BOARD_IN_KCONFIG := $(shell grep CONFIG_BOARD= $(KCONFIG_FILE) | grep -v '\#' | awk -F '"' '{print $$2}')
ifeq ($(BOARD_IN_KCONFIG),)
$(error no BOARD info in KCONFIG_FILE: $(KCONFIG_FILE))
endif
SCENARIO_IN_KCONFIG := $(shell grep -E "SDC=y|SDC2=y|INDUSTRY=y|LOGICAL_PARTITION=y|HYBRID=y" \
$(KCONFIG_FILE) | grep -v '\#' | awk -F "=" '{print $$1}' | cut -d '_' -f 2- | tr A-Z a-z)
ifeq ($(SCENARIO_IN_KCONFIG),)
$(error no SCENARIO info in KCONFIG_FILE: $(KCONFIG_FILE))
endif
override BOARD := $(BOARD_IN_KCONFIG)
override SCENARIO := $(SCENARIO_IN_KCONFIG)
RELEASE := $(shell grep CONFIG_RELEASE=y $(KCONFIG_FILE) | grep -v '\#')
ifneq ($(RELEASE),)
override RELEASE := 1
endif
endif
BOARD ?= kbl-nuc-i7
ifneq (,$(filter $(BOARD),apl-mrb))
@@ -35,13 +100,6 @@ BUILD_TAG ?=
GENED_ACPI_INFO_HEADER = $(T)/hypervisor/arch/x86/configs/$(BOARD)/$(BOARD)_acpi_info.h
HV_CFG_LOG = $(HV_OUT)/cfg.log
ifneq ($(BOARD_FILE),)
override BOARD_FILE := $(shell if [ -f $(BOARD_FILE) ]; then realpath $(BOARD_FILE); fi)
endif
ifneq ($(SCENARIO_FILE),)
override SCENARIO_FILE := $(shell if [ -f $(SCENARIO_FILE) ]; then realpath $(SCENARIO_FILE); fi)
endif
export TOOLS_OUT BOARD SCENARIO FIRMWARE RELEASE
.PHONY: all hypervisor devicemodel tools doc
@@ -54,40 +112,8 @@ else ifeq ($(BOARD), kbl-nuc-i7)
override BOARD := nuc7i7dnb
endif
#BOARD and SCENARIO definition priority:
# If we do menuconfig in advance, the menuconfig will define
# BOARD
# SCENARIO
# else if we have board/scenario file avaiable, BOARD and SCENARIO will be
# extracted from files.
# else if make comand has BORAD/SCENARIO parameters, BOARD and SCENARIO will
# be gotten from parameters
# else
# default value defined in this make file will be used
#
include $(T)/hypervisor/scripts/makefile/cfg_update.mk
ifeq ($(KCONFIG_FILE), $(wildcard $(KCONFIG_FILE)))
BOARD_IN_KCONFIG := $(shell grep CONFIG_BOARD= $(KCONFIG_FILE) | awk -F '"' '{print $$2}')
SCENARIO_IN_KCONFIG := $(shell grep -E "SDC=y|SDC2=y|INDUSTRY=y|LOGICAL_PARTITION=y|HYBRID=y" \
$(KCONFIG_FILE) | awk -F "=" '{print $$1}' | cut -d '_' -f 2- | tr A-Z a-z)
RELEASE := $(shell grep CONFIG_RELEASE=y $(KCONFIG_FILE))
ifneq ($(RELEASE),)
override RELEASE := 1
endif
ifneq ($(BOARD_IN_KCONFIG),$(BOARD))
override BOARD := $(BOARD_IN_KCONFIG)
endif
ifneq ($(SCENARIO_IN_KCONFIG),$(SCENARIO))
override SCENARIO := $(SCENARIO_IN_KCONFIG)
endif
endif
#help functions to build acrn and install acrn/acrn symbols
define build_acrn
$(MAKE) -C $(T)/hypervisor HV_OBJDIR=$(HV_OUT)-$(1)/$(2) BOARD=$(2) FIRMWARE=$(1) SCENARIO=$(4) RELEASE=$(RELEASE) clean