-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
175 lines (151 loc) · 7.52 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Compiler
CC := gcc
# Compiler flags
DEFINES := $(if $(filter all-without-colors, $(MAKECMDGOALS)),-DNO_USE_COLORS,)
CC_WFLAGS := -W -Wall -Wextra -pedantic -std=c89
CC_LFLAGS :=
CFLAGS := $(CC_OFLAGS) $(CC_WFLAGS) $(DEFINES) $(if $(filter sharedlib, $(MAKECMDGOALS)),-fPIC,)
AR_FLAGS := rcs
# Tools
RM := rm
RM_FLAGS := -rf
MKDIR := mkdir
MKDIR_FLAGS := -p
CP := cp
CP_FLAGS := -f
FIND := find
# Directories
BUILDDIR := build
BINLIBDIR := binlib
SOURCES := src/core/Decode/DecodeSos/DecodeSos.c \
src/core/Decode/DecodeWonderMail/DecodeWonderMail.c \
src/core/Decode/UtilDecode/UtilDecode.c \
src/core/Encode/EncodeSos/EncodeSos.c \
src/core/Encode/EncodeWonderMail/EncodeWonderMail.c \
src/core/Encode/UtilEncode/UtilEncode.c \
src/core/Convert/Convert.c \
src/core/UtilCore/UtilCore.c \
src/data/md1database/md1database.c \
src/util/messages.c
OBJECTS := $(BUILDDIR)/DecodeSos.o $(BUILDDIR)/DecodeWonderMail.o $(BUILDDIR)/UtilDecode.o \
$(BUILDDIR)/EncodeSos.o $(BUILDDIR)/EncodeWonderMail.o $(BUILDDIR)/UtilEncode.o \
$(BUILDDIR)/Convert.o \
$(BUILDDIR)/UtilCore.o \
$(BUILDDIR)/md1database.o \
$(BUILDDIR)/messages.o
TEST_SUITE := test/CuTest.c test/allTests.c
TEST_FILES := src/core/UtilCore/UtilCore_test.c \
src/core/Decode/UtilDecode/UtilDecode_test.c \
src/core/Encode/UtilEncode/UtilEncode_test.c \
src/core/Decode/DecodeWonderMail/DecodeWonderMail_test.c \
src/core/Decode/DecodeSos/DecodeSos_test.c \
src/core/Encode/EncodeWonderMail/EncodeWonderMail_test.c \
src/core/Encode/EncodeSos/EncodeSos_test.c \
src/core/Convert/Convert_test.c
TEST_RESULT := $(BUILDDIR)/tests
# Library header
LIB_HEADER_NAME := pokem.h
# Deployment
STATIC_LIB_NAME := libpokem.a
STATIC_LIB_DEPLOY_FILEPATH := $(BINLIBDIR)/$(STATIC_LIB_NAME)
SHARED_LIB_NAME := libpokem.so
SHARED_LIB_DEPLOY_FILEPATH := $(BINLIBDIR)/$(SHARED_LIB_NAME)
LIB_HEADER_DEPLOY_FILEPATH := $(BINLIBDIR)/$(LIB_HEADER_NAME)
# Messages
MSG := printf
# Colors
NOCOLOR := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[0m)
BLACK := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[0;30m)
DARKGRAY := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[1;30m)
RED := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[0;31m)
LIGHTRED := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[1;31m)
GREEN := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[0;32m)
LIGHTGREEN := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[1;32m)
ORANGE := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[0;33m)
YELLOW := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[1;33m)
BLUE := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[0;34m)
LIGHTBLUE := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[1;34m)
PURPLE := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[0;35m)
LIGHTPURPLE := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[1;35m)
CYAN := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[0;36m)
LIGHTCYAN := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[1;36m)
LIGHTGRAY := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[0;37m)
WHITE := $(if $(filter -DNO_USE_COLORS, $(DEFINES)),,\033[1;37m)
# ----------------------------------------------------------------------------------------------------
.DEFAULT_GOAL := all
.PHONY: all all-without-colors staticlib sharedlib clean help
all: $(STATIC_LIB_DEPLOY_FILEPATH) ## Build Pokem library (default)
# Check all-without-colors: $(DEFINED) += -DNO_USE_COLORS
all-without-colors: $(STATIC_LIB_DEPLOY_FILEPATH) ## Build Pokem library without color support
staticlib: $(BUILDDIR) $(STATIC_LIB_DEPLOY_FILEPATH) ## Build Pokem static library
sharedlib: $(BUILDDIR) $(SHARED_LIB_DEPLOY_FILEPATH) ## Build Pokem shared library
test: $(TEST_RESULT) ## Build and run tests
clean: ## Remove all leftovers from the previous build
@$(MSG) "$(YELLOW)Cleaning Pokem...$(NOCOLOR)\n\n"
@$(MSG) "$(ORANGE)Removing intermediate objects files...$(NOCOLOR)\n"
$(RM) $(RM_FLAGS) $(RM_FLAGS) $(RC_OBJ) $(OBJECTS) $(OBJS)
@$(MSG) "$(ORANGE)Removing binaries...$(NOCOLOR)\n"
$(RM) $(RM_FLAGS) $(RM_FLAGS) $(STATIC_LIB_DEPLOY_FILEPATH)
@$(MSG) "$(ORANGE)Removing headers...$(NOCOLOR)\n"
$(RM) $(RM_FLAGS) $(RM_FLAGS) $(STATIC_H)
@$(MSG) "$(ORANGE)Removing tests...$(NOCOLOR)\n"
$(RM) $(RM_FLAGS) $(RM_FLAGS) $(TEST_RESULT)
@$(MSG) "$(ORANGE)Removing directories...$(NOCOLOR)\n"
$(RM) $(RM_FLAGS) $(BUILDDIR)
$(RM) $(RM_FLAGS) $(BINLIBDIR)
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "$(WHITE)%-16s$(NOCOLOR) %s\n", $$1, $$2}'
# Static library header
$(LIB_HEADER_DEPLOY_FILEPATH): $(BINLIBDIR)
@$(MSG) "$(YELLOW)Deploying the library header file...$(NOCOLOR)\n"
@$(MSG) "#ifndef POKEM_H\n" > $@
@$(MSG) "#ifdef __cplusplus\n" >> $@
@$(MSG) "extern \"C\" {\n" >> $@
@$(MSG) "#endif\n" >> $@
@$(MSG) "#define POKEM_H\n" >> $@
@$(MSG) "\n#include <stdio.h>\n" >> $@
@$(MSG) "\n/** DEFINITIONS AND DATABASE: */\n" >> $@
@$(FIND) src/data -path "*.h" -type f -exec tools/printSingleHeaderContent.sh {} \; | grep -v '#include "' | grep -v '#include"' | grep -v '#include <' | grep -v '#include<' >> $@
@$(MSG) "\n/** CORE FUNCTIONALITIES: */\n" >> $@
@$(FIND) src/core -path "*.h" -type f -exec tools/printSingleHeaderContent.sh {} \; | grep -v '#include "' | grep -v '#include"' | grep -v '#include <' | grep -v '#include<' >> $@
@$(MSG) "\n/** UTILITIES: */\n" >> $@
@tools/printSingleHeaderContent.sh ./src/util/messages.h | grep -v '#include "' | grep -v '#include"' | grep -v '#include <' | grep -v '#include<' >> $@
@$(MSG) "#ifdef __cplusplus\n" >> $@
@$(MSG) "}\n" >> $@
@$(MSG) "#endif\n" >> $@
@$(MSG) "\n#endif /* POKEM_H */" >> $@
# Static library
$(STATIC_LIB_DEPLOY_FILEPATH): $(BUILDDIR) $(BINLIBDIR) $(OBJECTS) $(LIB_HEADER_DEPLOY_FILEPATH)
@$(MSG) "$(YELLOW)Building and linking static library file...$(NOCOLOR)\n"
$(AR) $(AR_FLAGS) $@ $(OBJECTS)
@$(MSG) "\n$(LIGHTGREEN)Done. The static library was built in the $(LIGHTBLUE)$(BINLIBDIR)$(LIGHTGREEN) directory.$(NOCOLOR)\n\n"
# Shared library
$(SHARED_LIB_DEPLOY_FILEPATH): $(BUILDDIR) $(BINLIBDIR) $(OBJECTS) $(LIB_HEADER_DEPLOY_FILEPATH)
@$(MSG) "$(YELLOW)Building and linking shared library file...$(NOCOLOR)\n"
$(CC) $(OBJECTS) -shared -o $@
@$(MSG) "\n$(LIGHTGREEN)Done. The shared library was built in the $(LIGHTBLUE)$(BINLIBDIR)$(LIGHTGREEN) directory.$(NOCOLOR)\n\n"
$(TEST_RESULT): $(BUILDDIR) $(TEST_FILES)
@$(MSG) "$(LIGHTGREEN)Building tests...$(NOCOLOR)\n"
$(CC) -o $@ $(TEST_SUITE) $(TEST_FILES) $(SOURCES)
@$(MSG) "$(LIGHTGREEN)Running tests...$(NOCOLOR)\n"
@$@
$(OBJECTS):
@$(MSG) "$(GREEN)Compiling $(BLUE)$<$(GREEN)...$(NOCOLOR)\n"
$(CC) -c $(CFLAGS) $< -o $@
$(BUILDDIR):
@$(MSG) "$(YELLOW)Creating $@ directory...$(NOCOLOR)\n"
$(MKDIR) $(MKDIR_FLAGS) $(BUILDDIR)
$(BINLIBDIR):
@$(MSG) "$(YELLOW)Creating $@ directory...$(NOCOLOR)\n"
$(MKDIR) $(MKDIR_FLAGS) $(BINLIBDIR)
# Intermediate objects build rules
$(BUILDDIR)/DecodeSos.o: src/core/Decode/DecodeSos/DecodeSos.c
$(BUILDDIR)/DecodeWonderMail.o: src/core/Decode/DecodeWonderMail/DecodeWonderMail.c
$(BUILDDIR)/UtilDecode.o: src/core/Decode/UtilDecode/UtilDecode.c
$(BUILDDIR)/EncodeSos.o: src/core/Encode/EncodeSos/EncodeSos.c
$(BUILDDIR)/EncodeWonderMail.o: src/core/Encode/EncodeWonderMail/EncodeWonderMail.c
$(BUILDDIR)/UtilEncode.o: src/core/Encode/UtilEncode/UtilEncode.c
$(BUILDDIR)/Convert.o: src/core/Convert/Convert.c
$(BUILDDIR)/UtilCore.o: src/core/UtilCore/UtilCore.c
$(BUILDDIR)/md1database.o: src/data/md1database/md1database.c
$(BUILDDIR)/messages.o: src/util/messages.c