use makefile build system

This commit is contained in:
Quinn
2025-04-09 14:56:24 +02:00
parent 28e8aeb707
commit 40c48980b4
2 changed files with 36 additions and 3 deletions

11
.gitignore vendored
View File

@@ -1,3 +1,8 @@
.vscode .*
build
package/usr !.github/
!.gitignore
/bin/
/obj/
/compile_commands.json

28
makefile Normal file
View File

@@ -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)