-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile.fn.in
More file actions
167 lines (152 loc) · 4.18 KB
/
Copy pathMakefile.fn.in
File metadata and controls
167 lines (152 loc) · 4.18 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
#
# Functions sub-Makefile
#
# Copyright (C) 2020-2026 Gabriele Galeotti
#
# This work is licensed under the terms of the MIT License.
# Please consult the LICENSE.txt file located in the top-level directory.
#
#
# Environment variables:
# NULL
# SPACE
# DEL
# OSTYPE
# VERBOSE
#
ifneq ($(MAKEFILE_FN_IN_INCLUDED),Y)
MAKEFILE_FN_IN_INCLUDED := Y
__CHARACTERS__ :=
__CHARACTERS__ += ! " \# $$ % & ' ( ) * + , - . /
__CHARACTERS__ += 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
__CHARACTERS__ += @ A B C D E F G H I J K L M N O
__CHARACTERS__ += P Q R S T U V W X Y Z [ \ ] ^ _
__CHARACTERS__ += ` a b c d e f g h i j k l m n o
__CHARACTERS__ += p q r s t u v w x y z { | } ~
#
# substring
#
# Usage:
# $(call substring,string,start,end)
#
# Return a substring of string, starting at start and ending at end.
#
substring = $(strip \
$(eval __t__ := $$(subst $$(SPACE),$(DEL)$(SPACE),$$1))\
$(eval \
$$(foreach c,$$(__CHARACTERS__),\
$$(eval \
__t__ := $$$$(subst $$$$c,$$$$c$$$$(SPACE),$$(__t__))\
)\
)\
)\
$(eval __t__ := $(wordlist $2,$3,$(__t__)))\
)$(subst $(DEL),$(SPACE),$(subst $(SPACE),,$(__t__)))
#
# unquote
#
# Usage:
# $(call unquote,"text")
#
# Remove double-quotes from a text string.
#
unquote = $(subst $(DEL),$(SPACE),$(subst $(SPACE),",$(strip \
$(subst ",$(SPACE),$(subst $(SPACE),$(DEL),$1))\
)))
#
# echo-print
#
# Usage:
# $(call echo-print,"something to print")
#
# Double-quotes must be used to delimit the string. The string must not
# contain other double-quotes inside.
#
ifeq ($(OSTYPE),cmd)
__echo-print-xform__ = $(subst <,^<,$(subst >,^>,$(subst &,^&,$(subst |,^|,$(call unquote,$1)))))
echo-print = $(if $(call __echo-print-xform__,$1),ECHO $(call __echo-print-xform__,$1),ECHO.&)
else
echo-print = printf "%s\n" "$(call unquote,$1)"
endif
# max. width = 24
BRIEFTEXT_WIDTH := 12
BRIEFTEXT_SPACES := $(call substring,$(NULL) $(NULL),1,$(BRIEFTEXT_WIDTH))
# 123456789012345678901234
export BRIEFTEXT_WIDTH
#
# brief-text
#
# Usage:
# $(call brief-text,text1,text2)
#
# Print the two arguments in brief-mode:
# - 1st argument, maximum BRIEFTEXT_WIDTH characters with padding
# - a space
# - 2nd argument
#
brief-text = $(call echo-print,"$(call substring,$1$(BRIEFTEXT_SPACES),1,$(BRIEFTEXT_WIDTH)) $2")
#
# brief-command
#
# Usage:
# $(call brief-command,<command_and_arguments>,"NAME","arguments to print")
#
# NAME:
# should be a short name of the command, maximum BRIEFTEXT_WIDTH letters
#
# This function will run "command and arguments", and either:
# - if VERBOSE=Y print the whole command and arguments
# - otherwise print a brief output in the format "NAME arguments to print"
# If called with only a single argument, will print nothing in brief-mode.
#
ifeq ($(OSTYPE),cmd)
brief-command = $(if $(findstring Y,$(VERBOSE)),$1,$(if $2,$(call brief-text,$2,$3)&$1,@$1))
else
brief-command = $(if $(findstring Y,$(VERBOSE)),$1,$(if $2,$(call brief-text,$2,$3);$1,@$1))
endif
#
# ls-dirs
#
# Usage:
# $(call ls-dirs)
#
# Print all directories in the current working directory.
#
ifeq ($(OSTYPE),cmd)
ls-dirs = DIR /A:D /B *
else
__ls-dirs-ts__ = ls -A -d */
ls-dirs = $(foreach d,$(call __ls-dirs-ts__),$(patsubst %/,%,$(d)))
endif
#
# create-emptyfile
#
# Usage:
# $(call create-emptyfile,filename)
#
# Create an empty file.
#
ifeq ($(OSTYPE),cmd)
create-emptyfile = TYPE nul>$1
else
create-emptyfile = touch $1
endif
#
# variable list handling
#
# Usage:
# $(call list-create,<variable_name>,item)
# $(call list-insert,<variable_name>,item)
# $(call list-append,<variable_name>,item)
# $(call list-delete,<variable_name>,item)
#
# list-create: create a list (with initialization items).
# list-insert: head-insert an item to a list.
# list-append: tail-append an item to a list.
# list-delete: delete an item from a list.
#
list-create = $(eval $$1 := $$2)
list-insert = $(eval $$1 := $$2 $$($$1))
list-append = $(eval $$1 := $$($$1) $$2)
list-delete = $(eval $$1 := $$(filter-out $$2,$$($$1)))
endif