include ../../$(CONFIG)

GARNAME = device-tools
GARVERSION = 1
CATEGORIES = meta

DEPENDS = 

include ../category.mk

AUTOTOOLS = libtool
TOOLS = fakeroot sbrsh strace gdbserver gdb

ENV =	TARGETNAME=$(COMPILER_NAME) \
	GCCDIR=$(SBOX_COMPILERS_DIR)/bin \
	GCCPREFIX=$(TARGET)- \
	CC=$(COMPILER_DIR)/bin/$(TARGET)-gcc \
	CXX=$(COMPILER_DIR)/bin/$(TARGET)-g++ \
	TARGET=$(TARGET)

device-tools: build-fakeroot build-sbrsh  build-strace build-gdbserver 
	$(MAKECOOKIES)

arch-tools: build-libtool build-gdb
	$(MAKECOOKIES)

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

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

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

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

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

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

clean-all:
	for TOOLS in fakeroot sbrsh strace gdbserver gdb; do \
	  $(MAKE) -C ../../device_tools/$$TOOLS $(ENV) clean; \
	done
	$(MAKE) -C ../../autotools/libtool $(ENV) clean
	$(MAKECOOKIES)

#
# target for generating "master checksums" file
# makes checksums for all files needed for building specified toolchain
#
all-sums:
	set -e; \
	for tool in $(AUTOTOOLS); do \
		$(MAKE) -C ../../autotools/$$tool CHECKSUM_FILE=checksums makesum;\
		test -f ../../autotools/$$tool/checksums && cat ../../autotools/$$tool/checksums >> $(CHECKSUM_FILE);\
	done; \
	for tool in $(TOOLS); do \
		$(MAKE) -C ../../device_tools/$$tool CHECKSUM_FILE=checksums makesum;\
		test -f ../../device_tools/$$tool/checksums && cat ../../device_tools/$$tool/checksums >> $(CHECKSUM_FILE);\
	done; \
	sort -u -k 2 $(CHECKSUM_FILE) > $(CHECKSUM_FILE).sorted; \
	mv $(CHECKSUM_FILE).sorted $(CHECKSUM_FILE)


