Skip to content

Commit

Permalink
Use pkg-config in Autotools
Browse files Browse the repository at this point in the history
This commit treats the following:

- Detects if pkg-config or pkgconf is available

- Uses pkg-config to set the correct flags for dependencies. In
  particular, this solves issues when compiling against static
  libraries.

- Cleans up configure.ac

- Sets LDFLAGS, CFLAGS, CPPFLAGS and LIBS correctly and trims their
  corresponding string

- Now pushes -lgc if GC is used. Seems to have gone unnoticed.
  • Loading branch information
albinahlback committed Oct 21, 2024
1 parent 4352a58 commit c3268b8
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 72 deletions.
50 changes: 50 additions & 0 deletions acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,56 @@ define(FAST_VROUNDPD_PATTERN,
[[znver[2-4]* | sandybridge* | ivybridge*]])



dnl FLINT_SET_LIBFLAGS(lib,lib-path,include-path,[library_alias])
dnl -----------------------
dnl Sets lib_LDFLAGS and lib_CPPFLAGS to include and link library.
dnl If pkg-config is available, lib_CFLAGS, lib_LIBS, lib_libdir,
dnl lib_includedir are also set and also sets lib_LIBS with the appropriate
dnl `-l' flag(s). Else, straight up use lib-path and include-path.

AC_DEFUN([FLINT_SET_LIBFLAGS],
[tmpalias=m4_default([$4],[$1])
if test "x$PKG_CONFIG" != "x";
then
if test "x$2" != "x";
then
withpath="--with-path=$2"
fi
# libdir
tmp=`$PKG_CONFIG --variable=libdir $withpath $1` dnl ' Fix Vim syntax
eval "${tmpalias}_libdir=\"\${tmp}\""
# includedir
tmp=`$PKG_CONFIG --variable=includedir $withpath $1` dnl ' Fix Vim syntax
eval "${tmpalias}_includedir=\"\${tmp}\""
# LIBS
tmp=`$PKG_CONFIG --libs-only-l $withpath $1` dnl ' Fix Vim syntax
eval "${tmpalias}_LIBS=\"\${tmp}\""
# LDFLAGS
tmp=`$PKG_CONFIG --libs-only-L $withpath $1` dnl ' Fix Vim syntax
eval "${tmpalias}_LDFLAGS=\"\${tmp}\""
# CPPFLAGS
tmp=`$PKG_CONFIG --cflags-only-other $withpath $1 | sed -n 's/\(-D\w\+\)\(\|=\w\+\)/\n\1\2\n/gp' | sed -n '/^-D/p'` dnl ' Fix Vim syntax
tmp="`$PKG_CONFIG --cflags-only-I $withpath $1` $tmp" dnl ' Fix Vim syntax
eval "${tmpalias}_CPPFLAGS=\"\${tmp}\""
# CFLAGS
tmp=`$PKG_CONFIG --cflags-only-other $withpath $1 | sed 's/\(-D\w\+\)\(\|=\w\+\)//g' | sed 's/ / /g'` dnl ' Fix Vim syntax
eval "${tmpalias}_CFLAGS=\"\${tmp}\""
else
eval "${tmpalias}_LDFLAGS=\"-L\${2}\""
eval "${tmpalias}_CPPFLAGS=\"-I\${3}\""
fi
])



dnl FLINT_CC_IS_GCC([action-if-true],[action-if-false])
dnl -----------------------
dnl Checks if compiler is GCC.
Expand Down
Loading

0 comments on commit c3268b8

Please sign in to comment.