-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·111 lines (83 loc) · 2.78 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# **************************************************************************** #
# NAME #
# **************************************************************************** #
NAME = libasm.a
#NAME = libft.a
# **************************************************************************** #
# COMPILER #
# **************************************************************************** #
RM = rm -rf
MKDIR = mkdir
MAKE = make
AR = ar
ARFLAGS = rcs
AS = nasm
ASFLAGS = -f macho64
CC = gcc
CPPFLAGS =
CFLAGS = -Wall -Wextra -Werror -Wpedantic -Wshadow -O2
CFLAGS += -I./include
# **************************************************************************** #
# DIRS #
# **************************************************************************** #
SRC_DIR := src
OBJ_DIR := obj
INC_DIR := include
# **************************************************************************** #
# SOURCES #
# **************************************************************************** #
SRC_FILES := \
ft_strlen.s \
ft_strcpy.s \
ft_strcmp.s \
ft_write.s \
ft_read.s \
ft_strdup.s \
OBJ_FILES := $(patsubst %.s,%.o,$(patsubst %.c,%.o,$(SRC_FILES)))
SRC := $(addprefix $(SRC_DIR)/, $(SRC_FILES))
OBJ := $(addprefix $(OBJ_DIR)/, $(OBJ_FILES))
# **************************************************************************** #
# TESTS #
# **************************************************************************** #
TEST_DIR := mini-unit
TEST_SRC_FILES := \
ft_strlen_test.c \
ft_strcpy_test.c \
ft_strcmp_test.c \
ft_write_test.c \
ft_read_test.c \
TEST_SRC := $(addprefix $(SRC_DIR)/, $(TEST_SRC_FILES))
# **************************************************************************** #
# RULES #
# **************************************************************************** #
# all
SILENT := all
PHONY := all
all: $(NAME)
# name
$(NAME): $(OBJ)
$(AR) $(ARFLAGS) $@ $^
# obj
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.s | $(OBJ_DIR)
$(AS) $(ASFLAGS) -o $@ $<
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
$(OBJ_DIR):
$(MKDIR) $@
# tests
SILENT += check
PHONY += check
check:
$(MAKE) -C $(TEST_DIR) SRC='$(SRC)' TEST_SRC='$(TEST_SRC)' RELATIVE_PATH='..' INCLUDES='$(INC_DIR)'
# utils
PHONY += clean
clean:
$(MAKE) -C $(TEST_DIR) fclean
$(RM) $(OBJ_DIR)
PHONY += fclean
fclean: clean
$(RM) $(NAME)
PHONY += re
re: fclean all
.SILENT: $(SILENT)
.PHONY: $(PHONY)