#----------------------------------------------------------------------
# Makefile for SVGAlib demo programs.
#
# This file is a part of SVGAlib.
#----------------------------------------------------------------------

ifeq (Makefile.cfg,$(wildcard Makefile.cfg))
include Makefile.cfg
CFLAGS = $(WARN) $(OPTIMIZE)
srcdir    = .
VPATH     = .
else
include ../Makefile.cfg
CFLAGS = $(WARN) $(OPTIMIZE) -I$(srcdir)/src -I$(srcdir)/gl
srcdir    = ..
VPATH     = $(srcdir)/demos
endif

#----------------------------------------------------------------------
# Compiler Section (overrides Makefile.cfg)
#----------------------------------------------------------------------

LFLAGS   = -N
#LFLAGS   = -L ../src -L ../gl

#----------------------------------------------------------------------
# Rules Section
#----------------------------------------------------------------------

PROGS    = fun testgl speedtest mousetest vgatest scrolltest \
	   keytest testaccel accel forktest
PROGS_O  = fun.o testgl.o speedtest.o mousetest.o vgatest.o scrolltest.o \
	   testlinear.o keytest.o testaccel.o accel.o forktest.o
LIBS     = -lvgagl -lvga
#LIBS     = -lvgagl -lvga -lg

all:	progs
.PHONY: all clean cleanbin dep

progs : $(PROGS)

objs:	$(PROGS_O)

$(PROGS_O): .depend

.c.o:
	$(CC) $(CFLAGS) -c -o $*.o $<

.c.s:
	$(CC) $(CFLAGS) -S -o $*.s $<

.o:
	$(CC) $(CFLAGS) $(LFLAGS) -o $* $*.o $(LIBS)
	chmod a+rs,go-w $*

testaccel: testaccel.o
	$(CC) $(CFLAGS) $(LFLAGS) -o testaccel testaccel.o $(LIBS) -lm
	chmod a+rs,go-w testaccel

clean:	cleanbin
	rm -f .depend *.o *~

cleanbin:
	rm -f $(PROGS)

dep:
	rm -f .depend
	make .depend

.depend:
	echo '# Program dependencies' >.depend
	gcc -MM $(patsubst %.o,$(srcdir)/demos/%.c,$(PROGS_O)) >>.depend

#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif
