#
#	Makefile -- Build instructions for Alfa/Hornet-UB
#

ROMFSIMG  = $(IMAGEDIR)/rootfs.bin
ZROMFSIMG = $(IMAGEDIR)/rootfs.bin.gz
UROMFSIMG = $(IMAGEDIR)/urootfs.bin
VMLINUX   = $(IMAGEDIR)/vmlinux
KERNEL    = $(IMAGEDIR)/kernel
LZKERNEL  = $(IMAGEDIR)/kernel.lzma
UKERNEL   = $(IMAGEDIR)/ukernel.bin

ROMFS_DIRS = \
	bin \
	dev \
	etc etc/config etc/default \
	home home/httpd \
	lib lib/modules \
	mnt \
	proc \
	sbin \
	tmp \
	usr usr/bin usr/sbin \
	var

DEVICES = \
	mem,c,1,1	kmem,c,1,2	null,c,1,3 \
	zero,c,1,5	random,c,1,8	urandom,c,1,9 \
	ram0,b,1,0	ram1,b,1,1	ram2,b,1,2	ram3,b,1,3 \
	\
	tty,c,5,0	console,c,5,1	cua0,c,5,64	cua1,c,5,65 \
	tty0,c,4,0	tty1,c,4,1	tty2,c,4,2	tty3,c,4,3 \
	ttyS0,c,4,64	ttyS1,c,4,65 \
	\
	ptyp0,c,2,0	ptyp1,c,2,1	ptyp2,c,2,2	ptyp3,c,2,3 \
	ptyp4,c,2,4	ptyp5,c,2,5	ptyp6,c,2,6	ptyp7,c,2,7 \
	ptyp8,c,2,8	ptyp9,c,2,9	ptypa,c,2,10	ptypb,c,2,11 \
	ptypc,c,2,12	ptypd,c,2,13	ptype,c,2,14	ptypf,c,2,15 \
	\
	ttyp0,c,3,0	ttyp1,c,3,1	ttyp2,c,3,2	ttyp3,c,3,3 \
	ttyp4,c,3,4	ttyp5,c,3,5	ttyp6,c,3,6	ttyp7,c,3,7 \
	ttyp8,c,3,8	ttyp9,c,3,9	ttypa,c,3,10	ttypb,c,3,11 \
	ttypc,c,3,12	ttypd,c,3,13	ttype,c,3,14	ttypf,c,3,15 \
	\
	mtd0,c,90,0	mtdr0,c,90,1	mtdblock0,b,31,0 \
	mtd1,c,90,2	mtdr1,c,90,3	mtdblock1,b,31,1 \
	mtd2,c,90,4	mtdr2,c,90,5	mtdblock2,b,31,2 \
	mtd3,c,90,6	mtdr3,c,90,7	mtdblock3,b,31,3 \
	mtd4,c,90,8	mtdr4,c,90,9	mtdblock4,b,31,4 \
	mtd5,c,90,10	mtdr5,c,90,11	mtdblock5,b,31,5 \
	mtd6,c,90,12	mtdr6,c,90,13	mtdblock6,b,31,6 \
	mtd7,c,90,14	mtdr7,c,90,15	mtdblock7,b,31,7 \
	\
	ipsec,c,36,10 \
	ppp,c,108,0

all:

clean:

mksquashfs:
	CC=$(HOSTCC) CFLAGS=$(HOSTCFLAGS) EXTRA_CFLAGS= make -C $(ROOTDIR)/user/squashfs-new/squashfs-tools mksquashfs
	ln -fs $(ROOTDIR)/user/squashfs-new/squashfs-tools/mksquashfs .

romfs:
	[ -d $(ROMFSDIR) ] || mkdir -p $(ROMFSDIR)
	for i in $(ROMFS_DIRS); do \
		[ -d $(ROMFSDIR)/$$i ] || mkdir -p $(ROMFSDIR)/$$i; \
	done
	$(ROMFSINST) /etc/rc
	$(ROMFSINST) /etc/inittab
	$(ROMFSINST) ../../Generic/romfs/etc/services /etc/services
	$(ROMFSINST) /etc/motd
	$(ROMFSINST) /etc/passwd
	$(ROMFSINST) /etc/group
	echo "$(VERSIONSTR) -- " `date` > $(ROMFSDIR)/etc/version

image: mksquashfs
	[ -d $(IMAGEDIR) ] || mkdir -p $(IMAGEDIR)
	rm -f $(ROMFSIMG)
	MKSQUASHFS=`pwd`/mksquashfs ; cd $(ROMFSDIR) ; \
	$$MKSQUASHFS . $(ROMFSIMG) -all-root -noappend
	cp $(ROOTDIR)/$(LINUXDIR)/vmlinux $(VMLINUX)
	$(OBJCOPY) -O binary $(VMLINUX) $(KERNEL)
	lzma -c $(KERNEL) > $(LZKERNEL)
	mkimage -A mips -O linux -T kernel -C lzma -a 0x80060000 -e 0x80060000 -n "Linux-3.x" -d $(LZKERNEL) $(UKERNEL)
	mkimage -A mips -O linux -T ramdisk -C none -a 0x80800000 -n "ramdisk" -d $(ROMFSIMG) $(UROMFSIMG)
	if [ -d /tftpboot ]; then \
		cp $(UKERNEL) /tftpboot ; \
		cp $(UROMFSIMG) /tftpboot ; \
	fi

