# ez3d -- grayscale PNG -> printable STL heightmap.
#
# Plain Makefile, gcc -Wall -Wextra -O2, in the style of ../pg_fcgi.
# vendor/stb_image.h is a pinned copy (v2.30, public domain):
#   curl -o vendor/stb_image.h \
#     https://raw.githubusercontent.com/nothings/stb/master/stb_image.h

CC = gcc
CFLAGS = -Wall -Wextra -O2 -DNDEBUG
# CFLAGS = -Wall -Wextra -ggdb
INCLUDES = -Ivendor -I.

OBJS = main.o image.o mesh.o stl_write.o verify.o trimesh.o decimate.o

ez3d: $(OBJS)
	$(CC) $(CFLAGS) -o $@ $(OBJS) -lm

%.o: %.c
	$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<

test: ez3d tests/gen_png.py tests/run_tests.sh tests/png/one.png
	./tests/run_tests.sh

clean:
	rm -f ez3d $(OBJS)

.PHONY: test clean

# Test PNG generated by python. We keep them in git anyhow because
# they are small, but perhaps they need regenerating at some point.
tests/png/%.png: tests/gen_png.py
	mkdir tests/png
	python3 tests/gen_png.py tests/png

tests/png/black2.png: tests/gen_png.py
tests/png/bump16.png: tests/gen_png.py
tests/png/corner10.png: tests/gen_png.py
tests/png/grad8.png: tests/gen_png.py
tests/png/holed8.png: tests/gen_png.py
tests/png/moat16.png: tests/gen_png.py
tests/png/one.png: tests/gen_png.py
tests/png/slot16.png: tests/gen_png.py
tests/png/stairs10.png: tests/gen_png.py
tests/png/white4.png: tests/gen_png.py

# Header dependencies: make does not track includes on its own.
# Keep these in database-style normalized format, and sorted.
decimate.o: decimate.c
decimate.o: decimate.h
decimate.o: trimesh.h
image.o: ez3d.h
image.o: image.c
image.o: image.h
image.o: vendor/stb_image.h
main.o: decimate.h
main.o: ez3d.h
main.o: image.h
main.o: main.c
main.o: mesh.h
main.o: stl_write.h
main.o: trimesh.h
main.o: verify.h
mesh.o: ez3d.h
mesh.o: mesh.c
mesh.o: mesh.h
mesh.o: image.h
mesh.o: stl_write.h
mesh.o: triangle.h
mesh.o: trimesh.h
stl_write.o: stl_write.c
stl_write.o: stl_write.h
stl_write.o: triangle.h
trimesh.o: triangle.h
trimesh.o: trimesh.c
trimesh.o: trimesh.h
verify.o: verify.c
verify.o: verify.h
