summaryrefslogtreecommitdiffstats
path: root/src/kmk/example-spaces.kmk
blob: 75330023a4437bb8833f720877c5802556aba03d (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
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
# $Id: example-spaces.kmk 3316 2020-03-31 01:13:22Z bird $
## @file
# kBuild - examples of GNU make filename quoting (escaping).
#

#
# Copyright (c) 2020 knut st. osmundsen <bird-kBuild-spamxx@anduin.net>
#
# This file is part of kBuild.
#
# kBuild is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# kBuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with kBuild.  If not, see <http://www.gnu.org/licenses/>
#
#


all: \
	phoney\ space\ \ 1 \
	phoney\ colon\:\ 2 \
	phoney\ hash\#\ 3 \
	phoney\ dollar$$\ 4 \
	phoney\ slash-space\\\ 5 \
	phoney\ slash-hash\\\#\ 6 \
	phoney\ slash-slash-hash\\\\\#\ 7 \
 	phoney\ percent%\ 10 \
	phoney\ pipe\|\ 11 \
	phoney\ plus+\ 12 \
	all-trailing-slashes1 \
       all-trailing-slashes2 \
       all-trailing-slashes3 \
       all-trailing-spaces1 \
       all-trailing-spaces2 \
       all-trailing-spaces3 \
       all-trailing-spaces4 \
	phoney\ 19-target-trailing-space-with-padding\  ignore \
	phoney\ 20-target-trailing-space-with-newline-padding\  ignore \
	phoney\ 21-target-trailing-space-with-newline-padding-and-tail\ my-tail-21


ignore:

#
# Trailing slashes are complicated in dependency lists:
#

# Variant #1: Must have a line-continutation to work if last in the list, but no extra escaping.
# This doesn't work: all-trailing-slashes1: phoney\ trailing-slash13\
# This doesn't work: all-trailing-slashes1: phoney\ trailing-slash13\\
all-trailing-slashes1: phoney\ trailing-slash13\ \

all-trailing-slashes2: phoney\ trailing-slash13b\ \
	\
	\
	\

# Variant #2: If there are more dependencies following it, we must escape the trailing slash
all-trailing-slashes3: \
	phoney\ trailing-slash14\\ \
	phoney\ space\ \ 1 # whatever

#
# Trailing spaces only works if there is a target following on the same line.
#
all-trailing-spaces1: phoney\ 15-trailing-space\  phoney_simple

# Note! No stripping spaces! Trailing space here that gets stripped instead of escaped.
all-trailing-spaces2: phoney\ 16-no-trailing-space\ 

all-trailing-spaces3: phoney\ 17-3x-escaped-newlines\ \
\
\
	becomes-single-space

# Note! Must have a trailing space or comment.
all-trailing-spaces4: phoney\ 18-3x-escaped-trailing-spaces-no-newline\ \ \ #


#
# TODO
#

#busted:	phoney\ equal\=\ 8 \
#impossible:	phoney\ semi\;\ 9 \


#
# The rules.
#

phoney_simple:

phoney\ space\ \ 1:
	echo "#1: '$@'"

phoney\ colon\:\ 2:
	echo "#2: '$@'"

phoney\ hash\#\ 3 :
	echo "#3: '$@'"

phoney\ dollar$$\ 4 :
	echo "#4: '$@'"

phoney\ slash-space\\\ 5:
	echo "#5: '$@'"

phoney\ slash-hash\\\#\ 6:
	echo "#6: '$@'"

phoney\ slash-slash-hash\\\\\#\ 7:
	echo "#7: '$@'"

## This is busted:
#phoney\ equal=\ 8:
#	echo "#8: '$@'"

## This seems impossible:
#phoney\ semi\;:
#	echo "#9: '$@'"

phoney\ percent\%\ 10: # Note! The percent is only escaped on the target side!
	echo "#10: '$@'"

phoney\ pipe|\ 11:     # Note! The pipe is only escaped on the dependency list side!
	echo "#11: '$@'"

phoney\ plus+\ 12:
	echo "#12: '$@'"

phoney\ trailing-slash13\\:
	echo "#13: '$@'"

phoney\ trailing-slash13b\\:
	echo "#13b: '$@'"

phoney\ trailing-slash14\\:
	echo "#14: '$@'"

phoney\ 15-trailing-space\ :
	echo "#15: '$@'"

phoney\ 16-no-trailing-space\\:
	echo "#16: '$@'"

phoney\ 17-3x-escaped-newlines\ becomes-single-space:
	echo "#17: '$@'"

phoney\ 18-3x-escaped-trailing-spaces-no-newline\ \ \\:
	echo "#18: '$@'"

phoney\ 19-target-trailing-space-with-padding\   :
	echo "#19: '$@'"

phoney\ 20-target-trailing-space-with-newline-padding\   \
\
:
	echo "#20: '$@'"

phoney\ 21-target-trailing-space-with-newline-padding-and-tail\ \
\
 \
		\
my-tail-21:
	echo "#21: '$@'"