# Módulo de imágenes y filtros.
#   make            compila filter_demo
#   make test_image compila las pruebas: no compilan hasta terminar la conversión
CC = gcc
CFLAGS = -Wall -Wextra -std=c17 -g -fsanitize=address,undefined
BUILD = build
MODULE = $(BUILD)/image.o $(BUILD)/filters.o

$(BUILD)/filter_demo: $(BUILD)/filter_demo.o $(MODULE)
	$(CC) $(CFLAGS) $^ -o $@

test_image: $(BUILD)/test_image

$(BUILD)/test_image: $(BUILD)/test_image.o $(MODULE)
	$(CC) $(CFLAGS) $^ -o $@

$(BUILD)/image.o: image.c image.h | $(BUILD)
	$(CC) $(CFLAGS) -c $< -o $@

# Estos tres incluyen filters.h, y filters.h incluye image.h.
$(BUILD)/filters.o: filters.c filters.h image.h | $(BUILD)
	$(CC) $(CFLAGS) -c $< -o $@

$(BUILD)/filter_demo.o: filter_demo.c filters.h image.h | $(BUILD)
	$(CC) $(CFLAGS) -c $< -o $@

$(BUILD)/test_image.o: test_image.c filters.h image.h | $(BUILD)
	$(CC) $(CFLAGS) -c $< -o $@

$(BUILD):
	mkdir -p $@

.PHONY: test_image clean
clean:
	rm -rf $(BUILD)
