-
Notifications
You must be signed in to change notification settings - Fork 0
/
Complex_Makefile
131 lines (111 loc) · 3.51 KB
/
Complex_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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
##
## This is a Basic Makefile Template
## Copyright (C) 2017 paul-marie.bettinelli@epitech.eu
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##
##
## To use it, you must to have the following architecture:
## source / object / include / tests - repository for C, or
## Source / Object / Include / Tests - repository for C++
##
LD = @ld
CC = @gcc
CXX = @g++
ASM = @nasm
ARM-AS = @arm-linux-gnueabi-as
ARM-LD = @arm-linux-gnueabi-ld
SRC = $(wildcard $(addprefix source/, *).asm)
NOM = $(basename $(notdir $(SRC)))
OBJ = $(addprefix object/, $(addsuffix .o, $(NOM)))
SRC-CRIT = $(wildcard $(addprefix tests/, *).c)
SRC-TEST = $(addprefix test/, main.c)
SRC-ARM = $(wildcard $(addprefix bonus/, *).S)
SRC-32 = $(wildcard $(addprefix bonus/, *).asm)
OBJ-TEST = $(SRC-TEST:.c=.o)
OBJ-CRIT = $(SRC-CRIT:.c=.o)
OBJ-ARM = $(SRC-ARM:.S=.o)
OBJ-32 = $(SRC-32:.asm=.o)
CPPFLAGS += -Wall -Wextra -fPIC -g3
LDFLAGS += -shared
CFLAGS += -Iinclude -fno-builtin
CXXFLAGS += -IInclude -fno-builtin
ASFLAGS += -felf64 -Iinclude/
32FLAGS += -felf32 -Iinclude/
CRITFLAGS = -lcriterion --coverage
SURNAME = asm
NAME = libasm.so
NARME = arm
NAME-32 = lib32.so
END = \033[0m
BOLD = \033[1m
GREY = \033[30m
RED = \033[31m
GREEN = \033[32m
YELLOW = \033[33m
BLUE = \033[34m
PURPLE = \033[35m
CYAN = \033[36m
WHITE = \033[37m
all: $(NAME)
$(NAME): $(OBJ)
@$(LD) $(LDFLAGS) -o $(NAME) $(OBJ)
@echo "$(GREEN)* * * * * COMPLETED * * * * *$(END)"
test_run: all $(OBJ-CRIT)
@$(CC) $(CFLAGS) $(CRITFLAGS) $(OBJ-CRIT) -ldl
@echo "$(GREEN)* * * * * COMPLETED * * * * *$(END)"
./a.out
intosh: $(OBJ-TEST)
@$(CC) -L$(NAME) -o $(SURNAME) $(OBJ-TEST)
@echo "$(GREEN)* * * TESTS COMPLETED * * *$(END)"
bonus: $(OBJ-ARM) $(OBJ-32)
@$(ARM-LD) -o $(NARME) $(OBJ-ARM)
@$(LD) $(LDFLAGS) -melf_i386 -o $(NAME-32) $(OBJ-32)
@echo "$(GREEN)* * * * * COMPLETED * * * * *$(END)"
clean:
@find . -type f \( -iname "*~" \) -delete
@$(RM) $(OBJ)
@$(RM) $(OBJ-ARM)
@$(RM) $(OBJ-TEST)
@$(RM) $(OBJ-CRIT)
@$(RM) $(OBJ-32)
@echo "$(RED)* * * * * CLEANED * * * * *$(END)"
fclean: clean
@$(RM) $(SURNAME)
@$(RM) $(NARME)
@$(RM) $(NAME)
@$(RM) $(NAME-32)
@$(RM) a.out
re: fclean all
object/%.o: %.c
@$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< \
&& echo "$(GREEN)[OK]$(BOLD)" $< "$(END)" \
|| echo "$(RED)[KO]$(BOLD)" $< "$(END)"
Object/%.o: Source/%.cpp
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< \
&& echo "$(GREEN)[OK]$(BOLD)" $< "$(END)" \
|| echo "$(RED)[KO]$(BOLD)" $< "$(END)"
object/%.o: source/%.asm
@$(ASM) $(ASFLAGS) -o $@ $< \
&& echo "$(GREEN)[OK]$(BOLD)" $< "$(END)" \
|| echo "$(RED)[KO]$(BOLD)" $< "$(END)"
%.o: %.S
@$(ARM-AS) -o $@ $< \
&& echo "$(GREEN)[OK]$(BOLD)" $< "$(END)" \
|| echo "$(RED)[KO]$(BOLD)" $< "$(END)"
%.o: %.asm
@$(ASM) $(32FLAGS) -o $@ $< \
&& echo "$(GREEN)[OK]$(BOLD)" $< "$(END)" \
|| echo "$(RED)[KO]$(BOLD)" $< "$(END)"
.PHONY: all clean fclean re intosh bonus