# Makefiel for ominOS 0.0.1
# jesus fuck...this is the shittiest makefile ever :( 
# 2005-05-22: used to be the worst. cleaned it up and redid it today.

.EXPORT_ALL_VARIABLES:

TOPDIR:=$(shell pwd)

include tools/defconfig

# Directories
KERNEL		= $(TOPDIR)/kernel
LIB		= $(TOPDIR)/omlib
DRIVERS		= $(TOPDIR)/drivers
MM		= $(TOPDIR)/mm
I386		= $(TOPDIR)/i386
BOOT		= $(TOPDIR)boot
INCLUDE		= $(TOPDIR)/include
MENU_CONFIG	= $(TOPDIR)/tools/lxdialog

# Program Files
CC		= gcc
LD		= ld
NASM		= nasm
RM		= rm
ifeq "$(CONFIG_GENERAL_SILENT)" "y"
MAKE		= make -s
else
MAKE		= make
endif

# Flags
DEBUG		=  
CFLAGS		= -Wall -O0 -ffreestanding -nostdinc -nostdlib -fno-builtin -Wstrict-prototypes -fno-leading-underscore -m32 -I$(INCLUDE) $(DEBUG)
LDFLAGS		= -T kernel.ld

KERNEL32_TARGET	= kernel.bin
KERNEL32_OUT = $(TOPDIR)/$(KERNEL32_TARGET)

SUBDIRS		= boot drivers i386 kernel mm omlib

default: all image clean distclean

noclean: all image 

all:
	@for dir in $(SUBDIRS);\
		do ( $(MAKE) -C $$dir all);\
	done
	@echo Linking...;
	$(LD) $(LDFLAGS) -o $(KERNEL32_OUT) *.o 

config:
	$(MAKE) -C $(MENU_CONFIG) all
	./config.sh	

image:
	dd if=boot.bin bs=512 count=1 of=ominos.img
	dd if=kernel.bin of=ominos.img seek=1

disk:
	dd if=ominos.img of=/dev/fd0

clean:
	@echo -n Cleaning up...
	@$(RM) *.o
	@$(RM) *.bin
	@for dir in $(SUBDIRS);\
		do ( $(MAKE) -C $$dir clean);\
	done
	@echo done

distclean:
	@echo -n Cleaning up dependencies... 
	@for dir in $(SUBDIRS);\
		do ( $(MAKE) -C $$dir distclean);\
	done
	@echo done

wc:
	@wc -l `find . -type f`

include buildrules.inc
