ifneq ("$(origin O)", "command line")
O:=output
CONFIG_DIR:=$(TOPDIR)
+NEED_WRAPPER=
else
# other packages might also support Linux-style out of tree builds
# with the O=<dir> syntax (E.G. Busybox does). As make automatically
CONFIG_DIR:=$(O)
# we need to pass O= everywhere we call back into the toplevel makefile
EXTRAMAKEARGS = O=$(O)
+NEED_WRAPPER=y
endif
# $(shell find . -name *_defconfig |sed 's/.*\///')
world: prepare dependencies dirs $(BASE_TARGETS) $(TARGETS_ALL)
-.PHONY: all world dirs clean distclean source \
+.PHONY: all world dirs clean distclean source outputmakefile \
$(BASE_TARGETS) $(TARGETS) $(TARGETS_ALL) \
$(TARGETS_CLEAN) $(TARGETS_DIRCLEAN) $(TARGETS_SOURCE) \
$(DL_DIR) $(TOOLCHAIN_DIR) $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
KCONFIG_TRISTATE=$(BUILD_DIR)/buildroot-config/tristate.config \
BUILDROOT_CONFIG=$(CONFIG_DIR)/.config
-xconfig: $(BUILD_DIR)/buildroot-config/qconf
+xconfig: $(BUILD_DIR)/buildroot-config/qconf outputmakefile
@mkdir -p $(BUILD_DIR)/buildroot-config
@if ! $(COMMON_CONFIG_ENV) $< $(CONFIG_CONFIG_IN); then \
test -f $(CONFIG_DIR)/.config.cmd || rm -f $(CONFIG_DIR)/.config; \
fi
-gconfig: $(BUILD_DIR)/buildroot-config/gconf
+gconfig: $(BUILD_DIR)/buildroot-config/gconf outputmakefile
@mkdir -p $(BUILD_DIR)/buildroot-config
@if ! $(COMMON_CONFIG_ENV) srctree=$(TOPDIR) \
$< $(CONFIG_CONFIG_IN); then \
test -f $(CONFIG_DIR)/.config.cmd || rm -f $(CONFIG_DIR)/.config; \
fi
-menuconfig: $(BUILD_DIR)/buildroot-config/mconf
+menuconfig: $(BUILD_DIR)/buildroot-config/mconf outputmakefile
@mkdir -p $(BUILD_DIR)/buildroot-config
@if ! $(COMMON_CONFIG_ENV) $< $(CONFIG_CONFIG_IN); then \
test -f $(CONFIG_DIR)/.config.cmd || rm -f $(CONFIG_DIR)/.config; \
fi
-nconfig: $(BUILD_DIR)/buildroot-config/nconf
+nconfig: $(BUILD_DIR)/buildroot-config/nconf outputmakefile
@mkdir -p $(BUILD_DIR)/buildroot-config
@if ! $(COMMON_CONFIG_ENV) $< $(CONFIG_CONFIG_IN); then \
test -f $(CONFIG_DIR)/.config.cmd || rm -f $(CONFIG_DIR)/.config; \
fi
-config: $(BUILD_DIR)/buildroot-config/conf
+config: $(BUILD_DIR)/buildroot-config/conf outputmakefile
@mkdir -p $(BUILD_DIR)/buildroot-config
@$(COMMON_CONFIG_ENV) $< $(CONFIG_CONFIG_IN)
-oldconfig: $(BUILD_DIR)/buildroot-config/conf
+oldconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
mkdir -p $(BUILD_DIR)/buildroot-config
@$(COMMON_CONFIG_ENV) $< --oldconfig $(CONFIG_CONFIG_IN)
-randconfig: $(BUILD_DIR)/buildroot-config/conf
+randconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
@mkdir -p $(BUILD_DIR)/buildroot-config
@$(COMMON_CONFIG_ENV) $< --randconfig $(CONFIG_CONFIG_IN)
-allyesconfig: $(BUILD_DIR)/buildroot-config/conf
+allyesconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
@mkdir -p $(BUILD_DIR)/buildroot-config
@$(COMMON_CONFIG_ENV) $< --allyesconfig $(CONFIG_CONFIG_IN)
-allnoconfig: $(BUILD_DIR)/buildroot-config/conf
+allnoconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
@mkdir -p $(BUILD_DIR)/buildroot-config
@$(COMMON_CONFIG_ENV) $< --allnoconfig $(CONFIG_CONFIG_IN)
-randpackageconfig: $(BUILD_DIR)/buildroot-config/conf
+randpackageconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
@mkdir -p $(BUILD_DIR)/buildroot-config
@grep -v BR2_PACKAGE_ $(CONFIG_DIR)/.config > $(CONFIG_DIR)/.config.nopkg
@$(COMMON_CONFIG_ENV) \
$< --randconfig $(CONFIG_CONFIG_IN)
@rm -f $(CONFIG_DIR)/.config.nopkg
-allyespackageconfig: $(BUILD_DIR)/buildroot-config/conf
+allyespackageconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
@mkdir -p $(BUILD_DIR)/buildroot-config
@grep -v BR2_PACKAGE_ $(CONFIG_DIR)/.config > $(CONFIG_DIR)/.config.nopkg
@$(COMMON_CONFIG_ENV) \
$< --allyesconfig $(CONFIG_CONFIG_IN)
@rm -f $(CONFIG_DIR)/.config.nopkg
-allnopackageconfig: $(BUILD_DIR)/buildroot-config/conf
+allnopackageconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
@mkdir -p $(BUILD_DIR)/buildroot-config
@grep -v BR2_PACKAGE_ $(CONFIG_DIR)/.config > $(CONFIG_DIR)/.config.nopkg
@$(COMMON_CONFIG_ENV) \
$< --allnoconfig $(CONFIG_CONFIG_IN)
@rm -f $(CONFIG_DIR)/.config.nopkg
-silentoldconfig: $(BUILD_DIR)/buildroot-config/conf
+silentoldconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
@mkdir -p $(BUILD_DIR)/buildroot-config
$(COMMON_CONFIG_ENV) $< --silentoldconfig $(CONFIG_CONFIG_IN)
-defconfig: $(BUILD_DIR)/buildroot-config/conf
+defconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
@mkdir -p $(BUILD_DIR)/buildroot-config
@$(COMMON_CONFIG_ENV) $< --defconfig $(CONFIG_CONFIG_IN)
-%_defconfig: $(BUILD_DIR)/buildroot-config/conf $(TOPDIR)/configs/%_defconfig
+%_defconfig: $(BUILD_DIR)/buildroot-config/conf $(TOPDIR)/configs/%_defconfig outputmakefile
@mkdir -p $(BUILD_DIR)/buildroot-config
@$(COMMON_CONFIG_ENV) $< --defconfig=$(TOPDIR)/configs/$@ $(CONFIG_CONFIG_IN)
-savedefconfig: $(BUILD_DIR)/buildroot-config/conf
+savedefconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
@mkdir -p $(BUILD_DIR)/buildroot-config
@$(COMMON_CONFIG_ENV) $< --savedefconfig=$(TOPDIR)/defconfig $(CONFIG_CONFIG_IN)
# Cleanup and misc junk
#
#############################################################
+
+# outputmakefile generates a Makefile in the output directory, if using a
+# separate output directory. This allows convenient use of make in the
+# output directory.
+outputmakefile:
+ifeq ($(NEED_WRAPPER),y)
+ $(Q)$(TOPDIR)/scripts/mkmakefile $(TOPDIR) $(O)
+endif
+
clean:
rm -rf $(STAGING_DIR) $(TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) \
$(STAMP_DIR) $(BUILD_DIR) $(TOOLCHAIN_DIR)
--- /dev/null
+#!/bin/sh
+# Generates a small Makefile used in the root of the output
+# directory, to allow make to be started from there.
+# The Makefile also allow for more convinient build of external modules
+
+# Usage
+# $1 - Kernel src directory
+# $2 - Output directory
+
+
+test ! -r $2/Makefile -o -O $2/Makefile || exit 0
+# Only overwrite automatically generated Makefiles
+# (so we do not overwrite buildroot Makefile)
+if test -e $2/Makefile && ! grep -q Automatically $2/Makefile
+then
+ exit 0
+fi
+if [ "${quiet}" != "silent_" ]; then
+ echo " GEN $2/Makefile"
+fi
+
+cat << EOF > $2/Makefile
+# Automatically generated by $0: don't edit
+
+lastword = \$(word \$(words \$(1)),\$(1))
+makedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST)))
+
+MAKEARGS := -C $1
+MAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst %/,%,\$(makedir))
+
+MAKEFLAGS += --no-print-directory
+
+.PHONY: all \$(MAKECMDGOALS)
+
+all := \$(filter-out all Makefile,\$(MAKECMDGOALS))
+
+all:
+ \$(MAKE) \$(MAKEARGS) \$(all)
+
+Makefile:;
+
+\$(all): all
+ @:
+
+%/: all
+ @:
+EOF