使用 autoconf/automake,如何指定包含文件路径? [英] With autoconf/automake, how do I specify include file paths?

查看:76
本文介绍了使用 autoconf/automake,如何指定包含文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想让生成的 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]) 并且它通过了,但似乎没有将它添加到 -I 传递给 g++ 中.

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.

推荐答案

将路径硬编码到包文件中绝对是错误的做法.如果您选择这样做,那么您需要意识到您违反了使用 autotools 构建包的基本规则.如果你在你的包文件中指定了 /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:

  1. 使用 config.site 文件.在 /usr/local/share/config.site(如有必要,请创建此文件)中,添加以下行:

  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"

现在任何使用 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 的同一行,并在 CONFIG_SITE=$HOME/config.site 中设置默认 shell 的环境.现在,每当您运行 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆