-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
64 lines (48 loc) · 1.49 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
NAME = program
AR = @ar
AR_FLAGS = -rcs
COMPILER = @gcc
COMPILER_FLAGS = -Wall -Werror -Wextra -Iincludes/
# Configuration
# Libft...
LIBFT = libft.a
LIBFT_FOLDER = ./libraries/libft
# Source Files...
SOURCE_FOLDER = ./srcs
SOURCE_FILES = ft_example.c
# Build Folder
BUILD_FOLDER = ./build
BUILD_FILES = $(addprefix $(BUILD_FOLDER)/, $(LIBFT))
# Object Files...
EXTRA_FOLDERS = $(SOURCE_FOLDER)
OBJECT_FOLDER = ./objects
OBJECT_FILES = $(addprefix $(OBJECT_FOLDER)/, $(addprefix $(SOURCE_FOLDER)/, $(SOURCE_FILES:.c=.o)))
.PHONY = $(NAME) all clean fclean re dev
# Compile the .c files to .o files...
$(OBJECT_FOLDER)/%.o: %.c
@mkdir -p $(OBJECT_FOLDER) $(addprefix $(OBJECT_FOLDER)/, $(dir $<))
@echo "Compiling \t$(notdir $<) (100%)"
@$(COMPILER) $(COMPILER_FLAGS) -c $< -o $@
# Compile the program...
$(NAME): $(LIBFT) $(OBJECT_FILES)
@echo "Building \t$(NAME)... (100%)"
$(COMPILER) $(COMPILER_FLAGS) $(OBJECT_FILES) $(BUILD_FILES) -o $(NAME)
# Compile Libft...
$(LIBFT):
@echo "Compiling \t$(LIBFT)..."
@$(MAKE) all -C $(LIBFT_FOLDER)
@mkdir -p $(BUILD_FOLDER)
@mv $(addprefix $(LIBFT_FOLDER)/, $(LIBFT)) $(addprefix $(BUILD_FOLDER)/, $(LIBFT))
all: $(NAME)
# Remove the `object` folder and files...
clean:
@rm -rf $(OBJECT_FILES) $(OBJECT_FOLDER)
# Remove the `object` and `build` folder and files...
fclean: clean
@rm -rf $(NAME)
# Clean the program up and re-compile it...
re: fclean all
# Re-compile the program and run the script...
dev: re
@echo "Running \t$(NAME)..."
@./$(NAME)