Project

General

Profile

Actions

Bug #19778

closed

mkmf.rb pkg_config() interaction with RbConfig::CONFIG["cflags"]

Added by rhenium (Kazuki Yamaguchi) 10 months ago. Updated 7 months ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 3.3.0dev (2023-07-21T09:38:29Z master 22f9735587) [x86_64-linux]
[ruby-core:114250]

Description

(This was first reported at https://github.com/ruby/openssl/issues/650: The extension's build breaks in a strange way if RbConfig::CONFIG["*flags"] contains the path of an OpenSSL installation but pkg-config returns the path of a different OpenSSL installation)

Commit 097c3e9cbbf23718371f08c24b2d2297b039f63f ("mkmf.rb: -I flags to $INCFLAGS", Ruby 2.2) changed how mkmf's pkg_config() handles the result of the pkg-config command. It now stores the -I flags in $INCFLAGS and others in $CFLAGS.

mkmf generates a Makefile that compiles source files with:

$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS)

and link the final library with:

$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)

This "new" behavior of pkg_config() is problematic when RbConfig::CONFIG["{C,CPP}FLAGS"] also provide -I flags and RbConfig::CONFIG["LDFLAGS"] provides the matching -L flags -- for example, if Ruby is compiled with ./configure --with-opt-dir=<dir>. This would end up with compiling sources with

[...] -I<from pkg-config> -I<from RbConfig> [...]

and then linking with

[...] -L<from RbConfig> -L<from pkg-config> [...]

This doesn't seem right. I don't know which should come earlier, but the order should be consistent. The commit in question clearly describes the change in the commit message, but it doesn't have a linked issue. What is it intended for? Also, what is $INCFLAGS?

On the other hand, dir_config() would prepend -I flags to $CPPFLAGS and -L flags to $LIBPATH, so it doesn't have issues with flags from RbConfig, albeit in a differently way.

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0