OBJS = init/head.o init/main.o kernel/kernel.o kernel/rlib/rlib.o modules/modules.o  
BOOT_SRCS = boot/boot.asm boot/loader.asm 
BOOT_OBJS = boot/boot.bin boot/loader.bin 


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

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

vmxnix: Makefile 
	ld -b elf64-x86-64 $(OBJS) -e init -T kernel.lds -o vmxnix


xnix.img: Makefile kbinary tools/initcfs tools/mkfs 
	dd if=/dev/zero of=xnix.img bs=1048576 count=64
	tools/mkfs xnix.img 
	tools/initcfs xnix.img boot/boot.bin boot/loader.bin kbinary 


lines: 
	wc -l `find ./ -name *.asm -o -name *.c -o -name *.h -o -name *.S -o -name *.s`

files: 
	find ./ -name *.asm -o -name *.c -o -name *.h -o -name *.S -o -name *.s | wc -l 

clear: 
	make -C boot/ clear
	make -C init/ clear
	make -C kernel/ clear
	make -C kernel/rlib clear
	make -C tools/ clear
	rm xnix.img kbinary kernel.o vmxnix 
	make -C modules/ clear

