-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcore.mk
More file actions
664 lines (578 loc) · 20.5 KB
/
core.mk
File metadata and controls
664 lines (578 loc) · 20.5 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# Makefile core module
#
# <https://github.com/Captive-Studio/makefile-core>
#
# DO NOT EDIT!
# Generated by the script/build.sh script.
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# CONSOLE
# @see src/console.mk
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# Terminal colors
ifneq ($(TERM),)
BOLD := $(shell tput bold)
BLACK := $(shell tput setaf 0)
RED := $(shell tput setaf 1)
GREEN := $(shell tput setaf 2)
YELLOW := $(shell tput setaf 3)
LIGHTPURPLE := $(shell tput setaf 4)
PURPLE := $(shell tput setaf 5)
BLUE := $(shell tput setaf 6)
WHITE := $(shell tput setaf 7)
RESET := $(shell tput sgr0)
SMUL := $(shell tput smul)
RMUL := $(shell tput rmul)
else
BOLD :=
BLACK :=
RED :=
GREEN :=
YELLOW :=
LIGHTPURPLE :=
PURPLE :=
BLUE :=
WHITE :=
RESET :=
SMUL :=
RMUL :=
endif
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# FUNCTIONS
# @see src/functions.mk
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# Return a newline character
#
# Example:
# $(newline)
define newline
endef
# Escape a shell string passed as a single quoted string
#
# Usage:
# $(call escape-shell,<string>)
#
# Example:
# embeddable-text = $(call escape-shell,$(SOME_TEXT))
#
escape-shell = $(subst $(newline),\$(newline),$(subst ','\'',$(1)))
# Lower-case a string value.
#
# Usage:
# $(call lowercase,<string>)
#
# Example:
# $(call lowercase,HeLlO wOrLd) # "hello world"
lowercase = $(shell echo $(call escape-shell,$(1)) | tr '[:upper:]' '[:lower:]')
# Upper-case a string value.
#
# Usage:
# $(call uppercase,<string>)
#
# Example:
# $(call uppercase,HeLlO wOrLd) # "HELLO WORLD"
uppercase = $(shell echo $(call escape-shell,$(1)) | tr '[:lower:]' '[:upper:]')
# Slugify a string value.
#
# Usage:
# $(call slugify,<string>)
#
# Example:
# $(call slugify,HeLlO wOrLd) # "hello-world"
slugify = $(shell echo $(call escape-shell,$(1)) | tr '[:upper:]' '[:lower:]' | tr '[:punct:]' '-' | tr ' ' '-' )
# Determine the "truthiness" of a value.
#
# A value is considered to be falsy if it is:
#
# - empty, or
# - equal to "0", "N", "NO", "F" or "FALSE" after upper-casing.
#
# If the value is truthy then the value is returned as-is, otherwise no value
# is returned.
#
# Usage:
# $(call filter-false,<string>)
#
# Example:
#
# truthy := y
# truthy-flag := $(call filter-false,$(truthy)) # "y"
#
# falsy := n
# falsy-flag := $(call filter-false,$(falsy)) # <empty>
#
# ifneq ($(call filter-false,$(FLAG_ENABLED)),)
# // will executed only when FLAG_ENABLED is truthy
# endif
#
filter-false = $(filter-out 0 n no f false,$(call lowercase,$(1)))
# Returns the first command found
#
# Usage:
# $(call resolve-command,<cmd1> <cmd2> ...)
#
# Example:
# NODE_VERSION_MANAGER := $(call resolve-command,asdf nodenv nvm)
#
define resolve-command
$(firstword $(foreach cmd,$(1),$(shell which $(cmd) &>/dev/null && echo $(cmd))))
endef
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# HOOKS
# @see src/hooks.mk
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# Returns a list of target from $(1)
#
# -> 1. Run .before_each
# -> 2. Run $(1).before
# -> 3. Run $(1)
# -> 4. Run $(1).after
# -> 5. Run .after_each
#
# Usage:
# $(call core-hooks,<target>)
#
# Example:
# .PHONY: my-target $(call core-hooks,.my-target)
# my-target: $(call core-hooks,.my-target)
# .my-target.before::
# @echo Before my-target !
# .my-target:
# @echo Run my-target !
# .my-target.after::
# @echo After my-target !
#
define core-hooks
.before_each $(1).before $(1) $(1).after .after_each
endef
# Global hook that should be run before each target
#
# Example:
# .before_each::
# @echo Before each !
#
.before_each::
@$(call log,debug,[Make] .before_each hook,0)
# Global hook that should be run after each target
#
# Example:
# .after_each::
# @echo After each !
#
.after_each::
@$(call log,debug,[Make] .after_each hook,0)
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# LOG
# @see src/log.mk
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# Externally define log levels
LOG_DEBUG := 0
LOG_INFO := 1
LOG_WARN := 2
LOG_ERROR := 3
LOG_FATAL := 4
## Set the log level (debug/info/warn/error/fatal default:info)
LOG_LEVEL ?= info
export LOG_LEVEL
# Define some commonly used values in log strings
LOG_HEADER_DEBUG := -d-
LOG_HEADER_INFO := =i=
LOG_HEADER_WARN := =!=
LOG_HEADER_ERROR := =!=
LOG_HEADER_FATAL := !!!
# Defined in makefile-core
LOG_COLOR_DEBUG := $(PURPLE)
LOG_COLOR_INFO := $(BLUE)
LOG_COLOR_WARN := $(YELLOW)
LOG_COLOR_ERROR := $(RED)
LOG_COLOR_FATAL := $(RED)
#define some useful macros
__log_to_upper = $(shell echo $(1) | tr '[:lower:]' '[:upper:]')
# __log_to_lower = $(shell echo $(1) | tr '[:upper:]' '[:lower:]')
# Define the logging macros
define __log_generic
([ $(LOG_$(call __log_to_upper,$(LOG_LEVEL))) -gt $(2) ] || echo "$(log_bold)$(3)$(4) $(5)$(1)$(RESET)")
endef
# Log a message to console
#
# Usage:
# $(call log,<level>,<message>,<indent_level>)
#
# Example:
# @$(call log,info,"[MyCategory] Install something...",0)
# @$(call log,info,"[MyCategory] Sub command with indent...",1)
#
define log
$(call __log_generic,$(2),$(LOG_$(call __log_to_upper,$(1))),$(LOG_COLOR_$(call __log_to_upper,$(1))),$(LOG_HEADER_$(call __log_to_upper,$(1))),$(shell [ "$(or $(3),0)" = 0 ] || for i in $(shell seq 1 $(or $(3),0)); do echo -n ' '; done))
endef
# Log a message with fatal level and exit program
#
# Usage:
# $(call panic,<message>)
# Example:
# $(call panic,Something wrong happened !)
#
define panic
$(call log,fatal,$(1));exit 1
endef
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# VARIABLES
# @see src/variables.mk
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# Disable built-in rules and variables
# (this increases performance and avoids hard-to-debug behaviour);
MAKEFLAGS += -rR
# Avoid messages "Entering directory ..."
MAKEFLAGS += --no-print-directory
# Avoid funny character set dependencies
unexport LC_ALL
LC_COLLATE=C
LC_NUMERIC=C
export LC_COLLATE LC_NUMERIC
## Set the make output as verbose
VERBOSE ?= false
# Binaries
BUNDLE := bundle
CAT := cat
CD := cd
CHMOD := chmod
CP := cp
CURL := curl
DOCKER := docker
FALSE := false
FIND := find
GIT := git
GREP := grep -E
JQ := jq
LN := ln
LS := ls
MKDIRP := mkdir -p
MV := mv
NOFAIL := 2>$(NULL) || $(TRUE)
NPM := npm
NULL := /dev/null
PRINTENV := printenv
PWD := pwd
RM := rm
SED := sed
TAIL := tail
TOUCH := touch
TRUE := true
# Make current process id
export MAKE_PID := $(shell echo $$PPID)
# Make parent process id
# We allow overriding for internal implementation. The parent make command will provide to the children
ifeq ($(MAKE_PPID),)
MAKE_PPID := $(MAKE_PID)
endif
export MAKE_PPID
# Read uname (Linux|Darwin|...|Unknown)
ifndef UNAME
UNAME := $(shell uname 2>/dev/null || echo Unknown)
endif
# Read uname short name (Linux|Darwin|...|Unknown)
ifndef OS
OS := $(shell uname -s 2>/dev/null || echo Unknown)
endif
# Host name (ex: MacBook-Pro-13-de-Julien.local)
ifndef HOSTNAME
HOSTNAME := $(shell hostname)
endif
# Quiet flag. The command will be logged in console only when $(VERBOSE) is truthy
# @example
# $(Q)echo 'foo'
ifneq ($(call filter-false,$(VERBOSE)),)
# Verbose output
Q=
else
# Quiet output
Q=@
endif
# Configure shell as bash and strict mode
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
# Use gdate on macOS
ifeq ($(UNAME),Darwin)
DATE := gdate
else
DATE := date
endif
ifeq ($(CWD),)
CWD := $(shell pwd)
endif
# Detect NPROC (number of processors)
ifeq ($(NPROC),)
NPROC := 1
ifeq ($(UNAME),Linux)
NPROC := $(shell nproc)
else ifeq ($(UNAME),Darwin)
NPROC := $(shell sysctl -n hw.ncpu)
endif
endif
# Directory containing all git modules
MODULES_PATH := .modules
# Makefile variables
# URL to the updater script
MAKEFILE_CORE := $(MODULES_PATH)/core.mk
## Upstream for core.mk used by make self-update
MAKEFILE_CORE_URL ?= https://raw.githubusercontent.com/Captive-Studio/makefile-core/main/core.mk
## Makefiles to be included (default ".modules/*/Makefile", ".modules/*/*.{mk,make}")
MAKEFILE_INCLUDE ?= $(wildcard $(MODULES_PATH)/*/module.make) $(wildcard $(MODULES_PATH)/*/module.mk)
## Makefiles to be excluded (default "$(MAKEFILE_CORE)")
MAKEFILE_EXCLUDE ?= $(MAKEFILE_CORE) # Filtrer les fichiers qui commencent par "_"
## Optional Makefile loaded to override locally any value (default "Makefile.local")
MAKEFILE_LOCAL ?= Makefile.local
# Main Makefile path
MAKEFILE_PATH := $(abspath $(firstword $(MAKEFILE_LIST)))
# This target will print every variables declared in $(.VARIABLES)
#
# Example : make print-variables
#
.PHONY: print-variables
print-variables: ## Print all declared variables
@$(foreach V,$(sort $(.VARIABLES)), \
$(if $(filter-out environment% default automatic, \
$(origin $V)),$(info $V=$(YELLOW)"$($V)$(RESET)$(YELLOW)"$(RESET)$(if $(filter-out $(value $V), $($V)),$(BLACK) # `$(value $V)$(RESET)`,)) \
) \
)
@exit 0
# This target will print a given variable
#
# Example : make print-VAR
#
.PHONY: print-%
print-%: ## Print given variable after "-" (ex: print-VAR)
@echo $($*)
# Define default goal to help
.DEFAULT_GOAL := help
# A common target to force rebuild
# @see https://www.gnu.org/software/make/manual/html_node/Force-Targets.html
FORCE: ;
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# UPDATER
# @see src/updater.mk
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
MODULES_FILE := module.json
##
MODULE_UPDATE_COMMIT_MESSAGE_PREFIX ?= 🔨 Upgrade
.self_add_module=$(or $(name), $(notdir $(url)), '')
# Returns a list of all module names from the modules.json file.
#
# Usage:
# make self-list
#
.PHONY: self-list
self-list: ## List all installed modules (in module.json)
$(Q)if [ ! -f "$(MODULES_FILE)" ]; then \
$(call panic,$(MODULES_FILE) does not exist. Try make self-add to add modules.); \
fi
$(Q)$(JQ) -r 'keys[]' $(MODULES_FILE)
# Returns a list of all module names from the modules.json file.
#
# Usage:
# make self-add name=<string> url=<git-repository>
#
# Example:
# make self-add name=makefile-ci url=https://github.com/Captive-Studio/makefile-ci
#
.PHONY: self-add
self-add: $(MODULES_PATH) ## url=<git-repository> [name=<string>] Install a module in .modules/ (using git subtree)
$(Q)if [ -z "$(.self_add_module)" ] || [ -z "$(url)" ]; then \
$(call panic,Usage: make self-add name=<string> url=<git-repository>); \
fi
# Create folder
$(Q)$(MKDIRP) $(MODULES_PATH)
# Check if module is already present
$(Q)if $(JQ) -e '.["$(.self_add_module)"]' $(MODULES_FILE) &>/dev/null; then \
$(call panic,$(.self_add_module) already present in $(MODULES_FILE)); \
elif [ -d "$(MODULES_PATH)/$(.self_add_module)" ]; then \
$(call panic,$(MODULES_PATH)/$(.self_add_module) should be empty); \
fi
# Linking repository
@$(call log,info,[Make] Adding subtree: $(.self_add_module) from $(url),0);
$(Q)$(GIT) subtree add --prefix=$(MODULES_PATH)/$(.self_add_module) $(url) main --squash;
# git commit -m "chore(subtree): add $(name) from $(repo)";
# Create empty file if it does not exist
$(Q)if [ ! -f "$(MODULES_FILE)" ]; then \
echo "{}" > $(MODULES_FILE); \
fi
# Edit module.json file
$(Q)echo "Adding $(.self_add_module) to $(MODULES_FILE)";
$(Q)$(JQ) \
'.["$(.self_add_module)"] = "$(url)"' \
$(MODULES_FILE) > $(MODULES_FILE).tmp \
&& mv $(MODULES_FILE).tmp $(MODULES_FILE)
# This target will
# 1. Update makefile/core.mk
# 2. Update all submodules
#
# Example : make self-update
#
.PHONY: self-update
self-update: ## Update all modules (in .modules/)
# Update core
$(Q)$(MAKE) -f $(firstword $(MAKEFILE_LIST)) self-update.core
# Update modules
$(Q)$(MAKE) -f $(firstword $(MAKEFILE_LIST)) self-update.modules
# Target for makefile core
.PHONY: self-update.core
self-update.core:
@$(call log,info,[Make] Updating $(MAKEFILE_CORE) from git...,0)
# Download file using curl
$(Q)-$(CURL) -sSfL "$(MAKEFILE_CORE_URL)" --output "$(MAKEFILE_CORE)"
# Update index (if file was not changed, we do not care about file time modification)
$(Q)-$(GIT) update-index --refresh $(MAKEFILE_CORE) || true
# Commit changes if needed
$(Q)$(GIT) diff --quiet HEAD -- $(MAKEFILE_CORE) \
|| $(GIT) commit -m "$(MODULE_UPDATE_COMMIT_MESSAGE_PREFIX) makefile-core" $(MAKEFILE_CORE)
# Target for makefile modules
.PHONY: self-update.modules
self-update.modules:
@$(call log,info,[Make] Updating $(MODULES_PATH)/* ...,0)
ifeq ($(wildcard $(MODULES_FILE)),)
# No module.json found
@$(call log,warn,[Make] Update skipped (no module.json found),0)
else
# module.json found
$(Q)$(JQ) -r 'to_entries[] | "\(.key) \(.value)"' $(MODULES_FILE) | while read name repo; do \
$(call log,info,>> $$name,1); \
git subtree pull --prefix=$(MODULES_PATH)/$$name $$repo main \
--squash \
--message "$(MODULE_UPDATE_COMMIT_MESSAGE_PREFIX) $$name"; \
done
@$(call log,info,[Make] Update finished,0)
endif
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# EVAL
# @see src/eval.mk
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# Evaluate a given command in the make environment.
#
# Usage:
# make eval command=<string>
# Example:
#
.PHONY: eval $(call core-hooks,.eval)
eval: $(call core-hooks,.eval) ## command=<string> Evaluate command in make environment
# Eval implementation
.eval:
$(Q)$(command)
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# PRINT-ENV
# @see src/print-env.mk
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# Variables that are defined in makefile
define .VARIABLES_ENV
$(foreach V,$(.VARIABLES), \
$(if $(filter-out environment% default automatic, $(origin $V)), $V) \
)
endef
# Not portable variables
.VARIABLES_INTERNAL_HIDDEN := PWD SHELL MAKEFLAGS MAKE_PID MAKE_PPID
.PHONY: env
print-env: .before_each ## Display all env variables exported by make
@env | \
grep -E "^($(shell echo $(CI_VARIABLES) $(filter-out $(.VARIABLES_INTERNAL_HIDDEN),$(.VARIABLES_ENV)) | tr ' ' '|'))=" | \
sort -f
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# DOCTOR
# @see src/doctor.mk
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# Makefile doctor list of targets
MAKEFILE_DOCTOR_TARGETS :=
# Display a diagnostic of common errors
#
# To add a new check just create a new target (.doctor is a convention)
# .doctor.my-target:
# //...
#
# MAKEFILE_DOCTOR_TARGETS += .doctor.my-target # Register target
#
# Example : make doctor
#
.PHONY: doctor
doctor: ## Check your system for potential problems.
@$(call log,info,"[Make] Doctor")
$(Q)FAILS=0; \
for target in $(MAKEFILE_DOCTOR_TARGETS); do \
$(MAKE) $$target || FAILS=1; \
done; \
if [ $$FAILS -eq 0 ]; then \
$(call log,info,"🎉 Everything is OK",1); \
else \
$(call log,fatal,"❌ Some problems need to be fixed",1); \
exit 1; \
fi
# Default doctor jobs that will check if git modules were initialized
.PHONY: .doctor.git-submodules
.doctor.git-submodules:
@$(call log,info,"✓ Checking git submodules",1);
$(Q)if [ ! -f .gitmodules ]; then \
exit 0; \
fi
$(Q)MISSING=$$(grep path .gitmodules | sed 's/.*= //' | xargs -n 1 sh -c 'test ! -d "$$0" && echo $$0'); \
if [ -n "$$MISSING" ]; then \
$(call log,error,Some git submodules are not installed,2); \
$(call log,error,Run 'make self-install to fix.',2); \
exit 1; \
fi
MAKEFILE_DOCTOR_TARGETS += .doctor.git-submodules
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# HELP
# @see src/help.mk
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# Display a list of all available targets and flags
#
# Example : make help
#
# Example of Makefile
#
# ```makefile
# ## This is a help message
# my_target:
# ```
#
HELP_COLOR_FLAGS = $(BLUE)
HELP_COLOR_TARGETS = $(YELLOW)
HELP_COLOR_RESET = $(RESET)
.PHONY: help
help: ## Show this help
@echo ''
@echo ' Usage:'
@echo ''
@echo ' make $(HELP_COLOR_TARGETS)<target>$(HELP_COLOR_RESET) $(HELP_COLOR_FLAGS)[FLAG1=...] [FLAG2=...]$(HELP_COLOR_RESET)'
@echo ''
@echo ' Targets:'
@echo ''
@$(SED) \
-e '/^[a-zA-Z0-9_\-]*:.*##/!d' \
-e 's/:.*##[[:space:]]*/|/' \
-e 's/\(.*\)|\(.*\)/$(HELP_COLOR_TARGETS)\1$(HELP_COLOR_RESET)|\2/' \
-e 's/\(.*\)/ \1/' \
$(MAKEFILE_LIST) | column -c2 -t -s '|' | sort
@echo ''
@echo ' Flags:'
@echo ''
@awk ' \
/^##/ { comment = substr($$0, 4); next } \
/^[a-zA-Z][a-zA-Z0-9_-]+ ?\?=/ && comment { \
sub(/\?\=/, "", $$2); \
printf " $(HELP_COLOR_FLAGS)%s$(HELP_COLOR_RESET)|%s\n", $$1, $$2 " " comment; \
comment = ""; \
} \
' $(MAKEFILE_LIST) | column -c2 -t -s '|' | sort
@echo ''
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
# MAIN
# @see src/main.mk
#⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
#
# Includes every makefiles configured by MAKEFILE_INCLUDE excluding MAKEFILE_EXCLUDE
#
include $(filter-out $(MAKEFILE_EXCLUDE),$(MAKEFILE_INCLUDE))
#
# Include Makefile.local if it exists
#
# /!\ WARNING : this must be at the end of all files
-include $(MAKEFILE_LOCAL)