Re: Wrong order of preprocessor and compiler flags

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

 



Hi Alex.

-------- Original Message --------
From: Alex Ameen <alex.ameen.tx@xxxxxxxxx>
Sent: Friday, March 25, 2022, 03:45 UTC+3
Subject: Wrong order of preprocessor and compiler flags

The rationale for placement of `CPPFLAGS` early is to allow users to better
control include ordering. This is similar to why `CFLAGS` is last.

Consider this situation :

User wants to preempt the default include path, and wants to override the C
standard.

make CPPFLAGS='-Ifoo/bar' CFLAGS='-std=c18';

If `CPPFLAGS` were at the end, the user must use `-quote foo/bar` to
successfully preempt which has a different meaning in some edge cases.
Notably if the includes are in carrots rather than quotes it ain't gonna
work.

Not sure that I got your point.
I've tested with GNU Make in empty dir (and GCC as 'cc'):
----------------
$ mkdir -p foo/bar

$ touch Makefile foo/bar/myheader.h

$ echo '#include <myheader.h>' > cincl.c

$ make CPPFLAGS='-Ifoo/bar' CFLAGS='-std=c18' cincl.o
cc -std=c18 -Ifoo/bar  -c -o cincl.o cincl.c

$ echo '#include "myheader.h"' > cincl2.c

$ make CPPFLAGS='-Ifoo/bar' CFLAGS='-std=c18' cincl2.o
cc -std=c18 -Ifoo/bar  -c -o cincl2.o cincl2.c

$ rm -f *.o

$ make CFLAGS='-std=c18' cincl.o
cc -std=c18   -c -o cincl.o cincl.c
cincl.c:1:10: fatal error: myheader.h: No such file or directory
    1 | #include <myheader.h>
      |          ^~~~~~~~~~~~
compilation terminated.
make: *** [<builtin>: cincl.o] Error 1

$ make CFLAGS='-std=c18' cincl2.o
cc -std=c18   -c -o cincl2.o cincl2.c
cincl2.c:1:10: fatal error: myheader.h: No such file or directory
    1 | #include "myheader.h"
      |          ^~~~~~~~~~~~
compilation terminated.
make: *** [<builtin>: cincl2.o] Error 1
----------------

GNU Make uses CPPFLAGS at the end of the parameters block without any problem. It just works.

In both cases the ordering is intended to allow users to override defaults.
I agree that this ordering isn't ideal for other flags like `-D`, but
considering a change would break builds with existing work arounds I think
any reordering is going to rouse the masses into an angry stupor.

The problem is that we already have reordering.
Tests/checks are performed by 'configure' as "$CC $CFLAGS $CPPFLAGS", but result is used in automake files as "$CC $CPPFLAGS $CFLAGS".

Either autoconf or automake should be corrected.

As no 'make' implementation uses CPPFLAGS before CFLAGS [1], others [2] use $CFLAGS $CPPFLAGS as well, it makes sense to correct automake to align with other tools and leave autoconf without changes.


[1] https://lists.gnu.org/archive/html/autoconf/2022-03/msg00010.html
[2] https://lists.gnu.org/archive/html/autoconf/2022-03/msg00008.html

--
Evgeny

Attachment: OpenPGP_0x460A317C3326D2AE.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux