CC = i586-mingw32msvc-gcc
CFLAGS = -g -Wall
LIBS = -lgdi32
LDFLAGS = -Wl,--subsystem,0x2	# Windows GUI
WINE = /usr/lib/wine/wine.bin
targets = onefile.exe dryhi.exe follow.exe circles.exe *.o

all: onefile.exe dryhi.exe follow.exe circles.exe

# for some bizarre reason, not having a stack size ulimit crashes WINE
# that took me more than 20 minutes to figure out! argh!
run: circles.exe
	bash -c "ulimit -s 8192; $(WINE) $<"
dryhi.exe: dryhi.o w32dry.o
	$(CC) dryhi.o w32dry.o $(LDFLAGS) -o $@ $(LIBS)
follow.exe: follow.o w32dry.o
	$(CC) follow.o w32dry.o $(LDFLAGS) -o $@ $(LIBS)
circles.exe: circles.o w32dry.o
	$(CC) circles.o w32dry.o $(LDFLAGS) -o $@ $(LIBS)
onefile.exe: onefile.o
	$(CC) onefile.o $(LDFLAGS) -o $@ $(LIBS)
# this reduces the size from almost 600kB per .exe to just over 7kB  
# depends on `all` to ensure we build everything first
strip: all
	strip *.exe
clean:
	rm -f $(targets)
targz:
	cd ..; tar czvf w32dry.tar.gz w32dry/circles.c w32dry/circles.exe \
		w32dry/dryhi.c w32dry/dryhi.exe w32dry/follow.c \
		w32dry/follow.exe w32dry/index.html w32dry/Makefile \
		w32dry/onefile.c w32dry/onefile.exe \
		w32dry/w32dry.c w32dry/w32dry.h \
		w32dry/follow.png w32dry/circles.png w32dry/dryhi.png
	mv ../w32dry.tar.gz .
