AUXDIR=/usr/local/lib/mit-scheme-i386

install: build
	install -m 644 prhello-types.bin $(AUXDIR)
	install -m 644 prhello-const.bin $(AUXDIR)
	install -m 644 prhello-shim.so $(AUXDIR)

uninstall:
	rm $(AUXDIR)/prhello-*

clean:
	rm prhello-const* prhello-types* prhello-shim* 

build: prhello-shim.so prhello-types.bin prhello-const.bin

prhello-shim.so: prhello-shim.o
	$(CC) -shared -fPIC -o $@ $^ `pkg-config --libs gtk+-3.0`

prhello-shim.o: prhello-shim.c
	$(CC) -I$(AUXDIR) -Wall -fPIC `pkg-config --cflags gtk+-3.0` -o $@ -c $<

prhello-shim.c prhello-const.c prhello-types.bin: prhello.cdecl
	echo '(generate-shim "prhello" "#include <gtk/gtk.h>")' \
	| mit-scheme --batch-mode

prhello-const.bin: prhello-const.scm
	echo '(sf "prhello-const")' | mit-scheme --batch-mode

prhello-const.scm: prhello-const
	./prhello-const

prhello-const: prhello-const.o
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) `pkg-config --libs gtk+-3.0`

prhello-const.o: prhello-const.c
	$(CC) `pkg-config --cflags gtk+-3.0` $(CFLAGS) -o $@ -c $<
