Makefile.am: How to use curl-config and xml2-config in configure.ac?

纵然是瞬间 提交于 2020-01-13 15:00:10

问题


I want to set include and lib paths given an existing Makefile (below) in configure.ac. But I don't know how can I use $(shell XYZ-config --libs) command in configure.ac.

Could anyone help please? Thanks!!

# --------------------------------------------------------------------------
# Acquire configuration information for libraries that libs3 depends upon

ifndef CURL_LIBS
    CURL_LIBS := $(shell curl-config --libs)
endif

ifndef CURL_CFLAGS
    CURL_CFLAGS := $(shell curl-config --cflags)
endif

ifndef LIBXML2_LIBS
    LIBXML2_LIBS := $(shell xml2-config --libs)
endif

ifndef LIBXML2_CFLAGS
    LIBXML2_CFLAGS := $(shell xml2-config --cflags)
endif

回答1:


I'd vouch for actually using pkgconfig instead of clumsy *-config scripts, which makes this a one-liner per package:

# configure.ac
PKG_CHECK_MODULES([libcurl], [curl])
PKG_CHECK_MODULES([libxml2], [libxml-2.0])

# Makefile.am
AM_CPPFLAGS = ${libcurl_CFLAGS} ${libxml2_CFLAGS}
bin_PROGRAMS = foo
foo_LDADD = ${libcurl_LIBS} ${libxml2_LIBS}

*-config scripts have a tendency to become large pieces of redundant code (just like syvVinit scripts vs. systemd unit files, for example) with deviating behavior: some -config scripts use --ccflags, others --cflags. Some use --libs, others use --ldflags—a terrible mess best avoided.




回答2:


for benefits of others, putting the actual thing i used with help from answer provided by j0rgensen above. hope it will help someone sometime :)

In configure.ac:

# Get xml2 library and include locations
AC_ARG_WITH([xml2-include-path],
  [AS_HELP_STRING([--with-xml2-include-path],
    [location of the xml2 headers, defaults to /usr/include/xml2])],
  [xml2_CFLAGS="-I$withval"],
  [xml2_CFLAGS='-I/usr/include'])
AC_SUBST([xml2_CFLAGS])

AC_ARG_WITH([xml2-lib-path],
  [AS_HELP_STRING([--with-xml2-lib-path], [location of the xml2 libraries])],
  [xml2_LIBS="-L$withval -lxml2"],
  [xml2_LIBS="-L/usr/lib -lxml2"])
AC_SUBST([xml2_LIBS])


# Get curl library and include locations
AC_ARG_WITH([curl-include-path],
  [AS_HELP_STRING([--with-curl-include-path],
    [location of the curl headers, defaults to /usr/include/curl])],
  [curl_CFLAGS="-I$withval"],
  [curl_CFLAGS='-I/Users/vshakya/durham_doll/curl/curl-7.23.1/BUILD/include'])
AC_SUBST([curl_CFLAGS])

AC_ARG_WITH([curl-lib-path],
  [AS_HELP_STRING([--with-curl-lib-path], [location of the curl libraries])],
  [curl_LIBS="-L$withval -lcurl"],
  [curl_LIBS="-L/Users/vshakya/durham_doll/curl/curl-7.23.1/BUILD/lib -lcurl"])
AC_SUBST([curl_LIBS])

Makefile.am, ditto like j0rgensen suggested above.




回答3:


The package maintainer is the wrong person to be doing this work. pkg-config is a reasonable tool, but it has no place in the autotools. PKG_CHECK_MODULES should be banned.

From the package maintainer's perspective, it is the responsibility of the user (the person or process who invokes the configure script) to correctly set LDFLAGS and CPPFLAGS to inform the configure script of how the system is set up. If the user wishes to make life simple, they will setup the system so that the libraries and headers can be found by the compiler without making assignments to LDFLAGS or CPPFLAGS (eg, libraries will be in /usr/lib, headers in /usr/include). If the user wishes to make life difficult, that is the user's choice and the package maintainer should not worry about fixing the user's bad decisions. If a user chooses to install libraries in a non-standard place and wants to use pkg-config to somewhat simplify their life in the face of that bad decision, they could use pkg-config within a config.site file to make the appropriate assignments to LDFLAGS and CPPFLAGS. pkg-config is a reasonable tool in a config.site, but it has absolutely no place in configure.ac. It is the user's issue, and not the package maintainer's.

The bottom line is that users who choose to install libraries in non-standard locations should not expect the package maintainer to fix their problem for them.



来源:https://stackoverflow.com/questions/8464569/makefile-am-how-to-use-curl-config-and-xml2-config-in-configure-ac

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!