-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
70 lines (55 loc) · 1.54 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
# Names of the programs
NAME = pipex
NAME_B = pipex_bonus
LIBFT = libft.a
LDIR = libft/
SDIR = src/
BONUS_DIR = src/bonus/
ODIR = obj/
# Compiler and flags
CC = gcc
CFLAGS = -Wall -Werror -Wextra -g
RM = rm -f
# Source and Object Files
SRCS = $(addprefix $(SDIR), pipex.c pipex_utilities.c pipex_execution.c)
OBJS = $(patsubst $(SDIR)%.c,$(ODIR)%.o,$(SRCS))
# Adding bonus source and object files
SRCS_B = $(addprefix $(BONUS_DIR), pipex_bonus.c pipex_utilities_bonus.c pipex_execution_bonus.c pipex_redirection_bonus.c pipex_heredoc_bonus.c pipex_pipeline_bonus.c)
OBJS_B = $(patsubst $(BONUS_DIR)%.c,$(ODIR)%.o,$(SRCS_B))
# Default rule
all: libft $(NAME)
@echo "pipex compiled"
# Rule for bonus program
bonus: libft $(NAME_B)
@echo "pipex_bonus compiled"
# Compilation rules for the main program
$(NAME): $(OBJS)
@$(CC) $(CFLAGS) $(OBJS) -o $(NAME) $(LDIR)$(LIBFT)
# Compilation rules for the bonus program
$(NAME_B): $(OBJS_B)
@$(CC) $(CFLAGS) $(OBJS_B) -o $(NAME_B) $(LDIR)$(LIBFT)
$(ODIR)%.o: $(SDIR)%.c
@mkdir -p $(ODIR)
@$(CC) $(CFLAGS) -c $< -o $@
$(ODIR)%.o: $(BONUS_DIR)%.c
@mkdir -p $(ODIR)
@$(CC) $(CFLAGS) -c $< -o $@
# Compiling libft
libft:
@echo "compiling libft"
@$(MAKE) -C $(LDIR)
# Cleaning up
clean:
@$(RM) $(OBJS) $(OBJS_B)
@make -C $(LDIR) clean
@echo "cleaned up object files"
fclean: clean
@$(RM) $(NAME) $(NAME_B)
@make -C $(LDIR) fclean
@echo "cleaned up all files"
# Re-compiling
re: fclean all
run:
@./run.sh
# Phony rules to avoid conflicts
.PHONY: all libft clean fclean re run bonus