#
# This makefile is intended to get you started in the setup of
# OpenEmbedded to build the OpenZipit distro.  To use this, 
# create a subdir in your user $HOME dir and put this makefile
# in there.  Go into that new dir and type "make".
# 
# This will then pull in all the OE sources and Zipit sources
# from the internet.  I do hope you have a fast internet
# connection!  OpenEmbedded is not "tiny" by any means, the initial
# "pull" of this makefile is about 270Meg.  The final "pull" from
# the web of the associated source files is about 166Meg.
#
# Pay attention to the final message from this makefile.  It will
# be telling you about adding to the PATH variable of your
# .bash_profile and a new BBPATH variable that will be needed.
#
# tom@openhardware.net
#
ifeq "$(BBPATH)" ""
NEEDPATH=setpaths
endif

MTNVER = "0.38"
BBVER = "1.8"

TARGET_DIR=$(shell pwd)
export PATH:=$(PATH):$(TARGET_DIR)/bitbake/bin/
export BBPATH:=$(TARGET_DIR)/build/:$(TARGET_DIR)/org.openembedded.dev

##################################################################

all: bitbake monotone oedatabase oelocal paths
	@echo
	@echo "OpenZipit has been installed.  Edit your .bash_profile to"
	@echo "add the BBPATH statement and add to your PATH.  Then, "
	@echo "type 'bitbake bootstrap-image' to build a basic command line"
	@echo "system to boot the zipit Z2 into Linux."
	@echo

# test for a local copy of bitbake.
bitbake: bitbake/bin/bitbake

bitbake/bin/bitbake:
	@echo "  *** installing a copy of bitbake v${BBVER}"
	@svn --quiet co http://svn.berlios.de/svnroot/repos/bitbake/branches/bitbake-${BBVER}/ bitbake



# test for a local copy of monotone (mtn).
monotone: bitbake/bin/mtn-${MTNVER}-linux-x86

bitbake/bin/mtn-${MTNVER}-linux-x86:
	@echo "  *** installing a copy of monotone v${MTNVER}"
	@(cd bitbake/bin ; \
	wget --quiet http://www.venge.net/monotone/downloads/${MTNVER}/mtn-${MTNVER}-linux-x86.bz2 ; \
	bunzip2 mtn-${MTNVER}-linux-x86.bz2 ; \
	chmod u+x mtn-${MTNVER}-linux-x86 ; \
	ln -s mtn-${MTNVER}-linux-x86 mtn ; )



# test for a local copy of the OE database.
oedatabase: OE.mtn

OE.mtn:
	@echo "  *** installing a copy of the OE database"
	@wget http://www.openembedded.org/snapshots/OE.mtn.bz2
	@bunzip2 <OE.mtn.bz2  >OE.mtn



# do we yet have a local working copy of OE?
oelocal: org.openembedded.dev

org.openembedded.dev:
	@mtn --db=OE.mtn checkout --branch=org.openembedded.dev
	@mtn --db=OE.mtn pull monotone.openembedded.org org.openembedded.dev


# tell user of path statements needed (if missing).
paths: $(NEEDPATH)

setpaths:
	@echo
	@echo "  !!! You must add these statements to your .bash_profile !!!"
	@echo
	@echo "export PATH=\$$PATH:${TARGET_DIR}/bitbake/bin/"
	@echo "export BBPATH=${TARGET_DIR}/build/:${TARGET_DIR}/org.openembedded.dev"
	@echo "if you want to use local-zipit2.conf you need to add also this:"
	@echo "export BBUSERROOT=${TARGET_DIR}"
	@echo

allclean:
	@rm -rf bitbake

