-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
86 lines (69 loc) · 2.99 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: antandre <antandre@student.42barcel> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/04/20 15:56:18 by antandre #+# #+# #
# Updated: 2024/10/27 19:29:57 by antandre ### ########.fr #
# #
# **************************************************************************** #
# Tool and flag definitions
RM = rm -f # Command to remove files
MKDIR_P = mkdir -p # Command to create directories
CC = cc # C compiler
CCFLAGS = -Wall -Wextra -Werror -DDEBUG=1 -g # Compiler flags
LIBMLX := ./lib/MLX42
LIBFT := ./lib/Libft
# Target definitions
NAME = so_long
SRC = $(shell find src -name "*.c")
OBJ = $(patsubst src/%.c,bin/%.o,$(SRC))
DEPS = $(patsubst src/%.c,bin/%.d,$(SRC))
LIBS := $(LIBMLX)/build/libmlx42.a $(LIBFT)/libft.a -ldl -lglfw -pthread -lm
HEADERS := -Iinclude -I $(LIBMLX)/include -I $(LIBFT)/include
# Number of source files
NUM_SRC = $(words $(SRC))
# Default target
all: libmlx libft $(NAME) # all target depends on $(NAME)
#Rules to create the libraries
libmlx:
@echo "Building libmlx..."
@cmake -Wno-dev -S $(LIBMLX) -B $(LIBMLX)/build -DCMAKE_BUILD_TYPE=Debug > /dev/null 2>&1 && \
make -C $(LIBMLX)/build -j4 > /dev/null 2>&1
@echo "libmlx built succesfully"
libft:
@echo "Building libft..."
@$(MAKE) -C $(LIBFT) > /dev/null
@echo "libft built succesfully"
# Rule to create the program
$(NAME): $(OBJ)
@echo "Creating $(NAME)"
@$(CC) $(OBJ) $(LIBS) $(HEADERS) -o $(NAME)
@echo "$(NAME) created successfully"
# Rule to compile .c files to .o files in bin/
bin/%.o: src/%.c
@$(MKDIR_P) $(dir $@) # Create the directory for the object file if it doesn't exist
@$(CC) $(CCFLAGS) -MMD -c $< -o $@ $(HEADERS)
@$(eval COUNT=$(shell expr $(COUNT) + 1))
@echo "[$(COUNT)/$(NUM_SRC)] Compiling $<\r"
# Clean up object and dependency files
clean:
@$(RM) -r bin/ # Remove the bin/ directory
@rm -rf $(LIBMLX)/build
@$(MAKE) --no-print-directory -C $(LIBFT) clean
@echo "Cleaned up object and dependency files"
# Clean up everything including the static library
fclean: clean
@$(RM) $(NAME) # Remove the program
@$(MAKE) --no-print-directory -C $(LIBFT) fclean
@echo "Cleaned up $(NAME)"
# Rebuild everything
re: fclean all # Run fclean and then all
# Include dependency files
-include $(DEPS)
# Declare phony targets
.PHONY: all, clean, fclean, re, libmlx, libft
# Initialize progress counter
COUNT = 0