Skip to content
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

Makefile: override CFLAGS and CPPFLAGS #161

Closed
wants to merge 1 commit into from
Closed

Makefile: override CFLAGS and CPPFLAGS #161

wants to merge 1 commit into from

Conversation

ffontaine
Copy link

Makefile specifies some CFLAGS and CPPFLAGS values, but it may be needed to pass additional custom flags on the make command line (e.g. when cross-compiling). To make this possible, we switch from a plain "+=" operator to the "override ... +=" operator.

Don't override the first occurence of CFLAGS to allow the user to finely tune optimisation flags and to avoid hardcoding -Werror which will raise unexpected build failures with old or new toolchains.

Signed-off-by: Fabrice Fontaine [email protected]

Makefile specifies some CFLAGS and CPPFLAGS values, but it may be needed
to pass additional custom flags on the make command line (e.g. when
cross-compiling). To make this possible, we switch from a plain "+="
operator to the "override ... +=" operator.

Don't override the first occurence of CFLAGS to allow the user to finely
tune optimisation flags and to avoid hardcoding -Werror which will raise
unexpected build failures with old or new toolchains.

Signed-off-by: Fabrice Fontaine <[email protected]>
@mutability
Copy link

Hi! Do you have a concrete example of how you're trying to invoke make with overridden CFLAGS/CPPFLAGS?

@ffontaine
Copy link
Author

Sure, here is an example of the issue:

make CPPFLAGS="-I/usr/local/include"
Building with:
  Version string:  unknown
  DSP mix:         x86
  RTLSDR support:  no
  BladeRF support: no
  HackRF support:  no
  LimeSDR support: no
cc -I/usr/local/include -std=c11 -O3 -g -Wall -Wmissing-declarations -Werror -W -D_DEFAULT_SOURCE -fno-common -c dump1090.c -o dump1090.o
In file included from dump1090.h:84,
                 from dump1090.c:50:
dsp/generated/starch.h:4:10: fatal error: dsp-types.h: Aucun fichier ou dossier de ce type
    4 | #include "dsp-types.h"
      |          ^~~~~~~~~~~~~

Overriding CFLAGS and CPPFLAGS are especially useful when cross-compiling (e.g. with buildroot)

@mutability
Copy link

Ok. What I might do instead is move the internally-generated options into a separate var and have only the stuff that really is overridable be in CFLAGS/CPPFLAGS.

@ffontaine
Copy link
Author

Indeed, that's another and probably better option.

@mutability
Copy link

Does b645f7d cover what you need?

@ffontaine
Copy link
Author

At first sight, -Werror should be moved from DUMP1090_CFLAGS to CFLAGS. Indeed, hardcoding -Werror will raise unexexpected build failures with old or new toolchains.

@mutability
Copy link

mutability commented Dec 7, 2021

The issue is that I really want -Werror in there by default, and the Debian toolchain is going to be providing CFLAGS that does not contain -Werror. What's the specific case you see where there are warnings generated?

(also, you could pass -Wno-error=whatever in CFLAGS)

@ffontaine
Copy link
Author

Then, I would suggest to add -Werror in its own variable (e.g. DUMP1090_WERROR) so I could disable it in buildroot.
From my experience, adding -Werror can break the build at each major gcc release, for example when gcc 10 decided to default to -fno-common (#65). More information on this topic can be found here: https://embeddedartistry.com/blog/2017/05/22/werror-is-not-your-friend/

@mutability
Copy link

mutability commented Dec 7, 2021

I understand your desire to have it "just build", but I really would prefer that you have to explicitly do something to say "hey, I know better than the toolchain". The -fno-common issue is actually a good example of this - ignoring that warning would have hidden a longstanding bug.

Does -Wno-error=specific-warning-that-I-have-examined in CFLAGS not work for you?

@mutability
Copy link

Actually I revisited the -fno-common issue and I think that was an outright (link) error, not a warning promoted to error by -Werror anyway

@eric1tran eric1tran closed this in b645f7d Jan 12, 2022
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