include VERSION

# Override this to make script work with external Linux-2.6 sources
BR_TREE=buildroot-git
TOP:=$(PWD)

BR_OFFICIAL_REPO:=git://git.buildroot.net/buildroot

default:
	@echo You must specifiy build target

# Target that download an install sources
install:
	@if ! `git --version > /dev/null` ; then \
	 echo ; \
	 echo "!!! You need to install git in order to download Linux sources";\
	 echo ; \
	 fi

# Download Git kernel is not already downloaded
	if [ ! -d "$(BR_TREE)" ]; then \
	 git clone $(BR_OFFICIAL_REPO) $(BR_TREE); \
	 fi

# Remove old LEON branch if already there
	-cd $(BR_TREE); \
	 git clean -f; \
	 git checkout master; \
	 git branch -D leon-$(VERSION);

# Update master branch if not already updated
	cd $(BR_TREE); \
	 git pull;

# Create branch for this LEON version, and check it out
	cd $(BR_TREE); \
	 git branch leon-$(VERSION) $(BR_GIT_COMMIT); \
	 git checkout leon-$(VERSION);

# Install patches
	cd $(BR_TREE); \
	 git am $(TOP)/patches/*.patch


#
# Different Configure interfaces
#

menuconfig:
	cd $(BR_TREE); make menuconfig

xconfig:
	cd $(BR_TREE); make xconfig

gconfig:
	cd $(BR_TREE); make gconfig

build:
	cd $(BR_TREE); make
