1# 2# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. 3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4# 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. 10# 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). 16# 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. 20# 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 23# questions. 24# 25 26ifeq (,$(_MAKEBASE_GMK)) 27 $(error You must include MakeBase.gmk prior to including MakeIO.gmk) 28endif 29 30################################################################################ 31# 32# Functions for dealing with reading and writing from makefiles. Prior to GNU 33# Make 4.0, this was tricky business. 34# 35################################################################################ 36 37 38################################################################################ 39# ListPathsSafely can be used to print command parameters to a file. This is 40# typically done if the command line lenght 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. 43# 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. 48ifeq ($(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))))) 56 endef 57 58else # HAS_FILE_FUNCTION = false 59 60 $(eval compress_paths = \ 61 $(strip $(shell $(CAT) $(TOPDIR)/make/common/support/ListPathsSafely-pre-compress.incl))) 62 compress_paths += \ 63 $(subst $(TOPDIR),X97, \ 64 $(subst $(OUTPUTDIR),X98, \ 65 $(subst X,X00, \ 66 $(subst $(SPACE),\n,$(strip $1))))) 67 $(eval compress_paths += \ 68 $(strip $(shell $(CAT) $(TOPDIR)/make/common/support/ListPathsSafely-post-compress.incl))) 69 70 decompress_paths=$(SED) -f $(TOPDIR)/make/common/support/ListPathsSafely-uncompress.sed \ 71 -e 's|X99|\\n|g' \ 72 -e 's|X98|$(OUTPUTDIR)|g' -e 's|X97|$(TOPDIR)|g' \ 73 -e 's|X00|X|g' 74 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)) 80 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!) 87 endif 88 $$(call MakeDir, $$(dir $2)) 89 ifneq ($$(strip $3), true) 90 $$(shell $(RM) $$(strip $2)) 91 endif 92 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) 97 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) 102 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) 107 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) 112 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) 117 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) 122 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) 127 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) 132 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) 137 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) 142 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) 147 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) 152 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) 157 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) 162 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) 167 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) 172 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) 177 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) 182 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) 187 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) 192 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) 197 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) 202 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) 207 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) 212 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) 217 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) 222 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) 227 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) 232 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) 237 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) 242 endef 243endif # HAS_FILE_FUNCTION 244 245################################################################################ 246# Write to and read from file 247 248# Param 1 - File to read 249ReadFile = \ 250 $(shell $(CAT) $1) 251 252# Param 1 - Text to write 253# Param 2 - File to write to 254ifeq ($(HAS_FILE_FUNCTION), true) 255 WriteFile = \ 256 $(file >$2,$(strip $1)) 257else 258 # Use printf to get consistent behavior on all platforms. 259 WriteFile = \ 260 $(shell $(PRINTF) "%s" $(call ShellQuote, $1) > $2) 261endif 262 263# Param 1 - Text to write 264# Param 2 - File to write to 265ifeq ($(HAS_FILE_FUNCTION), true) 266 AppendFile = \ 267 $(file >>$2,$(strip $1)) 268else 269 # Use printf to get consistent behavior on all platforms. 270 AppendFile = \ 271 $(shell $(PRINTF) "%s" $(call ShellQuote, $1) >> $2) 272endif 273