2
# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
# This code is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 2 only, as
7
# published by the Free Software Foundation. Oracle designates this
8
# particular file as subject to the "Classpath" exception as provided
9
# by Oracle in the LICENSE file that accompanied this code.
11
# This code is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
# version 2 for more details (a copy is included in the LICENSE file that
15
# accompanied this code).
17
# You should have received a copy of the GNU General Public License version
18
# 2 along with this work; if not, write to the Free Software Foundation,
19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
# or visit www.oracle.com if you need additional information or have any
26
ifeq (,$(_MAKEBASE_GMK))
27
$(error You must include MakeBase.gmk prior to including MakeIO.gmk)
30
################################################################################
32
# Functions for dealing with reading and writing from makefiles. Prior to GNU
33
# Make 4.0, this was tricky business.
35
################################################################################
38
################################################################################
39
# ListPathsSafely can be used to print command parameters to a file. This is
40
# typically done if the command line length risk being too long for the
41
# OS/shell. In later make versions, the file function can be used for this
42
# purpose. For earlier versions, a more complex implementation is provided.
44
# The function ListPathsSafely can be called either directly or, more commonly
45
# from a recipe line. If called from a recipe, it will be executed in the
46
# evaluation phase of that recipe, which means that it will write to the file
47
# before any other line in the recipe has been run.
48
ifeq ($(HAS_FILE_FUNCTION), true)
49
# Param 1 - Name of variable containing paths/arguments to output
50
# Param 2 - File to print to
51
# Param 3 - Set to true to append to file instead of overwriting
52
define ListPathsSafely
53
$$(call MakeDir, $$(dir $$(strip $2)))
54
$$(file $$(if $$(filter true, $$(strip $3)),>>,>) \
55
$$(strip $2),$$(subst $$(SPACE),$$(NEWLINE),$$(strip $$($$(strip $1)))))
58
else # HAS_FILE_FUNCTION = false
60
$(eval compress_paths = \
61
$(strip $(shell $(CAT) $(TOPDIR)/make/common/support/ListPathsSafely-pre-compress.incl)))
63
$(subst $(TOPDIR),X97, \
64
$(subst $(OUTPUTDIR),X98, \
66
$(subst $(SPACE),\n,$(strip $1)))))
67
$(eval compress_paths += \
68
$(strip $(shell $(CAT) $(TOPDIR)/make/common/support/ListPathsSafely-post-compress.incl)))
70
decompress_paths=$(SED) -f $(TOPDIR)/make/common/support/ListPathsSafely-uncompress.sed \
72
-e 's|X98|$(OUTPUTDIR)|g' -e 's|X97|$(TOPDIR)|g' \
75
ListPathsSafely_IfPrintf = \
76
$(if $(word $3,$($(strip $1))), \
77
$(shell $(PRINTF) -- "$(strip $(call EscapeDollar, \
78
$(call compress_paths, $(wordlist $3,$4,$($(strip $1))))))\n" \
79
| $(decompress_paths) >> $2))
81
# Param 1 - Name of variable containing paths/arguments to output
82
# Param 2 - File to print to
83
# Param 3 - Set to true to append to file instead of overwriting
84
define ListPathsSafely
85
ifneq (,$$(word 30001,$$($$(strip $1))))
86
$$(error Cannot list safely more than 30000 paths. $1 has $$(words $$($$(strip $1))) paths!)
88
$$(call MakeDir, $$(dir $2))
89
ifneq ($$(strip $3), true)
90
$$(shell $(RM) $$(strip $2))
93
$$(call ListPathsSafely_IfPrintf,$1,$2,1,250)
94
$$(call ListPathsSafely_IfPrintf,$1,$2,251,500)
95
$$(call ListPathsSafely_IfPrintf,$1,$2,501,750)
96
$$(call ListPathsSafely_IfPrintf,$1,$2,751,1000)
98
$$(call ListPathsSafely_IfPrintf,$1,$2,1001,1250)
99
$$(call ListPathsSafely_IfPrintf,$1,$2,1251,1500)
100
$$(call ListPathsSafely_IfPrintf,$1,$2,1501,1750)
101
$$(call ListPathsSafely_IfPrintf,$1,$2,1751,2000)
103
$$(call ListPathsSafely_IfPrintf,$1,$2,2001,2250)
104
$$(call ListPathsSafely_IfPrintf,$1,$2,2251,2500)
105
$$(call ListPathsSafely_IfPrintf,$1,$2,2501,2750)
106
$$(call ListPathsSafely_IfPrintf,$1,$2,2751,3000)
108
$$(call ListPathsSafely_IfPrintf,$1,$2,3001,3250)
109
$$(call ListPathsSafely_IfPrintf,$1,$2,3251,3500)
110
$$(call ListPathsSafely_IfPrintf,$1,$2,3501,3750)
111
$$(call ListPathsSafely_IfPrintf,$1,$2,3751,4000)
113
$$(call ListPathsSafely_IfPrintf,$1,$2,4001,4250)
114
$$(call ListPathsSafely_IfPrintf,$1,$2,4251,4500)
115
$$(call ListPathsSafely_IfPrintf,$1,$2,4501,4750)
116
$$(call ListPathsSafely_IfPrintf,$1,$2,4751,5000)
118
$$(call ListPathsSafely_IfPrintf,$1,$2,5001,5250)
119
$$(call ListPathsSafely_IfPrintf,$1,$2,5251,5500)
120
$$(call ListPathsSafely_IfPrintf,$1,$2,5501,5750)
121
$$(call ListPathsSafely_IfPrintf,$1,$2,5751,6000)
123
$$(call ListPathsSafely_IfPrintf,$1,$2,6001,6250)
124
$$(call ListPathsSafely_IfPrintf,$1,$2,6251,6500)
125
$$(call ListPathsSafely_IfPrintf,$1,$2,6501,6750)
126
$$(call ListPathsSafely_IfPrintf,$1,$2,6751,7000)
128
$$(call ListPathsSafely_IfPrintf,$1,$2,7001,7250)
129
$$(call ListPathsSafely_IfPrintf,$1,$2,7251,7500)
130
$$(call ListPathsSafely_IfPrintf,$1,$2,7501,7750)
131
$$(call ListPathsSafely_IfPrintf,$1,$2,7751,8000)
133
$$(call ListPathsSafely_IfPrintf,$1,$2,8001,8250)
134
$$(call ListPathsSafely_IfPrintf,$1,$2,8251,8500)
135
$$(call ListPathsSafely_IfPrintf,$1,$2,8501,8750)
136
$$(call ListPathsSafely_IfPrintf,$1,$2,8751,9000)
138
$$(call ListPathsSafely_IfPrintf,$1,$2,9001,9250)
139
$$(call ListPathsSafely_IfPrintf,$1,$2,9251,9500)
140
$$(call ListPathsSafely_IfPrintf,$1,$2,9501,9750)
141
$$(call ListPathsSafely_IfPrintf,$1,$2,9751,10000)
143
$$(call ListPathsSafely_IfPrintf,$1,$2,10001,10250)
144
$$(call ListPathsSafely_IfPrintf,$1,$2,10251,10500)
145
$$(call ListPathsSafely_IfPrintf,$1,$2,10501,10750)
146
$$(call ListPathsSafely_IfPrintf,$1,$2,10751,11000)
148
$$(call ListPathsSafely_IfPrintf,$1,$2,11001,11250)
149
$$(call ListPathsSafely_IfPrintf,$1,$2,11251,11500)
150
$$(call ListPathsSafely_IfPrintf,$1,$2,11501,11750)
151
$$(call ListPathsSafely_IfPrintf,$1,$2,11751,12000)
153
$$(call ListPathsSafely_IfPrintf,$1,$2,12001,12250)
154
$$(call ListPathsSafely_IfPrintf,$1,$2,12251,12500)
155
$$(call ListPathsSafely_IfPrintf,$1,$2,12501,12750)
156
$$(call ListPathsSafely_IfPrintf,$1,$2,12751,13000)
158
$$(call ListPathsSafely_IfPrintf,$1,$2,13001,13250)
159
$$(call ListPathsSafely_IfPrintf,$1,$2,13251,13500)
160
$$(call ListPathsSafely_IfPrintf,$1,$2,13501,13750)
161
$$(call ListPathsSafely_IfPrintf,$1,$2,13751,14000)
163
$$(call ListPathsSafely_IfPrintf,$1,$2,14001,14250)
164
$$(call ListPathsSafely_IfPrintf,$1,$2,14251,14500)
165
$$(call ListPathsSafely_IfPrintf,$1,$2,14501,14750)
166
$$(call ListPathsSafely_IfPrintf,$1,$2,14751,15000)
168
$$(call ListPathsSafely_IfPrintf,$1,$2,15001,15250)
169
$$(call ListPathsSafely_IfPrintf,$1,$2,15251,15500)
170
$$(call ListPathsSafely_IfPrintf,$1,$2,15501,15750)
171
$$(call ListPathsSafely_IfPrintf,$1,$2,15751,16000)
173
$$(call ListPathsSafely_IfPrintf,$1,$2,16001,16250)
174
$$(call ListPathsSafely_IfPrintf,$1,$2,16251,16500)
175
$$(call ListPathsSafely_IfPrintf,$1,$2,16501,16750)
176
$$(call ListPathsSafely_IfPrintf,$1,$2,16751,17000)
178
$$(call ListPathsSafely_IfPrintf,$1,$2,17001,17250)
179
$$(call ListPathsSafely_IfPrintf,$1,$2,17251,17500)
180
$$(call ListPathsSafely_IfPrintf,$1,$2,17501,17750)
181
$$(call ListPathsSafely_IfPrintf,$1,$2,17751,18000)
183
$$(call ListPathsSafely_IfPrintf,$1,$2,18001,18250)
184
$$(call ListPathsSafely_IfPrintf,$1,$2,18251,18500)
185
$$(call ListPathsSafely_IfPrintf,$1,$2,18501,18750)
186
$$(call ListPathsSafely_IfPrintf,$1,$2,18751,19000)
188
$$(call ListPathsSafely_IfPrintf,$1,$2,19001,19250)
189
$$(call ListPathsSafely_IfPrintf,$1,$2,19251,19500)
190
$$(call ListPathsSafely_IfPrintf,$1,$2,19501,19750)
191
$$(call ListPathsSafely_IfPrintf,$1,$2,19751,20000)
193
$$(call ListPathsSafely_IfPrintf,$1,$2,20001,20250)
194
$$(call ListPathsSafely_IfPrintf,$1,$2,20251,20500)
195
$$(call ListPathsSafely_IfPrintf,$1,$2,20501,20750)
196
$$(call ListPathsSafely_IfPrintf,$1,$2,20751,21000)
198
$$(call ListPathsSafely_IfPrintf,$1,$2,21001,21250)
199
$$(call ListPathsSafely_IfPrintf,$1,$2,21251,21500)
200
$$(call ListPathsSafely_IfPrintf,$1,$2,21501,21750)
201
$$(call ListPathsSafely_IfPrintf,$1,$2,21751,22000)
203
$$(call ListPathsSafely_IfPrintf,$1,$2,22001,22250)
204
$$(call ListPathsSafely_IfPrintf,$1,$2,22251,22500)
205
$$(call ListPathsSafely_IfPrintf,$1,$2,22501,22750)
206
$$(call ListPathsSafely_IfPrintf,$1,$2,22751,23000)
208
$$(call ListPathsSafely_IfPrintf,$1,$2,23001,23250)
209
$$(call ListPathsSafely_IfPrintf,$1,$2,23251,23500)
210
$$(call ListPathsSafely_IfPrintf,$1,$2,23501,23750)
211
$$(call ListPathsSafely_IfPrintf,$1,$2,23751,24000)
213
$$(call ListPathsSafely_IfPrintf,$1,$2,24001,24250)
214
$$(call ListPathsSafely_IfPrintf,$1,$2,24251,24500)
215
$$(call ListPathsSafely_IfPrintf,$1,$2,24501,24750)
216
$$(call ListPathsSafely_IfPrintf,$1,$2,24751,25000)
218
$$(call ListPathsSafely_IfPrintf,$1,$2,25001,25250)
219
$$(call ListPathsSafely_IfPrintf,$1,$2,25251,25500)
220
$$(call ListPathsSafely_IfPrintf,$1,$2,25501,25750)
221
$$(call ListPathsSafely_IfPrintf,$1,$2,25751,26000)
223
$$(call ListPathsSafely_IfPrintf,$1,$2,26001,26250)
224
$$(call ListPathsSafely_IfPrintf,$1,$2,26251,26500)
225
$$(call ListPathsSafely_IfPrintf,$1,$2,26501,26750)
226
$$(call ListPathsSafely_IfPrintf,$1,$2,26751,27000)
228
$$(call ListPathsSafely_IfPrintf,$1,$2,27001,27250)
229
$$(call ListPathsSafely_IfPrintf,$1,$2,27251,27500)
230
$$(call ListPathsSafely_IfPrintf,$1,$2,27501,27750)
231
$$(call ListPathsSafely_IfPrintf,$1,$2,27751,28000)
233
$$(call ListPathsSafely_IfPrintf,$1,$2,28001,28250)
234
$$(call ListPathsSafely_IfPrintf,$1,$2,28251,28500)
235
$$(call ListPathsSafely_IfPrintf,$1,$2,28501,28750)
236
$$(call ListPathsSafely_IfPrintf,$1,$2,28751,29000)
238
$$(call ListPathsSafely_IfPrintf,$1,$2,29001,29250)
239
$$(call ListPathsSafely_IfPrintf,$1,$2,29251,29500)
240
$$(call ListPathsSafely_IfPrintf,$1,$2,29501,29750)
241
$$(call ListPathsSafely_IfPrintf,$1,$2,29751,30000)
243
endif # HAS_FILE_FUNCTION