Makefile: move mkdir rule to after HOST_DIR is defined
PATCH 1/2 Makefile: move mkdir rule to after HOST_DIR is defined
HOST_DIR is defined twice: once to its default value before .config is included, and once more to BR2_HOST_DIR after .config is included. However, the rule that defines the mkdir for HOST_DIR comes between these two, so it will always use the default definition. Therefore, if a non-default BR2_HOST_DIR is used, there will be no rule to create that directory, while the dirs target depends on it.
This happens to work at the moment, because in the dirs target, $(STAGING_DIR) comes before $(HOST_DIR), so $(HOST_DIR) will be created implicitly. However, this will fail in top-level parallel builds where both will be created in parallel.
--- Makefile | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
Makefile +5 -9
@@ -231,15 +231,6 @@ LEGAL_MANIFEST_CSV_HOST = $(LEGAL_INFO_DIR)/host-manifest.csv LEGAL_WARNINGS = $(LEGAL_INFO_DIR)/.warnings LEGAL_REPORT = $(LEGAL_INFO_DIR)/README -################################################################################ -# -# staging and target directories do NOT list these as -# dependencies anywhere else -# -################################################################################ -$(BUILD_DIR) $(TARGET_DIR) $(HOST_DIR) $(BINARIES_DIR) $(LEGAL_INFO_DIR) $(REDIST_SOURCES_DIR_TARGET) $(REDIST_SOURCES_DIR_HOST): - @mkdir -p $@ - BR2_CONFIG = $(CONFIG_DIR)/.config # Pull in the user's configuration file
@@ -926,6 +917,11 @@ savedefconfig: $(BUILD_DIR)/buildroot-config/conf prepare-kconfig # ################################################################################ +# staging and target directories do NOT list these as +# dependencies anywhere else +$(BUILD_DIR) $(TARGET_DIR) $(HOST_DIR) $(BINARIES_DIR) $(LEGAL_INFO_DIR) $(REDIST_SOURCES_DIR_TARGET) $(REDIST_SOURCES_DIR_HOST): + @mkdir -p $@ + # outputmakefile generates a Makefile in the output directory, if using a # separate output directory. This allows convenient use of make in the # output directory.
Signature · 1 line
2.13.3
PATCH 2/2 Makefile: create symlink to non-default HOST_DIR
If BR2_HOST_DIR is not the default, it can be difficult to find the host directory (i.e., HOST_DIR always has to be passed explicitly in addition to the output directory). For example, the Eclipse plugin assumes that HOST_DIR=BASE_DIR/host.
Create a symlink from $(BASE_DIR)/host to $(HOST_DIR) if it is not the default. Also remove it in the clean target.
When BR2_HOST_DIR is the default, HOST_DIR_SYMLINK will be empty so there will be no additional dependency to dirs and nothing to remove in clean.
Fixes https://bugs.busybox.net/show_bug.cgi?id=10151
---
This depends on the previous patch, otherwise there are two rules for the $(BASE_DIR)/host target.
Note that this implementation assumes that HOST_DIR is an absolute path, but that assumption is made in dozens of other places as well. Perhaps an abspath should be added to it.
--- Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
Makefile +8 -2
@@ -430,6 +430,12 @@ TAR_OPTIONS = $(call qstrip,$(BR2_TAR_OPTIONS)) -xf # packages compiled for the host go here HOST_DIR := $(call qstrip,$(BR2_HOST_DIR)) +ifneq ($(HOST_DIR),$(BASE_DIR)/host) +HOST_DIR_SYMLINK = $(BASE_DIR)/host +$(HOST_DIR_SYMLINK): $(BASE_DIR) + ln -snf $(HOST_DIR) $(BASE_DIR)/host +endif + # Quotes are needed for spaces and all in the original PATH content. BR_PATH = "$(HOST_DIR)/bin:$(HOST_DIR)/sbin:$(PATH)"
@@ -533,7 +539,7 @@ endif .PHONY: dirs dirs: $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \ - $(HOST_DIR) $(HOST_DIR)/usr $(BINARIES_DIR) + $(HOST_DIR) $(HOST_DIR_SYMLINK) $(HOST_DIR)/usr $(BINARIES_DIR) $(BUILD_DIR)/buildroot-config/auto.conf: $(BR2_CONFIG) $(MAKE1) $(EXTRAMAKEARGS) HOSTCC="$(HOSTCC_NOCCACHE)" HOSTCXX="$(HOSTCXX_NOCCACHE)" silentoldconfig
@@ -955,7 +961,7 @@ printvars: .PHONY: clean clean: - rm -rf $(TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) \ + rm -rf $(TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) $(HOST_DIR_SYMLINK) \ $(BUILD_DIR) $(BASE_DIR)/staging \ $(LEGAL_INFO_DIR) $(GRAPHS_DIR)
Signature · 1 line
2.13.3
PATCH 1/2 Makefile: move mkdir rule to after HOST_DIR is defined
In reply to Arnout Vandecappelle (Essensium/Mind)Hello,
Quoted 12 lines · Arnout Vandecappelle (Essensium/Mind)
HOST_DIRis defined twice: once to its default value before .config is included, and once more toBR2_HOST_DIRafter .config is included. However, the rule that defines the mkdir forHOST_DIRcomes between these two, so it will always use the default definition. Therefore, if a non-defaultBR2_HOST_DIRis used, there will be no rule to create that directory, while the dirs target depends on it.This happens to work at the moment, because in the dirs target, $(STAGING_DIR) comes before $(HOST_DIR), so $(HOST_DIR) will be created implicitly. However, this will fail in top-level parallel builds where both will be created in parallel.
Quoted 4 lines
--- Makefile | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
Both applied to master. Thanks!
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com