Reputation: 13051
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)\"
and:
src_foo_CPPFLAGS = \
$(AM_CPPFLAGS) \
-I$(top_builddir)/src \
-DDATADIR='"$(datadir)"' \
-DMODULEDIR='"$(moduledir)"' \
-DLIBEXECDIR='"$(libexecdir)"'
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
?
Upvotes: 3
Views: 1514
Reputation: 13051
DEFS
is defined in autoconf as follows:
-D options to pass to the C compiler. If AC_CONFIG_HEADERS is called, configure replaces ‘@DEFS@’ with -DHAVE_CONFIG_H instead (see Configuration Headers). This variable is not defined while configure is performing its tests, only when creating the output files. See Setting Output Variables, for how to check the results of previous tests.
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.
Assuming the AC_CONFIG_HEADERS
macro is called then DEFS
is initially defined as follows:
DEFS = -DHAVE_CONFIG_H
Assuming we define DEFS
as follows:
DEFS += \
-DLOCALEDIR=\"$(localedir)\" \
-DDATADIR=\"$(datadir)\" \
-DPKGDATADIR=\"$(pkgdatadir)\"
then DEFS
is going to look like this:
DEFS = -DHAVE_CONFIG_H -DLOCALEDIR=\"$(localedir)\" -DDATADIR=\"$(datadir)\" \
-DPKGDATADIR=\"$(pkgdatadir)\"
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)
As we can see, DEFS
appears first, followed by some other variables and the AM_CPPFLAGS
Every further occurrence of DEFS
is always followed by another occurrence of AM_CPPFLAGS
and its variants such as foo_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
.
Upvotes: 5