使用autoconf/automake,如何指定包含文件路径? [英] With autoconf/automake, how do I specify include file paths?
问题描述
比方说,我想让生成makefile将某些特定的头文件路径传递给g ++.
Let's say I want to have the generate makefile pass some specific header paths to g++.
我需要添加什么到configure.ac或Makefile.am来指定此内容?
What do I need to add to configure.ac or Makefile.am to specify this?
(注意-我不想使用./configure在CPPFLAGS中传递它.我希望在此步骤之前将这些路径引入)
(note - I do not want to pass it in the CPPFLAGS with ./configure. I want those paths baked in before that step)
具体来说,我想包括/usr/include/freetype和/mypath/include.
Specifically, I want to to include let's say /usr/include/freetype and /mypath/include.
我放了AC_CHECK_HEADERS([freetype/config/ftheader.h])并通过了,但是似乎没有将它添加到传递给g ++的-I中.
I put AC_CHECK_HEADERS([freetype/config/ftheader.h]) and it passes, but doesn't seem to add it to the -I passed to g++.
我也确实尝试添加CPPFLAGS = -I.:/usr/include/freetype:/mypath/include,但是它搞砸了,并把-I两次,第一个为-I.并且忽略了第二个-I.
I also did try adding CPPFLAGS=-I.:/usr/include/freetype:/mypath/include, but it screws up and puts -I twice, the first as -I. and it ignores the 2nd -I.
推荐答案
硬编码到包文件中的路径绝对是错误的做法.如果选择这样做,则需要知道您违反了使用自动工具构建软件包的基本规则.如果在软件包文件中指定/mypath/include
,则将在打算在所有计算机上使用的软件包中指定特定于计算机的内容;显然那是错误的.看起来您想要的是包(在计算机上构建时)要在/mypath
中查找头文件.这很容易完成,而无需盲目打包.至少有3种方法可以做到:
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:
-
使用config.site文件.在
/usr/local/share/config.site
(如有必要,请创建此文件)中,添加以下行:
Use a config.site file. In
/usr/local/share/config.site
(create this file if necessary), add the line:
CPPFLAGS="$CPPFLAGS -I/mypath/include"
现在,任何使用autoconf生成的带有默认前缀(/usr/local
)的配置脚本的软件包都将-I/mypath/include
附加到CPPFLAGS
,并且将找到/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.
如果要为所有内部版本分配任务(不仅是要在/usr/local
中安装的版本),可以使用以下方法:
If you want the assignment to be made for all builds (not just those to be installed in /usr/local
), you can use this:
在$HOME/config.site
中放置指定CPPFLAGS
的同一行,并在默认shell的环境中设置CONFIG_SITE=$HOME/config.site
.现在,无论何时运行autoconf生成的配置脚本,都会从$HOME/config.site
进行分配.
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.
只需在默认Shell环境中指定CPPFLAGS
.
Simply specify CPPFLAGS
in the environment of your default shell.
与修改构建文件相比,所有这些解决方案均具有两个主要优点.首先,它们将适用于所有由autoconf生成的程序包(只要它们遵循规则,并且不执行诸如在构建文件中分配用户变量(例如CPPFLAGS
之类的操作)之类的操作即可.其次,他们不会将您机器的特定信息放入应该在所有机器上都可以使用的程序包中.
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.
这篇关于使用autoconf/automake,如何指定包含文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!