Skip to content

Commit 39e6288

Browse files
committed
build: move -std=gnu11 to CFLAGS
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
1 parent 168ad33 commit 39e6288

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,9 @@ PKG_CONFIG_PATH := $(SQLITE_PREFIX)/lib/pkgconfig:$(PKG_CONFIG_PATH)
289289
endif
290290
endif
291291

292-
CPPFLAGS += -DCLN_NEXT_VERSION="\"$(CLN_NEXT_VERSION)\"" -DPKGLIBEXECDIR="\"$(pkglibexecdir)\"" -DBINDIR="\"$(bindir)\"" -DPLUGINDIR="\"$(plugindir)\"" -DCCAN_TAL_NEVER_RETURN_NULL=1 -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS
293-
CFLAGS = $(CWARNFLAGS) $(CDEBUGFLAGS) $(COPTFLAGS) -I $(CCANDIR) $(EXTERNAL_INCLUDE_FLAGS) -I . -I$(CPATH) $(SQLITE3_CFLAGS) $(SODIUM_CFLAGS) $(POSTGRES_INCLUDE) $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) $(PIE_CFLAGS) $(COMPAT_CFLAGS) $(CSANFLAGS)
292+
# Put the environment-inherited flags *last* so the user has the final say.
293+
CPPFLAGS := -DCLN_NEXT_VERSION="\"$(CLN_NEXT_VERSION)\"" -DPKGLIBEXECDIR="\"$(pkglibexecdir)\"" -DBINDIR="\"$(bindir)\"" -DPLUGINDIR="\"$(plugindir)\"" -DCCAN_TAL_NEVER_RETURN_NULL=1 -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS $(CPPFLAGS)
294+
CFLAGS := $(CWARNFLAGS) $(CDEBUGFLAGS) $(COPTFLAGS) -I $(CCANDIR) $(EXTERNAL_INCLUDE_FLAGS) -I . -I$(CPATH) $(SQLITE3_CFLAGS) $(SODIUM_CFLAGS) $(POSTGRES_INCLUDE) $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) $(PIE_CFLAGS) $(COMPAT_CFLAGS) $(CSANFLAGS) $(CFLAGS)
294295

295296
# If CFLAGS is already set in the environment of make (to whatever value, it
296297
# does not matter) then it would export it to subprocesses with the above value

configure

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,14 @@ set_defaults()
166166
# which matters since you might explicitly set of these blank.
167167
PREFIX=${PREFIX:-/usr/local}
168168
CC=${CC:-cc}
169+
# A more compact way of setting the default value of a variable.
170+
# Similar to the above, ":=" means assign if empty or unset; "=" means assign only if unset.
171+
# The quotes suppress the globbing that would otherwise occur after variable expansion.
172+
: "${CFLAGS=-std=gnu11}"
169173
# Detect macOS and use appropriate debug flags for libbacktrace compatibility
170174
if [ "$(uname -s)" = "Darwin" ]; then
171175
# Always override to avoid DWARF 5
172-
CDEBUGFLAGS="-std=gnu11 -g -gdwarf-4 -fno-standalone-debug -fstack-protector-strong"
176+
CDEBUGFLAGS="-g -gdwarf-4 -fno-standalone-debug -fstack-protector-strong"
173177
# Set SDKROOT for macOS
174178
SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"
175179

@@ -178,7 +182,7 @@ set_defaults()
178182
echo "Warning: dsymutil not found. Install Xcode Command Line Tools for better debug support."
179183
fi
180184
else
181-
CDEBUGFLAGS=${CDEBUGFLAGS--std=gnu11 -g -fstack-protector-strong}
185+
CDEBUGFLAGS=${CDEBUGFLAGS--g -fstack-protector-strong}
182186
fi
183187
DEBUGBUILD=${DEBUGBUILD:-0}
184188
COMPAT=${COMPAT:-1}
@@ -233,6 +237,7 @@ usage()
233237
# We assume we have a modern gcc.
234238
DEFAULT_CWARNFLAGS="$(default_cwarnflags ""$DEFAULT_COPTFLAGS"" 1 1)"
235239
usage_with_default "CC" "$CC"
240+
usage_with_default "CFLAGS" "$CFLAGS"
236241
usage_with_default "CWARNFLAGS" "$DEFAULT_CWARNFLAGS"
237242
usage_with_default "COPTFLAGS" "$DEFAULT_COPTFLAGS"
238243
usage_with_default "CDEBUGFLAGS" "$CDEBUGFLAGS"
@@ -607,6 +612,7 @@ fi
607612
add_var PREFIX "$PREFIX"
608613
add_var CC "$CC"
609614
add_var CONFIGURATOR_CC "$CONFIGURATOR_CC"
615+
add_var CFLAGS "$CFLAGS"
610616
add_var CWARNFLAGS "$CWARNFLAGS"
611617
add_var CDEBUGFLAGS "$CDEBUGFLAGS"
612618
add_var COPTFLAGS "$COPTFLAGS"

0 commit comments

Comments
 (0)