OBJS = boot/bootsect 
KOBJS = init/head.o init/main.o modules/tty.o kernel/tty.o kernel/int.o kernel/trap.o
KSRCS = init/head.S init/main.c modules/tty.c kernel/tty.S kernel/int.c kernel/trap.S

all: Makefile
	make -C boot/
	make -C init/
	make -C modules/
	make -C kernel/ 
	make xnix.img

kbinary: $(KSRCS) boot/bootsect Makefile
	ld -b elf64-x86-64 -o kernel.o $(KOBJS) -T kernel.lds
	objcopy -I elf64-x86-64 -S -R ".comment" -R ".eh_frame" -O binary kernel.o kbinary

vmxnix:
    gcc kernel.o –s init vmxnix
xnix.img: boot/bootsect $(KSRCS) Makefile kbinary
	dd if=/dev/zero of=xnix.img bs=1024 count=1440
	dd if=boot/bootsect of=xnix.img conv=notrunc seek=0
	dd if=kbinary of=xnix.img conv=notrunc bs=512 seek=2


lines: Makefile
	wc -l `find ./ -name *.asm -o -name *.c -o -name *.h -o -name *.S -o -name *.s`
	wc -l `find ./ -name *.asm -o -name *.c -o -name *.h -o -name *.S -o -name *.s`|grep total|awk '{print $1}'>lines


clear: Makefile
	make -C boot/ clear
	make -C init/ clear
	make -C modules/ clear
	make -C kernel/ clear
	rm boot/bootsect
	rm xnix.img kbinary kernel.o



