#
#  Makefile
#
#  T.Harbaum@tu-bs.de - http://www.ibr.cs.tu-bs.de/~harbaum/pilot
#
#  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.
#

# $@ = target
# $< = first dep
# $? = all dep
# $* = stem

BACK = ../back0000.bin

IMAG = ../imag0000.bin ../imag0001.bin ../imag0002.bin ../imag0003.bin\
       ../imag0004.bin ../imag0005.bin ../imag0006.bin ../imag0007.bin\
       ../imag0008.bin ../imag0009.bin ../imag000a.bin ../imag000b.bin\
       ../imag000c.bin ../imag000d.bin

SPRT = ../sprt0000.bin ../sprt0001.bin ../sprt0002.bin ../sprt0003.bin\
       ../sprt0004.bin ../sprt0005.bin ../sprt0006.bin ../sprt0007.bin\
       ../sprt0008.bin ../sprt0009.bin ../sprt000a.bin ../sprt000b.bin\
       ../sprt000c.bin ../sprt000d.bin ../sprt000e.bin ../sprt000f.bin\
       ../sprt0010.bin ../sprt0011.bin ../sprt0012.bin ../sprt0013.bin\
       ../sprt0014.bin	

IMAGCONV = -gamma 0.5

all: $(BACK) $(IMAG) $(SPRT) ../graphics.h

../graphics.h: $(BACK) $(IMAG) $(SPRT)
	echo "/* graphics.h - autogenerated */" > ../graphics.h
	echo "#define GRAPHIC_BACK `ls $(BACK) | wc -w`" >> ../graphics.h
	echo "#define GRAPHIC_IMAG `ls $(IMAG) | wc -w`" >> ../graphics.h
	echo "#define GRAPHIC_SPRT `ls $(SPRT) | wc -w`" >> ../graphics.h

../%.bin: %_gr.bmp bmp2bin
	./bmp2bin $< $@

%_gr.bmp: %.bmp grey
	./grey $< $@

%_gr.bmp: %_l.gif
	convert $(IMAGCONV) -compress none $< $@

%.bmp: %.gif
	convert -compress none $< $@

bmp2bin: bmp2bin.c

grey: grey.c

clean::
	rm -f bmp2bin grey back0000.bmp *~
	rm -f *_gr.bmp *.bin ../graphics.h
	rm -rf .xvpics

edit_level::
	for i in imag*_l.gif  ; do convert $(IMAGCONV) -crop 16x16+0+0 $$i GRAY:bd`echo $$i | cut -b 5-8`.raw ; done
	for i in imag*_gr.gif ; do convert -crop 16x16+0+0 $$i GRAY:bd`echo $$i | cut -b 5-8`.raw ; done
	for i in imag*.gif ; do convert -crop 16x16+18+0 $$i GRAY:bm`echo $$i | cut -b 5-8`.raw ; done
	for i in imag*.gif ; do cat bd`echo $$i | cut -b 5-8`.raw bd`echo $$i | cut -b 5-8`.raw bd`echo $$i | cut -b 5-8`.raw bm`echo $$i | cut -b 5-8`.raw > button`echo $$i | cut -b 5-8`.raw ; done
	for i in imag*.gif ; do convert -size 16x16 -interlace plane RGBA:button`echo $$i | cut -b 5-8`.raw button`echo $$i | cut -b 5-8`.gif; done
	rm bd????.raw bm????.raw button????.raw
	convert -crop 160x160+16+0 back0000.gif buttonback.gif
	./argoned ../levl0000.lev
	rm button*
