# Copyright (c) 2004, 2005 Nokia
# Authors:
# 	lauri.leukkunen@nokia.com
# 	Timo Savola <tsavola@movial.fi>
#
# Licenced under GPL, see the top level COPYING file for details
#
# This Makefile drives the building of those scratchbox components
# which are built inside scratchbox
#
# USAGE:
#
# o This target can be called with COMPILERGAR, ARCH, SUB_ARCH and optional CPU:
#
#     build-toolchain
#
# o These targets can be called with GCCDIR, GCCPREFIX, CC and TARGETNAME:
#
#     build-devicetools
#     build-archtools
#     build-testtools
#
#     build-fakeroot
#     build-sbrsh
#     build-strace
#     build-gdb
#     build-gdbserver
#     build-libtool
#

default:
	@echo "Use custom-target-kit.sh instead..."
	@false

PATH = $(shell echo /scratchbox/devkits/debian/bin:$$PATH)
export PATH

configure:
	@if ! dpkg --version > /dev/null 2>&1; then \
		echo "ERROR: You need the Debian tools (/scratchbox/devkits/debian/bin) to build these!"; \
		false; \
	fi
	@if ! (touch /scratchbox/.test && rm /scratchbox/.test); then \
		echo "ERROR: You must have write access to /scratchbox/ to build these!"; \
		echo "ERROR: See 'scripts/permhack' in the Scratchbox source tree..."; \
		false; \
	fi

build-toolchain:
	$(MAKE) -C $(COMPILERGAR) ARCH=$(ARCH) SUB_ARCH=$(SUB_ARCH) CPU=$(CPU) COMPILERNAME=$(COMPILERNAME) superclean
	$(MAKE) -C $(COMPILERGAR) ARCH=$(ARCH) SUB_ARCH=$(SUB_ARCH) CPU=$(CPU) COMPILERNAME=$(COMPILERNAME) install

build-devicetools: build-fakeroot build-sbrsh build-strace build-gdbserver

build-fakeroot:
	$(MAKE) -C ../../device_tools/fakeroot clean
	$(MAKE) -C ../../device_tools/fakeroot install

build-sbrsh:
	$(MAKE) -C ../../device_tools/sbrsh clean
	$(MAKE) -C ../../device_tools/sbrsh install

build-strace:
	$(MAKE) -C ../../device_tools/strace clean
	$(MAKE) -C ../../device_tools/strace install

build-gdbserver:
	$(MAKE) -C ../../device_tools/gdbserver clean
	$(MAKE) -C ../../device_tools/gdbserver install

build-archtools: build-libtool build-gdb

build-libtool:
	$(MAKE) -C ../../autotools/libtool clean
	$(MAKE) -C ../../autotools/libtool install

build-gdb:
	$(MAKE) -C ../../device_tools/gdb clean
	$(MAKE) -C ../../device_tools/gdb install

build-testtools:
	$(MAKE) -C ../../test_tools/tcl clean
	$(MAKE) -C ../../test_tools/tcl install
	$(MAKE) -C ../../test_tools/expect clean
	$(MAKE) -C ../../test_tools/expect install
	$(MAKE) -C ../../test_tools/dejagnu clean
	$(MAKE) -C ../../test_tools/dejagnu install
