# This makefile uses dispatch.sh to build using an
# architecture-independent makefile, ie: Makefile.x86.  The makefile is
# chosen based on the value of Config.sh's BOOTARCH.

all: 
	scripts/dispatch.sh all

rescue: testonce
	scripts/dispatch.sh rescue

superrescue: testonce
	scripts/dispatch.sh superrescue

CD-ROM:
	scripts/dispatch.sh CD-ROM

path:
	scripts/dispatch.sh $@

device:
	scripts/dispatch.sh device

OBDR:
	scripts/dispatch.sh OBDR

clean:
	scripts/dispatch.sh clean

test:
	scripts/dispatch.sh test

testonce:
	rm -f /tmp/.mkcdrec.tests.not.passed ; \
	if [ ! -f /tmp/.mkcdrec.tests.passed ]; then \
		make test ; \
	fi ;\
	if [ -f /tmp/.mkcdrec.tests.not.passed ]; then \
	   exit 1 ; \
	fi

help:
	scripts/dispatch.sh help

debug:
	mkdir -p /mnt/iso /mnt/img /mnt/img2 /mnt/img3
	mount -o loop /tmp/CDrec.iso /mnt/iso
	mount -o loop /mnt/iso/boot/boot.img /mnt/img
	cp /mnt/img/boot/initrd.img /tmp/initrd.img.gz
	cp /mnt/iso/rd-base.img.bz2 /tmp/
	rm -f /tmp/initrd.img
	gunzip -c /tmp/initrd.img.gz > /tmp/initrd.img
	rm -f /tmp/rd-base.img
	bunzip2 -c /tmp/rd-base.img.bz2 > /tmp/rd-base.img
	mount -o loop /tmp/initrd.img /mnt/img2
	mount -o loop /tmp/rd-base.img /mnt/img3
	chroot /mnt/img3 

install:
	sed -e 's;^MKCDREC_HOME=/var/opt/mkcdrec;MKCDREC_HOME=$(PWD);' < contributions/mkcdrec >/usr/sbin/mkcdrec
	#echo "cd $(PWD); make \$$@" >/usr/sbin/mkcdrec
	chmod +x /usr/sbin/mkcdrec
	@echo "Command /usr/sbin/mkcdrec installed"
