-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
90 lines (73 loc) · 2.71 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: yiyli <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/03/16 16:28:52 by yiyli #+# #+# #
# Updated: 2024/05/27 21:54:04 by yiyli ### ########.fr #
# #
# **************************************************************************** #
NAME := libft.a
SOURCE_DIR := srcs
OBJECT_DIR := objs
INCLUDE_DIR := includes
DIST_DIR := dist
# CC
CC := cc
CFLAGS := -Wall -Wextra -Werror -I $(INCLUDE_DIR)
# Norminette
NORM := norminette
NORM_FLAGS := -R CheckForbiddenSourceHeader -R CheckDefine
MKDIR = mkdir -p
# Helper function to list all files matching pattern recursively
# e.g. List all *.c files in srcs/ folder
rwildcard = $(shell find $(1) -type f -name '$(2)')
# Find all files we work with
# e.g. srcs/**/*.c, include/**/*.h
sources := $(call rwildcard,$(SOURCE_DIR),*.c)
# Convert c files to o files
# e.g. srcs/main.c srcs/dict/dict.c => objs/main.o objs/dict/dict.o
objects := $(sources:$(SOURCE_DIR)/%.c=$(OBJECT_DIR)/%.o)
.PHONY: all
all: $(NAME)
# Compile binary from all o files
# e.g. objs/main.o objs/dict/dict.o => rush-02
$(NAME): $(objects)
ar rcs $@ $^
# Compile each c file to o file
# Also, consider h file, though it is not included for compilation
# e.g. srcs/dict/dict.c (srcs/dict/dict.h) => objs/dict/dict.o
$(OBJECT_DIR)/%.o: $(SOURCE_DIR)/%.c
@$(NORM) $(NORM_FLAGS) $<
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $@
.PHONY: clean
clean:
$(RM) -r $(OBJECT_DIR)
.PHONY: fclean
fclean: clean
$(RM) $(NAME)
.PHONY: re
re: fclean all
# Run norminette on all c files and h files
.PHONY: norm
norm:
$(NORM) $(NORM_FLAGS) $(sources)
$(NORM) $(NORM_FLAGS) $(wildcard $(INCLUDE_DIR)/*.h)
# flatten all files in srcs/ and include/ to dist/
# e.g. srcs/**/*.c include/**/*.h => dist/
# dist/ is the folder to be submitted to vogsphere
.PHONY: dist
dist:
find $(DIST_DIR) -type f \( -name '*.c' -o -name '*.h' -o -name '*.o' \) -exec $(RM) {} +
$(MKDIR) -p $(DIST_DIR)
find $(SOURCE_DIR) -type f -exec cp {} $(DIST_DIR) \;
find $(INCLUDE_DIR) -type f -exec cp {} $(DIST_DIR) \;
# Generate documentation using doxygen
.PHONY: doc
doc:
make dist
doxygen doxyfile
open html/index.html