From a8c10c8298f77b3d1343e116dcf66343ff4ed2e3 Mon Sep 17 00:00:00 2001 From: Christian Walter Date: Fri, 1 Jul 2022 11:12:25 +0200 Subject: [PATCH] Makefile: Add targets to add and remove symlinks When "make symlink" is run, it looks for symlink.txt files recursively under site-local directory, and make symbolic links accordingly. "make clean-symlink" removes the symbolic links made. One application is for development of support for new processors and/or new mainboards, where new directories are added, along with some common code changes. Change-Id: I3fa119675ecca1626d70375a61e8a71abec6a53b Signed-off-by: Christian Walter Signed-off-by: Jonathan Zhang Reviewed-on: https://review.coreboot.org/c/coreboot/+/65093 Tested-by: build bot (Jenkins) Reviewed-by: Martin L Roth --- Makefile | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6bdd44a856..58cd85b7d3 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,11 @@ COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE +# Make does not offer a recursive wildcard function, so here's one: +rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2)) +SYMLINK_LIST = $(call rwildcard,site-local/,symlink.txt) + + # directory containing the toplevel Makefile.inc TOPLEVEL := . @@ -455,6 +460,29 @@ sphinx: sphinx-lint: $(MAKE) SPHINXOPTS=-W -C Documentation -f Makefile.sphinx html +symlink: + @echo "Creating Symbolic Links.."; \ + for link in $(SYMLINK_LIST); do \ + SYMLINK=`cat $$link`; \ + REALPATH=`realpath $$link`; \ + if [ -L "$$SYMLINK" ]; then \ + continue; \ + elif [ ! -e "$$SYMLINK" ]; then \ + echo -e "\tLINK $$SYMLINK -> $$(dirname $$REALPATH)"; \ + ln -s $$(dirname $$REALPATH) $$SYMLINK; \ + else \ + echo -e "\tFAILED: $$SYMLINK exists"; \ + fi \ + done + +clean-symlink: + @echo "Deleting symbolic link";\ + EXISTING_SYMLINKS=`find -L ./src -xtype l | grep -v 3rdparty`; \ + for link in $$EXISTING_SYMLINKS; do \ + echo -e "\tUNLINK $$link"; \ + rm "$$link"; \ + done + clean-for-update: rm -rf $(obj) .xcompile @@ -482,4 +510,4 @@ distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils rm -f abuild*.xml junit.xml* util/lint/junit.xml .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean sphinx sphinx-lint -.PHONY: ctags-project cscope-project clean-ctags +.PHONY: ctags-project cscope-project clean-ctags symlink clean-symlink