aboutsummaryrefslogtreecommitdiff
path: root/make/util.mk
blob: 43923fc0a97e6d1c315cc2d1a915509bb3b249eb (plain)
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
#
# mal (Make Lisp) utility functions/definitions
#

ifndef __mal_util_included
__mal_util_included := true

_TOP_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(_TOP_DIR)gmsl.mk

SEMI := ;
COMMA := ,
LCURLY := {
RCURLY := }
LPAREN := (
RPAREN := )
LBRACKET := [
RBRACKET := ]
DQUOTE := "# "
SLASH := $(strip \ )
ESC_DQUOTE := $(SLASH)$(DQUOTE)
SQUOTE := '# '
QQUOTE := `# `
SPACE := 
SPACE += 
NUMBERS := 0 1 2 3 4 5 6 7 8 9
UNQUOTE := ~
SPLICE_UNQUOTE := ~@
define NEWLINE


endef
CARET := ^
ATSIGN := @

# \u00ab
_LP := «
# \u00bb
_RP := »
# \u00ed
_LC := í
# \u00ec
_RC := ì
## \u00a7
_SP := §
## \u00ae
_SUQ := ®
## \u015e
_DOL := Ş
## \u00b6
_NL := ¶
## \u00a8
###_EDQ := ¨


#
# Utility functions
#

_EQ = $(if $(subst x$1,,x$2)$(subst x$2,,x$1),,true)

_NOT = $(if $1,,true)

# READ: read and parse input
str_encode = $(strip $(eval __temp := $$(subst $$$$,$(_DOL) ,$$(subst $(SPLICE_UNQUOTE),$(_SUQ) ,$$(subst $$(LPAREN),$$(_LP) ,$$(subst $$(RPAREN),$$(_RP) ,$$(subst $$(LCURLY),$$(_LC) ,$$(subst $$(RCURLY),$$(_RC) ,$$(subst $$(NEWLINE),$$(_NL) ,$$(subst $$(SPACE),$(_SP) ,$$1)))))))))$(foreach a,$(__gmsl_characters),$(eval __temp := $$(subst $$a,$$a$$(SPACE),$(__temp))))$(__temp))

str_decode = $(subst $(_SP),$(SPACE),$(subst $(_NL),$(NEWLINE),$(subst $(_LC),$(LCURLY),$(subst $(_RC),$(RCURLY),$(subst $(_LP),$(LPAREN),$(subst $(_RP),$(RPAREN),$(subst $(_SUQ),$(SPLICE_UNQUOTE),$(subst $(_DOL),$$,$(strip $(call gmsl_merge,,$(1)))))))))))

# Read a whole file substituting newlines with $(_NL)
_read_file = $(subst $(_NL),$(NEWLINE),$(shell out=""; while read -r l; do out="$${out}$${l}$(_NL)"; done < $(1); echo "$$out"))

endif