
# happyness is a good makefile. save much time in debugging
# if someting gets changed depends on something else...
# this one has some bugs, but is pretty good
# bugs are: the includes for game.c: Models/xxx_init.c should be in here

# binutils are version 2.7.1
# gcc is version 2.7.2.3 (shouldn't be important */

# ld version 2.7 with bfd 2.7
LD = /usr/mips/bin/mips-sgi-irix5-ld

# 2.7.2.3 gcc
CC = /usr/mips/bin/mips-sgi-irix-gcc

# as is version 2.7
AS = /usr/mips/bin/mips-sgi-irix-as

# my ppm converter, look in Textures for source
PPM2C = ./Textures/ppm2c

# sox converter: mainly for .wav to .raw
SOX = ./Sounds/sox

# raw to c
RAW2C = ./Sounds/sound2c

INCLUDES =	-I. -I/usr/include/PR -I/usr/include -I./Textures -I./Models -I./font

# -G 0 and -fno-common keep all data in .data instead of .lit* .?common etc.
# makes ld.script easier 
CFLAGS =	-O3 -mips2 -mcpu=r4000 -non_shared -G 0 -fno-common -mgas -mfp32 \
		-fomit-frame-pointer -fcaller-saves -fdelayed-branch -fschedule-insns \
		-fverbose-asm

ASFLAGS =	-O3 -mips2 -mcpu=r4000

# mapfile is if I screw something up (typically model/textures in wrong seg)
LDFLAGS = -Map mapfile

# objcopy is v 2.7
MAKEROM = /usr/mips/bin/mips-sgi-irix-objcopy --input-target=ecoff-bigmips \
	--output-target=binary

# stan's tools
CHKSUM = /usr/people/paul/n64/linux/chksum/bin-unix/chksum64.linux-binary
TALK64 = /usr/people/paul/n64/linux/talk64/src/talk64

# it optimizes now!!! convert softimage .hrc into .gbi
HRC2GBI = ./Models/hrc2gbi

# general purpose file hacker/swabber
DD = dd

# compiled for irix5... same as ld
# binutils version 2.8.1 has --adjust-vma
DIS = /usr/mips/bin/mips-sgi-irix5-objdump --target=binary \
	--architecture=mips -D -EB --adjust-vma 0x80000400 

APP = myrom.o

HFILES = stdio.h font.h game.h

TARGET = makka.V64

PPMS = ./Textures/scales.c

# .o are aligned on 16 byte boundaries
TEXTURES = ./Textures/scales.o

HRCS = Models/M_breakup.c

MODELS = Models/M_breakup.o

RAWS = 

SOUNDS = 

# bootstrap.c is a hack that allow us to link bins to our stuff
# MODELS and TEXTURES get put in ld.script, all others go here
OBJECTS = main.o explode.o\
	bootstrap.o static.o crt0.o stdio.o font.o \
	gfxlib.o time.o dram_stack.o \
	$(SOUNDS)

OFILES = $(SOUNDS) $(MODELS) $(TEXTURES) $(OBJECTS)

# crt0.s is our c-runtime-0 file, it zero's bss loads sp and calls boot()
# time returns the r4300 real-time register
SFILES = crt0.s time.s

default: $(TARGET)

.c.o : $(HFILES)
	$(CC) $(CFLAGS) -c $(INCLUDES) -o $*.o $*.c

.s.o :
	$(AS) $(AFLAGS) -o $*.o $*.s

$(HRCS):
	$(HRC2GBI) $*.hrc $*

$(PPMS):
	$(PPM2C) $*.ppm $*.c

# use sox to convert .wav to .raw
#	$(SOX) -V $*.wav -r 11025 -s -w -c 2 $*.raw
# -r 11025 rate, -s=sign 2's complement, -w = word, -c 2=2 channel

$(RAWS) :
	$(RAW2C) $*.raw $*.c

# models and textures must be put in ld.script
# but dependencies go in OFILE (ie: if they change $APP will be rebuilt)
$(APP):	$(OFILES) ld.script
		$(LD) $(LDFLAGS) -o $(APP) $(OBJECTS) /usr/lib/PR/libultra.a -T ld.script

$(TARGET): $(APP)
		$(MAKEROM) $(APP) $(TARGET)
		$(CHKSUM) $(TARGET)

talk : $(TARGET)
	$(TALK64) -l $(TARGET)

dis : $(TARGET)
	echo $(DIS)
	$(DD) if=$(TARGET) of=$(TARGET).noheader bs=4096 skip=1
	$(DIS) $(TARGET).noheader > $(TARGET).noheader.dis

clean :
	rm -f $(OFILES) $(TEXTURES) $(MODELS) $(TARGET) $(APP) mapfile

backup :
	cd ..; tar -cvf makka.tar makka; gzip makka.tar

