# Semana 15: LFS, SSDs, integridad y sistemas distribuidos.
#   make         compila todo
#   make test    corre cada programa con los ejemplos de las diapositivas
#   make clean   borra los binarios y los archivos de prueba
CFLAGS = -Wall -Wextra -g
PROGS  = udprpc checksum scrub ftl
# Las soluciones aún no publicadas (code/.ocultos) no están en el repositorio:
# se omiten los programas sin fuente y sus líneas en las pruebas.
PROGS := $(foreach p,$(PROGS),$(if $(wildcard $(p).c),$(p)))
RUN    = $(if $(wildcard $(1).c),./$(1),@: sin $(1).c)
T      = /tmp/w15

all: $(PROGS)

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

test: $(PROGS)
	$(call RUN,udprpc) 200 0
	$(call RUN,udprpc) 200 20
	$(call RUN,udprpc) 200 20 dedup
	mkdir -p $(T)
	seq 1 1000 > $(T)/num.txt
	./checksum $(T)/num.txt 100
	seq 1 5000 > $(T)/datos.txt
	./scrub sign $(T)/datos.txt
	./scrub check $(T)/datos.txt
	printf 'X' | dd of=$(T)/datos.txt bs=1 seek=9000 conv=notrunc status=none
	./scrub check $(T)/datos.txt || true
	./ftl 50
	./ftl 70
	./ftl 90
	./ftl 90 hot

clean:
	rm -f $(PROGS)
	rm -rf $(T)

.PHONY: all test clean
