本文介绍了autoconf和automake中的DEFS和CPPFLAGS有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了 CFLAGS和CPPFLAGS 之间的区别.但是我的Makefile.am当前同时使用DEFS和CPPFLAGS,因此我不确定是否有区别.

I already read about the difference between CFLAGS and CPPFLAGS. But my Makefile.am currently uses both DEFS and CPPFLAGS and I am not sure about the difference.

DEFS += -DLOCALEDIR=\"$(localedir)\" -DDATADIR=\"$(datadir)\" -DPKGDATADIR=\"$(pkgdatadir)\"

和:

src_foo_CPPFLAGS = \
    $(AM_CPPFLAGS) \
    -I$(top_builddir)/src \
    -DDATADIR='"$(datadir)"' \
    -DMODULEDIR='"$(moduledir)"' \
    -DLIBEXECDIR='"$(libexecdir)"'

CPPFLAGS和DEFS似乎都使用-D选项创建了定义.那么有什么区别.我可以删除DEFS并仅将缺少的定义(PKGDATADIRLOCALEDIR)添加到CPPFLAGS吗?

Both the CPPFLAGS and the DEFS seems to create defines with the -D option. So whats the difference. Can I remove DEFS and just add the missing defines (PKGDATADIR and LOCALEDIR) to CPPFLAGS?

推荐答案

DEFS在autoconf中定义如下:

DEFS is defined in autoconf as follows:

使用-p标志(例如make -p > rules)执行make时.我们可以检查生成的rules文件,以了解make实际执行的操作.

When make is executed with the -p flag (e.g. make -p > rules). We can examine the resulting rules file to find out what make make will actually do.

假设调用AC_CONFIG_HEADERS宏,则最初定义DEFS的方法如下:

Assuming the AC_CONFIG_HEADERS macro is called then DEFS is initially defined as follows:

DEFS = -DHAVE_CONFIG_H

假设我们定义DEFS如下:

DEFS += \
    -DLOCALEDIR=\"$(localedir)\" \
    -DDATADIR=\"$(datadir)\" \
    -DPKGDATADIR=\"$(pkgdatadir)\"

然后DEFS看起来像这样:

DEFS = -DHAVE_CONFIG_H -DLOCALEDIR=\"$(localedir)\" -DDATADIR=\"$(datadir)\"  \
       -DPKGDATADIR=\"$(pkgdatadir)\"

接下来,让我们看看在自动makemake生成的Makefile中使用DEFS的方式,Makefile中的编译规则将如下所示:

Next lets look at the way DEFS is used in the Makefiles that are generated by automake, the compile rule in the Makefile will look like this:

COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
          $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)

如我们所见,DEFS首先出现,然后是其他一些变量和AM_CPPFLAGS每次出现DEFS后,总是出现另一个AM_CPPFLAGS及其变体,例如foo_CPPFLAGS.

As we can see, DEFS appears first, followed by some other variables and the AM_CPPFLAGSEvery further occurrence of DEFS is always followed by another occurrence of AM_CPPFLAGS and its variants such as foo_CPPFLAGS.

因此,总结这个问题,我认为很明显,可以删除DEFS,而可以将其内容放入CPPFLAGS中.我也在自动工具频道中的IRC上问了这个问题.我建议不要使用DEFS,而只能使用CPPFLAGS.

So to conclude this question, I think its clear that DEFS can be removed and instead its content can be put into CPPFLAGS. I also asked this question on IRC in the autotools channel. It was suggested to me, not to use DEFS and only use CPPFLAGS.

这篇关于autoconf和automake中的DEFS和CPPFLAGS有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 19:54