Skip to content

Conversation

@olebole
Copy link
Contributor

@olebole olebole commented Dec 20, 2024

When packaging Montage for Debian, we want to use specific compilation flags for all source files, to control optimization and debug symbols, but also enable security hardening of the executables and libraries. This is done by setting CFLAGS, CPPFLAGS and LDFLAGS in the environment before the build is started.

This requires that these flags are recognized throughout the Makefiles: Not overwritten but appended with the specific flags in a directory. This PR splits the original CFLAGS in each repository into CPPFLAGS (for the preprocessor) and CFLAGS and assignment by an appending of local flags. Each linking step now gets LDFLAGS added.

Also the CC variable is no longer set by default, allowing to set it from the command line (f.e. specific gcc compiler versions, or to use clang instead). This variable was anyway not consequently set; sometimes cc, sometimes gcc

We also take the opportunity to clean up the Makefiles a bit, by removing rules (specifically .c.o: that are default, and to harmonize the linking step by consequently listing all objects as prequisites and use the same rule ($(CC) $(LDFLAGS) -o $@ $^ $(LIBS)) to link the executables.

@JohnGood could I ask you to review and (if satisfactory) merge? I'd happily adjust the PR if you have other/further requirements or comments. Having this patch applied would greatly simplify the packaging for Debian, but probably also for Fedora and other Linux distributions.

@olebole olebole force-pushed the propagate-cflags branch 3 times, most recently from 1ca455e to 85e07d6 Compare December 20, 2024 20:52
Split CFLAGS into CPPFLAGS (preprocessor definitions and include
paths) CFLAGS (C standard, -fPIC), and allow to have them defined on
command line. This moves possible optimization (-O2), debugging
symbols (-g), and warnings (-Wall) into the responsibility of the
caller, so that they can be adjusted globally.
This makes it possible to globally adjust f.e. hardening options for
Debian builds.
and use a standard rule to build them.
@olebole olebole force-pushed the propagate-cflags branch 2 times, most recently from bbee8a4 to f100637 Compare December 21, 2024 08:35
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