# Semana 11: variables de condición y semáforos.
#   make         compila todo
#   make test    corre cada demostración (unos 15 s en total)
#                prioinv necesita CAP_SYS_NICE (SCHED_FIFO); sin él, solo avisa
#   make clean   borra los binarios
CFLAGS = -Wall -Wextra -g -pthread
LDLIBS = -pthread
PROGS  = join pc pcbug sempc rwlock philo throttle barrier priosim prioinv
# 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)

all: $(PROGS)

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

test: $(PROGS)
	./join ok
	./join nostate
	./join nolock
	./pc 4 2 3 100000
	./pcbug if
	./pcbug while
	./pcbug onecv
	./pcbug twocv
	./sempc ok
	./sempc outside
	$(call RUN,rwlock) 1
	$(call RUN,rwlock) 8
	./philo naive
	./philo ordered
	./throttle 8 2
	$(call RUN,barrier) 4 3
	./priosim none
	./priosim inherit
	./priosim ceiling
	./prioinv none
	./prioinv inherit

clean:
	rm -f $(PROGS)

.PHONY: all test clean
