1 ksplice-makefile := $(word $(words $(MAKEFILE_LIST)), $(MAKEFILE_LIST))
2 ksplice-script = $(dir $(ksplice-makefile))ksplice-obj.pl
5 $(if $(filter_out snap diff,$(KSPLICE_MODE)), \
6 $(error Invalid KSPLICE_MODE $(KSPLICE_MODE).))
7 ksplice-mode-$(KSPLICE_MODE) = y
9 KSPLICE_ONLY_TARGETS ?= %
14 ksplice-extra = $(filter $(KSPLICE_EXTRA_MATCH),$(lib-y) $(single-used-m) $(multi-objs-y) $(multi-objs-m))
15 ksplice-objs = $(foreach o,$(1),$(o:=.KSPLICE) $(addsuffix .KSPLICE_helper,$(filter $(ksplice-extra),$(o))))
17 quiet_cmd_ksplice-combine = COMBINE $(@:.KSPLICE=)
18 cmd_ksplice-combine = $(ksplice-script) combine $@ $(filter $(call ksplice-objs,$(ksplice-link-deps)),$^)
19 quiet_cmd_ksplice-snap = SNAP $(@:.KSPLICE=)
20 cmd_ksplice-snap = $(ksplice-script) snap $@
21 quiet_cmd_ksplice-diff = DIFF $(@:.KSPLICE=)
22 cmd_ksplice-diff = $(ksplice-script) diff $@
23 quiet_cmd_ksplice-ignore = IGNORE $(@:.KSPLICE=)
24 cmd_ksplice-ignore = touch $@
25 quiet_cmd_ksplice-cow = COW $@
26 cmd_ksplice-cow = cp -a $@ $@.KSPLICE_pre
27 rule_ksplice-mod = $(Q)if [ -s $< ]; then echo $(<:.o.KSPLICE=) > $@; elif [ -e $@ ]; then rm -f $@; fi
28 quiet_cmd_ksplice-helper = HELPER $(@:.KSPLICE_helper=)
29 cmd_ksplice-helper = $(ksplice-script) helper $@
31 ifeq ($(KERNELRELEASE),)
33 # Makefile.lib must be included before Makefile because they contain
34 # different filechk definitions in 2.6.12.
35 include scripts/Makefile.lib
37 CFLAGS_KERNEL += -ffunction-sections -fdata-sections
38 CFLAGS_MODULE += -ffunction-sections -fdata-sections
39 ksplice-mods += vmlinux
40 ksplice-dirs += $(addprefix _ksplice_,$(vmlinux-dirs))
41 ifdef ksplice-mode-snap
42 ksplice-before += prepare0 prepare scripts
45 ksplice-vmlinux-objs = $(filter-out $(head-y),$(if $(vmlinux-all),$(vmlinux-all),$(vmlinux-objs)))
46 $(obj)/vmlinux.o.KSPLICE: ksplice-link-deps = $(ksplice-vmlinux-objs)
47 $(obj)/vmlinux.o.KSPLICE: $(call ksplice-objs,$(ksplice-vmlinux-objs)) FORCE
48 $(call if_changed,ksplice-combine)
49 ksplice-targets += $(obj)/vmlinux.o.KSPLICE
50 $(ksplice-vmlinux-objs:=.KSPLICE): $(ksplice-dirs) ;
54 include $(srctree)/scripts/Makefile.build
55 ksplice-mods += $(obj-m:.o=)
56 ksplice-deps += $(if $(filter $(KSPLICE_ONLY_TARGETS),vmlinux),$(builtin-target:=.KSPLICE) $(lib-target:=.KSPLICE))
57 ksplice-dirs += $(addprefix _ksplice_,$(subdir-ym))
60 $(builtin-target:=.KSPLICE): ksplice-link-deps = $(obj-y)
61 $(builtin-target:=.KSPLICE): $(call ksplice-objs,$(obj-y)) FORCE
62 $(call if_changed,ksplice-combine)
63 ksplice-targets += $(builtin-target:=.KSPLICE)
67 $(lib-target:=.KSPLICE): ksplice-link-deps = $(lib-y)
68 $(lib-target:=.KSPLICE): $(call ksplice-objs,$(lib-y)) FORCE
69 $(call if_changed,ksplice-combine)
70 ksplice-targets += $(lib-target:=.KSPLICE)
73 $(sort $(multi-used-y:=.KSPLICE) $(multi-used-m:=.KSPLICE)): ksplice-link-deps = $(addprefix $(obj)/,$($(patsubst $(obj)/%,%,$(@:.o.KSPLICE=-objs))) $($(patsubst $(obj)/%,%,$(@:.o.KSPLICE=-y))))
74 $(sort $(multi-used-y:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(call ksplice-objs,$(multi-objs-y)) FORCE
75 $(call if_changed,ksplice-combine)
76 $(sort $(multi-used-m:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(call ksplice-objs,$(multi-objs-m)) FORCE
77 $(call if_changed,ksplice-combine)
78 ksplice-targets += $(sort $(multi-used-y:=.KSPLICE) $(multi-used-m:=.KSPLICE))
80 ifdef ksplice-mode-snap
81 $(obj)/%.o.KSPLICE: $(obj)/%.o FORCE
82 $(if $(strip $(wildcard $<.KSPLICE_pre) $(filter $<,$?)), \
83 $(call cmd,ksplice-snap))
85 $(obj)/%.o.KSPLICE: $(obj)/%.o
86 $(call cmd,ksplice-diff)
90 $(call cmd,ksplice-ignore)
92 $(sort $(subdir-obj-y:=.KSPLICE)): $(ksplice-dirs) ;
96 ksplice-modnames = $(filter $(KSPLICE_ONLY_TARGETS),$(notdir $(ksplice-mods)))
97 ksplice-deps += $(ksplice-modnames:%=$(MODVERDIR)/%.mod.KSPLICE)
98 $(MODVERDIR)/%.mod.KSPLICE: $(obj)/%.o.KSPLICE
100 .PRECIOUS: $(obj)/%.o.KSPLICE
102 $(obj)/%.o.KSPLICE_helper: $(obj)/%.o.KSPLICE
103 $(call cmd,ksplice-helper)
105 define ksplice-cow-check
106 $(if $(filter-out %.KSPLICE,$@), \
107 $(if $(ksplice-mode-diff), \
108 $(if $(strip $(filter-out $(PHONY),$?) $(filter-out $(cmd_$(1)),$(cmd_$@)) $(filter-out $(cmd_$@),$(cmd_$(1)))), \
109 $(if $(wildcard $@), \
110 $(if $(wildcard $@.KSPLICE_pre),, \
111 $(call cmd,ksplice-cow))))))
115 $(foreach v,if_changed if_changed_dep if_changed_rule, \
116 $(eval $(v)=$$(ksplice-cow-check)$(value $(v))))
118 __ksplice: $(ksplice-deps) $(ksplice-dirs)
121 ksplice-cmd-files := $(wildcard $(foreach f,$(sort $(ksplice-targets)),$(dir $(f)).$(notdir $(f)).cmd))
122 ifneq ($(ksplice-cmd-files),)
123 include $(ksplice-cmd-files)
126 ksplice := -f $(ksplice-makefile) obj
128 PHONY += $(ksplice-dirs)
129 $(ksplice-dirs): $(ksplice-before)
130 $(Q)$(MAKE) $(ksplice)=$(patsubst _ksplice_%,%,$@)