-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
241 lines (176 loc) · 5.3 KB
/
Copy pathMakefile
File metadata and controls
241 lines (176 loc) · 5.3 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# Makefile at <external-search/>
# ==============================
# Last update: 14/09/24.
.PHONY: build_and_run build rebuild run clean full-clean
# Directories
# -----------
dir_src := src/
dir_hdr := $(dir_src)/include/
dir_drv := drv/
dir_bin := bin/
dir_lib := $(dir_bin)
dir_obj := $(dir_bin)obj/
dir_exe := $(dir_bin)exe/
dir_data := data/
dir_cache := $(dir_bin)cache/
# Files
# -----
source_files := $(wildcard $(dir_src)*.c)
header_files := $(wildcard $(dir_hdr)*.h)
driver_sources := $(wildcard $(dir_drv)*.c)
object_files := $(foreach object,$(subst .c,.o,$(subst $(dir_src),,$(source_files))),$(dir_obj)$(object))
target_executables := $(foreach executables,$(subst .c,.exe,$(subst $(dir_drv),,$(driver_sources))),$(dir_exe)$(executables))
es_exe := $(dir_exe)ordena.exe
maintain_data_exe := $(dir_exe)prepare-data.exe
order_data_files := data/PROVAO_ASCENDING.txt data/PROVAO_DESCENDING.txt bin/cache/NOTHING-AS.bin bin/cache/NOTHING-DS.bin
__dummy_cache_file := $(dir_cache)__nothing.nothing
# Static library
# --------------
target_libname := external-search.lib
target_lib := $(dir_lib)$(target_libname)
# Running
# =======
# Running directives
METHOD ?= 3
QTT ?= 100
SITUATION ?= 3
PRINT ?= true
HELP ?= false
CONCAT ?= true
__METHOD := $(METHOD)
__QTT := $(QTT)
__PRINT :=
__HELP :=
__CONCAT :=
ifeq ($(METHOD),eqs)
__METHOD = 3
else ifeq ($(METHOD),e2fms)
__METHOD = 2
else ifeq ($(METHOD),e2fmu)
__METHOD = 1
endif
ifeq ($(QTT),all)
__QTT = 471705
endif
ifeq ($(PRINT),true)
__PRINT = -P
endif
ifeq ($(HELP),true)
__HELP = -H
endif
ifeq ($(CONCAT),false)
__CONCAT = -C
endif
build_and_run: __build run
run:
./$(es_exe) $(__METHOD) $(__QTT) $(SITUATION) $(__PRINT) $(__HELP) $(__CONCAT)
# Building make build <FLAGS>
# ================================
# Building directives
__OPTIONAL_COMPILE_DIRECTIVES :=
VERBOSE ?= false
ifeq ($(VERBOSE),true)
__OPTIONAL_COMPILE_DIRECTIVES += -D ES_VERBOSE=true -D ES_DEBUG_EXECUTION=false
else ifeq ($(VERBOSE),+)
__OPTIONAL_COMPILE_DIRECTIVES += -D ES_VERBOSE=true -D ES_DEBUG_EXECUTION=false
else ifeq ($(VERBOSE),true+)
__OPTIONAL_COMPILE_DIRECTIVES += -D ES_VERBOSE=true -D ES_DEBUG_EXECUTION=true
else ifeq ($(VERBOSE),++)
__OPTIONAL_COMPILE_DIRECTIVES += -D ES_VERBOSE=true -D ES_DEBUG_EXECUTION=true
else
__OPTIONAL_COMPILE_DIRECTIVES += -D ES_VERBOSE=false -D ES_DEBUG_EXECUTION=false
endif
# Compiling directives
__COMMON_CMPL_DIRECTIVES := -Wall -Wextra -pedantic -O3 -std=c11 $(__OPTIONAL_COMPILE_DIRECTIVES)
EXE_COMPILE_DIRECTIVES := $(__COMMON_CMPL_DIRECTIVES) -I"$(dir_hdr)" -L"$(dir_lib)" -l:"$(target_libname)" -lm
OBJ_COMPILE_DIRECTIVES := $(__COMMON_CMPL_DIRECTIVES) -I"$(dir_hdr)"
# Building the path...
ifeq ($(OS),Windows_NT)
define MAKEDIR =
if not exist "$(@D)" mkdir "$(@D)"
endef
else
define MAKEDIR
mkdir -p "$(@D)"
endef
endif
build: __build
@echo Tudo construido.
__build: $(target_executables) __build_cache __maintain_data
__build_cache: $(__dummy_cache_file)
$(__dummy_cache_file):
@$(MAKEDIR)
# Compiling the drivers.
$(dir_exe)%.exe: $(dir_drv)%.c $(target_lib)
@$(MAKEDIR)
@gcc -o $@ $< $(__OPTIONAL_COMPILE_DIRECTIVES) $(EXE_COMPILE_DIRECTIVES)
@echo Assembling $<.
#$(target_executable): $(target_lib)
# @$(MAKEDIR)
# gcc -o $@ $< $(EXE_COMPILE_DIRECTIVES)
# @echo Assembling $<.
# Joining in the library.
$(target_lib): $(object_files)
@$(MAKEDIR)
@ar cr $@ $^
@echo Libraryd.
# Assembling each object file.
$(dir_obj)%.o: $(dir_src)%.c $(header_files)
@$(MAKEDIR)
@gcc -c $(__OPTIONAL_COMPILE_DIRECTIVES) $< -o $@ $(OBJ_COMPILE_DIRECTIVES)
@echo Compiled $@.
# ./$(<)
ifeq ($(VERBOSE),false)
define __EXECUTE_PREPARE_DATA =
./$(maintain_data_exe)
endef
else
define __EXECUTE_PREPARE_DATA =
echo preparacao desativada
endef
endif
__maintain_data: $(maintain_data_exe) $(order_data_files)
$(order_data_files):
@$(__EXECUTE_PREPARE_DATA)
# Re-building make rebuild <FLAGS>
# ======================================
rebuild: clean __build
#@echo System rebuilt.
# Cleaning make clean
# make full-clean
# =============================
# In case of windows, "rmdir /s /q" deletes
# all subdirectories and files of it (and finally the original directory)
# without asking for confirmation. The equivallent in unix systems
# will be -r and -f, respectively.
# Deletes automatically the path specified by the
# firstmost dependency.
ifeq ($(OS),Windows_NT)
CMD_REMOVE = if exist "$<" rmdir /s /q "$<"
else
CMD_REMOVE = rm -rf "$<"
endif
# The path up to where the makefile is on the system.
# It is for guaranteeing the deletion will occur correctly.
ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
full-clean: __clean_obj __clean_cache __clean_bin
@echo Full cleaned.
# By the way CMD_REMOVE works, every cleaning part,
# is separately resolved.
clean: __clean_obj
@echo All clean.
# Byproduct of the library construction object's file.
__clean_obj: $(dir_obj)
@$(CMD_REMOVE)
__clean_cache: $(dir_cache)
@$(CMD_REMOVE)
__clean_bin: $(dir_bin)
@$(CMD_REMOVE)
# * Each dependency of its respective cleaning part need
# not be analyzed. Their purpose is to become sort of a
# "parameter" for CMD_REMOVE, so they're hereby ignored...
$(dir_obj):
$(dir_cache):
$(dir_bin):
.PHONY: __build __build_cache __maintain_data
.PHONY: __clean_obj __clean_bin __clean_cache