CC=gcc LD=gcc # I'm using GCC to link code. This is prefered over using LD directly since # it will handle all the GLIBC linkage for you. SRCS = $(wildcard src/*.c) OBJS = ${SRCS:.c=.o} DEST = pong CC_FLAGS = -I include/ -g -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -O3 LD_FLAGS = LIBS = -lSDL2 # This is to let make know these are not actually file targets but rather # command targets. .PHONY = all clean format debug run all: $(DEST) # Link all objects together into one binary $(DEST): ${OBJS} $(LD) ${LD_FLAGS} $^ $(LIBS) -o $(DEST) # For every c file, compile it to an object file %.o: %.c $(CC) ${CC_FLAGS} -c $< -o $@ # Run the formatter format: clang-format -i src/*.c include/*.h # Run the created binary run: $(DEST) ./$(DEST) # Run the created binary using the debugger debug: $(DEST) gdb ./$(DEST) -ex "set disassembly-flavor intel" # Clean the project of all build files clean: $(info [INFO] Cleaning directory) rm -rf ${OBJS} $(DEST)