# MAKEFILE - MAKEFILE
#
# Copyright (c) 2012 Mark Ball. All rights reserved.
# Started by Mark Ball, August 2012
#
# Makefile for Duckie Egg
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

.SUFFIXES: .o .s .c

#--------------------------------------------------------------------------
# ROM style.
#--------------------------------------------------------------------------
ROM_NAME = duckie.rom        # Output ROM name.
ROM_TYPE = cart             # cart or bjl for the linker's script.

#--------------------------------------------------------------------------
# Output control.
#--------------------------------------------------------------------------
#MAP_FILE = -M      # Uncomment to generate a symbol table.
#TRACE_LINK = -t    # Uncomment to trace linker's file access.
#VERBOSE_OUT = -v   # Uncomment to see verbose output.

#--------------------------------------------------------------------------
# Paths (relative to this one).
#--------------------------------------------------------------------------
TOOLS_PATH  = ..\..\bin    # Location of the compiler/assembler etc.
VBCC_PATH   = ..\..\lib    # Location of the VBCC library.
INC_PATH    = ..\inc       # Location of the header files.
LIB_PATH    = ..\lib       # Location of the libraries.
CFG_PATH    = ..\..\cfg    # Location of the ROM link scripts.

#--------------------------------------------------------------------------
# Tools.
#--------------------------------------------------------------------------
AS = $(TOOLS_PATH)\smac.exe    # Assembler.
CC = $(TOOLS_PATH)\vc.exe      # "C" compiler.
LD = $(TOOLS_PATH)\vlink.exe   # Linker.
#LD = $(TOOLS_PATH)\vc.exe   # Linker.

#--------------------------------------------------------------------------
# Tool command lines.
#--------------------------------------------------------------------------
AFLAGS = -fb -i$(INC_PATH)\asm
CFLAGS = $(VERBOSE_OUT) -DJAGUAR -I$(INC_PATH) -c99 -O2 -c -final -unsigned-char -maxoptpasses=50
LFLAGS = -b rawbin2 $(TRACE_LINK) -s -S -x -X -T$(CFG_PATH)\$(ROM_TYPE).link
LFLAGS = $(LFLAGS) startup.o -L$(VBCC_PATH) -lvbcc -L$(LIB_PATH) -ljlibc -lu235se -ljaghw

#--------------------------------------------------------------------------
# Rules
#--------------------------------------------------------------------------

# *.c to *.o
.c.o:
	@$(CC) -o $(*).o $(CFLAGS) $<

# *.s to *.o
.s.o:
	@$(AS) -o $@ $(AFLAGS) $<

STARTUP =  startup.o

#--------------------------------------------------------------------------
# Object files that make the example.
#--------------------------------------------------------------------------
OBJS =   chuckie.o \
        main.o \
        screen.o \
        utils.o \
        leveldata.o \
        leveldataa.o \
        blitbitmap.o \
        tilesa.o \
        hensa.o \
        playera.o \
        liftsa.o \
        titlea.o \
        sound.o \
        sounda.o \
        font.o \
        fonta.o \
        credits.o \
        highscores.o \
        options.o \
        effectsa.o \
        backsa.o 

#--------------------------------------------------------------------------
# All.
#--------------------------------------------------------------------------
all: clean $(STARTUP) $(OBJS) rom
#all: $(STARTUP) $(OBJS) rom padding copy

#--------------------------------------------------------------------------
# newgfx
#--------------------------------------------------------------------------
newgfx: clean $(STARTUP) $(OBJS) rom padding

#--------------------------------------------------------------------------
# ROM.
#--------------------------------------------------------------------------
rom:
    $(LD) -o $(ROM_NAME) $(MAP_FILE) $(LFLAGS) $(OBJS) ..\lib\dsp.o

#--------------------------------------------------------------------------
# PADDING
#--------------------------------------------------------------------------
padding:
    if "$(ROM_TYPE)" == "cart" jagpad.exe $(ROM_NAME)

#--------------------------------------------------------------------------
# COPY
#--------------------------------------------------------------------------
copy:
    @if exist $(ROM_NAME) copy $(ROM_NAME) ..\..\vj\software

#--------------------------------------------------------------------------
# Clean up.
#--------------------------------------------------------------------------
clean:
    @if exist $(ROM_NAME) del $(ROM_NAME)
    @if exist *.o del *.o
    @if exist *.bin del *.bin
    @if exist *.bjl del *.bjl
    @if exist *.bin.* del *.bin.*
    @if exist *.rom del *.rom
    @if exist *.rom.* del *.rom.*
    @if exist *.asm del *.asm
    @if exist virtualjaguar.log del virtualjaguar.log
  	
