Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,9 @@ PKG_CONFIG_PATH := $(SQLITE_PREFIX)/lib/pkgconfig:$(PKG_CONFIG_PATH)
endif
endif

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

# If CFLAGS is already set in the environment of make (to whatever value, it
# does not matter) then it would export it to subprocesses with the above value
Expand Down Expand Up @@ -330,16 +331,16 @@ FORCE:
endif

show-flags: config.vars
@$(ECHO) "CC: $(CC) $(CFLAGS) -c -o"
@$(ECHO) "LD: $(LINK.o) $(filter-out %.a,$^) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) -o"
@$(ECHO) "CC: $(COMPILE.c) -o"
@$(ECHO) "LD: $(LINK.c) $(filter-out %.a,$^) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) -o"

# We will re-generate, but we won't generate for the first time!
ccan/config.h config.vars &: configure ccan/tools/configurator/configurator.c
@if [ ! -f config.vars ]; then echo 'File config.vars not found: you must run ./configure before running make.' >&2; exit 1; fi
./configure --reconfigure

%.o: %.c
@$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<)
@$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<)

# tools/update-mocks.sh does nasty recursive make, must not do this!
ifeq ($(SUPPRESS_GENERATION),1)
Expand Down Expand Up @@ -760,7 +761,7 @@ $(ALL_TEST_PROGRAMS) $(ALL_FUZZ_TARGETS): %: %.o
# (as per EXTERNAL_LDLIBS) so we filter them out here. We have to put the other
# .a files (if any) at the end of the link line.
$(ALL_PROGRAMS) $(ALL_TEST_PROGRAMS):
@$(call VERBOSE, "ld $@", $(LINK.o) $(filter-out %.a,$^) $(filter-out external/%,$(filter %.a,$^)) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) $($(@)_LDLIBS) -o $@)
@$(call VERBOSE, "ld $@", $(LINK.c) $(filter-out %.a,$^) $(filter-out external/%,$(filter %.a,$^)) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) $($(@)_LDLIBS) -o $@)
ifeq ($(OS),Darwin)
@$(call VERBOSE, "dsymutil $@", dsymutil $@)
endif
Expand Down
35 changes: 21 additions & 14 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ check_command()
name="$1"
shift 1

echo -n "checking for $name... "
printf 'checking for %s... ' "${name}" >&2
if "$@" >/dev/null 2>&1 </dev/null; then
echo 'found'
echo 'found' >&2
return 0
fi
echo 'not found'
echo 'not found' >&2
return 1
}

Expand Down Expand Up @@ -166,10 +166,14 @@ set_defaults()
# which matters since you might explicitly set of these blank.
PREFIX=${PREFIX:-/usr/local}
CC=${CC:-cc}
# A more compact way of setting the default value of a variable.
# Similar to the above, ":=" means assign if empty or unset; "=" means assign only if unset.
# The quotes suppress the globbing that would otherwise occur after variable expansion.
: "${CFLAGS=-std=gnu11}"
# Detect macOS and use appropriate debug flags for libbacktrace compatibility
if [ "$(uname -s)" = "Darwin" ]; then
# Always override to avoid DWARF 5
CDEBUGFLAGS="-std=gnu11 -g -gdwarf-4 -fno-standalone-debug -fstack-protector-strong"
CDEBUGFLAGS="-g -gdwarf-4 -fno-standalone-debug -fstack-protector-strong"
# Set SDKROOT for macOS
SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"

Expand All @@ -178,7 +182,7 @@ set_defaults()
echo "Warning: dsymutil not found. Install Xcode Command Line Tools for better debug support."
fi
else
CDEBUGFLAGS=${CDEBUGFLAGS--std=gnu11 -g -fstack-protector-strong}
CDEBUGFLAGS=${CDEBUGFLAGS--g -fstack-protector-strong}
fi
DEBUGBUILD=${DEBUGBUILD:-0}
COMPAT=${COMPAT:-1}
Expand Down Expand Up @@ -233,6 +237,7 @@ usage()
# We assume we have a modern gcc.
DEFAULT_CWARNFLAGS="$(default_cwarnflags ""$DEFAULT_COPTFLAGS"" 1 1)"
usage_with_default "CC" "$CC"
usage_with_default "CFLAGS" "$CFLAGS"
usage_with_default "CWARNFLAGS" "$DEFAULT_CWARNFLAGS"
usage_with_default "COPTFLAGS" "$DEFAULT_COPTFLAGS"
usage_with_default "CDEBUGFLAGS" "$CDEBUGFLAGS"
Expand Down Expand Up @@ -272,9 +277,9 @@ usage()
add_var()
{
if [ -n "$2" ]; then
echo "Setting $1... $2"
echo "Setting $1... $2" >&2
else
echo "$1 not found"
echo "$1 not found" >&2
fi
echo "$1=$2" >> $CONFIG_VAR_FILE.$$
[ -z "$3" ] || echo "#define $1 $2" >> "$3"
Expand Down Expand Up @@ -306,6 +311,7 @@ for opt in "$@"; do
;;
CC=*) CC="${opt#CC=}";;
CONFIGURATOR_CC=*) CONFIGURATOR_CC="${opt#CONFIGURATOR_CC=}";;
CFLAGS=*) CFLAGS="${opt#CFLAGS=}";;
CWARNFLAGS=*) CWARNFLAGS="${opt#CWARNFLAGS=}";;
CDEBUGFLAGS=*) CDEBUGFLAGS="${opt#CDEBUGFLAGS=}";;
COPTFLAGS=*) COPTFLAGS="${opt#COPTFLAGS=}";;
Expand All @@ -329,10 +335,10 @@ for opt in "$@"; do
--disable-fuzzing) FUZZING=0;;
--enable-rust) RUST=1;;
--disable-rust) RUST=0;;
--help|-h) usage;;
--help|-h) usage >&2;;
*)
echo "Unknown option '$opt'" >&2
usage
usage >&2
;;
esac
done
Expand All @@ -342,7 +348,7 @@ set_defaults

if [ "$ASAN" = "1" ]; then
if [ "$VALGRIND" = "1" ]; then
echo "Address sanitizer (ASAN) and valgrind cannot be enabled at the same time"
echo "Address sanitizer (ASAN) and valgrind cannot be enabled at the same time" >&2
exit 1
fi

Expand Down Expand Up @@ -376,16 +382,16 @@ else
fi

# We assume warning flags don't affect congfigurator that much!
echo -n "Compiling $CONFIGURATOR..."
printf 'Compiling %s...' "${CONFIGURATOR}" >&2
$CC ${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS $LDFLAGS -o $CONFIGURATOR $CONFIGURATOR.c
echo "done"
echo "done" >&2

if [ "$CLANG_COVERAGE" = "1" ]; then
case "$CC" in
(*"clang"*)
;;
(*)
echo "Clang coverage requires building with CC=clang."
echo "Clang coverage requires building with CC=clang." >&2
exit 1
;;
esac
Expand All @@ -396,7 +402,7 @@ if [ "$FUZZING" = "1" ]; then
(*"clang"*)
;;
(*)
echo "Fuzzing is currently only supported with clang."
echo "Fuzzing is currently only supported with clang." >&2
exit 1
;;
esac
Expand Down Expand Up @@ -607,6 +613,7 @@ fi
add_var PREFIX "$PREFIX"
add_var CC "$CC"
add_var CONFIGURATOR_CC "$CONFIGURATOR_CC"
add_var CFLAGS "$CFLAGS"
add_var CWARNFLAGS "$CWARNFLAGS"
add_var CDEBUGFLAGS "$CDEBUGFLAGS"
add_var COPTFLAGS "$COPTFLAGS"
Expand Down
Loading