cleaner1=tr '\n' ' ' | tr -s ' ' | sed -e 's/ $$//' -e 's/ / '
cleaner2=' /g'

sdlCFLAGS=-C $(shell sdl-config --cflags | $(cleaner1)-C$(cleaner2))
sdlLDADD=-L $(shell sdl-config --libs | $(cleaner1)-L$(cleaner2)) \
	-L -lSDL_ttf \
	-L -lSDL_image \
	-L -lSDL_gfx \
	-L -lSDL_net

CSC=csc
CSCCC=$(CSC) $(sdlCFLAGS)
CSCLD=$(CSC) $(sdlCFLAGS) $(sdlLDADD)

TARGETS=\
	sdl.so \
	sdl-csi \
	test-sdl

EGG_CONTENTS=\
	sdl.html \
	COPYING \
	Makefile \
	heap.scm \
	timer.scm \
	sdl.scm \
	sdl.setup \
	sdl-csi.scm \
	test-sdl.scm \
	test-sdl-body.scm \
	test-heap.scm \
	test-net.scm \
	unknown2-scale8.jpg

all: $(TARGETS)

extension: sdl.so sdl-csi

install: all
	chicken-setup sdl

uninstall:
	chicken-setup -uninstall sdl

egg: sdl.egg

sdl.egg:
	tar -zcvf $@ $(EGG_CONTENTS)

%.so: %.scm
	$(CSCLD) -s -o $@ $<
#	strip $@

clean:
	rm -f $(TARGETS)
	rm -f STACKTRACE
	rm -f sdl.egg

%: %.scm
	$(CSCLD) -o $@ $<