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