#!/bin/sh
#*******************************************************************************
# Copyright (c) 2008-2011 VMware, Inc.  All rights reserved.
#
# This file is part of the esxboot project.
#
# esxboot is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation version 2 and no later version.
#
# esxboot is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#*******************************************************************************

copyright='#*******************************************************************************
# Copyright (c) 2008-2011 VMware, Inc.  All rights reserved.
#
# This file is part of the esxboot project.
#
# esxboot is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation version 2 and no later version.
#
# esxboot is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#*******************************************************************************
'

toolchain='#
# Tool Chain
#

# Delete this line once the tool chain is setup.
$(error Please setup your toolchain in env/toolchain.mk)

# Known to work with gcc 4.4.3.
CC         := <Path to gcc>
GCCINC     := <Path to gcc headers>

# Known to work with binutils 2.20.1.
LD         := <Path to ld>
AR         := <Path to ar>
OBJCOPY    := <Path to objcopy>

# Known to work with nasm 2.01.
AS         := <Path to nasm>

# Known to work with libbfd 2.17.50.
LIBBFD     := <Path to libbfd.a>
LIBBFDINC  := <Path to bfd.h>'

makfile='#
# Master Makefile
#

include env/common.mk

SUBDIRS := com32 uefi64 uefi32

.PHONY: all clean $(SUBDIRS)

all: $(SUBDIRS)

$(SUBDIRS):
	$(MAKE) -f Makefile.main BUILDENV=$@

clean:
	$(MAKE) -f Makefile.main clean'

write_config()
{
    if [ -f $2 ]; then
        return 1
    fi

    echo "${copyright}" > $2
    echo "$1" >> $2

    return 0
}

echo "Configuring the build system"
echo ""

echo -n "     Makefile...  "
if write_config "${makfile}" Makefile; then
    echo "Created"
else
    echo "Already exists"
fi

echo -n "     Toolchain...  "
if write_config "${toolchain}" env/toolchain.mk; then
    config="SETUP"
    echo "Created"
else
    config="VERIFY"
    echo "Already exists"
fi

echo ""
echo "PLEASE ${config} YOUR TOOL CHAIN IN env/toolchain.mk"
