-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
89 lines (75 loc) · 2.42 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
87
88
89
#******************************************************************************#
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: bwaegene <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2016/07/18 09:48:23 by bwaegene #+# #+# #
# Updated: 2017/02/05 12:54:43 by bwaegene ### ########.fr #
# #
#******************************************************************************#
# Disable implicit rules
.SUFFIXES:
# Compiler configuration
CC = gcc
CFLAGS = -Wall -Wextra -Werror
## Flags for the C preprocessor
CPPFLAGS = -I$(INCLUDE) -I$(LIB)/$(INCLUDE)
## Libraries path
LDFLAGS = -L$(LIB)
## Libraries to link into the executable
LDLIBS = -lft
NAME = ft_ls
# Project related variables
SRC_PATH = src
SRC_NAME = usage.c \
file_mode.c \
file_type.c \
error.c \
display_long.c \
display_one.c \
options.c \
dirent.c \
sort.c \
padding.c \
argument.c \
display_file.c \
put_stuff.c \
ft_ls.c
OBJ_PATH = obj
OBJ_NAME = $(SRC_NAME:.c=.o)
SRC = $(addprefix $(SRC_PATH)/,$(SRC_NAME))
OBJ = $(addprefix $(OBJ_PATH)/,$(OBJ_NAME))
LIB = libft
INCLUDE = include
HEADER = $(INCLUDE)/$(NAME).h
DEBUG ?= 0
ifeq ($(DEBUG), 1)
CFLAGS += -g
endif
all: $(NAME)
$(NAME): $(LIB)/$(LIB).a $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(OBJ) -o $(NAME)
$(OBJ_PATH):
mkdir $@
$(OBJ): | $(OBJ_PATH)
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c $(HEADER)
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# /!\ Dirty workaround /!\
# If make on the libft directory should rebuild something then PHONY the rule
# libft to build it. Otherwise it relink.
ifeq ($(shell $(MAKE) --question -C ./$(LIB) ; echo $$?), 1)
.PHONY: $(LIB)/$(LIB).a
endif
$(LIB)/$(LIB).a:
$(MAKE) -C ./$(LIB)
.PHONY: clean
clean:
$(MAKE) -C ./$(LIB) clean
$(RM) -r $(OBJ_PATH)
fclean: clean
$(MAKE) -C ./$(LIB) fclean
$(RM) -r $(NAME) *.dSYM list_dir list_recur test_opt inspect_file
re: fclean
$(MAKE) all