Skip to content

Commit

Permalink
Merge pull request #6164 from kmk3/build-header-depfiles
Browse files Browse the repository at this point in the history
build: automatically generate header dependencies
  • Loading branch information
kmk3 authored Jan 30, 2024
2 parents 57c95f8 + e665769 commit 272e095
Show file tree
Hide file tree
Showing 24 changed files with 81 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.d
*.o
*.so
*~
Expand Down
7 changes: 5 additions & 2 deletions config.mk.in
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,31 @@ LDFLAGS=@LDFLAGS@

# Project variables
EXTRA_CFLAGS =@EXTRA_CFLAGS@
DEPS_CFLAGS =@DEPS_CFLAGS@
COMMON_CFLAGS = \
-ggdb -O2 -DVERSION='"$(VERSION)"' \
-Wall -Wextra $(HAVE_FATAL_WARNINGS) \
-Wformat -Wformat-security \
-fstack-protector-all -D_FORTIFY_SOURCE=2 \
-DPREFIX='"$(prefix)"' -DSYSCONFDIR='"$(sysconfdir)/firejail"' \
-DLIBDIR='"$(libdir)"' -DBINDIR='"$(bindir)"' \
-DVARDIR='"/var/lib/firejail"' \
-DVARDIR='"/var/lib/firejail"'

PROG_CFLAGS = \
$(COMMON_CFLAGS) \
$(HAVE_GCOV) $(MANFLAGS) \
$(EXTRA_CFLAGS) \
$(DEPS_CFLAGS) \
-fPIE

SO_CFLAGS = \
$(COMMON_CFLAGS) \
$(DEPS_CFLAGS) \
-fPIC

EXTRA_LDFLAGS =@EXTRA_LDFLAGS@
PROG_LDFLAGS = -Wl,-z,relro -Wl,-z,now -fPIE -pie $(EXTRA_LDFLAGS)
SO_LDFLAGS = -Wl,-z,relro -Wl,-z,now -fPIC
LIBS =@LIBS@

CLEANFILES = *.o *.gcov *.gcda *.gcno *.plist
CLEANFILES = *.d *.o *.gcov *.gcda *.gcno *.plist
47 changes: 46 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ PKG_CONFIG_PATH
PKG_CONFIG
HAVE_APPARMOR
HAVE_IDS
DEPS_CFLAGS
OBJEXT
EXEEXT
ac_ct_CC
Expand Down Expand Up @@ -3270,8 +3271,51 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
ac_compiler_gnu=$ac_cv_c_compiler_gnu
HAVE_SPECTRE="no"
DEPS_CFLAGS=""
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -MMD -MP" >&5
printf %s "checking whether C compiler accepts -MMD -MP... " >&6; }
if test ${ax_cv_check_cflags___MMD__MP+y}
then :
printf %s "(cached) " >&6
else $as_nop
ax_check_save_flags=$CFLAGS
CFLAGS="$CFLAGS -MMD -MP"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main (void)
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
ax_cv_check_cflags___MMD__MP=yes
else $as_nop
ax_cv_check_cflags___MMD__MP=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
CFLAGS=$ax_check_save_flags
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___MMD__MP" >&5
printf "%s\n" "$ax_cv_check_cflags___MMD__MP" >&6; }
if test "x$ax_cv_check_cflags___MMD__MP" = xyes
then :
DEPS_CFLAGS="$DEPS_CFLAGS -MMD -MP"
else $as_nop
:
fi
HAVE_SPECTRE="no"
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -mindirect-branch=thunk" >&5
printf %s "checking whether C compiler accepts -mindirect-branch=thunk... " >&6; }
if test ${ax_cv_check_cflags___mindirect_branch_thunk+y}
Expand Down Expand Up @@ -5311,6 +5355,7 @@ Compile options:
CPPFLAGS: $CPPFLAGS
LDFLAGS: $LDFLAGS
EXTRA_CFLAGS: $EXTRA_CFLAGS
DEPS_CFLAGS: $DEPS_CFLAGS
EXTRA_LDFLAGS: $EXTRA_LDFLAGS
LIBS: $LIBS
fatal warnings: $HAVE_FATAL_WARNINGS
Expand Down
7 changes: 7 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ AC_CONFIG_MACRO_DIR([m4])

AC_PROG_CC

DEPS_CFLAGS=""
AC_SUBST([DEPS_CFLAGS])
AX_CHECK_COMPILE_FLAG([-MMD -MP], [
DEPS_CFLAGS="$DEPS_CFLAGS -MMD -MP"
])

HAVE_SPECTRE="no"
AX_CHECK_COMPILE_FLAG([-mindirect-branch=thunk], [
HAVE_SPECTRE="yes"
Expand Down Expand Up @@ -279,6 +285,7 @@ Compile options:
CPPFLAGS: $CPPFLAGS
LDFLAGS: $LDFLAGS
EXTRA_CFLAGS: $EXTRA_CFLAGS
DEPS_CFLAGS: $DEPS_CFLAGS
EXTRA_LDFLAGS: $EXTRA_LDFLAGS
LIBS: $LIBS
fatal warnings: $HAVE_FATAL_WARNINGS
Expand Down
2 changes: 0 additions & 2 deletions src/etc-cleanup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = ../include/etc_groups.h

include $(ROOT)/src/prog.mk
2 changes: 0 additions & 2 deletions src/fbuilder/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = ../include/common.h ../include/syscall.h

include $(ROOT)/src/prog.mk
1 change: 0 additions & 1 deletion src/fcopy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = ../include/common.h ../include/syscall.h
EXTRA_OBJS = ../lib/common.o

include $(ROOT)/src/prog.mk
2 changes: 0 additions & 2 deletions src/fids/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = ../include/common.h

include $(ROOT)/src/prog.mk
7 changes: 0 additions & 7 deletions src/firecfg/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = \
../include/common.h \
../include/euid_common.h \
../include/libnetlink.h \
../include/firejail_user.h \
../include/pid.h

EXTRA_OBJS = ../lib/common.o ../lib/firejail_user.o

include $(ROOT)/src/prog.mk
13 changes: 0 additions & 13 deletions src/firejail/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = \
../include/rundefs.h \
../include/common.h \
../include/ldd_utils.h \
../include/euid_common.h \
../include/pid.h \
../include/seccomp.h \
../include/syscall_i386.h \
../include/syscall_x86_64.h \
../include/firejail_user.h \
../include/etc_groups.h


EXTRA_OBJS = \
../lib/common.o \
../lib/ldd_utils.o \
Expand Down
1 change: 0 additions & 1 deletion src/firemon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = ../include/common.h ../include/pid.h
EXTRA_OBJS = ../lib/common.o ../lib/pid.o

include $(ROOT)/src/prog.mk
1 change: 0 additions & 1 deletion src/fldd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = ../include/common.h ../include/syscall.h ../include/ldd_utils.h
EXTRA_OBJS = ../lib/common.o ../lib/ldd_utils.o

include $(ROOT)/src/prog.mk
1 change: 0 additions & 1 deletion src/fnet/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = ../include/common.h ../include/libnetlink.h
EXTRA_OBJS = ../lib/common.o ../lib/libnetlink.o

include $(ROOT)/src/prog.mk
1 change: 0 additions & 1 deletion src/fnetfilter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = ../include/common.h ../include/syscall.h
EXTRA_OBJS = ../lib/common.o

include $(ROOT)/src/prog.mk
1 change: 0 additions & 1 deletion src/fsec-optimize/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = ../include/common.h ../include/seccomp.h ../include/syscall.h
EXTRA_OBJS = ../lib/common.o ../lib/errno.o

include $(ROOT)/src/prog.mk
1 change: 0 additions & 1 deletion src/fsec-print/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = ../include/common.h ../include/seccomp.h ../include/syscall.h
EXTRA_OBJS = ../lib/common.o ../lib/errno.o ../lib/syscall.o

include $(ROOT)/src/prog.mk
1 change: 0 additions & 1 deletion src/fseccomp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = ../include/common.h ../include/syscall.h
EXTRA_OBJS = ../lib/common.o ../lib/errno.o ../lib/syscall.o

include $(ROOT)/src/prog.mk
2 changes: 0 additions & 2 deletions src/fzenity/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = ../include/common.h

include $(ROOT)/src/prog.mk
1 change: 0 additions & 1 deletion src/jailcheck/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = ../include/common.h ../include/pid.h
EXTRA_OBJS = ../lib/common.o ../lib/pid.o

include $(ROOT)/src/prog.mk
2 changes: 0 additions & 2 deletions src/libpostexecseccomp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ MOD_DIR = $(ROOT)/src/$(MOD)
SO = $(MOD_DIR)/$(MOD).so
TARGET = $(SO)

EXTRA_HDRS = ../include/seccomp.h ../include/rundefs.h

include $(ROOT)/src/so.mk
2 changes: 0 additions & 2 deletions src/libtracelog/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ MOD_DIR = $(ROOT)/src/$(MOD)
SO = $(MOD_DIR)/$(MOD).so
TARGET = $(SO)

EXTRA_HDRS = ../include/rundefs.h

include $(ROOT)/src/so.mk
2 changes: 0 additions & 2 deletions src/profstats/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ MOD_DIR = $(ROOT)/src/$(MOD)
PROG = $(MOD_DIR)/$(MOD)
TARGET = $(PROG)

EXTRA_HDRS = ../include/common.h

include $(ROOT)/src/prog.mk
16 changes: 11 additions & 5 deletions src/prog.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
# Note: $(ROOT)/config.mk must be included before this file.
#
# The includer should probably define PROG and TARGET and may also want to
# define EXTRA_HDRS and EXTRA_OBJS and extend CLEANFILES.
# define EXTRA_OBJS and extend CLEANFILES.

HDRS := $(sort $(wildcard $(MOD_DIR)/*.h)) $(EXTRA_HDRS)
HDRS :=
SRCS := $(sort $(wildcard $(MOD_DIR)/*.c))
OBJS := $(SRCS:.c=.o) $(EXTRA_OBJS)
OBJS := $(SRCS:.c=.o)
DEPS := $(sort $(wildcard $(OBJS:.o=.d)))

ifeq ($(DEPS),)
HDRS := $(sort $(wildcard $(MOD_DIR)/*.h $(ROOT)/src/include/*.h))
endif

.PHONY: all
all: $(TARGET)
-include $(DEPS)

%.o : %.c $(HDRS) $(ROOT)/config.mk
$(CC) $(PROG_CFLAGS) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

$(PROG): $(OBJS) $(ROOT)/config.mk
$(CC) $(PROG_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
$(PROG): $(OBJS) $(EXTRA_OBJS) $(ROOT)/config.mk
$(CC) $(PROG_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(EXTRA_OBJS) $(LIBS)

.PHONY: clean
clean:; rm -fr $(PROG) $(CLEANFILES)
16 changes: 11 additions & 5 deletions src/so.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
# Note: $(ROOT)/config.mk must be included before this file.
#
# The includer should probably define SO and TARGET and may also want to define
# EXTRA_HDRS and EXTRA_OBJS and extend CLEANFILES.
# EXTRA_OBJS and extend CLEANFILES.

HDRS := $(sort $(wildcard $(MOD_DIR)/*.h)) $(EXTRA_HDRS)
HDRS :=
SRCS := $(sort $(wildcard $(MOD_DIR)/*.c))
OBJS := $(SRCS:.c=.o) $(EXTRA_OBJS)
OBJS := $(SRCS:.c=.o)
DEPS := $(sort $(wildcard $(OBJS:.o=.d)))

ifeq ($(DEPS),)
HDRS := $(sort $(wildcard $(MOD_DIR)/*.h $(ROOT)/src/include/*.h))
endif

.PHONY: all
all: $(TARGET)
-include $(DEPS)

%.o : %.c $(HDRS) $(ROOT)/config.mk
$(CC) $(SO_CFLAGS) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

$(SO): $(OBJS) $(ROOT)/config.mk
$(CC) $(SO_LDFLAGS) -shared $(LDFLAGS) -o $@ $(OBJS) -ldl
$(SO): $(OBJS) $(EXTRA_OBJS) $(ROOT)/config.mk
$(CC) $(SO_LDFLAGS) -shared $(LDFLAGS) -o $@ $(OBJS) $(EXTRA_OBJS) -ldl

.PHONY: clean
clean:; rm -fr $(SO) $(CLEANFILES)

0 comments on commit 272e095

Please sign in to comment.