#########################################################################
# Makefile for the ALMOS-MKH "init" application on the TSAR architecture
#########################################################################

CC = mipsel-unknown-elf-gcc
AS = mipsel-unknown-elf-as
LD = mipsel-unknown-elf-ld
DU = mipsel-unknown-elf-objdump
AR = mipsel-unknown-elf-ar

LIBS = ../../libs

HAL  = ../../hal

KERNEL = ../../kernel

CFLAGS = -Wall -ffreestanding -mno-gpopt -mips32 -g -O2 \
		 -fno-delete-null-pointer-checks -fomit-frame-pointer

OBJS = init.o                    \
       $(LIBS)/build/stdlib.o    \
       $(LIBS)/build/stdio.o     \
       $(LIBS)/build/pthread.o   \
       $(LIBS)/build/malloc.o    \
       $(LIBS)/build/hal_user.o

INCLUDES = -I.                   \
           -I../..               \
           -I$(LIBS)/            \
           -I$(KERNEL)/syscalls  \
           -I$(HAL)/generic

init.elf : $(OBJS) init.ld
	$(LD) -o $@ -T init.ld $(OBJS) 
	$(DU) -D $@ > $@.txt

init.o : init.c
	$(CC) $(INCLUDES) $(CFLAGS) -c -o  $@ $<
	$(DU) -D $@ > $@.txt

$(LIBS)/build/hal_user.o : $(HAL)/tsar_mips32/core/hal_user.c $(HAL)/generic/hal_user.h
	$(CC) $(INCLUDES) $(CFLAGS) -c -o  $@ $<
	$(DU) -D $@ > $@.txt

$(LIBS)/build/stdlib.o : $(LIBS)/stdlib.c $(LIBS)/stdlib.h
	$(CC) $(INCLUDES) $(CFLAGS) -c -o  $@ $<
	$(DU) -D $@ > $@.txt

$(LIBS)/build/stdio.o : $(LIBS)/stdio.c $(LIBS)/stdio.h
	$(CC) $(INCLUDES) $(CFLAGS) -c -o  $@ $<
	$(DU) -D $@ > $@.txt

$(LIBS)/build/pthread.o : $(LIBS)/pthread.c $(LIBS)/pthread.h
	$(CC) $(INCLUDES) $(CFLAGS) -c -o  $@ $<
	$(DU) -D $@ > $@.txt

$(LIBS)/build/malloc.o : $(LIBS)/malloc.c $(LIBS)/malloc.h
	$(CC) $(INCLUDES) $(CFLAGS) -c -o  $@ $<
	$(DU) -D $@ > $@.txt



clean:
	rm -f *.o *.elf *.txt core $(LIBS)/build/*.o $(LIBS)/build/*.txt
