# This makefile is for sfrotz v0.02 on Debian

 NOW = $(shell date +'%Y%m%d')

 RM = rm -f
 CP = cp -p

 DO := ./

 SDLINC = `sdl-config --cflags`
 FTCFLAGS = `freetype-config --cflags`
 FTLIBS = `freetype-config --libs`

 SYSTEMNAME = Linux


CC = gcc

# Define your optimization flags.
# Debugging (don't use)
#OPTS=-g 
# Standard
#OPTS=-O2 -fomit-frame-pointer
OPTS = -O2

# These defines add various features to the interpreter:
#    -DUSE_QUETZAL:   Use the interpreter-independent QUETZAL format for save
#                     files.
#    -DSOUND_SUPPORT: Enable sound support.

DEFS = -DUSE_QUETZAL -DSOUND_SUPPORT

CFLAGS = $(OPTS) $(DEFS)
LD = gcc

ifneq ($(MAKECMDGOALS),withoutsamplerate)
  SRSRC = sf_resample.c
  SRLIB = -lsamplerate
endif

LIBS = -ljpeg -lpng -lz -lSDL -lSDL_mixer $(SRLIB)

SFROTZ = buffer.c err.c fastmem.c files.c getopt.c hotkey.c input.c \
  main.c math.c object.c process.c quetzal.c random.c redirect.c \
  screen.c sound.c stream.c table.c text.c variable.c blorblib.c

SSDL = sf_resource.c sf_images.c sf_fonts.c sf_sound.c sf_util.c \
  sf_video.c sf_msg_en.c sf_deffont.c sf_font3.c \
  sf_ftype.c sf_osfdlg.c sf_sig.c sf_aiffwav.c $(SRSRC)

OFROTZ = $(SFROTZ:.c=.o)
OSDL = $(SSDL:.c=.o)

OBJS = $(OFROTZ) $(OSDL)

all: sfrotz

withoutsamplerate: sfrotz

LDFLAGS = -rdynamic

sfrotzmanual.html: sfm.txt makeman
	./makeman < sfm.txt > sfrotzmanual.html

makeman: makeman.c
	$(CC) -o makeman makeman.c

sfrotz: $(OBJS)
	$(LD) $(LDFLAGS) -o sfrotz -Xlinker -Map -Xlinker mymap.map $(OBJS) $(IMGLIB) $(LIBS) $(FTLIBS)

#################################################################

SOURCES = $(SFROTZ) $(SSDL)
HEADERS = frotz.h blorb.h blorblow.h sf_frotz.h

BACKUPNAME = back/s3$(NOW).tar

BACKUP = $(SOURCES) $(HEADERS) makefile makefile.mingw .sfrotzrc blx.c blorbscan2.c dfont.c sfm.txt makeman.c blurb.txt README INSTALL COPYING CHANGELOG

TRUEDIST = $(SOURCES) $(HEADERS) makefile makefile.mingw .sfrotzrc sfrotzmanual.html README INSTALL COPYING CHANGELOG
TRUEDISTNAME = sfrotz002.tar

##############################################################


backup:
	tar -c -f $(BACKUPNAME) $(BACKUP)
	gzip -vN $(BACKUPNAME)

distribution: sfrotzmanual.html
	tar -c -f $(TRUEDISTNAME) $(TRUEDIST)
	gzip -vN $(TRUEDISTNAME)

##################################

# dependency

#automatic dependencies 
buffer.o: buffer.c frotz.h
err.o: err.c frotz.h
fastmem.o: fastmem.c frotz.h
files.o: files.c frotz.h
getopt.o: getopt.c
hotkey.o: hotkey.c frotz.h
input.o: input.c frotz.h
main.o: main.c frotz.h
math.o: math.c frotz.h
object.o: object.c frotz.h
process.o: process.c frotz.h
quetzal.o: quetzal.c frotz.h
random.o: random.c frotz.h
redirect.o: redirect.c frotz.h
screen.o: screen.c frotz.h
sound.o: sound.c frotz.h
stream.o: stream.c frotz.h
table.o: table.c frotz.h
text.o: text.c frotz.h
variable.o: variable.c frotz.h

blorblib.o: blorblib.c blorb.h blorblow.h
sf_resource.o: sf_resource.c blorb.h frotz.h sf_frotz.h
sf_fonts.o: sf_fonts.c sf_frotz.h frotz.h 
sf_sig.o: sf_sig.c sf_frotz.h frotz.h 
sf_osfdlg.o: sf_osfdlg.c sf_frotz.h frotz.h 
sf_msg_en.o: sf_msg_en.c sf_frotz.h  frotz.h 
sf_aiffwav.o: sf_aiffwav.c sf_frotz.h  frotz.h 
sf_resample.o: sf_resample.c sf_frotz.h  frotz.h 

sf_util.o: sf_util.c sf_frotz.h  frotz.h 
	$(CC) $(CFLAGS) $(ZINC) -o sf_util.o -c sf_util.c

sf_images.o: sf_images.c sf_frotz.h frotz.h 
	$(CC) $(CFLAGS) $(IMGINC) -o sf_images.o -c sf_images.c

sf_video.o: sf_video.c sf_frotz.h frotz.h 
	$(CC) $(CFLAGS) $(SDLINC) -o sf_video.o -c sf_video.c

sf_sound.o: sf_sound.c sf_frotz.h  frotz.h 
	$(CC) $(CFLAGS) $(SDLINC) -o sf_sound.o -c sf_sound.c

sf_ftype.o: sf_ftype.c sf_frotz.h  frotz.h 
	$(CC) $(CFLAGS) $(FTCFLAGS) -o sf_ftype.o -c sf_ftype.c

compile: $(OBJS)

clean:
	rm -f *.o
	rm -f sfrotz
