CC=clang DEBUG=yes EXEC=test # all c files in this directory SRC = $(wildcard *.c) # otherwise #SRC = $(wildcard src_dir1/*.c) \ # $(wildcard src_dir2/*.c) # -g for debug # -Wall to get all the possible warnings # -ansi -pendantic to get portable code ifeq ($(DEBUG),yes) CFLAGS=-Wall -Wpedantic -g3 -Wextra -Wconversion -Wshadow -fsanitize=address,undefined -fno-omit-frame-pointer -fno-optimize-sibling-calls LDFLAGS= -Wall -lm -fsanitize=address,undefined else CFLAGS=-W -Wall -pedantic -std=c23 -O3 LDFLAGS= -Wall -lm endif ############################################### # end of the configuration ############################################### all: $(EXEC) obj = $(SRC:.c=.o) dep = $(obj:.o=.d) $(EXEC): $(obj) $(CC) -o $@ $^ $(LDFLAGS) .PHONY: tests tests: $(EXEC) ./test -include $(dep) %.d: %.c @$(CC) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@ %.o: %.c $(CC) $(CFLAGS) -o $@ -c $< .PHONY: clean clean: rm -f $(obj) $(EXEC) $(dep)