(I'm not subscribed to pkgsrc-users, and replying by cut&paste from the
mail archive. Apologies in advance for any threading breakage which
results. Please CC me on replies.)

Robert Elz wrote:

What I still don't know is from where pkgsrc (and it must be pkgsrc,
somewhere) gets the value for the LDFLAGS it puts in the environment when
it runs configure.

These values come from each package's BUILDLINK_LIBDIRS.<pkg> and
BUILDLINK_RPATHDIRS.<pkg> variables, which are autogenerated to sensible
things for the vast majority of packages.

They are then concatenated in the order that the packages appear in
BUILDLINK_TREE, although x11-links comes first if it is present.

BUILDLINK_TREE is built in each buildlink3.mk file, and simply tracks
the ordering of inclusion of each buildlink3.mk file.

Duplicates are removed. Only the first occurrence remains.

The full list for x11/gtk2 is below, with duplicates still included,
with annotations showing which package each came from.

libX11 is pulled in from x11/gtk2/options.mk, before any other
buildlink3.mk files.

A possible workaround to this is to move the inclusion of options.mk to
the end of x11/gtk2/Makefile, and that gets the build past the configure
stage on my box. This feels too flaky to be a proper fix, though.