

BR2_EXTERNAL ?= $(BR_PROJECT)/../../bsp/buildroot_external/

BR_ENV = BR2_EXTERNAL=$(BR2_EXTERNAL) O=$(BR_STAGING)/buildroot/ WORKSPACE_DIR=$(BR_STAGING) BUILDS_ROOT=$(BR_LOCAL_BUILDS_ROOT) BOARD=$(BR_BOARD) PROJECT=$(BR_PROJECT)

buildroot.menuconfig: buildroot.config
	$(MAKE) $(BR_ENV) -C $(BR_PROJECT)/../../bsp/buildroot/ menuconfig
	cmp -s $(BR_STAGING)/buildroot/.config $(BR_PROJECT)/configs/buildroot.config; \
	if test $$? -ne 0; then echo "Config Files has changed......"; \
		cp $(BR_STAGING)/buildroot/.config $(BR_PROJECT)/configs/buildroot.config; \
	fi

buildroot: buildroot.config
	$(MAKE) LD_LIBRARY_PATH=$(BR_STAGING)/cross/opt/ext-toolchain/lib/ $(BR_ENV) -C $(BR_PROJECT)/../../bsp/buildroot/

buildroot.shell: buildroot.config
	$(eval export $(BR_ENV))
	cd $(BR_STAGING)/buildroot/; $(BR_ENV) bash

buildroot.config:
	@mkdir -p $(BR_STAGING)/buildroot/
ifeq ("$(wildcard $(BR_STAGING)/buildroot/.config)","")
	@cp $(BR_PROJECT)/configs/buildroot.config $(BR_STAGING)/buildroot/.config
else
	cmp -s $(BR_PROJECT)/configs/buildroot.config $(BR_STAGING)/buildroot/.config; \
	if test $$? -ne 0; then echo "Config Files has changed......"; \
		cp $(BR_PROJECT)/configs/buildroot.config $(BR_STAGING)/buildroot/.config; \
	fi
endif

install.sd:
	sudo dd if=$(BR_STAGING)/buildroot/images/sdcard.img of=/dev/mmcblk0 && sync && sync
