Skip to content

Pedantic fixes to build system (configure, Makefile)#8933

Open
whitslack wants to merge 4 commits intoElementsProject:masterfrom
whitslack:build-system-pedantry
Open

Pedantic fixes to build system (configure, Makefile)#8933
whitslack wants to merge 4 commits intoElementsProject:masterfrom
whitslack:build-system-pedantry

Conversation

@whitslack
Copy link
Collaborator

Checklist

Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:

  • The changelog has been updated in the relevant commit(s) according to the guidelines.
  • Tests have been added or modified to reflect the changes. (N/A)
  • Documentation has been reviewed and updated as needed. (N/A)
  • Related issues have been listed and linked, including any that this PR closes. (N/A)
  • Important All PRs must consider how to reverse any persistent changes for tools/lightning-downgrade (N/A)

It's not POSIX-compatible. Use printf instead.

Changelog-None
Make predefines variables COMPILE.c and LINK.c, providing the default
commands for compiling and linking C programs:

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

Use these variables where appropriate.

A few points of interest:

* Using $(LINK.o) to link a C program is not correct, as it does not pass
  $(CFLAGS) to the linker driver. Passing $(CFLAGS) may be necessary for
  correct operation. For instance, -m32 can be specified in CFLAGS to build
  for a 32-bit ABI on a 64-bit-native system, and -flto can be specified in
  CFLAGS to enable link-time optimization. The linker driver needs to be
  told both of these in order to produce correct output.

* CFLAGS is not supposed to subsume CPPFLAGS. The latter are logically the
  flags for the C preprocessor, while the former are the flags for the C
  compiler. The standard COMPILE.c variable incorporates both sets of flags
  since it invokes both the preprocessor and the compiler with one command.
  The standard LINK.c variable also incorporates both since it can be used
  to preprocess, compile, and link a C program all in one shot. In its more
  typical usage (linking precompiled object files), the linker driver
  accepts but makes no use of any preprocessor flags supplied to it.

* CFLAGS logically shouldn't include any -D (or -U) options, as those are
  meant for the preprocessor and not the compiler. It arguably shouldn't
  include any -I options either, but I didn't make that fix here.

Changelog-None
It doesn't logically belong in CDEBUGFLAGS.

Makefile now *prepends* its default CPPFLAGS and CFLAGS to the environment-
supplied flags. This allows the user to override individual flags by setting
these variables through configure, without disturbing all the rest of the
flags that Makefile wants by default.

Changelog-None
@whitslack whitslack force-pushed the build-system-pedantry branch from 39e6288 to d8f5abf Compare March 7, 2026 20:09
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.

1 participant