Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions make/common/Utils.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,42 @@ uppercase = \
$(uppercase_result) \
)

lowercase_table := A,a B,b C,c D,d E,e F,f G,g H,h I,i J,j K,k L,l M,m N,n O,o \
P,p Q,q R,r S,s T,t U,u V,v W,w X,x Y,y Z,z

lowercase_internal = \
$(if $(strip $1), $$(subst $(firstword $1), $(call lowercase_internal, \
$(wordlist 2, $(words $1), $1), $2)), $2)

# Convert a string to lower case. Works only on a-z.
# $1 - The string to convert
lowercase = \
$(strip \
$(eval lowercase_result := $(call lowercase_internal, $(lowercase_table), $1)) \
$(lowercase_result) \
)

lowercase_letters := a b c d e f g h i j k l m n o p q r s t u v w x y z
uppercase_letters := A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

titlecase_internal = \
$(strip $(or \
$(strip $(foreach l, $(lowercase_letters) $(uppercase_letters), \
$(if $(filter $l%, $1), \
$(call uppercase, $l)$(call lowercase, $(patsubst $l%,%,$1))))), \
$1))

# Convert a string to Title Case. Works only on a-z.
# $1 - The string to convert
titlecase = \
$(strip $(foreach w, $1, $(call titlecase_internal, $w)))

# Returns the first character of a string. Works only on a-z.
# $1 - The string to extract the first character from
firstchar = \
$(strip $(foreach l, $(lowercase_letters) $(uppercase_letters), \
$(if $(filter $l%, $(firstword $1)), $l)))

################################################################################
# Creates a sequence of increasing numbers (inclusive).
# Param 1 - starting number
Expand Down
228 changes: 228 additions & 0 deletions make/common/modules/GensrcStreamPreProcessing.gmk
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
#
# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code 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
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

include MakeIncludeStart.gmk
ifeq ($(INCLUDE), true)

################################################################################
# This file defines macros that sets up rules for running the spp.Spp build tool
################################################################################

include Execute.gmk
include $(TOPDIR)/make/ToolsJdk.gmk

NON_BYTE_NUMBER_TYPES := char short int long float double
NUMBER_TYPES := byte $(NON_BYTE_NUMBER_TYPES)
PRIMITIVE_TYPES := boolean $(NUMBER_TYPES)

################################################################################
# The Conv function converts a type given as first argument (as a normal Java
# native type name), into one of several corresponding strings, depending on
# the aspect given in the second argument
#
# The implementation dispatches the call to one of several Conv_<aspect> macros.
#
# arg $1: the type to convert
# arg $2: the aspect to convert for
# arg $3: byte order (only needed for certain aspects)
#
Conv = \
$(strip $(call Conv_$(strip $2),$(strip $1),$(strip $3)))

################################################################################
# Conv_<aspect> implementations

# Return a single letter representing the type (lowercase first letter)
Conv_x = \
$(call firstchar, $1)

# Return capitalized type name
Conv_Type = \
$(call titlecase, $1)

# Return the full descriptive name of the type, e.g. int -> integer
Conv_fulltype = \
$(if $(filter char, $1), \
character, \
$(if $(filter int, $1), \
integer, \
$1 \
) \
)

# Return the capitalized full descriptive name of the type, e.g. int -> Integer
Conv_Fulltype = \
$(call titlecase, $(call Conv_fulltype, $1))

# Return log2 bits per value (0-3)
Conv_LBPV = \
$(if $(filter byte, $1), \
0, \
$(if $(filter char short, $1), \
1, \
$(if $(filter int float, $1), \
2, \
$(if $(filter long double, $1), \
3))))

# Return float or int category
Conv_category = \
$(if $(filter float double, $1), \
floatingPointType, \
integralType \
)

# Return stream information for char
Conv_streams = \
$(if $(filter char, $1), streamableType)

# Return stream type information for char
Conv_streamtype = \
$(if $(filter char, $1), int)

# Return capitalized stream type information for char
Conv_Streamtype = \
$(if $(filter char, $1), Int)

# Return article to use for type in English text
Conv_a = \
$(if $(filter int, $1), an, a)

# Return capitalized article to use for type in English text
Conv_A = \
$(if $(filter int, $1), An, A)

# Return integer type with same size as the type
Conv_memtype = \
$(if $(filter float, $1), int, $(if $(filter double, $1), long, $1))

# Return capitalized integer type with same size as the type
Conv_Memtype = \
$(call titlecase, $(call Conv, $1, memtype))

# Return capitalized full descriptive name for integer type with same size as the type
Conv_FullMemtype = \
$(call Conv, $(call Conv, $1, memtype), Fulltype)

# Return Type or Memtype depending on byte order
# arg $2: BYTE_ORDER
Conv_Swaptype = \
$(if $(filter U, $2), \
$(call Conv, $1, Type), \
$(call Conv, $1, Memtype))

# Return fromBits method name for floating types, depending on byte order
# arg $2: BYTE_ORDER
Conv_fromBits = \
$(if $(filter float double, $1), \
$(if $(filter U, $2), , \
$(call Conv, $1, Type).$(call Conv, $1, memtype)BitsTo$(call Conv, $1, Type)))

# Return toBits method name for floating types, depending on byte order
# arg $2: BYTE_ORDER
Conv_toBits = \
$(if $(filter float double, $1), \
$(if $(filter U, $2), , \
$(call Conv, $1, Type).$1ToRaw$(call Conv, $(call Conv, $1, memtype), Type)Bits))

# Return swap method name, depending on byte order
# arg $2: BYTE_ORDER
Conv_swap = \
$(if $(filter S, $2), Bits.swap)

# Return word describing the number of bytes required by type
Conv_nbytes = \
$(if $(filter 0, $(call Conv, $1, LBPV)), one, \
$(if $(filter 1, $(call Conv, $1, LBPV)), two, \
$(if $(filter 2, $(call Conv, $1, LBPV)), four, \
$(if $(filter 3, $(call Conv, $1, LBPV)), eight))))

# Return word describing the number of bytes required by type, minus one
Conv_nbytesButOne = \
$(if $(filter 0, $(call Conv, $1, LBPV)), zero, \
$(if $(filter 1, $(call Conv, $1, LBPV)), one, \
$(if $(filter 2, $(call Conv, $1, LBPV)), three, \
$(if $(filter 3, $(call Conv, $1, LBPV)), seven))))

################################################################################
# Setup make rules that runs the spp.Spp build tool on an input file.
#
# Parameter 1 is the name of the rule. This name is used as variable prefix,
# and the targets generated are listed in a variable by that name.
#
# Remaining parameters are named arguments. These include:
# BEGIN_END Set to true to exclude everything outside #begin/#end (default: false)
# SUBST_EMPTY_LINES Set to false to not generate empty lines for removed lines (default: true)
# SOURCE_FILE The input file to process (required)
# OUTPUT_FILE The output file (required)
# INFO Override default message to print (optional)
# KEYS One or more keys to control the generation (optional)
# REPLACEMENTS one or more text replacement patterns, using the syntax:
# VAR=VALUE [VAR=VALUE] ...
#
SetupStreamPreProcessing = $(NamedParamsMacroTemplate)
define SetupStreamPreProcessingBody
# Verify arguments
ifeq ($$($1_SOURCE_FILE), )
$$(error Must specify SOURCE_FILE (in $1))
endif
ifeq ($$($1_OUTPUT_FILE), )
$$(error Must specify OUTPUT_FILE (in $1))
endif

$1_COMMAND_LINE :=
ifeq ($$($1_BEGIN_END), true)
$1_COMMAND_LINE += -be
endif

ifeq ($$($1_SUBST_EMPTY_LINES), false)
$1_COMMAND_LINE += -nel
endif

$1_COMMAND_LINE += $$(foreach k, $$($1_KEYS), -K$$k)
$1_COMMAND_LINE += $$(subst $$$$(SPACE), ,$$(foreach d, $$($1_REPLACEMENTS), -D$$d))

$1_COMMAND_LINE += -i$$($1_SOURCE_FILE) -o$$($1_OUTPUT_FILE).tmp

ifeq ($$($1_INFO), )
$1_INFO := Preprocessing $$(notdir $$($1_SOURCE_FILE)) for $(MODULE)
endif

$$(eval $$(call SetupExecute, RUN_SPP_$1, \
INFO := $$($1_INFO), \
DEPS := $$($1_SOURCE_FILE) $$(BUILD_TOOLS_JDK), \
OUTPUT_FILE := $$($1_OUTPUT_FILE), \
COMMAND := $$(TOOL_SPP) $$($1_COMMAND_LINE), \
PRE_COMMAND := $$(RM) $$($1_OUTPUT_FILE).tmp $$($1_OUTPUT_FILE), \
POST_COMMAND := $$(MV) $$($1_OUTPUT_FILE).tmp $$($1_OUTPUT_FILE), \
))

$1 += $$(RUN_SPP_$1)
endef

################################################################################

endif # include guard
include MakeIncludeEnd.gmk
4 changes: 2 additions & 2 deletions make/modules/java.base/Gensrc.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
################################################################################

include GensrcCommon.gmk
include GensrcProperties.gmk
include GensrcStreamPreProcessing.gmk

include gensrc/GensrcBuffer.gmk
include gensrc/GensrcCharacterData.gmk
Expand Down Expand Up @@ -71,8 +73,6 @@ TARGETS += $(CLDR_GEN_DONE)

################################################################################

include GensrcProperties.gmk

$(eval $(call SetupCompileProperties, LIST_RESOURCE_BUNDLE, \
SRC_DIRS := $(MODULE_SRC)/share/classes/sun/launcher/resources, \
CLASS := ListResourceBundle, \
Expand Down
Loading