bug-autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Wrong order of preprocessor and compiler flags


From: Evgeny Grin
Subject: Re: Wrong order of preprocessor and compiler flags
Date: Thu, 24 Mar 2022 21:38:49 +0300
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0



-------- Original Message --------
From: Evgeny Grin <k2k@narod.ru>
Sent: Thursday, March 24, 2022, 14:26 UTC+3
Subject: Wrong order of preprocessor and compiler flags


I've found that everywhere in autoconf scripts flags are used like:
$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD
while automake and libtool use flags in the other order:
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)

I agree that this should be made consistent, but before we change anything, we need to check what the rules *built into GNU and BSD Make* do with CFLAGS and CPPFLAGS (and also CXXFLAGS, OBJCFLAGS, etc) because those are much much harder to get changed than anything in Automake or Autoconf, so we should aim to harmonize everything with them.

Can you look into that please, Evgeny?

Yes, definitely makes sense to align with major 'make' implementations, as all autotools are build to top of them.
I'll check it.


I've made some experiments and research.
In this message, I would like to simply state the current situation.

Debian SID
---------------
Variables defined in https://git.savannah.gnu.org/cgit/make.git/tree/src/default.c?id=667d70eac2b5c0d7b70941574fd51a76ae93b0f4#n606
"COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c"
"COMPILE.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c"
===============
$ LC_ALL=C make -v
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ touch Makefile testc.c testcpp.cc

$ make CPPFLAGS=-DNICE_MACRO CFLAGS=-g0 CXXFLAGS=-g1 CCFLAGS=-g2 testc.o
cc -g0 -DNICE_MACRO  -c -o testc.o testc.c

$ make CPPFLAGS=-DNICE_MACRO CFLAGS=-g0 CXXFLAGS=-g1 CCFLAGS=-g2 testcpp.o
g++ -g1 -DNICE_MACRO  -c -o testcpp.o testcpp.cc
===============


FreeBSD 13.0.
---------------
Suffixes defined in /usr/share/mk/bsd.suffixes.mk:
.c.o:
        ${CC} ${STATIC_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
        ${CTFCONVERT_CMD}
.cc.o .cpp.o .cxx.o .C.o:
        ${CXX} ${STATIC_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
===============
$ make -V MAKE_VERSION
20210110

$ touch Makefile testc.c testcpp.cc

$ make CPPFLAGS=-DNICE_MACRO CFLAGS=-g0 CXXFLAGS=-g1 CCFLAGS=-g2 testc.o
cc  -g0 -c testc.c -o testc.o

$ make CPPFLAGS=-DNICE_MACRO CFLAGS=-g0 CXXFLAGS=-g1 CCFLAGS=-g2 testcpp.o
c++  -g1 -c testcpp.cc -o testcpp.o
===============


OpenBSD 7.0
---------------
Variables defined in /usr/share/mk/sys.mk:
COMPILE.c?=     ${CC} ${CFLAGS} ${CPPFLAGS} -c
COMPILE.cc?=    ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c
===============
$ touch Makefile testc.c testcpp.cc

$ make CPPFLAGS=-DNICE_MACRO CFLAGS=-g0 CXXFLAGS=-g1 CCFLAGS=-g2 testc.o
cc -g0 -DNICE_MACRO -c testc.c

$ make CPPFLAGS=-DNICE_MACRO CFLAGS=-g0 CXXFLAGS=-g1 CCFLAGS=-g2 testcpp.o
c++ -g1 -DNICE_MACRO -c testcpp.cc
===============


NetBSD 9
---------------
Variables defined in /usr/share/mk/sys.mk:
COMPILE.c?=     ${CC} ${CFLAGS} ${DTRACE_OPTS} ${CPPFLAGS} -c
COMPILE.cc?=    ${CXX} ${_CXXSEED} ${CXXFLAGS} ${DTRACE_OPTS} ${CPPFLAGS} -c
===============
$ touch Makefile testc.c testcpp.cc

$ make CPPFLAGS=-DNICE_MACRO CFLAGS=-g0 CXXFLAGS=-g1 CCFLAGS=-g2 testc.o
cc -g0  -DNICE_MACRO -c testc.c

$ make CPPFLAGS=-DNICE_MACRO CFLAGS=-g0 CXXFLAGS=-g1 CCFLAGS=-g2 testcpp.o
c++  -g1  -DNICE_MACRO -c testcpp.cc
===============


Solaris 11.4
---------------
Variables defined in /usr/share/lib/make/make.rules:
COMPILE.c=$(CC) $(CFLAGS) $(CPPFLAGS) -c
COMPILE.cc=$(CCC) $(CCFLAGS) $(CPPFLAGS)  -c
===============
$ touch Makefile testc.c testcpp.cc

$ make CPPFLAGS=-DNICE_MACRO CFLAGS=-g0 CXXFLAGS=-g1 CCFLAGS=-g2 testc.o
cc -g0 -DNICE_MACRO -c  testc.c
"testc.c", line 1: warning: empty translation unit

$ make CPPFLAGS=-DNICE_MACRO CFLAGS=-g0 CXXFLAGS=-g1 CCFLAGS=-g2 testcpp.o
CC -g2 -DNICE_MACRO  -c  testcpp.cc

$ rm -f *.o

$ dmake --version
dmake: Studio 12.6 Distributed Make 8.4 SunOS_x64 2017/05/30

$ dmake -m serial CPPFLAGS=-DNICE_MACRO CFLAGS=-g0 CXXFLAGS=-g1 CCFLAGS=-g2 testc.o
cc -g0 -DNICE_MACRO -c  testc.c
"testc.c", line 1: warning: empty translation unit

$ dmake -m serial CPPFLAGS=-DNICE_MACRO CFLAGS=-g0 CXXFLAGS=-g1 CCFLAGS=-g2 testcpp.o
CC -g2 -DNICE_MACRO  -c  testcpp.cc
===============


Conclusions:
* All checked "make" implementations, except FreeBSD's "make", use "${CFLAGS} ${CPPFLAGS}";
* FreeBSD's "make" doesn't use CPPFLAGS at all
* No checked "make" implementation uses CPPFLAGS before CFLAGS

Looks like FreeBSD follows POSIX which has nothing about CPPFLAGS:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html#tag_20_76_13_09

--
Evgeny

PS Sorry for crossposting. Let's more this discussion to the autoconf@gnu.org list.

Attachment: OpenPGP_0x460A317C3326D2AE.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]