-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
79 lines (62 loc) · 2.64 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: antandre <antandre@student.42barcel> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/04/20 15:56:18 by antandre #+# #+# #
# Updated: 2024/11/13 16:27:34 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 # Compiler flags
LIBFT := ./lib/Libft
# Target definitions
NAME = push_swap
SRC = $(shell find src -name "*.c")
OBJ = $(patsubst src/%.c,bin/%.o,$(SRC))
DEPS = $(patsubst src/%.c,bin/%.d,$(SRC))
LIBS := $(LIBFT)/libft.a
HEADERS := -Iinclude -I $(LIBFT)/include
# Number of source files
NUM_SRC = $(words $(SRC))
# Default target
all: libft $(NAME) # all target depends on $(NAME)
#Rules to create the libraries
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
@$(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