From 571e384c8e0e0e434fc6b8c1db1ede2c419094ab Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Sun, 22 May 2022 12:20:10 -0500 Subject: [PATCH] Respect/prefer/remember user specified CPPFLAGS/CFLAGS/LDFLAGS While we remembered a configure-time CC, we didn't do the same for other common user specified build variables, i.e. CPPFLAGS, CFLAGS, and LDFLAGS. Fix that, and arrange for the user's values to come last so that they can override the configuration values. This matches expectations established by other tools, in particular autoconf/automake, and avoids having to remember to specify overrides to every invocation of make. Signed-off-by: Rob Browning Tested-by: Rob Browning --- GNUmakefile | 16 +++++++--------- README.md | 7 +++++++ config/config.vars.in | 4 ++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index a6335ae..48725d2 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,6 +1,5 @@ MAKEFLAGS += --warn-undefined-variables -OUTPUT_OPTION = -MMD -MP -o $@ SHELL := bash .DEFAULT_GOAL := all @@ -32,14 +31,13 @@ current_sampledata := test/sampledata/var/rev/v$(sampledata_rev) os := $(shell ($(pf); uname | sed 's/[-_].*//') $(isok)) os := $(call shout,$(os),Unable to determine OS) +# CFLAGS CPPFLAGS LDFLAGS are handled vis config/config.vars.in + # Satisfy --warn-undefined-variables -CFLAGS ?= DESTDIR ?= -CPPFLAGS ?= -LDFLAGS ?= TARGET_ARCH ?= -bup_shared_cflags := -O2 -Wall -Werror -Wformat=2 +bup_shared_cflags := -O2 -Wall -Werror -Wformat=2 -MMD -MP bup_shared_cflags := -Wno-unknown-pragmas -Wsign-compare $(bup_shared_cflags) bup_shared_cflags := -D_FILE_OFFSET_BITS=64 $(bup_shared_cflags) bup_shared_cflags := $(bup_config_cflags) $(bup_shared_cflags) @@ -160,8 +158,8 @@ embed_ldflags := $(bup_python_ldflags_embed) $(bup_shared_ldflags) config/config.h: config/config.vars clean_paths += config/config.h.tmp -cc_bin = $(CC) $(embed_cflags) $(CFLAGS) $^ $(embed_ldflags) $(LDFLAGS) -fPIE \ - -I src $(OUTPUT_OPTION) +cc_bin = $(CC) $(embed_cflags) -I src $(CPPFLAGS) $(CFLAGS) $^ \ + $(embed_ldflags) $(LDFLAGS) -fPIE -o $@ clean_paths += dev/python-proposed generated_dependencies += dev/python-proposed.d @@ -194,8 +192,8 @@ lib/cmd/bup: lib/cmd/bup.c src/bup/compat.c src/bup/io.c clean_paths += lib/bup/_helpers$(soext) generated_dependencies += lib/bup/_helpers.d lib/bup/_helpers$(soext): lib/bup/_helpers.c lib/bup/bupsplit.c - $(CC) $(helpers_cflags) $(CFLAGS) $^ \ - $(helpers_ldflags) $(LDFLAGS) $(OUTPUT_OPTION) + $(CC) $(helpers_cflags) $(CPPFLAGS) $(CFLAGS) $^ \ + $(helpers_ldflags) $(LDFLAGS) -o $@ test/tmp: mkdir test/tmp diff --git a/README.md b/README.md index c88116d..53f84d2 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,13 @@ From source `config/config.var/bup-python-config`, and you can change the selection by re-running `./configure`. +- If you want to specify your own `CPPFLAGS`, `CFLAGS`, or `LDFLAGS`, + you can set them for individual `make` invocations, e.g. `make + CFLAGS=-O0 check`, or persistently via `./configure` with + `CFLAGS=-O0 ./configure`. At the moment, `make clean` clears the + configuration, but we may change that at some point, perhaps by + adding and requiring a `make distclean` to clear the configuration. + From binary packages -------------------- diff --git a/config/config.vars.in b/config/config.vars.in index 4101ed3..f354e5f 100644 --- a/config/config.vars.in +++ b/config/config.vars.in @@ -2,6 +2,10 @@ CONFIGURE_FILES=@CONFIGURE_FILES@ GENERATED_FILES=@GENERATED_FILES@ CC = @CC@ +CFLAGS = @CFLAGS@ +CPPFLAGS = @CPPFLAGS@ +LDFLAGS = @LDFLAGS@ + bup_config_cflags = @bup_config_cflags@ bup_make=@bup_make@ -- 2.39.2