include ../Makefile.cfg

NASM ?= nasm
VOODOOC ?= env RUBYLIB=$(PWD)/../lib:$(RUBYLIB) ../bin/voodooc

TARGETS = bitwise call div fact goto hello if many-vars mod mul plusminus \
	set-byte set-word tail-calls vtable 99bottles gcd

all : $(TARGETS)

clean :
	-for target in $(TARGETS); do rm "$$target.asm" "$$target.o"; done

distclean : clean
	-rm $(TARGETS)

test : $(TARGETS)
	env RUBYLIB=$(PWD)/../lib:$(RUBYLIB) RUBY=$(RUBY) ./test

99bottles.o : 99bottles.rb
	env RUBYLIB=$(PWD)/../lib:$(RUBYLIB) $(RUBY) 99bottles.rb

gcd.o : gcd.rb
	env RUBYLIB=$(PWD)/../lib:$(RUBYLIB) $(RUBY) gcd.rb

.SUFFIXES : .asm .o .voo

.asm.o :
	$(NASM) -f elf $<

.o :
	$(CC) $< -o $@

.s.o :
	$(GAS) $< -o $@

.voo.asm :
	$(VOODOOC) -f nasm -o $@ $<

.voo.o :
	$(VOODOOC) -o $@ $<

.voo.s :
	$(VOODOOC) -f gas -o $@ $<

.PHONY : all clean distclean test
