-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
102 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
90
91
92
93
94
95
96
97
98
99
100
101
102
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: amahla <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/06/14 17:09:53 by amahla #+# #+# #
# Updated: 2023/06/14 19:51:34 by amahla ### ########.fr #
# #
# **************************************************************************** #
# ---
LIBSRCDIR := src
LIBOBJDIR := libasm
LIBASM := libasm.a
LIBSRC := ft_strlen.s \
ft_strcpy.s \
ft_strcmp.s \
ft_write.s \
ft_read.s \
ft_strdup.s \
ft_atoi_base.s \
ft_list_push_front.s \
ft_list_size.s \
ft_list_sort.s \
ft_list_remove_if.s
# ---
UNITSRCDIR := src
UNITOBJDIR := units
INCLUDEDIR := -I ./include
UNIT := units
UNITSRC := units.c
# ---
NASM := nasm
CC := clang
AR := ar rcs
RM := rm -rf
NASMFLAGS := -f elf64
CCFLAGS := -Wall -Wextra -Werror
LIBFLAGS := -L . -lasm
OPTFLAG :=
NAME := $(LIBASM)
OUTDIR := ./obj
OUTLIBDIR := $(addprefix $(OUTDIR)/, $(LIBSRCDIR))
OUTUNITDIR := $(addprefix $(OUTDIR)/, $(UNITSRCDIR))
# ---
ifdef DEBUG
OPTFLAG := -g
endif
# ---
all : $(NAME)
$(OUTLIBDIR)/%.o : $(LIBSRCDIR)/%.s
@mkdir -p $(dir $@)
$(NASM) $(NASMFLAGS) -o $@ $<
$(OUTUNITDIR)/%.o : $(UNITSRCDIR)/%.c
@mkdir -p $(dir $@)
$(CC) -MMD -MF $(addprefix $(OUTUNITDIR)/,$(UNITSRC:.c=.d)) $(OPTFLAG) $(CCFLAGS) $(INCLUDEDIR) -o $@ -c $<
$(NAME) : $(addprefix $(OUTLIBDIR)/,$(LIBSRC:.s=.o))
$(AR) $@ $^
ranlib $@
$(UNIT) : $(LIBASM) $(addprefix $(OUTUNITDIR)/,$(UNITSRC:.c=.o))
$(CC) $(OPTFLAG) -o $@ $(addprefix $(OUTUNITDIR)/,$(UNITSRC:.c=.o)) $(LIBFLAGS)
debug :
ifndef DEBUG
$(MAKE) $(UNIT) DEBUG=1
endif
gdb : $(UNIT)
gdb -q $(UNIT)
clean :
$(RM) $(OUTDIR)
fclean : clean
$(RM) $(NAME) $(UNIT)
re : fclean
$(MAKE) $(NAME)
.PHONY : all clean fclean re debug gdb