chore: added Makefile
This commit is contained in:
parent
08ef79a782
commit
8d14e2fd92
1 changed files with 48 additions and 0 deletions
48
Makefile
Normal file
48
Makefile
Normal file
|
|
@ -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)/c8 # 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue