# br2-external-common standalone build wrapper
#
# Usage:
#   make rpi_common_test_defconfig  - Load a defconfig
#   make                            - Build the image
#   make menuconfig                 - Open configuration menu
#   make savedefconfig              - Save config back to the original defconfig
#   make linux-rebuild              - Rebuild a specific package
#   make clean                      - Clean build artifacts
#
# Any valid Buildroot target works — it is passed through directly.
#
# The buildroot source is expected at ./buildroot (git submodule).
# The output directory is ./output (gitignored).

BUILDROOT_DIR := $(CURDIR)/buildroot
OUTPUT_DIR    := $(CURDIR)/output
BR2_EXTERNAL  := $(CURDIR)

CONFIG_EXISTS := $(wildcard $(OUTPUT_DIR)/.config)

.PHONY: all

all:
ifeq ($(CONFIG_EXISTS),)
	@echo "No .config found. Load a defconfig first, e.g.:"
	@echo "  make raspberrypi_common_defconfig"
	@exit 1
endif
	$(MAKE) -C $(BUILDROOT_DIR) BR2_EXTERNAL=$(BR2_EXTERNAL) O=$(OUTPUT_DIR)

%:
	$(MAKE) -C $(BUILDROOT_DIR) BR2_EXTERNAL=$(BR2_EXTERNAL) O=$(OUTPUT_DIR) $@
