#
# Makefile for the Arcade Graphics Editor (AGE)
#
#  Written by Ivan Mackintosh (ivan@rcp.co.uk)
#         and Scott "Jerry" Lawrence (jerry@mail.csh.rit.edu)
#         ans Chris "Zwaxy" Moore (chris.moore@writeme.com)
#

# Compiler flags
# 
#CFLAGS = -m486 -s -Wall
#  yields 507k executable (and compiles the fastest!)
#
#CFLAGS = -m486 -s -O3 -finline-functions -funroll-all-loops -fomit-frame-pointer -Wall
#  yields 499k executable
#
#CFLAGS = -m486 -s -O3 -Wall
#  yields 379k executable
#
CFLAGS = -m486 -s -O2 -fomit-frame-pointer -Wall
#  yields 367k executable
#
# -O2 is great for size reduction, -O3 turns on -finline-functions
#  which chews up lotsa space for the executable.  
#  Since AGE doesn't need to be superfast, -O2 should be enough


OBJS = age.o \
	ini.o \
	drivers.o \
	coding.o \
	fileio.o \
	scratch.o \
	mouse.o \
	tools.o \
	palette.o \
	utils.o \
	texted.o \
	snap.o \
	maped.o \
   help.o

MAPED = maped/pacman.o 

DRIVERS = drivers/centiped.o \
	  drivers/pacman.o \
	  drivers/scramble.o \
	  drivers/rallyx.o \
	  drivers/galaxian.o \
	  drivers/galaga.o \
	  drivers/vanguard.o \
	  drivers/frogger.o \
	  drivers/boblbobl.o \
	  drivers/mrdo.o \
	  drivers/mcr2.o \
	  drivers/mappy.o \
	  drivers/gottleib.o \
	  drivers/dkong.o \
	  drivers/brubber.o \
	  drivers/amidar.o \
	  drivers/jrpacman.o \
	  drivers/digdug.o \
	  drivers/pooyan.o \
     drivers/cps1.o

LIBS = -lalleg 

all: age.exe

# build the main executable:
age.exe: $(OBJS) $(DRIVERS) $(MAPED) 
	gcc -g -o age.exe $(OBJS) $(MAPED) $(DRIVERS) $(LIBS)

# build the keystroke grabber
keys.exe: keys.o
	gcc -g -o keys.exe keys.o


%.o:   %.c age.h drivers.h
	gcc $(CFLAGS) -c -o $@ $<

# for this next bit, you're going to need the DJP compression utility
# found at the djgpp archive in v2misc/mlp106b.zip (only a 50k download)
# this reduces the executable from 370k -> 155k !
distrib: clean age.exe
	strip age.exe
	djp age.exe
	if exist distrib\*.txt del distrib\*.txt
	if exist distrib\*.exe del distrib\*.exe
	mkdir distrib
	copy age.exe distrib
	copy readme.txt distrib
	copy maped.txt distrib
	copy texted.txt distrib
	copy whatsnew.txt distrib

# clean your room!  do your homework!  get a haircut!
clean:
	if exist *.o del *.o 
	if exist *.pcx del *.pcx 
	if exist drivers\*.o del drivers\*.o
	if exist maped\*.o del maped\*.o
	if exist snapshot\*.pcx del snapshot\*.pcx
	if exist distrib\*.* deltree /y distrib
	if exist age.exe del age.exe
	if exist keys.exe del keys.exe
	if exist *.ini del *.ini 

# if you don't have the unix-style commands: rm, mv, cp, you need to 
# get them from the File Utils package available at any DJGPP/GCC 
# distribution site.. 
backup: clean
	if exist \zip\age6_old.zip del \zip\age6_old.zip
	if exist \zip\age6_bak.zip copy \zip\age6_bak.zip \zip\age6_old.zip
	if exist \zip\age6_bak.zip del \zip\age6_bak.zip
	pkzip -rp -ex \zip\age6_bak.zip *.*

# make a backup onto a floppy disk
floppy: backup
	if exist a:\age6_bak.zip del a:\age6_bak.zip
	copy \zip\age6_bak.zip a:\
