With autoconf/automake, how do I specify include file paths?

前端 未结 2 909
清歌不尽
清歌不尽 2021-01-06 00:12

Let\'s say I want to have the generate makefile pass some specific header paths to g++.

What do I need to add to configure.ac or Makefile.am to specify this?

相关标签:
2条回答
  • 2021-01-06 00:54

    Since the question was about what to put in an automakefile, I would have thought AM_CPPFLAGS was the right variable to use to add includes and defines for all C/C++ compiles. See http://www.gnu.org/software/automake/manual/html_node/Program-Variables.html

    Example:

    AM_CPPFLAGS = -I/usr/local/custom/include/path
    
    0 讨论(0)
  • 2021-01-06 01:15

    Hard coding paths into the package files is absolutely the wrong thing to do. If you choose to do that, then you need to be aware that you are violating the basic rules of building a package with the autotools. If you specify /mypath/include in your package files, you are specifying things specific to your machine in a package that is intended to work on all machines; clearly that is wrong. It looks like what you want is for your package (when built on your machine) to look for header files in /mypath. That is easy to accomplish without bastardizing your package. There are (at least) 3 ways to do it:

    1. Use a config.site file. In /usr/local/share/config.site (create this file if necessary), add the line:

      CPPFLAGS="$CPPFLAGS -I/mypath/include"
      

      Now any package using an autoconf generated configure script with the default prefix (/usr/local) will append -I/mypath/include to CPPFLAGS and the headers in /mypath/include will be found.

    2. If you want the assignment to be made for all builds (not just those to be installed in /usr/local), you can use this:

      Put the same line specifying CPPFLAGS in $HOME/config.site, and set CONFIG_SITE=$HOME/config.site in the environment of your default shell. Now, whenever you run an autoconf generated configure script, the assignments from $HOME/config.site will be made.

    3. Simply specify CPPFLAGS in the environment of your default shell.

    All of these solutions have two primary advantages over modifying your build files. First, they will work for all autoconf generated packages (as long as they follow the rules and don't do things like assigning user variables such as CPPFLAGS in the build files). Second, they do not put your machine specific information into a package that ought to work on all machines.

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题