From 2c1ae5a57563ad48b370fcb2a1ccb3d6d7565894 Mon Sep 17 00:00:00 2001 From: En Yi Date: Sat, 9 Jul 2022 16:43:16 +0800 Subject: [PATCH] Add Makefile --- .gitignore | 2 +- Makefile | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index 9639276..f21a7da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -Make* main.code-workspace main .vscode +build/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..deb2c40 --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +SRC_FILES = $(wildcard *.c) $(wildcard obj/*.c) $(wildcard utilities/*.c) +EXE = main +BUILD_DIR = build/ +OBJ = $(patsubst %.c,$(BUILD_DIR)%.o,$(SRC_FILES)) +DEP = $(OBJ:.o=.d) + +RAYLIB_DIR ?= $(HOME)/Documents/Coding/raylib/build/ +LIB_DIRS = -L$(RAYLIB_DIR)lib +INCLUDE_DIRS = -I$(RAYLIB_DIR)include -I./include +LIBS = -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 + +CFLAGS = -MMD -MP $(INCLUDE_DIRS) +LDFLAGS = $(LIB_DIRS) $(LIBS) + +all: CFLAGS += -O2 +all: $(EXE) + +debug: CFLAGS += -DDEBUG -O0 -ggdb +debug: $(EXE) + +$(EXE): $(OBJ) + $(CC) -o $@ $^ $(LDFLAGS) + +$(BUILD_DIR)%.o: %.c + @ mkdir -p $(BUILD_DIR) + @ mkdir -p $(BUILD_DIR)/obj + @ mkdir -p $(BUILD_DIR)/utilities + @ $(CC) $(CFLAGS) -o $@ -c $< + +-include $(DEP) + +.PHONY: cleanall +cleanall: clean cleandep + +.PHONY: clean +clean: + rm -f $(OBJ) $(EXE) + +.PHONY: cleandep +cleandep: + rm -f $(DEP)