Here's the perfect Makefile.
CC = clang
CFLAGS = -Wall -Wextra -pedantic -I include -g
SRC = $(wildcard *.c src/*.c)
HEAD = $(wildcard include/*.h)
OBJ = $(SRC:.c=.o)
EXEC = out/proj
all: clean $(OBJ) $(EXEC) $(HEAD)
$(EXEC): $(OBJ)
$(CC) $^ -o $@
rm -rf src/*.o
%.o: %.cpp
$(CC) $(CFLAGS) $^ -o $@
clean:
rm -rf *.o src/*.o $(EXEC)
Before you run this makefile, make sure your already have the following directories in your project.
src # contains all your C code
include # contains your header/include files
out # will contain the outputted binary