1 #
2 # Copyright (c) 2025, 2026, 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
26 include MakeIncludeStart.gmk
27 ifeq ($(INCLUDE), true)
28
29 ################################################################################
30 # This file defines macros that sets up rules for running the spp.Spp build tool
31 ################################################################################
32
33 include Execute.gmk
34 include $(TOPDIR)/make/ToolsJdk.gmk
35
36 NON_BYTE_INTEGER_TYPES := char short int long
37 NON_BYTE_NUMBER_TYPES := $(NON_BYTE_INTEGER_TYPES) float double
38 NUMBER_TYPES := byte $(NON_BYTE_NUMBER_TYPES)
39 INTEGER_NUMBER_TYPES := byte $(NON_BYTE_INTEGER_TYPES)
40 PRIMITIVE_TYPES := boolean $(NUMBER_TYPES)
41 BITWISE_PRIMITIVE_TYPES := boolean $(INTEGER_NUMBER_TYPES)
42
43 ################################################################################
44 # The Conv function converts a type given as first argument (as a normal Java
45 # native type name), into one of several corresponding strings, depending on
46 # the aspect given in the second argument
47 #
48 # The implementation dispatches the call to one of several Conv_<aspect> macros.
49 #
50 # arg $1: the type to convert
51 # arg $2: the aspect to convert for
52 # arg $3: byte order (only needed for certain aspects)
53 #
54 Conv = \
55 $(strip $(call Conv_$(strip $2),$(strip $1),$(strip $3)))
56
57 ################################################################################
58 # Conv_<aspect> implementations
59
60 # Return a single letter representing the type (lowercase first letter)
61 Conv_x = \
62 $(call firstchar, $1)
63
64 # Return capitalized type name
65 Conv_Type = \
66 $(call titlecase, $1)
67
68 # Return the full descriptive name of the type, e.g. int -> integer
69 Conv_fulltype = \
70 $(if $(filter char, $1), \
71 character, \
72 $(if $(filter int, $1), \
73 integer, \
74 $1 \
75 ) \
76 )
77
78 # Return the capitalized full descriptive name of the type, e.g. int -> Integer
79 Conv_Fulltype = \
80 $(call titlecase, $(call Conv_fulltype, $1))
81
82 # Return log2 bits per value (0-3)
83 Conv_LBPV = \
84 $(if $(filter byte, $1), \
85 0, \
86 $(if $(filter char short, $1), \
87 1, \
88 $(if $(filter int float, $1), \
89 2, \
90 $(if $(filter long double, $1), \
91 3))))
92
93 # Return float or int category
94 Conv_category = \
95 $(if $(filter float double, $1), \
96 floatingPointType, \
97 integralType \
98 )
99
100 # Return stream information for char
101 Conv_streams = \
102 $(if $(filter char, $1), streamableType)
103
104 # Return stream type information for char
105 Conv_streamtype = \
106 $(if $(filter char, $1), int)
107
108 # Return capitalized stream type information for char
109 Conv_Streamtype = \
110 $(if $(filter char, $1), Int)
111
112 # Return article to use for type in English text
113 Conv_a = \
114 $(if $(filter int, $1), an, a)
115
116 # Return capitalized article to use for type in English text
117 Conv_A = \
118 $(if $(filter int, $1), An, A)
119
120 # Return integer type with same size as the type
121 Conv_memtype = \
122 $(if $(filter float, $1), int, $(if $(filter double, $1), long, $1))
123
124 # Return capitalized integer type with same size as the type
125 Conv_Memtype = \
126 $(call titlecase, $(call Conv, $1, memtype))
127
128 # Return capitalized full descriptive name for integer type with same size as the type
129 Conv_FullMemtype = \
130 $(call Conv, $(call Conv, $1, memtype), Fulltype)
131
132 # Return Type or Memtype depending on byte order
133 # arg $2: BYTE_ORDER
134 Conv_Swaptype = \
135 $(if $(filter U, $2), \
136 $(call Conv, $1, Type), \
137 $(call Conv, $1, Memtype))
138
139 # Return fromBits method name for floating types, depending on byte order
140 # arg $2: BYTE_ORDER
141 Conv_fromBits = \
142 $(if $(filter float double, $1), \
143 $(if $(filter U, $2), , \
144 $(call Conv, $1, Type).$(call Conv, $1, memtype)BitsTo$(call Conv, $1, Type)))
145
146 # Return toBits method name for floating types, depending on byte order
147 # arg $2: BYTE_ORDER
148 Conv_toBits = \
149 $(if $(filter float double, $1), \
150 $(if $(filter U, $2), , \
151 $(call Conv, $1, Type).$1ToRaw$(call Conv, $(call Conv, $1, memtype), Type)Bits))
152
153 # Return swap method name, depending on byte order
154 # arg $2: BYTE_ORDER
155 Conv_swap = \
156 $(if $(filter S, $2), Bits.swap)
157
158 # Return word describing the number of bytes required by type
159 Conv_nbytes = \
160 $(if $(filter 0, $(call Conv, $1, LBPV)), one, \
161 $(if $(filter 1, $(call Conv, $1, LBPV)), two, \
162 $(if $(filter 2, $(call Conv, $1, LBPV)), four, \
163 $(if $(filter 3, $(call Conv, $1, LBPV)), eight))))
164
165 # Return word describing the number of bytes required by type, minus one
166 Conv_nbytesButOne = \
167 $(if $(filter 0, $(call Conv, $1, LBPV)), zero, \
168 $(if $(filter 1, $(call Conv, $1, LBPV)), one, \
169 $(if $(filter 2, $(call Conv, $1, LBPV)), three, \
170 $(if $(filter 3, $(call Conv, $1, LBPV)), seven))))
171
172 ################################################################################
173 # Setup make rules that runs the spp.Spp build tool on an input file.
174 #
175 # Parameter 1 is the name of the rule. This name is used as variable prefix,
176 # and the targets generated are listed in a variable by that name.
177 #
178 # Remaining parameters are named arguments. These include:
179 # BEGIN_END Set to true to exclude everything outside #begin/#end (default: false)
180 # SUBST_EMPTY_LINES Set to false to not generate empty lines for removed lines (default: true)
181 # SOURCE_FILE The input file to process (required)
182 # OUTPUT_FILE The output file (required)
183 # INFO Override default message to print (optional)
184 # KEYS One or more keys to control the generation (optional)
185 # REPLACEMENTS one or more text replacement patterns, using the syntax:
186 # VAR=VALUE [VAR=VALUE] ...
187 #
188 SetupStreamPreProcessing = $(NamedParamsMacroTemplate)
189 define SetupStreamPreProcessingBody
190 # Verify arguments
191 ifeq ($$($1_SOURCE_FILE), )
192 $$(error Must specify SOURCE_FILE (in $1))
193 endif
194 ifeq ($$($1_OUTPUT_FILE), )
195 $$(error Must specify OUTPUT_FILE (in $1))
196 endif
197
198 $1_COMMAND_LINE :=
199 ifeq ($$($1_BEGIN_END), true)
200 $1_COMMAND_LINE += -be
201 endif
202
203 ifeq ($$($1_SUBST_EMPTY_LINES), false)
204 $1_COMMAND_LINE += -nel
205 endif
206
207 $1_COMMAND_LINE += $$(foreach k, $$($1_KEYS), -K$$k)
208 $1_COMMAND_LINE += $$(subst $$$$(SPACE), ,$$(foreach d, $$($1_REPLACEMENTS), -D$$d))
209
210 $1_COMMAND_LINE += -i$$($1_SOURCE_FILE) -o$$($1_OUTPUT_FILE).tmp
211
212 ifeq ($$($1_INFO), )
213 $1_INFO := Preprocessing $$(notdir $$($1_SOURCE_FILE)) for $(MODULE)
214 endif
215
216 $$(eval $$(call SetupExecute, RUN_SPP_$1, \
217 INFO := $$($1_INFO), \
218 DEPS := $$($1_SOURCE_FILE) $$(BUILD_TOOLS_JDK), \
219 OUTPUT_FILE := $$($1_OUTPUT_FILE), \
220 COMMAND := $$(TOOL_SPP) $$($1_COMMAND_LINE), \
221 PRE_COMMAND := $$(RM) $$($1_OUTPUT_FILE).tmp $$($1_OUTPUT_FILE), \
222 POST_COMMAND := $$(MV) $$($1_OUTPUT_FILE).tmp $$($1_OUTPUT_FILE), \
223 ))
224
225 $1 += $$(RUN_SPP_$1)
226 endef
227
228 ################################################################################
229
230 endif # include guard
231 include MakeIncludeEnd.gmk