#!/bin/bash
TOPDIR=`pwd`
BUILDROOT=buildroot-atmel
BUILDROOT_VER=2007-04-22
BUILDROOT_SOURCE=${BUILDROOT}-${BUILDROOT_VER}.cpio.bz2
BUILDROOT_SITE=ftp://at91dist:distrib@81.80.104.162/AT91_Third_Party_Design_Flow/Linux_Host/Source
DL_DIR=${TOPDIR}/Source
UNZIP=bzcat

function	prepare_directories()
{
	mkdir	-p	/tftpboot
	mkdir	-p	/usr/local/arm
	mkdir	-p	/usr/local/install/downloads
}

function	get_buildroot()
{
	if ! [ -d ${BUILDROOT} ] ; then
		mkdir -p ${DL_DIR}
		wget	-P ${DL_DIR}	${BUILDROOT_SITE}/${BUILDROOT_SOURCE}
		${UNZIP}	${DL_DIR}/${BUILDROOT_SOURCE} | cpio -idv
	fi
}

function	make_board()
{
	cd	${BUILDROOT}
	echo	"building board $1"
	make 	B=$1 board
	make	$2
	make	saveconfig
	cd	${TOPDIR}
}

function	make_all_boards()
{
	make_board	at91rm9200df	$1
	make_board	at91sam9260dfc	$1
	make_board	at91sam9261ek	$1
	make_board	at91sam9263ek	$1
}


prepare_directories
get_buildroot
make -C ${BUILDROOT} menuconfig
make_all_boards	source
make_all_boards
