/ Makefile
Makefile
 1  # Root Makefile template for 42-style exercises
 2  # - `configure` lists all `exNN` directories (NN = two digits)
 3  # - `all`, `re`, `clean`, `fclean` run the same target in each exNN directory
 4  
 5  SHELL := /bin/bash
 6  
 7  # Find directories named ex00..ex99 at the top level
 8  EX_DIRS := $(sort $(wildcard ex[0-9][0-9]))
 9  
10  .PHONY: configure all re clean fclean help
11  
12  define run_target
13  	@for d in $(EX_DIRS); do \
14  		if [ -d $$d ]; then \
15  			echo "----> $$d: $(1)"; \
16  			$(MAKE) -C $$d $(1) || exit $$?; \
17  		fi; \
18  	done
19  endef
20  
21  # Generic forwarding rule: if user runs `make <something>`, forward it to each exNN
22  # Usage: make try  -> runs `make try` inside each `exNN` directory
23  %:
24  	$(call run_target,$@)
25  
26  all:
27  	$(call run_target,all)
28  
29  help:
30  	@echo "Usage: make [target]"
31  	@echo "Targets:"
32  	@echo "  configure  - list exNN directories (NN = two digits)"
33  	@echo "  all        - run 'make all' in each exNN directory"
34  	@echo "  re         - run 'make re' in each exNN directory"
35  	@echo "  clean      - run 'make clean' in each exNN directory"
36  	@echo "  fclean     - run 'make fclean' in each exNN directory"