@@ -199,23 +199,51 @@ define _apply_version_seds
199199 {print}' $@ .tmp > $@ .tmp2 && mv $@ .tmp2 $@ .tmp
200200endef
201201
202- # The recipe builds $@.tmp then moves it into place atomically.
202+ # ----------------------------------------------------------------------------
203+ # Two .sql.in sources feed the same .sql.in -> .sql transform below (wrap with
204+ # @generated@ markers, then _apply_version_seds), producing two different
205+ # targets:
206+ #
207+ # sql/cat_tools.sql.in (hand-maintained master, committed)
208+ # --pattern rule--> sql/cat_tools.sql
209+ #
210+ # sql/cat_tools.sql.in
211+ # --copy rule, tags @generated@ as "VERSIONED FILE!"-->
212+ # sql/cat_tools--X.Y.Z.sql.in (committed per-version snapshot; frozen
213+ # once released, see CLAUDE.md's SQL file conventions)
214+ # --override rule, same transform as the pattern rule-->
215+ # sql/cat_tools--X.Y.Z.sql = $(EXTENSION_VERSION_FILES)
216+ # (what CREATE EXTENSION actually installs)
217+ #
218+ # The bottom (override) rule can't just be left to the sql/%.sql pattern rule
219+ # matching it: control.mk (auto-generated by pgxntool from cat_tools.control,
220+ # see pgxntool/base.mk) already defines its OWN recipe for
221+ # $(EXTENSION_VERSION_FILES) -- straight from cat_tools.sql, no .sql.in layer,
222+ # no version seds -- and GNU Make always prefers an explicit rule over a
223+ # pattern rule for the same target. Overriding it here is the only way to
224+ # route that target through the same .sql.in / version-sed pipeline as
225+ # everything else; its "overriding recipe" warning is expected. Both final
226+ # steps build $@.tmp then move it into place atomically.
227+ #
203228# TODO: refactor the version handling into a function.
229+ # ----------------------------------------------------------------------------
230+
231+ # @generated@ becomes the "-- GENERATED FILE! DO NOT EDIT!" marker below via a
232+ # plain, unanchored substring match -- it also fires on a handful of
233+ # coincidental @generated@ occurrences inside real-code comments in
234+ # cat_tools.sql.in, which is harmless (already inside a -- comment).
204235sql/% .sql : sql/% .sql.in pgxntool/safesed
205236 (echo @generated@ && cat $< && echo @generated@) | sed -e ' s#@generated@#-- GENERATED FILE! DO NOT EDIT! See $<#' > $@ .tmp
206237 $(_apply_version_seds )
207238 mv $@ .tmp $@
208239
209- # Make the current version's .sql.in by copying the base source ; the pattern
210- # rule above then turns it into the final .sql with SED substitutions applied.
211- # (EXTENSION_VERSION_FILES is just sql/cat_tools--<current version>.sql)
240+ # Appends " VERSIONED FILE!" after every @generated@ occurrence ; the pattern
241+ # rule above resolves the leading @generated@ either way, so the tag rides
242+ # through into the final marker text untouched.
212243$(EXTENSION_VERSION_FILES:.sql =.sql.in): sql/cat_tools.sql.in cat_tools.control
213- cp $< $@
244+ sed -e 's/@generated@/@generated@ VERSIONED FILE!/' $< > $@
214245
215- # Override control.mk's rule (which builds EXTENSION_VERSION_FILES straight from
216- # cat_tools.sql, skipping SED) so we build from the .sql.in above instead, with
217- # version-conditional substitutions applied. GNU Make's "overriding recipe"
218- # warning for this target is expected.
246+ # See the overview above for why this duplicates the pattern rule's recipe.
219247$(EXTENSION_VERSION_FILES ) : $(EXTENSION_VERSION_FILES:.sql=.sql.in ) pgxntool/safesed
220248 (echo @generated@ && cat $< && echo @generated@) | sed -e ' s#@generated@#-- GENERATED FILE! DO NOT EDIT! See $<#' > $@ .tmp
221249 $(_apply_version_seds )
0 commit comments