summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile14
-rw-r--r--board/cr50/build.mk5
-rw-r--r--include/config.h8
-rwxr-xr-xutil/env_changed.sh23
4 files changed, 49 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 70875ce540..b5e842a6d0 100644
--- a/Makefile
+++ b/Makefile
@@ -86,6 +86,15 @@ not_cfg = $(subst ro rw,y,$(filter-out $(1:y=ro rw),ro rw))
# The board makefile sets $CHIP and the chip makefile sets $CORE.
# Include those now, since they must be defined for _flag_cfg below.
include $(BDIR)/build.mk
+
+ifneq ($(ENV_VARS),)
+# Let's make sure $(out)/env_config.h changes if value any of the above
+# variables has changed since the prvious make invocation. This in turn will
+# make sure that relevant object files are re-built.
+current_set = $(foreach env_flag, $(ENV_VARS), $(env_flag)=$($(env_flag)))
+$(shell util/env_changed.sh "$(out)/env_config.h" "$(current_set)")
+endif
+
# Baseboard directory
ifneq (,$(BASEBOARD))
BASEDIR:=baseboard/$(BASEBOARD)
@@ -153,7 +162,10 @@ CPPFLAGS_RO+=$(foreach t,$(_tsk_cfg_ro),-D$(t)) \
CPPFLAGS_RW+=$(foreach t,$(_tsk_cfg_rw),-D$(t)) \
$(foreach t,$(_tsk_cfg_ro),-D$(t)_RO)
CPPFLAGS+=$(foreach t,$(_tsk_cfg),-D$(t))
-
+ifneq ($(ENV_VARS),)
+CPPFLAGS += -DINCLUDE_ENV_CONFIG
+CFLAGS += -I$(realpath $(out))
+endif
# Get the CONFIG_ and VARIANT_ options that are defined for this target and make
# them into variables available to this build script
_flag_cfg_ro:=$(shell $(CPP) $(CPPFLAGS) -P -dM -Ichip/$(CHIP) \
diff --git a/board/cr50/build.mk b/board/cr50/build.mk
index 00b88694f6..845d5ac9bf 100644
--- a/board/cr50/build.mk
+++ b/board/cr50/build.mk
@@ -15,6 +15,11 @@ CHIP_VARIANT ?= cr50_fpga
# a guard so that recipe definitions and variable extensions only happen the
# second time.
ifeq ($(BOARD_MK_INCLUDED_ONCE),)
+
+# List of variables which can be defined in the environment or set in the make
+# command line.
+ENV_VARS := CR50_DEV CR50_SQA H1_RED_BOARD
+
BOARD_MK_INCLUDED_ONCE=1
SIG_EXTRA = --cros
else
diff --git a/include/config.h b/include/config.h
index c3d95c243f..8d8d2631b2 100644
--- a/include/config.h
+++ b/include/config.h
@@ -18,6 +18,14 @@
#ifndef __CROS_EC_CONFIG_H
#define __CROS_EC_CONFIG_H
+#ifdef INCLUDE_ENV_CONFIG
+/*
+ * When building for an EC target, pick up the .h file which allows to
+ * keep track of changing make variables.
+ */
+#include "env_config.h"
+#endif
+
/*
* All config options are listed alphabetically and described here.
*
diff --git a/util/env_changed.sh b/util/env_changed.sh
new file mode 100755
index 0000000000..5bab64760d
--- /dev/null
+++ b/util/env_changed.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+# Copyright 2019 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# This script accepts two parameters: a file name and a string.
+#
+# If the file does not exist, or does not contain the passed in string wrapped
+# in '/*... */, the file is written with the wrapped passed in string.
+
+h_file="$1"
+current_set="/* $2 */"
+
+if [[ -f "${h_file}" ]]; then
+ old_set="$(cat "${h_file}")"
+ if [[ "${current_set}" == "${old_set}" ]]; then
+ exit 0
+ fi
+else
+ dest_dir="$(dirname "${h_file}")"
+ [[ -d "${dest_dir}" ]] || mkdir -p "${dest_dir}"
+fi
+printf "${current_set}" > "${h_file}"