public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Kaz Kylheku <kaz@kylheku.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: Sam James <sam@cmpct.info>,
	Fangrui Song via Libc-alpha <libc-alpha@sourceware.org>,
	toolchain@gentoo.org, "Andreas K. Huettel" <dilfridge@gentoo.org>,
	chewi@gentoo.org
Subject: Re: Best practices in regard to -D_TIME_BITS=64
Date: Wed, 05 Jan 2022 12:12:39 -0800	[thread overview]
Message-ID: <22016c8224e8fbf87cb15489188c8856@mail.kylheku.com> (raw)
In-Reply-To: <3e6da354-70ec-07c6-4df4-1c995d9f927e@cs.ucla.edu>

On 2022-01-04 20:43, Paul Eggert wrote:
> On 1/4/22 16:53, Sam James wrote:
> 
>> FWIW, we've hit issues in Gentoo with wget/gnutls: 
>> https://bugs.gentoo.org/828001 <https://bugs.gentoo.org/828001>.
> 
> Thanks for the heads-up.
> 
> Yes, not surprised about that, as mixing 64-bit time_t apps with
> 32-bit time_t libraries is a recipe for trouble if the APIs depend on
> time_t. For apps that use such libraries, it really has to be a big
> bang: configure all that stuff with --disable-year2038 -D_TIME_BITS=32
> before, and with --enable-year2038 CFLAGS=-D_TIME_BITS=64 after.
> 
>> https://wiki.gentoo.org/wiki/Project:Toolchain/time64_migration

I looked at this Wiki page and one thing stands out.

I would recommend to the Gentoo people to forget about CPPFLAGS, and
just use CFLAGS, even for -D material. If you put -D_TIME_BITS=64
into CFLAGS, you then don't have to deal with packages that perfectly
well honor CFLAGS, but not CPPFLAGS.

People don't know about CPPFLAGS. It seems to be just something invented
by GNU Make, referenced in some of its built-in recipes. Getting all
upstream packages to recognize CPPFLAGS (or else patching them locally)
is just a lot of make-work (pun intended).

I'm also aware of a historic *ad hoc* practice of using CPPFLAGS for C++ 
CFLAGS;
i.e. that for which CXXFLAGS is a better practice.

For what it's worth, POSIX's description of make mentions no CPPFLAGS,
but does mention CFLAGS, LDFLAGS. (It also doesn't mention LDLIBS, 
another
separation variable, but that I suspect is much more entrenched than 
CPPFLAGS,
and the separation is quite essential: you need to do that any time you 
specify
additional -l arguments for linking.)

GNU's built-in rules do some nonsensical things like:

   LINK.c := $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)

(If CPPFLAGS is needed all the way through linking C, what purpose does 
it serve
separate from CFLAGS? And if I'm writing my own linking recipe, do I 
have to
reproduce this?)

CPPFLAGS is something that would be useful for calling a standalone C 
preprocessor
that doesn't understand compiler options.

But:

You don't need that in a GCC environment, because you can call gcc with 
options
that perform preprocessing only, and still pass other options specific 
to
compiling.

Not only that, but GNU cpp is tolerant to gcc options not pertaining to
preprocessing:

No problem:

$ echo | cpp -fstrict-aliasing > /dev/null

$ echo | cpp -fNoNExistent > /dev/null
cpp: error: unrecognized command line option ‘-fNoNExistent’; did you 
mean ‘-fno-ident’?

You don't need CPPFLAGS in a non-GCC environment with GNU make, because 
you
can easily do some GNU Make text processing to separate the preprocessor
options, if you need them.

Proof-of-concept demo:

$ make CFLAGS="-Wall -I/path/to/include -UMAC -DFOO=bar -o foo.o -lm"
cpp_only_flags == -I/path/to/include -UMAC -DFOO=bar

Source:

cpp_only_flags := $(foreach arg,                        \
                      $(CFLAGS),				\
                      $(or $(filter -D%,$(arg)),         \
		          $(filter -U%,$(arg)),         \
		          $(filter -I%,$(arg)),         \
		          $(filter -iquote%,$(arg)),    \
			  $(filter -W%,$(arg)),         \
			  $(filter -M%,$(arg))))        \
                   $(CPPFLAGS) # also pull this in

all:
	@echo cpp_only_flags == $(cpp_only_flags)

In an application, if you want separated C preprocessing flags, that
is what you have to do; you can't assume that you're built in
a distro environment which will hand them to you in a separate
CPPFLAGS variable.

      reply	other threads:[~2022-01-05 20:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04 23:33 Kaz Kylheku
2022-01-05  0:49 ` Paul Eggert
2022-01-05  0:53   ` Sam James
2022-01-05  4:43     ` Paul Eggert
2022-01-05 20:12       ` Kaz Kylheku [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=22016c8224e8fbf87cb15489188c8856@mail.kylheku.com \
    --to=kaz@kylheku.com \
    --cc=chewi@gentoo.org \
    --cc=dilfridge@gentoo.org \
    --cc=eggert@cs.ucla.edu \
    --cc=libc-alpha@sourceware.org \
    --cc=sam@cmpct.info \
    --cc=toolchain@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).