ifeq ($(OSTYPE),cygwin)
cc = x86_64-w64-mingw32-gcc
cflags = -O3 -pedantic -Wall -Wextra -Werror -include rand_patch.h
lflags = -lm
else
ifeq ($(ASAN),1)
cc = clang
cflags = -O1 -Wall -pedantic -g -fsanitize=address -fno-omit-frame-pointer
lflags = -lm
else
cc = gcc
cflags = -O3 -pedantic -Wall -Wextra -Werror
lflags = -lm
endif
endif
image_width = 1920
image_height = 1080

.SUFFIXES: .c .exe .png

.c.exe:
	$(cc) $(cflags) $< $(lflags) -o $@

.exe.png:
	./$< $(image_width) $(image_height) | pnmtopng > $@


# Outputs from most targets, except "fractal_slow.c", since it's the same
# as fractal.c but slower.
all: \
	cafe_wall.png \
	circular_moire.png \
	circular_moire_bw.png \
	circular_moire_dither_atkinson.png \
	circular_moire_dither_bayer.png \
	circular_moire_dither_fs.png \
	distortion.png \
	fractal.png \
	fractal_bw.png \
	fractal_bw_inverted.png \
	fractal_constrained.png \
	fractal_constrained_bw.png \
	halftone.png \
	halftone_multilayer.png \
	hex.png \
	hex_bw.png \
	hex_pattern_dots.png \
	hex_pattern_stripes.png \
	linear_moire.png \
	linear_moire_bw.png \
	perlin_noise.png \
	perlin_noise_bw.png \
	random.png \
	random_bw.png \
	stripes.png \
	stripes_generic.png \
	swarm.png \
	trail.png \
	trail_gradient.png \
	trail_multi.png \
	voronoi.png \
	voronoi_4colors.png \
	voronoi_4colors_bw.png \
	worley_noise.png


# Always compile terminal_size.c with GCC, since MingW doesn't have sys/ioctl.h
terminal_size.exe: terminal_size.c
	gcc $< -o $@


test:
	bash ./test_compile_all.sh


clean:
	-rm -f *.exe *.png

backup:
	-rm -f backup.tar.gz
	tar czf backup.tar.gz *.c *.h *.sh Makefile
