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