# Generated automatically from Makefile.in by configure.
# Written by Peter Ekberg, peda@lysator.liu.se

CC           = gcc
DD           = dd

NO_SVGA      = 
SOUND        = no

DEFINES      = $(strip \
		 -DHIGHSCOREFILE=\"$(FULLHISCORE)\" \
		 -DVERSION=\"$(VERSION)\" \
		 -DHAVE_CONFIG_H)
OPTIMIZE     =  -fomit-frame-pointer -O9 -s
COMPILE      =  -Wall -Wstrict-prototypes -Wmissing-prototypes
ALL_CFLAGS   = $(strip \
		 $(DEFINES) $(OPTIMIZE) $(COMPILE) )
SVGA_LIBS    =  -lvgagl -lvga
LDFLAGS      = 

MAN          = thrust.man
HIGHSCORE    = thrust.hsc
FULLHISCORE  = $(HIGHSCORE)
VERSION_NR   = 0.83
VERSION      = 0.83c

LIBS         = -lm

HELPPRG      = $(addprefix helpers/, bin2c txt2c ppm2c reverse)

BIN8         = $(addprefix datasrc/, \
		 blks0.bin blks1.bin blks2.bin blks3.bin \
		 blks4.bin blks5.bin blks6.bin blks7.bin \
		 blks8.bin blks9.bin blksa.bin blksb.bin \
		 blksc.bin blksd.bin blkse.bin blksf.bin )

SOURCEOBJS   = $(addprefix src/, \
		 thrust.o fast_gr.o hiscore.o conf.o things.o init.o \
		 level.o font5x5.o graphics.o getopt.o getopt1.o )
DATAOBJS     = $(addprefix datasrc/, \
		 font.o blks.o ship.o shld.o colors.o bullet.o title.o \
		 level1.o level2.o level3.o level4.o level5.o level6.o \
		 demomove.o)
SOUNDITOBJS  = $(addprefix src/, soundIt.o)
SOUNDOBJS    = $(addprefix datasrc/, \
		 boom.o boom2.o harp.o thrust.o zero.o)
ifeq ($(SOUND),yes)
OBJS         = $(SOURCEOBJS) $(DATAOBJS) $(SOUNDITOBJS) $(SOUNDOBJS)
else
OBJS         = $(SOURCEOBJS) $(DATAOBJS)
endif
SVGA_OBJS    = $(addprefix src/, doskey.o svga.o)



#######################
#
# Targets.
#
#######################

all: thrust

clean:
	rm -rf $(strip *~ core thrust $(OBJS) $(SVGA_OBJS) \
		       $(HELPPRG) datasrc/blks*.bin .dep )

mostlyclean:
	rm -rf *~ core thrust $(SOURCEOBJS) $(SVGA_OBJS)

dep:
	$(CC) -M $(patsubst %.o,%.c,$(SOURCEOBJS)) > .dep
	$(CC) -M $(patsubst %.o,%.c,$(SVGA_OBJS)) >> .dep


#######################
#
# Implicit rules.
#
#######################

# Compile C files to object files.
%.o: %.c
	$(CC) $(ALL_CFLAGS) -c -o $(addprefix $(dir $<), $(notdir $@)) $<


# Extract palette information.
%.bin: %.pal
	$(DD) of=$@ if=$< bs=1 skip=790
# Extract picture information.
%.rev: %.bmp
	$(DD) of=$@ if=$< bs=1 skip=1078


# The bmp format stores rows backwards (last row first).
# These rules are used to "reverse" the order in which the rows are stored.
# There is one rule for each of the three used widths of the line.
%.bin: %-4.rev
	$(MAKE) helpers/reverse
	helpers/reverse 4 < $< > $@
%.bin: %-8.rev
	$(MAKE) helpers/reverse
	helpers/reverse 8 < $< > $@
%.bin: %-16.rev
	$(MAKE) helpers/reverse
	helpers/reverse 16 < $< > $@


# Make a C file out of a text file. The info is stored in an array of strings.
# One line in the original text file will be stored in one cell of the array.
%.c: %.def
	$(MAKE) helpers/txt2c
	helpers/txt2c $(notdir $(basename $<)) < $< > $@
# Make a C file out of a binary file. The info is stored in a byte array.
%.c: %.bin
	$(MAKE) helpers/bin2c
	helpers/bin2c bin_$(notdir $(basename $<)) < $< > $@
# Make a C file out of a sound file.


#######################
#
# Secondary targets.
#
#######################

#thrust:
thrust: $(OBJS) $(SVGA_OBJS)
	$(CC) $(LDFLAGS) -o thrust $(OBJS) $(SVGA_OBJS) $(SVGA_LIBS) $(LIBS)

datasrc/blks.bin: $(BIN8)
	rm -f datasrc/blksp?.bin
	copy /B datasrc\blks0.bin+datasrc\blks1.bin datasrc\blksp0.bin
	copy /B datasrc\blks2.bin+datasrc\blks3.bin datasrc\blksp1.bin
	copy /B datasrc\blks4.bin+datasrc\blks5.bin datasrc\blksp2.bin
	copy /B datasrc\blks6.bin+datasrc\blks7.bin datasrc\blksp3.bin
	copy /B datasrc\blks8.bin+datasrc\blks9.bin datasrc\blksp4.bin
	copy /B datasrc\blksa.bin+datasrc\blksb.bin datasrc\blksp5.bin
	copy /B datasrc\blksc.bin+datasrc\blksd.bin datasrc\blksp6.bin
	copy /B datasrc\blkse.bin+datasrc\blksf.bin datasrc\blksp7.bin
	copy /B datasrc\blksp0.bin+datasrc\blksp1.bin datasrc\blksp8.bin
	copy /B datasrc\blksp2.bin+datasrc\blksp3.bin datasrc\blksp9.bin
	copy /B datasrc\blksp4.bin+datasrc\blksp5.bin datasrc\blkspa.bin
	copy /B datasrc\blksp6.bin+datasrc\blksp7.bin datasrc\blkspb.bin
	copy /B datasrc\blksp8.bin+datasrc\blksp9.bin datasrc\blkspc.bin
	copy /B datasrc\blkspa.bin+datasrc\blkspb.bin datasrc\blkspd.bin
	copy /B datasrc\blkspc.bin+datasrc\blkspd.bin datasrc\blks.bin
	rm -f datasrc/blksp?.bin


helpers/reverse: helpers/reverse.c
	$(CC) -DHAVE_CONFIG_H $(COMPILE) $< -o $@

helpers/bin2c:  helpers/bin2c.c
	$(CC) -DHAVE_CONFIG_H $(COMPILE) $< -o $@

helpers/txt2c:  helpers/txt2c.c
	$(CC) -DHAVE_CONFIG_H $(COMPILE) $< -o $@


#######################
#
# Dependencies.
#
#######################

ifeq (.dep,$(wildcard .dep))
include .dep
endif
