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

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

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

pgcd.o : pgcd.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

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