diff --git a/Makefile.inc b/Makefile.inc index 4ea73cb..4828619 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -5,13 +5,15 @@ INSTALL = /usr/bin/install PREFIX ?= /usr/local LIBDIR ?= lib +LIBEXEC ?= libexec BINDIR = $(DESTDIR)$(PREFIX)/bin SBINDIR = $(DESTDIR)$(PREFIX)/sbin MODULESDIR = $(DESTDIR)$(PREFIX)/$(LIBDIR)/kpatch -LIBEXECDIR = $(DESTDIR)$(PREFIX)/libexec/kpatch +LIBEXECDIR = $(DESTDIR)$(PREFIX)/$(LIBEXEC)/kpatch DATADIR = $(DESTDIR)$(PREFIX)/share/kpatch MANDIR = $(DESTDIR)$(PREFIX)/share/man/man1 SYSTEMDDIR = $(DESTDIR)$(PREFIX)/lib/systemd/system +BUILDMOD ?= yes .PHONY: all install clean .DEFAULT: all diff --git a/kmod/Makefile b/kmod/Makefile index 2cbd2a1..61b0321 100644 --- a/kmod/Makefile +++ b/kmod/Makefile @@ -1,18 +1,26 @@ include ../Makefile.inc all: clean +ifeq ($(BUILDMOD),yes) $(MAKE) -C core +endif install: +ifeq ($(BUILDMOD),yes) $(INSTALL) -d $(MODULESDIR)/$(shell uname -r) $(INSTALL) -m 644 core/kpatch.ko $(MODULESDIR)/$(shell uname -r) $(INSTALL) -m 644 core/Module.symvers $(MODULESDIR)/$(shell uname -r) +endif $(INSTALL) -d $(DATADIR)/patch $(INSTALL) -m 644 patch/* $(DATADIR)/patch uninstall: +ifeq ($(BUILDMOD),yes) $(RM) -R $(MODULESDIR) +endif $(RM) -R $(DATADIR) clean: +ifeq ($(BUILDMOD),yes) $(MAKE) -C core clean +endif diff --git a/kmod/core/Makefile b/kmod/core/Makefile index 53ad8e4..3a01339 100644 --- a/kmod/core/Makefile +++ b/kmod/core/Makefile @@ -1,9 +1,10 @@ # make rules KPATCH_BUILD ?= /lib/modules/$(shell uname -r)/build +KERNELRELEASE := $(lastword $(subst /, , $(dir $(KPATCH_BUILD)))) THISDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) ifeq ($(wildcard $(KPATCH_BUILD)),) -$(error $(KPATCH_BUILD) doesn\'t exist. Try installing the kernel-devel-$(shell uname -r) RPM or linux-image-$(shell uname -r)-dbg DEB.) +$(error $(KPATCH_BUILD) doesn\'t exist. Try installing the kernel-devel-$(KERNELRELEASE) RPM or linux-headers-$(KERNELRELEASE) DEB.) endif KPATCH_MAKE = $(MAKE) -C $(KPATCH_BUILD) M=$(THISDIR) diff --git a/kpatch-build/Makefile b/kpatch-build/Makefile index 739aa0e..58d5ede 100644 --- a/kpatch-build/Makefile +++ b/kpatch-build/Makefile @@ -1,7 +1,7 @@ include ../Makefile.inc CFLAGS += -I../kmod/patch -Iinsn -Wall -g -Werror -LDFLAGS = -lelf +LDFLAGS += -lelf TARGETS = create-diff-object OBJS = create-diff-object.o lookup.o insn/insn.o insn/inat.o