#---------------------------------------------------------------
# project definitions
#---------------------------------------------------------------
project = labpro-cubis

#---------------------------------------------------------------
# creation order
#---------------------------------------------------------------
GPL_TARGETS = toolchain%step1 linux uClibc toolchain%step2 busybox firmware-gpl
GPL_SUBDIRS = toolchain linux uClibc busybox firmware-gpl

gpl-make-all = $(foreach target,$(GPL_TARGETS),gpl-make-all-$(target).done)

#-------------------------------------
# the build rule
#-------------------------------------
all : $(gpl-make-all)

maketarget-toolchain%step1=all-step1
maketarget-toolchain%step2=all-step2
maketarget-uClibc = all install

gpl-make-all-%.done :
	mkdir -vp build
	[ -d build/$(project)-$(word 1,$(subst %, ,$*)) ] || tar -C build -xjf $(project)-$(word 1,$(subst %, ,$*)).tar.bz2
	set -o pipefail && cd build/$(project)-$(word 1,$(subst %, ,$*)) && make $(maketarget-$*) 2>&1 | tee make-$*.log
	touch $@

clean: $(foreach subdir,$(GPL_SUBDIRS),clean-$(subdir))
	-rm -f $(all-targets) *.log

clean-% :
	-cd $(project)-$* && make clean

distclean: $(foreach subdir,$(GPL_SUBDIRS),distclean-$(subdir))
	-rm -f *.done *.log
	-rm -rf local

distclean-% :
	-cd $(project)-$* && make distclean
