From 6aef79af7e0da79789e489daf3344aead8e0f0a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=ABy=20Noort?= Date: Sun, 11 May 2025 19:53:20 +0200 Subject: [PATCH] chore: added Makefile --- Makefile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..03495ee --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +# Variables +CC = clang +CFLAGS = -Wall -Wextra -Werror -O3 +LDFLAGS = -lSDL2 -flto +LIBFT_DIR = libs/libft +LIBFT_BUILD_DIR = $(LIBFT_DIR)/build +LIBFT_LIB = $(LIBFT_BUILD_DIR)/libft.a +SRC_DIR = srcs +OBJ_DIR = obj +BIN_DIR = bin +HDR_DIR = hdrs +SRCS = $(wildcard $(SRC_DIR)/*.c) # List all .c files in srcs directory +OBJS = $(SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) # Convert .c to .o in obj directory +EXEC = $(BIN_DIR)/zboy # The output binary name + +# Default target +all: $(EXEC) + +# Create bin and obj directories if they don't exist +$(OBJ_DIR) $(BIN_DIR): + @mkdir -p $@ + +# Compile .c files to .o object files +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(HDR_DIR)/*.h | $(OBJ_DIR) + $(CC) $(CFLAGS) -I$(HDR_DIR) -I$(LIBFT_DIR)/hdrs -c $< -o $@ + +# Build libft.a by running make in libs/libft +$(LIBFT_LIB): + @echo "Building libft..." + $(MAKE) -C $(LIBFT_DIR) + +# Link object files and libft.a to create the final executable +$(EXEC): $(OBJS) $(LIBFT_LIB) | $(BIN_DIR) + $(CC) $(OBJS) -o $(EXEC) $(LIBFT_LIB) $(LDFLAGS) + +# Clean up object files and the executable +clean: + rm -rf $(OBJ_DIR)/*.o $(EXEC) + +# Remove all generated files including bin and obj directories +fclean: clean + rm -rf $(OBJ_DIR) $(BIN_DIR) + $(MAKE) -C $(LIBFT_DIR) fclean + +# Rebuild everything from scratch +re: fclean all + +.PHONY: all clean fclean re