ifeq ($(OSTYPE),cygwin)
target = victorique.exe
cc_target = victorique-cc.exe
d_target = victorique-d.exe
cc = i686-w64-mingw32-g++
cflags = -O3 -g0 -Wall -Werror -ansi -pedantic -static
cc_strip = i686-w64-mingw32-strip
d_strip = true
else
target = victorique
cc_target = $(target)-cc
d_target = $(target)-d
cc = g++
cflags = -O3 -g0 -Wall -Werror -ansi -pedantic
cc_strip = strip
d_strip = strip
endif
dmd = dmd
dflags = -nofloat -noboundscheck -O -release -wi -w -of

test_output = test_output.txt


all: $(target)

$(target): $(cc_target)
	cp $< $@

$(cc_target): victorique.cc
	$(cc) $(cflags) $< -o $@
	$(cc_strip) $@

$(d_target): victorique0.d
	$(dmd) $(dflags)$@ $<
	$(d_strip) $@

test: $(target)
	./$(target) > $(test_output)
	diff -w expected_output.txt $(test_output)
	-rm -f $(test_output)

clean:
	-rm -f *.map *.obj $(test_output)
	-rm -f $(target) $(cc_target) $(d_target)

backup:
	-rm -f backup.tar.xz
	tar cf backup.tar *.cc *.d *.txt Makefile
	xz -9 backup.tar

backup-logs:
	-rm -f logs.tar.xz
	tar cf logs.tar *.log
	xz -9 logs.tar
