2018-03-20 19:39:36 +00:00
|
|
|
EXT_ORIG ?= ORIG.o
|
|
|
|
EXT_PATCHED ?= PATCHED.o
|
|
|
|
EXT_FAIL ?= PATCHED.FAIL.o
|
|
|
|
EXT_TEST ?= test
|
|
|
|
EXT_OUTPUT ?= OUTPUT.o
|
|
|
|
EXT_TEST_OUTPUT ?= test.out
|
2018-05-11 09:51:00 +00:00
|
|
|
EXT_SYMTAB ?= symtab
|
|
|
|
EXT_SYMVERS ?= symvers
|
2019-02-08 14:09:18 +00:00
|
|
|
EXT_ENV ?= env
|
2018-03-20 19:39:36 +00:00
|
|
|
TNAME = $(@:.$(EXT_OUTPUT)=)
|
|
|
|
|
|
|
|
ifndef VERBOSE
|
2018-04-17 22:45:41 +00:00
|
|
|
MUTE_PASS := >/dev/null
|
|
|
|
MUTE_FAIL := >/dev/null 2>&1
|
2018-04-20 13:13:55 +00:00
|
|
|
.SILENT: $(TARGETS) $(TEST_TARGETS)
|
2018-03-20 19:39:36 +00:00
|
|
|
endif
|
|
|
|
|
2018-04-26 13:24:40 +00:00
|
|
|
SRC_PATH ?= $(realpath ../../../../)
|
2018-04-20 12:25:10 +00:00
|
|
|
CDO ?= $(SRC_PATH)/kpatch-build/create-diff-object
|
|
|
|
TEST_LIBRARY ?= $(SRC_PATH)/test/test-functions.sh
|
2018-03-20 19:39:36 +00:00
|
|
|
|
2018-04-20 12:25:10 +00:00
|
|
|
TEST_ENV = KPATCH_TEST_LIBRARY=$(TEST_LIBRARY)
|
2018-03-20 19:39:36 +00:00
|
|
|
|
|
|
|
TARGETS = $(patsubst %.$(EXT_ORIG),%.$(EXT_OUTPUT),$(wildcard *.$(EXT_ORIG)))
|
|
|
|
TEST_TARGETS = $(patsubst %.$(EXT_TEST),%.$(EXT_TEST_OUTPUT),$(wildcard *.$(EXT_TEST)))
|
|
|
|
|
2018-05-11 09:51:00 +00:00
|
|
|
SYMVERS_FILE = $(if $(wildcard $(TNAME).$(EXT_SYMVERS)),$(TNAME).$(EXT_SYMVERS),/dev/null)
|
|
|
|
|
2018-04-13 08:36:57 +00:00
|
|
|
define check_stripped =
|
|
|
|
$(if $(shell readelf --debug-dump $(1)),
|
|
|
|
$(error $(1) is not properly stripped, use 'strip --strip-debug --keep-file-symbols $(1)' to fix this),
|
|
|
|
)
|
|
|
|
endef
|
|
|
|
|
2018-04-13 08:55:58 +00:00
|
|
|
define check_all =
|
2019-02-19 18:11:42 +00:00
|
|
|
$(if $(findstring NOSTRIP,$(1)), , $(call check_stripped,$(1)))
|
2018-04-13 08:55:58 +00:00
|
|
|
endef
|
|
|
|
|
2019-07-23 08:57:43 +00:00
|
|
|
.DELETE_ON_ERROR: %.$(EXT_OUTPUT)
|
2018-05-11 09:51:00 +00:00
|
|
|
|
2018-03-20 19:39:36 +00:00
|
|
|
all: $(TARGETS) $(TEST_TARGETS)
|
|
|
|
|
|
|
|
clean:
|
2018-04-19 21:47:06 +00:00
|
|
|
rm -f *.$(EXT_TEST_OUTPUT) *.$(EXT_OUTPUT)
|
2018-03-20 19:39:36 +00:00
|
|
|
|
2018-05-11 09:51:00 +00:00
|
|
|
%.$(EXT_SYMTAB):
|
2019-07-22 19:37:59 +00:00
|
|
|
readelf -s --wide $(patsubst %.$(EXT_SYMTAB),%.$(EXT_ORIG),$(@)) | \
|
|
|
|
sed -r 's/\s+\[<localentry>: 8\]//' >$@
|
2018-05-11 09:51:00 +00:00
|
|
|
|
2018-04-20 12:25:10 +00:00
|
|
|
%.$(EXT_TEST_OUTPUT): %.$(EXT_OUTPUT) %.$(EXT_TEST) $(TEST_LIBRARY)
|
2018-04-20 13:13:55 +00:00
|
|
|
@echo "TEST $(@:.$(EXT_TEST_OUTPUT)=)"
|
2018-04-20 12:25:10 +00:00
|
|
|
$(TEST_ENV) bash $(@:.$(EXT_TEST_OUTPUT)=.$(EXT_TEST)) $<
|
2018-03-20 19:39:36 +00:00
|
|
|
# Don't rely on script creating this
|
|
|
|
@touch $@
|
|
|
|
|
2018-05-11 09:51:00 +00:00
|
|
|
%.$(EXT_OUTPUT): %.$(EXT_ORIG) %.$(EXT_PATCHED) %.$(EXT_SYMTAB) $(CDO)
|
2018-04-20 13:13:55 +00:00
|
|
|
@echo "BUILD $(TNAME)"
|
2018-04-13 08:55:58 +00:00
|
|
|
$(call check_all,$(TNAME).$(EXT_ORIG))
|
|
|
|
$(call check_all,$(TNAME).$(EXT_PATCHED))
|
2019-07-17 02:58:41 +00:00
|
|
|
$(CDO_ENV) $(shell cat $(TNAME).$(EXT_ENV) 2>/dev/null) $(CDO) $(TNAME).$(EXT_ORIG) $(TNAME).$(EXT_PATCHED) \
|
2018-05-11 09:51:00 +00:00
|
|
|
vmlinux $(TNAME).$(EXT_SYMTAB) $(SYMVERS_FILE) \
|
|
|
|
test_$(TNAME) $@ $(MUTE_PASS)
|
2018-03-20 19:39:36 +00:00
|
|
|
|
2018-05-11 09:51:00 +00:00
|
|
|
%.$(EXT_OUTPUT): %.$(EXT_ORIG) %.$(EXT_FAIL) %.$(EXT_SYMTAB) $(CDO)
|
2018-04-20 13:13:55 +00:00
|
|
|
@echo "BUILD $(TNAME)-FAIL"
|
2018-04-13 08:55:58 +00:00
|
|
|
$(call check_all,$(TNAME).$(EXT_ORIG))
|
|
|
|
$(call check_all,$(TNAME).$(EXT_FAIL))
|
2019-07-17 02:58:41 +00:00
|
|
|
! $(CDO_ENV) $(shell cat $(TNAME).$(EXT_ENV) 2>/dev/null) $(CDO) $(TNAME).$(EXT_ORIG) $(TNAME).$(EXT_FAIL) \
|
2018-05-11 09:51:00 +00:00
|
|
|
vmlinux $(TNAME).$(EXT_SYMTAB) $(SYMVERS_FILE) \
|
|
|
|
test_$(TNAME) $@ $(MUTE_FAIL)
|
2018-03-20 19:39:36 +00:00
|
|
|
# Expecting to fail, thus create output file manually so we won't rerun the
|
|
|
|
# test without clean
|
|
|
|
@touch $@
|