Skip to content

build: do not modify user-provided CFLAGS variable #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jengelh
Copy link

@jengelh jengelh commented Mar 31, 2025

$ ./configure CFLAGS="-U_FORTIFY_SOURCE -g3" && grep ^CFLAGS Makefile && make
...
CFLAGS = -std=gnu11 -U_FORTIFY_SOURCE -g3 -U_FORTIFY_SOURCE -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -mfunction-return=keep -mindirect-branch=keep -Wall -W -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wchar-subscripts -Wformat=2 -Wbad-function-cast -fno-builtin-strftime -Wstrict-aliasing=2
...
/usr/include/features.h:435:4: warning: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
  435 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)

This is not how ./configure CFLAGS=... should work. As per https://www.gnu.org/software/automake/manual/html_node/User-Variables.html CFLAGS is reserved for the user, should not be changed (and also should enjoy highest precedence).

AM_CFLAGS is the right variable to use here.

```
$ ./configure CFLAGS="-U_FORTIFY_SOURCE -g3" && grep ^CFLAGS Makefile && make
...
CFLAGS = -std=gnu11 -U_FORTIFY_SOURCE -g3 -U_FORTIFY_SOURCE -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -mfunction-return=keep -mindirect-branch=keep -Wall -W -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wchar-subscripts -Wformat=2 -Wbad-function-cast -fno-builtin-strftime -Wstrict-aliasing=2
...
/usr/include/features.h:435:4: warning: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
  435 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
```

This is not how `./configure CFLAGS=...` should work. As per
https://www.gnu.org/software/automake/manual/html_node/User-Variables.html
CFLAGS is reserved for the user and should not be changed.

AM_CFLAGS is the right variable to use here.
@cmouse
Copy link
Contributor

cmouse commented May 20, 2025

You could use EXTRA_CFLAGS instead

@jengelh
Copy link
Author

jengelh commented May 20, 2025

dovecot.m4 touches EXTRA_CFLAGS too and suffers from losing flags just like CFLAGS during ./configure --enable-ubsan && make EXTRA_CFLAGS=-O1 (loses e.g. sanitizer flags). Also, EXTRA_CFLAGS is nonstandard and not even documented in the source tree.
Please, let's just make CFLAGS behave right. I already wrote the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants