IN = src/
OUT = dist/
TMP = temp/

sources = $(shell find $(IN) -type f)
sourcedirs = $(shell find $(IN) -type d)
targetdirs = $(subst $(IN),$(OUT),$(sourcedirs))

copysources = $(sources)
copytargets = $(subst $(IN),$(OUT),$(filter-out $(IN)Makefile,$(copysources)))

all: $(copytargets)

# the | means that if the timestamp of anything on the right changes, no need to rebuild
# the two :'s mean that the implicit rule of "$(list): %.pdf: %.tex" is applied only to the targets in $(list)
$(copytargets): $(OUT)%: $(IN)% | $(targetdirs)
	cp $< $@

$(targetdirs) $(TMP):
	mkdir -p $@

clean:
	rm -rf $(OUT) $(TMP)
