From 40c48980b482344a582ad108dd22c23fe89fa5d0 Mon Sep 17 00:00:00 2001 From: Quinn Date: Wed, 9 Apr 2025 14:56:24 +0200 Subject: [PATCH] use makefile build system --- .gitignore | 11 ++++++++--- makefile | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 makefile diff --git a/.gitignore b/.gitignore index 646396f..042b4a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ -.vscode -build -package/usr \ No newline at end of file +.* + +!.github/ +!.gitignore + +/bin/ +/obj/ +/compile_commands.json diff --git a/makefile b/makefile new file mode 100644 index 0000000..fd843f3 --- /dev/null +++ b/makefile @@ -0,0 +1,28 @@ +CC := x86_64-pc-linux-gnu-gcc +CFLAGS := -Wall -Wextra -Wpedantic -O2 -std=gnu17 +LDFLAGS := + +SRC = $(shell find src/ -name '*.c') +OBJ := $(patsubst src/%,obj/%,$(SRC:.c=.o)) +BIN := bin/coinflip + +compile: compile_commands.json $(BIN) +clean: + rm -rf obj/ bin/ compile_commands.json + +# link the .o files +$(BIN): $(OBJ) + @mkdir -p $(@D) + $(CC) $(LDFLAGS) $(OBJ) -o $(BIN) + +# compile .o files (w/ .d files) +obj/%.o: src/%.c + @mkdir -p $(@D) + $(CC) -c -MD -MP $(CFLAGS) -o $@ $< + +compile_commands.json: makefile + $(MAKE) clean + @touch compile_commands.json + bear -- make compile + +-include $(OBJ:.o=.d)