-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
85 lines (62 loc) · 2.48 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
################################################################################
## 42 LABS ##
################################################################################
NAME := 42labs
ENCODER := encoder
DECODER := decoder
BIN_FILE := encoded.ft
CC := cc
CYAN := \33[1;36m
RESET := \033[0m
LOG := printf "[$(CYAN)INFO$(RESET)] %s\n"
################################################################################
## DIRECTORIES ##
################################################################################
OBJ_DIR := obj
INC_DIRS := include
SRC_DIRS := huffman_zip data_operations ipc enc_prog dec_prog
SRC_DIRS := $(addprefix src/, $(SRC_DIRS))
SRC_DIRS += src
vpath %.h $(INC_DIRS)
vpath %.c $(SRC_DIRS)
HEADERS := huffman.h sem_shm.h encoder.h decoder.h
SOURCES_ENC := encoder.c
SOURCES_ENC += huff_decode.c huff_dictionary.c huff_encode.c
SOURCES_ENC += huff_list.c huff_table.c huff_tree.c file.c
SOURCES_ENC += ipc_error.c ipc_sem.c ipc_shm.c enc_utils.c
SOURCES_ENC += dec_utils.c enc_sections.c dec_sections.c
SOURCES_DEC := decoder.c
SOURCES_DEC += huff_decode.c huff_dictionary.c huff_encode.c
SOURCES_DEC += huff_list.c huff_table.c huff_tree.c file.c
SOURCES_DEC += ipc_error.c ipc_sem.c ipc_shm.c enc_utils.c
SOURCES_DEC += dec_utils.c enc_sections.c dec_sections.c
OBJS_ENC := $(addprefix $(OBJ_DIR)/, $(SOURCES_ENC:.c=.o))
OBJS_DEC := $(addprefix $(OBJ_DIR)/, $(SOURCES_DEC:.c=.o))
################################################################################
## COMPILATION ##
################################################################################
CFLAGS := -Wall -Werror -Wextra -g $(addprefix -I,$(INC_DIRS))
all: $(NAME)
$(NAME): $(ENCODER) $(DECODER)
$(ENCODER): $(OBJS_ENC)
@$(LOG) "Linking objects to $@"
$(CC) $^ -lrt -lpthread -o $@
$(DECODER): $(OBJS_DEC)
@$(LOG) "Linking objects to $@"
$(CC) $^ -lrt -lpthread -o $@
$(OBJ_DIR)/%.o: %.c $(HEADERS) | $(OBJ_DIR)
@$(LOG) "Compiling $@"
$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR):
@$(LOG) "Creating objects directory"
@mkdir $@
clean:
@$(RM) -r $(OBJS_ENC) $(OBJS_DEC)
@$(LOG) "Removing objects"
@$(RM) -r $(OBJ_DIR)
@$(LOG) "Removing objects directory"
fclean: clean
@$(RM) -r $(ENCODER) $(DECODER) $(BIN_FILE)
@$(LOG) "Removing $(ENCODER) $(DECODER)"
re: fclean all
.PHONY: all clean fclean re