include Config

SRCS =  main.c movie.c visual.c xmenu.c canvas.c render.c tvertelim.c color.c \
	Memory.c error.c message.c debug.c globals.c List.c Bintree.c Octree.c \
	scene.c readrad.c readmgf.c cie.c pointoctree.c vectoroctree.c namedvertex.c \
	camera.c raycast.c \
	point.c pointlist.c vector.c vectorlist.c vertex.c vertexlist.c \
	patch.c jacobian.c polygon.c patchlist.c material.c materiallist.c surface.c \
	compound.c bounds.c geom.c geomlist.c interaction.c interactionlist.c \
	formfactor.c cubature.c shadowcaching.c shaftculling.c \
	radiance.c importance.c initiallinking.c hrefine.c southwell.c gauss_seidel.c \
	basis.c sole.c constant.c \
	select.c surfedit.c monitor.c \
	$(EXTRASRCS)

OBJS = $(SRCS:.c=.o)

SUBDIRS = mgflib

all: rad

config:
	if test -w render.c; then ($(RM) render.c); fi
	$(SYMLINK) $(DRIVER).c render.c

depend: config
	for i in $(SUBDIRS) ; do { $(MAKE) -C $$i depend || exit 1 ; } ; done
	$(MAKEDEPEND) $(CFLAGS) $(DRIVERINCLUDES) $(SRCS) > deps

render.o: render.c 
	$(CC) $(CFLAGS) $(DRIVERINCLUDES) -c -o render.o render.c

mgflib/libmgf.a:
	${MAKE} -C mgflib all

rad: $(OBJS) y.tab.o lex.yy.o mgflib/libmgf.a
	for i in $(SUBDIRS) ; do { $(MAKE) -C $$i all || exit 1 ; } ; done
	$(CC) $(LDFLAGS) -o rad $(OBJS) y.tab.o lex.yy.o -L./mgflib -lmgf $(LIBS)

clean:
	for i in $(SUBDIRS) ; do { $(MAKE) -C $$i clean || exit 1 ; } ; done
	-$(RM) -f rad showrad core *.o y.tab.[ch] lex.yy.c *~ cubatest soletest deps
	-$(TOUCH) deps

distclean: clean
	for i in $(SUBDIRS) ; do { $(MAKE) -C $$i distclean || exit 1 ; } ; done

y.tab.c: yacc.y
	$(YACC) yacc.y

lex.yy.c: lex.l yacc.y
	$(LEX) lex.l

cubatest: cubature.c cubature.h
	$(CC) $(CFLAGS) -DTEST -o cubatest cubature.c -lm

soletest: sole.c sole.h
	$(CC) $(CFLAGS) -DTEST -o soletest sole.c -lm

include deps
