annotate make/common/TextFileProcessing.gmk @ 51872:0ce279d8c9cd

8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug] Reviewed-by: goetz, psadhukhan
author mbaesken
date Tue, 24 Jul 2018 09:27:42 +0200
parents a74ba4179f11
children 28094715ae71
rev   line source
ihse@22479 1 #
erikj@41261 2 # Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
ihse@22479 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ihse@22479 4 #
ihse@22479 5 # This code is free software; you can redistribute it and/or modify it
ihse@22479 6 # under the terms of the GNU General Public License version 2 only, as
ihse@22479 7 # published by the Free Software Foundation. Oracle designates this
ihse@22479 8 # particular file as subject to the "Classpath" exception as provided
ihse@22479 9 # by Oracle in the LICENSE file that accompanied this code.
ihse@22479 10 #
ihse@22479 11 # This code is distributed in the hope that it will be useful, but WITHOUT
ihse@22479 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ihse@22479 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ihse@22479 14 # version 2 for more details (a copy is included in the LICENSE file that
ihse@22479 15 # accompanied this code).
ihse@22479 16 #
ihse@22479 17 # You should have received a copy of the GNU General Public License version
ihse@22479 18 # 2 along with this work; if not, write to the Free Software Foundation,
ihse@22479 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ihse@22479 20 #
ihse@22479 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ihse@22479 22 # or visit www.oracle.com if you need additional information or have any
ihse@22479 23 # questions.
ihse@22479 24 #
ihse@22479 25
ihse@27592 26 ifeq (,$(_MAKEBASE_GMK))
ihse@27592 27 $(error You must include MakeBase.gmk prior to including TextFileProcessing.gmk)
ihse@27592 28 endif
ihse@22479 29
ihse@22479 30 # Helper function for SetupTextFileProcessing; adds a rule for a single file
ihse@22479 31 # to be processed.
ihse@22479 32 # param 1 = The namespace argument, e.g. BUILD_VERSION_FILE
ihse@22479 33 # param 2 = the source file name (full path)
ihse@22479 34 # param 3 = the target base directory
ihse@22479 35 # param 4 = the target file name (possibly with a partial path)
ihse@22479 36 define SetupSingleTextFileForProcessing
erikj@28600 37 $(strip $3)/$(strip $4): $2 $$($1_VARDEPS_FILE)
erikj@35008 38 $$(call LogInfo, Processing $(strip $4))
erikj@35008 39 $$(call MakeDir, $$(@D))
erikj@35008 40 $(RM) '$$@' '$$@.includes.tmp' '$$@.replacements.tmp' ; \
erikj@35008 41 $$($1_INCLUDES_COMMAND_LINE) < '$$<' > '$$@.includes.tmp' ; \
erikj@35008 42 $$($1_REPLACEMENTS_COMMAND_LINE) < '$$@.includes.tmp' > '$$@.replacements.tmp' ; \
erikj@35008 43 $(RM) '$$@.includes.tmp' ; \
ihse@22479 44 $(MV) '$$@.replacements.tmp' '$$@'
ihse@22479 45
ihse@22479 46 $1 += $(strip $3)/$(strip $4)
ihse@22479 47 endef
ihse@22479 48
ihse@27592 49 # Setup make rules for processing one or more text files, in which specified
ihse@27592 50 # markers are replaced with a given text, or with the contents of a given file.
ihse@22479 51 #
ihse@27592 52 # Parameter 1 is the name of the rule. This name is used as variable prefix,
ihse@27592 53 # and the targets generated are listed in a variable by that name.
ihse@27592 54 #
ihse@27592 55 # Remaining parameters are named arguments. These include:
ihse@22479 56 # SOURCE_DIRS one or more directory roots to search for files to process
ihse@22479 57 # SOURCE_FILES complete paths to one or more files to process
ihse@22479 58 # OUTPUT_DIR the directory where we store the processed files.
ihse@22479 59 # OUTPUT_FILE the name of the resulting file. Only allowed if processing a
ihse@22479 60 # single file.
ihse@22479 61 # SOURCE_BASE_DIR a common root to all SOURCE_DIRS.
ihse@27592 62 # If specified, files will keep the path relative to the base in the
ihse@22479 63 # OUTPUT_DIR. Otherwise, the hierarchy will be flattened into the OUTPUT_DIR.
ihse@22479 64 # INCLUDE_FILES only include files matching these patterns (used only with
ihse@22479 65 # SOURCE_DIRS)
ihse@22479 66 # EXCLUDE_FILES exclude files matching these patterns (used only with
ihse@22479 67 # SOURCE_DIRS)
ihse@22479 68 # INCLUDES replace the occurances of a pattern with the contents of a file;
ihse@22479 69 # one or more such include pattern, using the syntax:
ihse@22479 70 # PLACEHOLDER => FILE_TO_INCLUDE ; ...
ihse@22479 71 # Each PLACEHOLDER must be on a single, otherwise empty line (whitespace
ihse@22479 72 # padding is allowed).
ihse@22479 73 # REPLACEMENTS one or more text replacement patterns, using the syntax:
ihse@22479 74 # PATTERN => REPLACEMENT_TEXT ; ...
ihse@22479 75 #
ihse@27595 76 # If both INCLUDES or REPLACEMENTS are present, then the includes will be
ihse@27595 77 # processed first, and replacements will be done on the included fragments as well.
ihse@27595 78 # If neither is present, the files will just be copied without modifications.
ihse@22479 79 #
erikj@29312 80 SetupTextFileProcessing = $(NamedParamsMacroTemplate)
erikj@29312 81 define SetupTextFileProcessingBody
ihse@22479 82
ihse@22479 83 ifneq ($$($1_SOURCE_FILES),)
ihse@22479 84 ifneq ($$($1_SOURCE_DIRS),)
ihse@22479 85 $$(error Cannot use both SOURCE_FILES and SOURCE_DIRS (in $1))
ihse@22479 86 endif
ihse@22479 87 ifneq ($$($1_SOURCE_BASE_DIR),)
ihse@22479 88 $$(error Cannot use SOURCE_BASE_DIR without SOURCE_DIRS (in $1))
ihse@22479 89 endif
ihse@22479 90 ifneq ($$($1_EXCLUDE_FILES)$$($1_INCLUDE_FILES),)
ihse@22479 91 $$(error Cannot INCLUDE/EXCLUDE_FILES with SOURCE_FILES (in $1))
ihse@22479 92 endif
ihse@22479 93 else
ihse@27595 94 ifeq ($$($1_SOURCE_DIRS),)
ihse@27595 95 $$(error Must specify either SOURCE_FILES or SOURCE_DIRS (in $1))
ihse@27595 96 endif
ihse@22479 97 # Find all files in the source trees. Sort to remove duplicates.
ihse@22479 98 $$(foreach src, $$($1_SOURCE_DIRS), $$(if $$(wildcard $$(src)), , \
ihse@22479 99 $$(error SOURCE_DIRS contains missing directory $$(src) (in $1))))
ihse@22479 100 ifneq ($$($1_SOURCE_BASE_DIR),)
ihse@22479 101 $$(foreach src, $$($1_SOURCE_DIRS), \
ihse@22479 102 $$(if $$(findstring $$($1_SOURCE_BASE_DIR), $$(src)), , \
ihse@22479 103 $$(error SOURCE_DIRS contains directory $$(src) outside \
ihse@22479 104 SOURCE_BASE_DIR $$($1_SOURCE_BASE_DIR) (in $1))))
ihse@22479 105 endif
ihse@22479 106 $1_SOURCE_FILES := $$(sort $$(call CacheFind,$$($1_SOURCE_DIRS)))
ihse@22479 107 $1_EXCLUDE_FILES:=$$(foreach i,$$($1_SOURCE_DIRS),$$(addprefix $$i/,$$($1_EXCLUDE_FILES)))
ihse@22479 108 $1_INCLUDE_FILES:=$$(foreach i,$$($1_SOURCE_DIRS),$$(addprefix $$i/,$$($1_INCLUDE_FILES)))
ihse@22479 109 $1_SOURCE_FILES := $$(filter-out $$($1_EXCLUDE_FILES),$$($1_SOURCE_FILES))
ihse@22479 110 ifneq (,$$(strip $$($1_INCLUDE_FILES)))
ihse@22479 111 $1_SOURCE_FILES := $$(filter $$($1_INCLUDE_FILES),$$($1_SOURCE_FILES))
ihse@22479 112 endif
ihse@22479 113 ifeq (,$$($1_SOURCE_FILES))
ihse@22479 114 $$(info No sources found for $1 when looking inside the dirs $$($1_SRC))
ihse@22479 115 endif
ihse@22479 116 endif
ihse@22479 117
ihse@22479 118 ifneq ($$($1_REPLACEMENTS),)
ihse@22479 119 # We have a replacement request, prepare it for the recipe
ihse@22479 120 ifneq ($$(findstring /,$$($1_REPLACEMENTS)),)
ihse@22479 121 # Cannot use / as separator
ihse@22479 122 ifneq ($$(findstring @,$$($1_REPLACEMENTS)),)
ihse@22479 123 # Cannot use @ as separator
ihse@22479 124 ifneq ($$(findstring |,$$($1_REPLACEMENTS)),)
ihse@22479 125 # Cannot use | as separator
ihse@22479 126 ifneq ($$(findstring !,$$($1_REPLACEMENTS)),)
ihse@22479 127 # Cannot use ! as separator. Give up.
ihse@22479 128 $$(error No suitable sed separator can be found for $1. Tested /, @, | and !)
ihse@22479 129 else
ihse@22479 130 $1_SEP := !
ihse@22479 131 endif
ihse@22479 132 else
ihse@22479 133 $1_SEP := |
ihse@22479 134 endif
ihse@22479 135 else
ihse@22479 136 $1_SEP := @
ihse@22479 137 endif
ihse@22479 138 else
ihse@22479 139 $1_SEP := /
ihse@22479 140 endif
ihse@22479 141
ihse@22479 142 # If we have a trailing "=>" (i.e. last rule replaces with empty, and is not
ihse@22479 143 # terminated by a ;), add a trailing ; to minimize the number of corner
ihse@22479 144 # cases in the hairy subst expression..
ihse@22479 145 ifeq ($$(lastword $$($1_REPLACEMENTS)), =>)
ihse@22479 146 $1_REPLACEMENTS += ;
ihse@22479 147 endif
ihse@22479 148
ihse@27595 149 # If we have a trailing ";", add a dummy replacement, since there is no easy
ihse@22479 150 # way to delete the last word in make.
ihse@22479 151 ifeq ($$(lastword $$($1_REPLACEMENTS)), ;)
ihse@22479 152 $1_REPLACEMENTS += DUMMY_REPLACEMENT => DUMMY_REPLACEMENT
ihse@22479 153 endif
ihse@22479 154
ihse@22479 155 # Convert the REPLACEMENTS syntax ( A => B ; C => D ; ...) to a sed command
erikj@49374 156 # line (-e "s/A/B/g" -e "s/C/D/g" ...), basically by replacing '=>' with '/'
erikj@49374 157 # and ';' with '/g" -e "s/', and adjusting for edge cases.
erikj@49374 158 $1_REPLACEMENTS_COMMAND_LINE := $(SED) -e 's$$($1_SEP)$$(subst $$(SPACE);$$(SPACE),$$($1_SEP)g' \
erikj@49374 159 -e 's$$($1_SEP),$$(subst $$(SPACE)=>$$(SPACE),$$($1_SEP),$$(subst $$(SPACE)=>$$(SPACE);$$(SPACE),$$($1_SEP)$$($1_SEP)g' \
erikj@49374 160 -e 's$$($1_SEP),$$(strip $$($1_REPLACEMENTS)))))$$($1_SEP)g'
ihse@22479 161 else
ihse@27595 162 # We don't have any replacements, just pipe the file through cat.
ihse@22479 163 $1_REPLACEMENTS_COMMAND_LINE := $(CAT)
ihse@22479 164 endif
ihse@22479 165
ihse@22479 166 ifneq ($$($1_INCLUDES),)
ihse@22479 167 # We have a include request, prepare it for the recipe.
ihse@22479 168 # Convert an INCLUDE like this PATTERN_1 => file1 ; PATTERN_2 => file2 ;
ihse@22479 169 # into an awk script fragment like this:
ihse@22479 170 # {
ihse@27595 171 # if (matches("PATTERN_1")) { include("file1") } else
ihse@27595 172 # if (matches("PATTERN_2")) { include("file2") } else
ihse@22479 173 # print
ihse@22479 174 # }
ihse@22479 175
ihse@22479 176 $1_INCLUDES_HEADER_AWK := \
ihse@22479 177 function matches(pattern) { return ($$$$0 ~ "^[ \t]*" pattern "[ \t]*$$$$") } \
ihse@22479 178 function include(filename) { while ((getline < filename) == 1) print ; close(filename) }
ihse@22479 179 $1_INCLUDES_PARTIAL_AWK := $$(subst $$(SPACE);,,$$(subst $$(SPACE)=>$$(SPACE),"$$(RIGHT_PAREN)$$(RIGHT_PAREN) \
ihse@22479 180 { include$$(LEFT_PAREN)",$$(subst $$(SPACE);$$(SPACE),"$$(RIGHT_PAREN) } \
ihse@22479 181 else if $$(LEFT_PAREN)matches$$(LEFT_PAREN)",$$(strip $$($1_INCLUDES)))))
ihse@22479 182 $1_INCLUDES_COMMAND_LINE := $(NAWK) '$$($1_INCLUDES_HEADER_AWK) \
ihse@22479 183 { if (matches("$$($1_INCLUDES_PARTIAL_AWK)") } else print }'
ihse@22479 184 else
ihse@27595 185 # We don't have any includes, just pipe the file through cat.
ihse@22479 186 $1_INCLUDES_COMMAND_LINE := $(CAT)
ihse@22479 187 endif
ihse@22479 188
erikj@28600 189 $1_VARDEPS := $$($1_INCLUDES_COMMAND_LINE) $$($1_REPLACEMENTS_COMMAND_LINE)
erikj@28600 190 $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS)
erikj@28600 191
ihse@22479 192 # Reset target list before populating it
ihse@27595 193 $1 :=
ihse@22479 194
ihse@22479 195 ifneq ($$($1_OUTPUT_FILE),)
ihse@22479 196 ifneq ($$(words $$($1_SOURCE_FILES)), 1)
ihse@22479 197 $$(error Cannot use OUTPUT_FILE for more than one source file (in $1))
ihse@22479 198 endif
ihse@22479 199
ihse@22479 200 # Note that $1 is space sensitive and must disobey whitespace rules
ihse@22479 201 $$(eval $$(call SetupSingleTextFileForProcessing,$1, $$($1_SOURCE_FILES), \
ihse@27595 202 $$(patsubst %/, %, $$(dir $$($1_OUTPUT_FILE))), $$(notdir $$($1_OUTPUT_FILE))))
ihse@22479 203 else
ihse@22479 204 ifeq ($$($1_OUTPUT_DIR),)
ihse@22479 205 $$(error Neither OUTPUT_FILE nor OUTPUT_DIR was specified (in $1))
ihse@22479 206 endif
ihse@22479 207
ihse@22479 208 # Now call add_native_source for each source file we are going to process.
ihse@22479 209 ifeq ($$($1_SOURCE_BASE_DIR),)
ihse@27595 210 # With no base dir specified, put all files in target dir, flattening any
ihse@22479 211 # hierarchies. Note that $1 is space sensitive and must disobey whitespace
ihse@22479 212 # rules.
ihse@22479 213 $$(foreach src, $$($1_SOURCE_FILES), \
ihse@22479 214 $$(eval $$(call SetupSingleTextFileForProcessing,$1, $$(src), \
ihse@27595 215 $$(patsubst %/, %, $$($1_OUTPUT_DIR)), $$(notdir $$(src)))))
ihse@22479 216 else
ihse@22479 217 # With a base dir, extract the relative portion of the path. Note that $1
ihse@22479 218 # is space sensitive and must disobey whitespace rules, and so is the
ihse@22479 219 # arguments to patsubst.
ihse@22479 220 $$(foreach src, $$($1_SOURCE_FILES), \
ihse@22479 221 $$(eval $$(call SetupSingleTextFileForProcessing,$1, $$(src), \
ihse@27595 222 $$(patsubst %/, %, $$($1_OUTPUT_DIR)), \
ihse@27595 223 $$(patsubst $$($1_SOURCE_BASE_DIR)/%,%,$$(src)))))
ihse@22479 224 endif
ihse@22479 225 endif
ihse@22479 226 endef