#================================================================
#  Makefile
#               Makefile for 25thanni
#
#================================================================
#
# 25thanni, a demo dedicated to the 25th anniversary of the ZX81.
#
# (c)2006 Bodo Wenzel
#
# 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 2 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, write to the Free
# Software Foundation Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#================================================================
# The tools used for this project:
# Z80 assembler and linker from SDCC 2.3.0 (sdcc.sourceforge.net)
# Intelhex converter Hex2Bin 1.0.0 by Jacques Pelletier
# Make, zip, bash, and other common unix stuff...
#================================================================

.DELETE_ON_ERROR:

.PHONY:	all graph dist

all:	25thanni.p
graph:	graph.p
dist:	25thanni.zip

# Options for the assembler:
# p  disable listing pagination
# l  create list file <file>.lst
# o  create object file (name given)
# ff flag relocatable by mode in listing
ASFLAGS= -ploff

# Options for the linker:
# n disable echo to stdout
# c command line mode
# - flags the following parameters as input
# b specifies a base address for an area
# m create a map file <file>.map
# u update listing file(s) <file>.rst
# At each explizit link line:
# i specifies the filename stem for the intelhex file, full name
#   works also
LDFLAGS= -n -c -- -bVAR=0x4009 -m -u

# Options for the hex2bin converter:
# e specifies the extension of the binary file
HBFLAGS= -e p

25thanni.ihx:	basic.o main.o matrix.o fire.o jump.o magnify.o \
		wobble.o hopper.o hidden.o text.o hrg.o delay.o \
		random.o math.o unpack.o
	link-z80 $(LDFLAGS) -i $@ $^

matrix.o:	matr_scr.inc matr_sl.inc

fire.o:		fire_sl.inc

jump.o:		jump_sl.inc

magnify.o:	magn_bg.inc magn_sl.inc

wobble.o:	wobb_lg.inc wobb_sl.inc

hopper.o:	hopp_bg.inc hopp_sl.inc

hidden.o:	hidd_lg.inc

math.o:		sinetab.inc acostab.inc

sinetab.inc:	gen_sine
	$< > $@

acostab.inc:	gen_acos
	$< > $@

%.p:		%.ihx
	hex2bin $(HBFLAGS) $< > /dev/null

%.o:		%.s
	as-z80 $(ASFLAGS) $@ $<

%.inc:		%.xpm xpm2s
	xpm2s < $< > $@

%.inc:		%.txt txt2s
	txt2s < $< > $@

xpm2s:		xpm2s.c pack.c
	gcc -std=c99 -Wall -s $^ -o $@

txt2s:		txt2s.c pack.c
	gcc -std=c99 -Wall -s $^ -o $@

gen_sine:	gen_sine.c
	gcc -std=c99 -Wall -s $< -lm -o $@

gen_acos:	gen_acos.c
	gcc -std=c99 -Wall -s $< -lm -o $@

25thanni.zip:	README COPYING 25thanni.p Makefile \
		xpm2s.c txt2s.c pack.c pack.h \
		gen_sine.c gen_acos.c \
		basic.s main.s graph.s \
		matrix.s matr_scr.txt matr_scr.inc matr_sl.txt \
		matr_sl.inc \
		fire.s fire_sl.txt fire_sl.inc \
		jump.s jump_sl.txt jump_sl.inc \
		magnify.s magn_bg.xpm magn_bg.inc magn_sl.txt \
		magn_sl.inc \
		wobble.s wobb_lg.xpm wobb_lg.inc wobb_sl.txt \
		wobb_sl.inc \
		hopper.s hopp_bg.xpm hopp_bg.inc hopp_sl.txt \
		hopp_sl.inc \
		hidden.s hidd_lg.xpm hidd_lg.inc \
		text.s hrg.s delay.s random.s math.s \
		sinetab.inc acostab.inc unpack.s
	zip $@ $^

### The end #####################################################
