#########################################################################
# Makefile for the ALMOS-MKH "ksh" 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 = ksh.o                    \
       $(LIBS)/build/stdlib.o   \
       $(LIBS)/build/stdio.o    \
       $(LIBS)/build/nostdio.o  \
       $(LIBS)/build/string.o   \
       $(LIBS)/build/malloc.o   \
       $(LIBS)/build/pthread.o  \
       $(LIBS)/build/hal_user.o
       

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

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

ksh.o : ksh.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/nostdio.o : $(LIBS)/nostdio.c $(LIBS)/nostdio.h
	$(CC) $(INCLUDES) $(CFLAGS) -c -o  $@ $<
	$(DU) -D $@ > $@.txt

$(LIBS)/build/string.o : $(LIBS)/string.c $(LIBS)/string.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

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

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


