diff options
author | Kelvin M. Klann <kmk3.code@protonmail.com> | 2022-11-30 00:27:48 -0300 |
---|---|---|
committer | Kelvin M. Klann <kmk3.code@protonmail.com> | 2022-12-08 06:41:08 -0300 |
commit | 87948b3ffe9e8e704c55509cd6c747547b3c7072 (patch) | |
tree | f43a175d6bced67b6daf75aaf511527437cb6cbc /src | |
parent | build: move library flags from EXTRA_LDFLAGS to LIBS (diff) | |
download | firejail-87948b3ffe9e8e704c55509cd6c747547b3c7072.tar.gz firejail-87948b3ffe9e8e704c55509cd6c747547b3c7072.tar.zst firejail-87948b3ffe9e8e704c55509cd6c747547b3c7072.zip |
makefiles: stop overriding CFLAGS/LDFLAGS
From the manual of GNU Automake (version 1.16.5)[1] [2]:
> 3.6 Variables reserved for the user
>
> Some `Makefile` variables are reserved by the GNU Coding Standards for
> the use of the "user"—the person building the package. For instance,
> `CFLAGS` is one such variable.
>
> Sometimes package developers are tempted to set user variables such
> as `CFLAGS` because it appears to make their job easier. However, the
> package itself should never set a user variable, particularly not to
> include switches that are required for proper compilation of the
> package. Since these variables are documented as being for the
> package builder, that person rightfully expects to be able to override
> any of these variables at build time.
>
> To get around this problem, Automake introduces an
> automake-specific shadow variable for each user flag variable.
> (Shadow variables are not introduced for variables like `CC`, where
> they would make no sense.) The shadow variable is named by prepending
> `AM_` to the user variable's name. For instance, the shadow variable
> for `YFLAGS` is `AM_YFLAGS`. The package maintainer—that is, the
> author(s) of the `Makefile.am` and `configure.ac` files—may adjust
> these shadow variables however necessary.
>
> Note Flag Variables Ordering::, for more discussion about these
> variables and how they interact with per-target variables.
See also the description of CFLAGS in the GNU Autoconf manual[3].
Note: We do not use automake (save for aclocal) nor generally follow the
GNU Coding Standards, but the concept still applies. Also, the closest
analogous in the project to the `AM_` prefix would currently likely be
`EXTRA_`.
[1] https://www.gnu.org/software/automake/manual/1.16.5/html_node/User-Variables.html
[2] https://www.gnu.org/software/automake/manual/1.16.5/html_node/Flag-Variables-Ordering.html
[3] https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Preset-Output-Variables.html
Diffstat (limited to 'src')
-rw-r--r-- | src/prog.mk | 11 | ||||
-rw-r--r-- | src/so.mk | 8 |
2 files changed, 10 insertions, 9 deletions
diff --git a/src/prog.mk b/src/prog.mk index 84f43142d..b2ccf6147 100644 --- a/src/prog.mk +++ b/src/prog.mk | |||
@@ -9,25 +9,26 @@ HDRS := $(sort $(wildcard *.h)) $(MOD_HDRS) | |||
9 | SRCS := $(sort $(wildcard *.c)) $(MOD_SRCS) | 9 | SRCS := $(sort $(wildcard *.c)) $(MOD_SRCS) |
10 | OBJS := $(SRCS:.c=.o) $(MOD_OBJS) | 10 | OBJS := $(SRCS:.c=.o) $(MOD_OBJS) |
11 | 11 | ||
12 | CFLAGS += \ | 12 | PROG_CFLAGS = \ |
13 | -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' \ | 13 | -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' \ |
14 | -fstack-protector-all -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security \ | 14 | -fstack-protector-all -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security \ |
15 | -fPIE \ | 15 | -fPIE \ |
16 | -DPREFIX='"$(prefix)"' -DSYSCONFDIR='"$(sysconfdir)/firejail"' \ | 16 | -DPREFIX='"$(prefix)"' -DSYSCONFDIR='"$(sysconfdir)/firejail"' \ |
17 | -DLIBDIR='"$(libdir)"' -DBINDIR='"$(bindir)"' \ | 17 | -DLIBDIR='"$(libdir)"' -DBINDIR='"$(bindir)"' \ |
18 | -DVARDIR='"/var/lib/firejail"' \ | 18 | -DVARDIR='"/var/lib/firejail"' \ |
19 | $(HAVE_GCOV) $(MANFLAGS) | 19 | $(HAVE_GCOV) $(MANFLAGS) \ |
20 | $(EXTRA_CFLAGS) | ||
20 | 21 | ||
21 | LDFLAGS += -pie -fPIE -Wl,-z,relro -Wl,-z,now | 22 | PROG_LDFLAGS = -pie -fPIE -Wl,-z,relro -Wl,-z,now $(EXTRA_LDFLAGS) |
22 | 23 | ||
23 | .PHONY: all | 24 | .PHONY: all |
24 | all: $(TARGET) | 25 | all: $(TARGET) |
25 | 26 | ||
26 | %.o : %.c $(HDRS) $(ROOT)/config.mk | 27 | %.o : %.c $(HDRS) $(ROOT)/config.mk |
27 | $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(INCLUDE) -c $< -o $@ | 28 | $(CC) $(PROG_CFLAGS) $(CFLAGS) $(INCLUDE) -c $< -o $@ |
28 | 29 | ||
29 | $(PROG): $(OBJS) $(ROOT)/config.mk | 30 | $(PROG): $(OBJS) $(ROOT)/config.mk |
30 | $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(EXTRA_LDFLAGS) | 31 | $(CC) $(PROG_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) |
31 | 32 | ||
32 | .PHONY: clean | 33 | .PHONY: clean |
33 | clean:; rm -fr *.o $(PROG) *.gcov *.gcda *.gcno *.plist $(TOCLEAN) | 34 | clean:; rm -fr *.o $(PROG) *.gcov *.gcda *.gcno *.plist $(TOCLEAN) |
@@ -9,21 +9,21 @@ HDRS := $(sort $(wildcard *.h)) $(MOD_HDRS) | |||
9 | SRCS := $(sort $(wildcard *.c)) $(MOD_SRCS) | 9 | SRCS := $(sort $(wildcard *.c)) $(MOD_SRCS) |
10 | OBJS := $(SRCS:.c=.o) $(MOD_OBJS) | 10 | OBJS := $(SRCS:.c=.o) $(MOD_OBJS) |
11 | 11 | ||
12 | CFLAGS += \ | 12 | SO_CFLAGS = \ |
13 | -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' \ | 13 | -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' \ |
14 | -fstack-protector-all -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security \ | 14 | -fstack-protector-all -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security \ |
15 | -fPIC | 15 | -fPIC |
16 | 16 | ||
17 | LDFLAGS += -pie -fPIE -Wl,-z,relro -Wl,-z,now | 17 | SO_LDFLAGS = -pie -fPIE -Wl,-z,relro -Wl,-z,now |
18 | 18 | ||
19 | .PHONY: all | 19 | .PHONY: all |
20 | all: $(TARGET) | 20 | all: $(TARGET) |
21 | 21 | ||
22 | %.o : %.c $(HDRS) $(ROOT)/config.mk | 22 | %.o : %.c $(HDRS) $(ROOT)/config.mk |
23 | $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ | 23 | $(CC) $(SO_CFLAGS) $(CFLAGS) $(INCLUDE) -c $< -o $@ |
24 | 24 | ||
25 | $(SO): $(OBJS) $(ROOT)/config.mk | 25 | $(SO): $(OBJS) $(ROOT)/config.mk |
26 | $(CC) $(LDFLAGS) -shared -fPIC -z relro -o $@ $(OBJS) -ldl | 26 | $(CC) $(SO_LDFLAGS) -shared -fPIC -z relro $(LDFLAGS) -o $@ $(OBJS) -ldl |
27 | 27 | ||
28 | .PHONY: clean | 28 | .PHONY: clean |
29 | clean:; rm -fr $(OBJS) $(SO) *.plist $(TOCLEAN) | 29 | clean:; rm -fr $(OBJS) $(SO) *.plist $(TOCLEAN) |