aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Kelvin M. Klann <kmk3.code@protonmail.com>2023-07-05 23:56:06 -0300
committerLibravatar Kelvin M. Klann <kmk3.code@protonmail.com>2024-01-22 18:05:47 -0300
commite665769f5225062565b3a75677ce43eb37b988c5 (patch)
treeba46eebf03f497bfa9669c85d10e41fcef946895 /src
parentbuild: move EXTRA vars directly into targets (diff)
downloadfirejail-e665769f5225062565b3a75677ce43eb37b988c5.tar.gz
firejail-e665769f5225062565b3a75677ce43eb37b988c5.tar.zst
firejail-e665769f5225062565b3a75677ce43eb37b988c5.zip
build: automatically generate header dependencies
Instead of manually specifying which source files depend on which headers, use compiler flags to automatically generate depfiles (.d), which declare the correct header (make) dependencies for each source file (.c). Use `-MMD` (which ignores system headers) to generate the dependencies and `-MP` to prevent make from complaining when a header file is removed while it is listed as a dependency in a depfile. If depfiles exist, just include them. If not, make each object file (.o) unconditionally depend on all header files in its source directory and in src/include, to ensure that rebuilds are done when needed. The latter case applies to the first build after `make clean` (which would build everything anyway) and when the compiler does not support generating depfiles. Note that both gcc and clang have supported these options for a long time. Misc: This depends on the changes from commit 5b1bd33c7 ("build: use full paths on compile/link targets", 2023-07-02) / PR #6158 to avoid issues with make dependency tracking.
Diffstat (limited to 'src')
-rw-r--r--src/etc-cleanup/Makefile2
-rw-r--r--src/fbuilder/Makefile2
-rw-r--r--src/fcopy/Makefile1
-rw-r--r--src/fids/Makefile2
-rw-r--r--src/firecfg/Makefile7
-rw-r--r--src/firejail/Makefile13
-rw-r--r--src/firemon/Makefile1
-rw-r--r--src/fldd/Makefile1
-rw-r--r--src/fnet/Makefile1
-rw-r--r--src/fnetfilter/Makefile1
-rw-r--r--src/fsec-optimize/Makefile1
-rw-r--r--src/fsec-print/Makefile1
-rw-r--r--src/fseccomp/Makefile1
-rw-r--r--src/fzenity/Makefile2
-rw-r--r--src/jailcheck/Makefile1
-rw-r--r--src/libpostexecseccomp/Makefile2
-rw-r--r--src/libtracelog/Makefile2
-rw-r--r--src/profstats/Makefile2
-rw-r--r--src/prog.mk12
-rw-r--r--src/so.mk12
20 files changed, 18 insertions, 49 deletions
diff --git a/src/etc-cleanup/Makefile b/src/etc-cleanup/Makefile
index 23121c521..d9dcdbea8 100644
--- a/src/etc-cleanup/Makefile
+++ b/src/etc-cleanup/Makefile
@@ -7,6 +7,4 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = ../include/etc_groups.h
11
12include $(ROOT)/src/prog.mk 10include $(ROOT)/src/prog.mk
diff --git a/src/fbuilder/Makefile b/src/fbuilder/Makefile
index f0e374a52..70c5fb008 100644
--- a/src/fbuilder/Makefile
+++ b/src/fbuilder/Makefile
@@ -7,6 +7,4 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = ../include/common.h ../include/syscall.h
11
12include $(ROOT)/src/prog.mk 10include $(ROOT)/src/prog.mk
diff --git a/src/fcopy/Makefile b/src/fcopy/Makefile
index a9f706eb8..4897980e7 100644
--- a/src/fcopy/Makefile
+++ b/src/fcopy/Makefile
@@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = ../include/common.h ../include/syscall.h
11EXTRA_OBJS = ../lib/common.o 10EXTRA_OBJS = ../lib/common.o
12 11
13include $(ROOT)/src/prog.mk 12include $(ROOT)/src/prog.mk
diff --git a/src/fids/Makefile b/src/fids/Makefile
index 7bdbe0590..dadb17a1b 100644
--- a/src/fids/Makefile
+++ b/src/fids/Makefile
@@ -7,6 +7,4 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = ../include/common.h
11
12include $(ROOT)/src/prog.mk 10include $(ROOT)/src/prog.mk
diff --git a/src/firecfg/Makefile b/src/firecfg/Makefile
index cc7a27c52..6cbd1b5ba 100644
--- a/src/firecfg/Makefile
+++ b/src/firecfg/Makefile
@@ -7,13 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = \
11../include/common.h \
12../include/euid_common.h \
13../include/libnetlink.h \
14../include/firejail_user.h \
15../include/pid.h
16
17EXTRA_OBJS = ../lib/common.o ../lib/firejail_user.o 10EXTRA_OBJS = ../lib/common.o ../lib/firejail_user.o
18 11
19include $(ROOT)/src/prog.mk 12include $(ROOT)/src/prog.mk
diff --git a/src/firejail/Makefile b/src/firejail/Makefile
index 1c4b1b5c2..e7b334cd8 100644
--- a/src/firejail/Makefile
+++ b/src/firejail/Makefile
@@ -7,19 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = \
11../include/rundefs.h \
12../include/common.h \
13../include/ldd_utils.h \
14../include/euid_common.h \
15../include/pid.h \
16../include/seccomp.h \
17../include/syscall_i386.h \
18../include/syscall_x86_64.h \
19../include/firejail_user.h \
20../include/etc_groups.h
21
22
23EXTRA_OBJS = \ 10EXTRA_OBJS = \
24../lib/common.o \ 11../lib/common.o \
25../lib/ldd_utils.o \ 12../lib/ldd_utils.o \
diff --git a/src/firemon/Makefile b/src/firemon/Makefile
index 0e39f8b01..02e3b6eed 100644
--- a/src/firemon/Makefile
+++ b/src/firemon/Makefile
@@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = ../include/common.h ../include/pid.h
11EXTRA_OBJS = ../lib/common.o ../lib/pid.o 10EXTRA_OBJS = ../lib/common.o ../lib/pid.o
12 11
13include $(ROOT)/src/prog.mk 12include $(ROOT)/src/prog.mk
diff --git a/src/fldd/Makefile b/src/fldd/Makefile
index 246cbc183..3e48b43ab 100644
--- a/src/fldd/Makefile
+++ b/src/fldd/Makefile
@@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = ../include/common.h ../include/syscall.h ../include/ldd_utils.h
11EXTRA_OBJS = ../lib/common.o ../lib/ldd_utils.o 10EXTRA_OBJS = ../lib/common.o ../lib/ldd_utils.o
12 11
13include $(ROOT)/src/prog.mk 12include $(ROOT)/src/prog.mk
diff --git a/src/fnet/Makefile b/src/fnet/Makefile
index c98326dc4..dfeefdc47 100644
--- a/src/fnet/Makefile
+++ b/src/fnet/Makefile
@@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = ../include/common.h ../include/libnetlink.h
11EXTRA_OBJS = ../lib/common.o ../lib/libnetlink.o 10EXTRA_OBJS = ../lib/common.o ../lib/libnetlink.o
12 11
13include $(ROOT)/src/prog.mk 12include $(ROOT)/src/prog.mk
diff --git a/src/fnetfilter/Makefile b/src/fnetfilter/Makefile
index c8992c3d6..778de3a8b 100644
--- a/src/fnetfilter/Makefile
+++ b/src/fnetfilter/Makefile
@@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = ../include/common.h ../include/syscall.h
11EXTRA_OBJS = ../lib/common.o 10EXTRA_OBJS = ../lib/common.o
12 11
13include $(ROOT)/src/prog.mk 12include $(ROOT)/src/prog.mk
diff --git a/src/fsec-optimize/Makefile b/src/fsec-optimize/Makefile
index caead9d54..babed1fdb 100644
--- a/src/fsec-optimize/Makefile
+++ b/src/fsec-optimize/Makefile
@@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = ../include/common.h ../include/seccomp.h ../include/syscall.h
11EXTRA_OBJS = ../lib/common.o ../lib/errno.o 10EXTRA_OBJS = ../lib/common.o ../lib/errno.o
12 11
13include $(ROOT)/src/prog.mk 12include $(ROOT)/src/prog.mk
diff --git a/src/fsec-print/Makefile b/src/fsec-print/Makefile
index 43cc42fed..bf383d2d0 100644
--- a/src/fsec-print/Makefile
+++ b/src/fsec-print/Makefile
@@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = ../include/common.h ../include/seccomp.h ../include/syscall.h
11EXTRA_OBJS = ../lib/common.o ../lib/errno.o ../lib/syscall.o 10EXTRA_OBJS = ../lib/common.o ../lib/errno.o ../lib/syscall.o
12 11
13include $(ROOT)/src/prog.mk 12include $(ROOT)/src/prog.mk
diff --git a/src/fseccomp/Makefile b/src/fseccomp/Makefile
index 89b12f629..66bb58444 100644
--- a/src/fseccomp/Makefile
+++ b/src/fseccomp/Makefile
@@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = ../include/common.h ../include/syscall.h
11EXTRA_OBJS = ../lib/common.o ../lib/errno.o ../lib/syscall.o 10EXTRA_OBJS = ../lib/common.o ../lib/errno.o ../lib/syscall.o
12 11
13include $(ROOT)/src/prog.mk 12include $(ROOT)/src/prog.mk
diff --git a/src/fzenity/Makefile b/src/fzenity/Makefile
index 3c1aa0574..4cebe7ac5 100644
--- a/src/fzenity/Makefile
+++ b/src/fzenity/Makefile
@@ -7,6 +7,4 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = ../include/common.h
11
12include $(ROOT)/src/prog.mk 10include $(ROOT)/src/prog.mk
diff --git a/src/jailcheck/Makefile b/src/jailcheck/Makefile
index 1823ee9d0..431a21c8e 100644
--- a/src/jailcheck/Makefile
+++ b/src/jailcheck/Makefile
@@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = ../include/common.h ../include/pid.h
11EXTRA_OBJS = ../lib/common.o ../lib/pid.o 10EXTRA_OBJS = ../lib/common.o ../lib/pid.o
12 11
13include $(ROOT)/src/prog.mk 12include $(ROOT)/src/prog.mk
diff --git a/src/libpostexecseccomp/Makefile b/src/libpostexecseccomp/Makefile
index f66fdd0d7..a8d3fd8b7 100644
--- a/src/libpostexecseccomp/Makefile
+++ b/src/libpostexecseccomp/Makefile
@@ -7,6 +7,4 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7SO = $(MOD_DIR)/$(MOD).so 7SO = $(MOD_DIR)/$(MOD).so
8TARGET = $(SO) 8TARGET = $(SO)
9 9
10EXTRA_HDRS = ../include/seccomp.h ../include/rundefs.h
11
12include $(ROOT)/src/so.mk 10include $(ROOT)/src/so.mk
diff --git a/src/libtracelog/Makefile b/src/libtracelog/Makefile
index a83726167..e9330236c 100644
--- a/src/libtracelog/Makefile
+++ b/src/libtracelog/Makefile
@@ -7,6 +7,4 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7SO = $(MOD_DIR)/$(MOD).so 7SO = $(MOD_DIR)/$(MOD).so
8TARGET = $(SO) 8TARGET = $(SO)
9 9
10EXTRA_HDRS = ../include/rundefs.h
11
12include $(ROOT)/src/so.mk 10include $(ROOT)/src/so.mk
diff --git a/src/profstats/Makefile b/src/profstats/Makefile
index 8f33ce1de..213b1476d 100644
--- a/src/profstats/Makefile
+++ b/src/profstats/Makefile
@@ -7,6 +7,4 @@ MOD_DIR = $(ROOT)/src/$(MOD)
7PROG = $(MOD_DIR)/$(MOD) 7PROG = $(MOD_DIR)/$(MOD)
8TARGET = $(PROG) 8TARGET = $(PROG)
9 9
10EXTRA_HDRS = ../include/common.h
11
12include $(ROOT)/src/prog.mk 10include $(ROOT)/src/prog.mk
diff --git a/src/prog.mk b/src/prog.mk
index debdf3572..a639e87fc 100644
--- a/src/prog.mk
+++ b/src/prog.mk
@@ -3,16 +3,22 @@
3# Note: $(ROOT)/config.mk must be included before this file. 3# Note: $(ROOT)/config.mk must be included before this file.
4# 4#
5# The includer should probably define PROG and TARGET and may also want to 5# The includer should probably define PROG and TARGET and may also want to
6# define EXTRA_HDRS and EXTRA_OBJS and extend CLEANFILES. 6# define EXTRA_OBJS and extend CLEANFILES.
7 7
8HDRS := $(sort $(wildcard $(MOD_DIR)/*.h)) 8HDRS :=
9SRCS := $(sort $(wildcard $(MOD_DIR)/*.c)) 9SRCS := $(sort $(wildcard $(MOD_DIR)/*.c))
10OBJS := $(SRCS:.c=.o) 10OBJS := $(SRCS:.c=.o)
11DEPS := $(sort $(wildcard $(OBJS:.o=.d)))
12
13ifeq ($(DEPS),)
14HDRS := $(sort $(wildcard $(MOD_DIR)/*.h $(ROOT)/src/include/*.h))
15endif
11 16
12.PHONY: all 17.PHONY: all
13all: $(TARGET) 18all: $(TARGET)
19-include $(DEPS)
14 20
15%.o : %.c $(HDRS) $(EXTRA_HDRS) $(ROOT)/config.mk 21%.o : %.c $(HDRS) $(ROOT)/config.mk
16 $(CC) $(PROG_CFLAGS) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ 22 $(CC) $(PROG_CFLAGS) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
17 23
18$(PROG): $(OBJS) $(EXTRA_OBJS) $(ROOT)/config.mk 24$(PROG): $(OBJS) $(EXTRA_OBJS) $(ROOT)/config.mk
diff --git a/src/so.mk b/src/so.mk
index 95b524081..ac76ffc30 100644
--- a/src/so.mk
+++ b/src/so.mk
@@ -3,16 +3,22 @@
3# Note: $(ROOT)/config.mk must be included before this file. 3# Note: $(ROOT)/config.mk must be included before this file.
4# 4#
5# The includer should probably define SO and TARGET and may also want to define 5# The includer should probably define SO and TARGET and may also want to define
6# EXTRA_HDRS and EXTRA_OBJS and extend CLEANFILES. 6# EXTRA_OBJS and extend CLEANFILES.
7 7
8HDRS := $(sort $(wildcard $(MOD_DIR)/*.h)) 8HDRS :=
9SRCS := $(sort $(wildcard $(MOD_DIR)/*.c)) 9SRCS := $(sort $(wildcard $(MOD_DIR)/*.c))
10OBJS := $(SRCS:.c=.o) 10OBJS := $(SRCS:.c=.o)
11DEPS := $(sort $(wildcard $(OBJS:.o=.d)))
12
13ifeq ($(DEPS),)
14HDRS := $(sort $(wildcard $(MOD_DIR)/*.h $(ROOT)/src/include/*.h))
15endif
11 16
12.PHONY: all 17.PHONY: all
13all: $(TARGET) 18all: $(TARGET)
19-include $(DEPS)
14 20
15%.o : %.c $(HDRS) $(EXTRA_HDRS) $(ROOT)/config.mk 21%.o : %.c $(HDRS) $(ROOT)/config.mk
16 $(CC) $(SO_CFLAGS) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ 22 $(CC) $(SO_CFLAGS) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
17 23
18$(SO): $(OBJS) $(EXTRA_OBJS) $(ROOT)/config.mk 24$(SO): $(OBJS) $(EXTRA_OBJS) $(ROOT)/config.mk