EXECUTABLE = helloworld-c-make INSTALL_PREFIX = /usr/local CFLAGS = -std=c17 -Wall -Wextra -pedantic -pedantic-errors -O2 LFLAGS = LD=gcc CC=gcc SOURCE_FILES = \ src/main.c OBJECT_FILES = $(patsubst src/%.c, build/%.o, $(SOURCE_FILES)) HEADER_FILES = $(shell find src/ -name *.h) all: build/$(EXECUTABLE) build/compile_flags.txt install: build/$(EXECUTABLE) cp build/$(EXECUTABLE) $(INSTALL_PREFIX)/bin/$(EXECUTABLE) build/$(EXECUTABLE): $(OBJECT_FILES) $(LD) -o $@ $(LFLAGS) $^ build/%.o: src/%.c $(HEADER_FILES) build-folder $(CC) -c -o $@ $(CFLAGS) $< build-folder: mkdir -p build/ clean: $(RM) build/ build/compile_flags.txt: echo -xc $(CFLAGS) \ | tr ' ' '\n' \ > $@