Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pkgconfig and dependency handling improvements #3

Merged
merged 7 commits into from
Jan 25, 2025

Conversation

orlitzky
Copy link
Contributor

As a follow-up to,

we can make some similar improvements in m4rie and simplify its detection of m4ri:

  1. Remove OpenMP detection and OPENMP_FLAGS entirely. This does not appear to be used by m4rie, and it isn't needed to use an m4ri that was built with OpenMP support.
  2. List m4ri under Requires in m4rie's pkg-config file rather than explicitly appending m4ri's flags to those of m4rie. The Requires line is designed to handle this situation automatically. Here's what it does on my (patched) system:
    $ pkg-config --libs m4rie
    -lm4rie -lm4ri -lm
    
    $ cat /usr/lib64/pkgconfig/m4rie.pc 
    prefix=/usr
    exec_prefix=${prefix}
    libdir=/usr/lib64
    includedir=${prefix}/include
    
    Name: M4RIE
    Description: Dense linear algebra over GF(2^e).
    Version: 20250103
    Requires: m4ri >= 20240729
    Libs: -L${libdir} -lm4rie -lm
    Libs.private: 
    Cflags: -I${includedir}
    
  3. Use pkg-config to detect mr4i and obtain its CFLAGS/LIBS (if --with-m4ri=<path> was not specified). This makes pkg-config a requirement, but it kind of is anyway. If someone wants to link against m4rie, they should be using pkg-config to get the correct flags because otherwise it's not obvious that -lm4ri needs to go there. And at that point, not much is lost by also requiring pkg-config to build m4rie in the first place.

CC: @kiwifb, @dimpase, @tornaria, @arojas, @isuruf

OpenMP is not used in m4rie, and its flags are not needed to build
m4rie against an m4ri that _does_ have OpenMP support. The one
scenario where m4ri/m4rie might need to agree on the matter is when
linking a static executable that uses them both; but for this, it will
be easier to rely on pkg-config to provide the correct linker flags
(and only when necessary).
Now that m4ri has a pkg-config file, we can use it to automatically
obtain the correct preprocessor/linker flags for m4ri, rather than
detecting and including them ourselves.
Now that m4ri has a pkg-config file, we can use it to obtain
$M4RI_CFLAGS and $M4RI_LIBS in configure.ac rather than using the
custom macro AX_M4RI_CFLAGS() from m4/ax_m4ri_flags.m4.

This commit replaces AX_M4RI_CFLAGS() with PKG_CHECK_MODULES(), leaves
$M4RI_CFLAGS alone, and replaces -lm4ri with $M4RI_LIBS throughout the
build system. The old macro defined only $M4RI_CFLAGS, but now we get
$M4RI_LIBS separately.
@malb
Copy link
Owner

malb commented Jan 22, 2025

I don't think we currently require pkg-config, but use it if it's there. True, people need to figure it out themselves what flags to use, but currently they can.

@orlitzky
Copy link
Contributor Author

orlitzky commented Jan 22, 2025 via email

@malb
Copy link
Owner

malb commented Jan 22, 2025

Thank you!

Now if pkg-config fails to find m4ri, we will try to link against the
system copy with -lm4ri. It is only an error if both methods fail (and
if --with-m4ri was not given).
The three methods we have for detecting m4ri,

  1. By fiat using --with-m4ri
  2. pkg-config
  3. AC_SEARCH_LIBS

now all use the same two variables to store the necessary preprocessor
and linker flags, $M4RI_CFLAGS and $M4RI_LIBS (these are the
pkg-config names, don't blame me). This obsoletes the
M4RIE_M4RI_CFLAGS and M4RIE_M4RI_LDFLAGS variables, which otherwise
would have been used in combination with M4RI_CFLAGS and M4RI_LIBS,
and could have lead to confusion.
This is redundant at the moment because AC_SEARCH_LIBS() already
prepends -lm to $LIBS, but m4ri.pc includes -lm and m4ri.h includes
math.h, so it's probably best to explicitly include -lm when linking
m4ri.
Only one file (bench/benchmarking.c) includes math.h directly. Others
include it indirectly via m4ri headers, but those cases should be
covered by $M4RI_LIBS.
@orlitzky
Copy link
Contributor Author

Further improvements:

  • We now try to link with -lm4ri -lm if pkg-config fails.
  • The variables $M4RIE_M4RI_CFLAGS/$M4RI_CFLAGS and$M4RIE_M4RI_LDFLAGS/$M4RI_LIBS have been consolidated. After combining the -L and -l flags into $M4RI_LIBS (like pkg-config does), they contain the same information.
  • The math.h header is included only incidentally via m4ri's headers, so I have removed any explicit -lm from m4rie, but it will still be included as part of $M4RI_LIBS.

@malb malb merged commit 0bae2c6 into malb:master Jan 25, 2025
@malb
Copy link
Owner

malb commented Jan 25, 2025

Looks good to me, thank you!

@orlitzky
Copy link
Contributor Author

orlitzky commented Jan 25, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants