1 ksplice-makefile := $(word $(words $(MAKEFILE_LIST)), $(MAKEFILE_LIST))
2 ksplice-script = $(dir $(ksplice-makefile))ksplice.pl
5 $(if $(filter_out snap diff,$(KSPLICE_MODE)), \
6 $(error Invalid KSPLICE_MODE $(KSPLICE_MODE).))
7 ksplice-mode-$(KSPLICE_MODE) = y
12 quiet_cmd_ksplice-combine = COMBINE $(@:.KSPLICE=)
13 cmd_ksplice-combine = $(ksplice-script) combine $@ $(filter $(ksplice-link-deps),$^)
14 quiet_cmd_ksplice-snap = SNAP $(@:.KSPLICE=)
15 cmd_ksplice-snap = $(ksplice-script) snap $@
16 quiet_cmd_ksplice-diff = DIFF $(@:.KSPLICE=)
17 cmd_ksplice-diff = $(ksplice-script) diff $@
18 quiet_cmd_ksplice-ignore = IGNORE $(@:.KSPLICE=)
19 cmd_ksplice-ignore = touch $@
20 quiet_cmd_ksplice-cow = COW $@
21 cmd_ksplice-cow = cp -a $@ $@.KSPLICE_pre
22 rule_ksplice-mod = $(Q)if [ -s $< ]; then echo $(<:.o.KSPLICE=) > $@; elif [ -e $@ ]; then rm -f $@; fi
24 ifeq ($(KERNELRELEASE),)
26 # Makefile.lib must be included before Makefile because they contain
27 # different filechk definitions in 2.6.12.
28 include scripts/Makefile.lib
30 CFLAGS_KERNEL += -ffunction-sections -fdata-sections
31 CFLAGS_MODULE += -ffunction-sections -fdata-sections
32 ksplice-deps += $(MODVERDIR)/vmlinux.mod.KSPLICE
33 ksplice-dirs += $(addprefix _ksplice_,$(vmlinux-dirs))
34 ksplice-before += prepare0 prepare scripts
36 ksplice-vmlinux-objs = $(filter-out $(head-y),$(if $(vmlinux-all),$(vmlinux-all),$(vmlinux-objs)))
37 vmlinux.o.KSPLICE: ksplice-link-deps = $(ksplice-vmlinux-objs:=.KSPLICE)
38 vmlinux.o.KSPLICE: $(ksplice-vmlinux-objs:=.KSPLICE) FORCE
39 $(call if_changed,ksplice-combine)
40 ksplice-targets += vmlinux.o.KSPLICE
41 $(ksplice-vmlinux-objs:=.KSPLICE): $(ksplice-dirs) ;
43 $(MODVERDIR)/vmlinux.mod.KSPLICE: vmlinux.o.KSPLICE
48 include $(srctree)/scripts/Makefile.build
49 ksplice-deps += $(builtin-target:=.KSPLICE) $(lib-target:=.KSPLICE) $(addprefix $(MODVERDIR)/,$(notdir $(obj-m:.o=.mod.KSPLICE)))
50 ksplice-dirs += $(addprefix _ksplice_,$(subdir-ym))
53 $(builtin-target:=.KSPLICE): ksplice-link-deps = $(obj-y:=.KSPLICE)
54 $(builtin-target:=.KSPLICE): $(obj-y:=.KSPLICE) FORCE
55 $(call if_changed,ksplice-combine)
56 ksplice-targets += $(builtin-target:=.KSPLICE)
60 $(lib-target:=.KSPLICE): ksplice-link-deps = $(lib-y:=.KSPLICE)
61 $(lib-target:=.KSPLICE): $(lib-y:=.KSPLICE) FORCE
62 $(call if_changed,ksplice-combine)
63 ksplice-targets += $(lib-target:=.KSPLICE)
66 $(sort $(multi-used-y:=.KSPLICE) $(multi-used-m:=.KSPLICE)): ksplice-link-deps = $(addsuffix .KSPLICE,$(addprefix $(obj)/,$($(patsubst $(obj)/%,%,$(@:.o.KSPLICE=-objs))) $($(patsubst $(obj)/%,%,$(@:.o.KSPLICE=-y)))))
67 $(sort $(multi-used-y:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(multi-objs-y:=.KSPLICE) FORCE
68 $(call if_changed,ksplice-combine)
69 $(sort $(multi-used-m:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(multi-objs-m:=.KSPLICE) FORCE
70 $(call if_changed,ksplice-combine)
71 ksplice-targets += $(sort $(multi-used-y:=.KSPLICE) $(multi-used-m:=.KSPLICE))
73 ifdef ksplice-mode-snap
74 $(obj)/%.o.KSPLICE: $(obj)/%.o FORCE
75 $(if $(strip $(wildcard $<.KSPLICE_pre) $(filter $<,$?)), \
76 $(call cmd,ksplice-snap))
78 $(obj)/%.o.KSPLICE: $(obj)/%.o
79 $(call cmd,ksplice-diff)
83 $(call cmd,ksplice-ignore)
85 $(sort $(subdir-obj-y:=.KSPLICE)): $(ksplice-dirs) ;
87 $(MODVERDIR)/%.mod.KSPLICE: $(obj)/%.o.KSPLICE
89 .PRECIOUS: $(obj)/%.o.KSPLICE
93 define ksplice-cow-check
94 $(if $(filter-out %.KSPLICE,$@), \
95 $(if $(ksplice-mode-diff), \
96 $(if $(strip $(filter-out $(PHONY),$?) $(filter-out $(cmd_$(1)),$(cmd_$@)) $(filter-out $(cmd_$@),$(cmd_$(1)))), \
97 $(if $(wildcard $@), \
98 $(if $(wildcard $@.KSPLICE_pre),, \
99 $(call cmd,ksplice-cow))))))
103 $(foreach v,if_changed if_changed_dep if_changed_rule, \
104 $(eval $(v)=$$(ksplice-cow-check)$(value $(v))))
106 __ksplice: $(ksplice-deps) $(ksplice-dirs)
109 ksplice-cmd-files := $(wildcard $(foreach f,$(sort $(ksplice-targets)),$(dir $(f)).$(notdir $(f)).cmd))
110 ifneq ($(ksplice-cmd-files),)
111 include $(ksplice-cmd-files)
114 ksplice := -f $(ksplice-makefile) obj
116 PHONY += $(ksplice-dirs)
117 $(ksplice-dirs): $(ksplice-before)
118 $(Q)$(MAKE) $(ksplice)=$(patsubst _ksplice_%,%,$@)