Skip to content

Commit

Permalink
makefiles: deduplicate lib makefiles into so.mk
Browse files Browse the repository at this point in the history
The following makefiles are nearly identical, except for the main target
name and for any extra headers that they might use:

* src/libpostexecseccomp/Makefile
* src/libtrace/Makefile
* src/libtracelog/Makefile

So move all of their (duplicated) code into a new src/so.mk file, and
add an include of src/so.mk, which leaves only variables, and the
includes of config.mk and src/so.mk in place.

With this commit, CFLAGS and LDFLAGS are only defined/changed in the
following files:

* config.mk.in
* src/common.mk
* src/so.mk
  • Loading branch information
kmk3 committed Nov 21, 2022
1 parent a1e29ac commit adbd02f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 60 deletions.
21 changes: 1 addition & 20 deletions src/libpostexecseccomp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,4 @@ TARGET = $(SO)

MOD_HDRS = ../include/seccomp.h ../include/rundefs.h

HDRS := $(sort $(wildcard *.h)) $(MOD_HDRS)
SRCS := $(sort $(wildcard *.c)) $(MOD_SRCS)
OBJS := $(SRCS:.c=.o) $(MOD_OBJS)
CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security
LDFLAGS += -pie -fPIE -Wl,-z,relro -Wl,-z,now

.PHONY: all
all: $(TARGET)

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

$(SO): $(OBJS) $(ROOT)/config.mk
$(CC) $(LDFLAGS) -shared -fPIC -z relro -o $@ $(OBJS) -ldl

.PHONY: clean
clean:; rm -fr $(OBJS) $(SO) *.plist

.PHONY: distclean
distclean: clean
include $(ROOT)/src/so.mk
21 changes: 1 addition & 20 deletions src/libtrace/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,4 @@ ROOT = ../..
SO = libtrace.so
TARGET = $(SO)

HDRS := $(sort $(wildcard *.h)) $(MOD_HDRS)
SRCS := $(sort $(wildcard *.c)) $(MOD_SRCS)
OBJS := $(SRCS:.c=.o) $(MOD_OBJS)
CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security
LDFLAGS += -pie -fPIE -Wl,-z,relro -Wl,-z,now

.PHONY: all
all: $(TARGET)

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

$(SO): $(OBJS) $(ROOT)/config.mk
$(CC) $(LDFLAGS) -shared -fPIC -z relro -o $@ $(OBJS) -ldl

.PHONY: clean
clean:; rm -fr $(OBJS) $(SO) *.plist

.PHONY: distclean
distclean: clean
include $(ROOT)/src/so.mk
21 changes: 1 addition & 20 deletions src/libtracelog/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,4 @@ TARGET = $(SO)

MOD_HDRS = ../include/rundefs.h

HDRS := $(sort $(wildcard *.h)) $(MOD_HDRS)
SRCS := $(sort $(wildcard *.c)) $(MOD_SRCS)
OBJS := $(SRCS:.c=.o) $(MOD_OBJS)
CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security
LDFLAGS += -pie -fPIE -Wl,-z,relro -Wl,-z,now

.PHONY: all
all: $(TARGET)

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

$(SO): $(OBJS) $(ROOT)/config.mk
$(CC) $(LDFLAGS) -shared -fPIC -z relro -o $@ $(OBJS) -ldl

.PHONY: clean
clean:; rm -fr $(OBJS) $(SO) *.plist

.PHONY: distclean
distclean: clean
include $(ROOT)/src/so.mk
25 changes: 25 additions & 0 deletions src/so.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Common definitions for making shared objects.
#
# Note: $(ROOT)/config.mk must be included before this file.

HDRS := $(sort $(wildcard *.h)) $(MOD_HDRS)
SRCS := $(sort $(wildcard *.c)) $(MOD_SRCS)
OBJS := $(SRCS:.c=.o) $(MOD_OBJS)

CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security
LDFLAGS += -pie -fPIE -Wl,-z,relro -Wl,-z,now

.PHONY: all
all: $(TARGET)

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

$(SO): $(OBJS) $(ROOT)/config.mk
$(CC) $(LDFLAGS) -shared -fPIC -z relro -o $@ $(OBJS) -ldl

.PHONY: clean
clean:; rm -fr $(OBJS) $(SO) *.plist

.PHONY: distclean
distclean: clean

0 comments on commit adbd02f

Please sign in to comment.