-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
84 lines (63 loc) · 1.18 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
# Release/Debug
DEBUG=yes
# Directories
SRC_DIR = SRC
INC_DIR = INC
OBJ_DIR = OBJ
BIN_DIR = BIN
CC = gcc
CFLAGS = -W -Wall -Wextra -O2 -lm
BIN = TestLib
ifeq ($(DEBUG), yes)
CFLAGS += -g -DDEBUG
endif
SRC = $(foreach dir, $(SRC_DIR), $(wildcard $(dir)/*.c))
OBJ = $(addsuffix .o, $(basename $(subst ${SRC_DIR}, ${OBJ_DIR}, ${SRC})))
.PHONY: clear dir
.SUFFIXES:
all: dir $(BIN_DIR)/$(BIN)
#
# BIN creation.
#
$(BIN_DIR)/$(BIN): $(OBJ)
ifeq ($(DEBUG), yes)
$(CC) $(OBJ) -o $@ -I $(INC_DIR) $(CFLAGS)
else
@$(CC) $(OBJ) -o $@ -I $(INC_DIR) $(CFLAGS)
endif
@echo "$(BIN) well created !"
#
# Object files creation.
#
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
ifeq ($(DEBUG), yes)
$(CC) -c $^ -o $@ -I $(INC_DIR) $(CFLAGS)
else
@$(CC) -c $^ -o $@ -I $(INC_DIR) $(CFLAGS)
@echo -e "Creating $@"
endif
#
# Other usefull targets.
#
clean:
ifeq ($(DEBUG), yes)
rm -rf ./$(OBJ_DIR);
rm -rf ./$(BIN_DIR);
else
@rm -rf ./$(OBJ_DIR);
@echo -e "Remove object file and directory"
@rm -rf ./$(BIN_DIR);
@echo -e "Remove executable and remove bin directory"
endif
rebuild: clean all
#
# Screen cleaning.
#
clear:
clear
#
# Repository creation.
#
dir:
@mkdir -p $(OBJ_DIR)
@mkdir -p $(BIN_DIR)