From 8b1ae48d7cc392bccdd67070b7c2c90aecf0c068 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 23 Sep 2014 09:45:04 -0500 Subject: [PATCH] improve kpatch-build Makefile Right now, the makefile has one target, create-diff-object, which contains all the source/headers as one long list and all the source files compiled in one command to make create-diff-object. This doesn't scale well and doesn't accurately portray the dependencies of each object that contribute to the final binary. This commit renames create-diff-object.c to main.c so that it can be compiled and linked seperately and cleanly in Make and autogenerates dependencies for each .o. This should make it easier to add additional object files, or refactor the very large main.o into seperate object file, later. --- .gitignore | 1 + kpatch-build/Makefile | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 01b74a7..cfb7038 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.ko.cmd *.mod.c *.swp +*.d .tmp_versions Module.symvers kpatch-build/lookup diff --git a/kpatch-build/Makefile b/kpatch-build/Makefile index 6ac29d8..f8c7176 100644 --- a/kpatch-build/Makefile +++ b/kpatch-build/Makefile @@ -4,13 +4,18 @@ CFLAGS += -I../kmod/patch -Iinsn -Wall -g LDFLAGS = -lelf TARGETS = create-diff-object +OBJS = create-diff-object.o lookup.o insn/insn.o insn/inat.o +SOURCES = create-diff-object.c lookup.c insn/insn.c insn/inat.c all: $(TARGETS) -create-diff-object: create-diff-object.c list.h lookup.c lookup.h insn/insn.c \ - insn/inat.c insn/inat-tables.c insn/asm/inat.h \ - insn/asm/insn.h insn/asm/inat_types.h - $(CC) $(CFLAGS) create-diff-object.c lookup.c insn/insn.c insn/inat.c -o $@ $(LDFLAGS) +-include $(SOURCES:.c=.d) + +%.o : %.c + $(CC) -MMD -MP $(CFLAGS) -c -o $@ $< + +create-diff-object: $(OBJS) + $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) install: all $(INSTALL) -d $(LIBEXECDIR) @@ -23,4 +28,4 @@ uninstall: $(RM) $(BINDIR)/kpatch-build clean: - $(RM) $(TARGETS) + $(RM) $(TARGETS) $(OBJS) *.d insn/*.d