1 ksplice-makefile := $(word $(words $(MAKEFILE_LIST)), $(MAKEFILE_LIST))
2 ksplice-script = $(dir $(ksplice-makefile))ksplice-obj.pl
5 $(if $(filter_out snap diff revert modinst,$(KSPLICE_MODE)), \
6 $(error Invalid KSPLICE_MODE $(KSPLICE_MODE).))
8 KSPLICE_ONLY_TARGETS ?= %
14 ksplice-extra = $(filter $(KSPLICE_EXTRA_MATCH),$(lib-y) $(real-objs-m) $(real-objs-y))
15 ksplice-objs = $(foreach o,$(1),$(o:=.KSPLICE) $(addsuffix .KSPLICE_helper,$(filter $(ksplice-extra),$(o))))
17 escsq ?= $(subst ','\'',$(1))
18 echo-cmd ?= $(if $($(quiet)cmd_$(1)),echo ' $(call escsq,$($(quiet)cmd_$(1)))';)
20 quiet_cmd_ksplice-combine = COMBINE $(@:.KSPLICE=)
21 cmd_ksplice-combine = $(ksplice-script) combine $@ $(filter $(call ksplice-objs,$(ksplice-link-deps)),$^)
22 quiet_cmd_ksplice-snap = SNAP $(@:.KSPLICE=)
23 cmd_ksplice-snap = $(ksplice-script) snap $@
24 quiet_cmd_ksplice-diff = DIFF $(@:.KSPLICE=)
25 cmd_ksplice-diff = $(ksplice-script) diff $@
26 quiet_cmd_ksplice-ignore = IGNORE $(@:.KSPLICE=)
27 cmd_ksplice-ignore = touch $@
28 quiet_cmd_ksplice-cow = COW $@
29 cmd_ksplice-cow = cp -a $@ $@.KSPLICE_pre
30 quiet_cmd_ksplice-mod = MOD $(@:$(KSPLICE_KMODSRC)/%.mod.KSPLICE=%)
31 cmd_ksplice-mod = echo $(<:.o.KSPLICE=) > $@; cp -a $< $(<:.KSPLICE=.KSPLICE_primary) $(<:.KSPLICE=.KSPLICE_helper) $(KSPLICE_KMODSRC)/
32 rule_ksplice-mod = if [ -s $< ]; then $(echo-cmd) $(cmd_$(1)); fi
33 quiet_cmd_ksplice-helper = HELPER $(@:.KSPLICE_helper=)
34 cmd_ksplice-helper = $(ksplice-script) helper $@
35 quiet_cmd_ksplice-freeze = FREEZE $(@:_ksplice-revert_%.KSPLICE_pre=%)
36 cmd_ksplice-freeze = rm -f $(@:_ksplice-revert_%=%)
37 quiet_cmd_ksplice-revert = REVERT $(@:_ksplice-revert_%.KSPLICE_pre=%)
38 cmd_ksplice-revert = mv $(@:_ksplice-revert_%=%) $(@:_ksplice-revert_%.KSPLICE_pre=%)
39 quiet_cmd_ksplice-revert-snap = SNAP $(@:_ksplice-revert-snap_%.KSPLICE=%)
40 cmd_ksplice-revert-snap = $(ksplice-script) snap $(@:_ksplice-revert-snap_%=%)
41 quiet_cmd_ksplice-clean = CLEAN $(@:_ksplice-clean_%=%)
42 cmd_ksplice-clean = rm -f $(@:_ksplice-clean_%=%)
46 ifneq ($(wildcard include/linux/compile.h),)
47 MAKE += --old-file=include/linux/compile.h
49 ifneq ($(filter snap diff,$(KSPLICE_MODE)),)
50 # Makefile.lib must be included before Makefile because they contain
51 # different filechk definitions in 2.6.12.
52 include $(if $(KBUILD_SRC),$(KBUILD_SRC)/)scripts/Makefile.lib
54 include $(if $(KBUILD_SRC),$(KBUILD_SRC)/)Makefile
56 ifneq ($(skip-makefile),)
60 $(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) \
61 KBUILD_SRC=$(CURDIR) \
62 KBUILD_EXTMOD="$(KBUILD_EXTMOD)" -f $(ksplice-makefile) \
63 $(if $(wildcard $(KBUILD_OUTPUT)/include/config/kernel.release),--old-file=include/config/kernel.release)
67 CC := ksplice-cc.pl $(CC)
68 CFLAGS_KSPLICE = -ffunction-sections -fdata-sections -ksplice-cflags-api=1
69 CFLAGS_KERNEL += $(CFLAGS_KSPLICE)
70 CFLAGS_MODULE += $(CFLAGS_KSPLICE)
72 ifeq ($(KSPLICE_MODE),revert)
74 ksplice-dirs += $(vmlinux-alldirs:%=_ksplice_%)
78 ifneq ($(filter snap diff,$(KSPLICE_MODE)),)
80 ksplice-mods += vmlinux
81 ifdef KSPLICE_BUILD_MODULES
82 ksplice-deps += ksplice_modpost
84 ksplice-deps += $(vmlinux-dirs)
86 ksplice-vmlinux-objs = $(if $(vmlinux-all),$(vmlinux-all),$(vmlinux-objs))
87 $(obj)/vmlinux.o.KSPLICE: ksplice-link-deps = $(ksplice-vmlinux-objs)
88 $(obj)/vmlinux.o.KSPLICE: $(call ksplice-objs,$(ksplice-vmlinux-objs)) FORCE
89 $(call if_changed,ksplice-combine)
90 ksplice-targets += $(obj)/vmlinux.o.KSPLICE
91 $(ksplice-vmlinux-objs:=.KSPLICE): $(vmlinux-dirs) ;
93 PHONY += ksplice_modpost
94 ksplice_modpost: $(vmlinux-dirs) vmlinux
95 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
99 ifeq ($(KSPLICE_MODE),modinst)
101 ksplice-deps += ksplice_modinst
102 PHONY += ksplice_modinst
104 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
108 endif # skip-makefile
112 ifeq ($(KSPLICE_MODE),revert)
114 -include .config # workaround for missing obj- = subdir/ declarations
115 include $(srctree)/scripts/Makefile.clean
116 ksplice-dirs += $(subdir-ymn:%=_ksplice_%)
120 ifneq ($(filter snap diff,$(KSPLICE_MODE)),)
122 ifdef KSPLICE_BUILD_MODULES
126 include $(srctree)/scripts/Makefile.build
127 ksplice-mods += $(obj-m:.o=)
128 ksplice-deps += $(if $(filter $(KSPLICE_ONLY_TARGETS),vmlinux),$(builtin-target:=.KSPLICE) $(lib-target:=.KSPLICE))
129 ifdef KSPLICE_BUILD_MODULES
130 ksplice-deps += __build
132 ksplice-deps += $(subdir-ym)
135 $(builtin-target:=.KSPLICE): ksplice-link-deps = $(obj-y)
136 $(builtin-target:=.KSPLICE): $(call ksplice-objs,$(obj-y)) FORCE
137 $(call if_changed,ksplice-combine)
138 ksplice-targets += $(builtin-target:=.KSPLICE)
142 $(lib-target:=.KSPLICE): ksplice-link-deps = $(lib-y)
143 $(lib-target:=.KSPLICE): $(call ksplice-objs,$(lib-y)) FORCE
144 $(call if_changed,ksplice-combine)
145 ksplice-targets += $(lib-target:=.KSPLICE)
148 $(sort $(multi-used-y:=.KSPLICE) $(multi-used-m:=.KSPLICE)): ksplice-link-deps = $($(@:$(obj)/%.o.KSPLICE=%-objs):%=$(obj)/%) $($(@:$(obj)/%.o.KSPLICE=%-y):%=$(obj)/%)
149 $(sort $(multi-used-y:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(call ksplice-objs,$(multi-objs-y)) FORCE
150 $(call if_changed,ksplice-combine)
151 $(sort $(multi-used-m:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(call ksplice-objs,$(multi-objs-m)) FORCE
152 $(call if_changed,ksplice-combine)
153 ksplice-targets += $(sort $(multi-used-y:=.KSPLICE) $(multi-used-m:=.KSPLICE))
155 ifeq ($(KSPLICE_MODE),snap)
156 $(obj)/%.o.KSPLICE: $(obj)/%.o FORCE
157 $(if $(strip $(wildcard $<.KSPLICE_pre) $(filter $<,$?)), \
158 $(call cmd,ksplice-snap))
160 $(obj)/%.o.KSPLICE: $(obj)/%.o
161 $(call cmd,ksplice-diff)
164 $(obj)/%.lds.KSPLICE:
165 $(call cmd,ksplice-ignore)
167 $(sort $(subdir-obj-y:=.KSPLICE)): $(subdir-ym) ;
169 ifeq ($(MAKECMDGOALS),missing-syscalls)
177 ifeq ($(skip-makefile),)
179 ifeq ($(KSPLICE_MODE),revert)
181 ksplice-revert-obj := $(wildcard $(obj)/*.KSPLICE_pre)
182 ksplice-revert-files := $(ksplice-revert-obj)
183 ifneq ($(obj),$(src))
184 ksplice-revert-files += $(wildcard $(src)/*.KSPLICE_pre)
186 ksplice-revert-deps := $(ksplice-revert-files:%=_ksplice-revert_%)
187 ksplice-deps += $(ksplice-revert-deps)
188 PHONY += $(ksplice-revert-deps)
189 $(ksplice-revert-deps): FORCE
191 $(call cmd,ksplice-freeze)
193 $(call cmd,ksplice-revert)
196 ksplice-revert-snap-files := $(wildcard $(ksplice-revert-obj:.KSPLICE_pre=.KSPLICE))
197 ksplice-revert-snap-deps := $(ksplice-revert-snap-files:%=_ksplice-revert-snap_%)
198 ksplice-deps += $(ksplice-revert-snap-deps)
199 PHONY += $(ksplice-revert-snap-deps)
200 $(ksplice-revert-snap-deps): $(ksplice-revert-snap-files:%.KSPLICE=_ksplice-revert_%.KSPLICE_pre) FORCE
201 $(call cmd,ksplice-revert-snap)
203 ksplice-clean-files := $(filter-out $(ksplice-revert-snap-files:.KSPLICE_pre=.KSPLICE_primary) $(ksplice-revert-snap-files:.KSPLICE_pre=.KSPLICE_helper),$(wildcard $(obj)/*.KSPLICE_primary $(obj)/*.KSPLICE_helper))
204 ksplice-clean-deps = $(ksplice-clean-files:%=_ksplice-clean_%)
205 ksplice-deps += $(ksplice-clean-deps)
206 PHONY += $(ksplice-clean-deps)
207 $(ksplice-clean-deps): FORCE
208 $(call cmd,ksplice-clean)
212 ifneq ($(filter snap diff,$(KSPLICE_MODE)),)
214 ksplice-modnames = $(filter $(KSPLICE_ONLY_TARGETS),$(notdir $(ksplice-mods)))
215 ifdef KSPLICE_KMODSRC
216 ksplice-deps += $(ksplice-modnames:%=$(KSPLICE_KMODSRC)/%.mod.KSPLICE)
217 $(KSPLICE_KMODSRC)/%.mod.KSPLICE: $(obj)/%.o.KSPLICE
218 $(Q)$(call rule_ksplice-mod,ksplice-mod)
220 ksplice-deps += $(ksplice-modnames:%=$(obj)/%.o.KSPLICE)
222 .PRECIOUS: $(obj)/%.o.KSPLICE
224 $(obj)/%.o.KSPLICE_helper: $(obj)/%.o.KSPLICE
225 $(call cmd,ksplice-helper)
227 ifeq ($(KSPLICE_MODE),diff)
229 define ksplice-cow-check
230 $(if $(filter-out %.KSPLICE,$@), \
231 $(if $(strip $(filter-out $(PHONY),$?) $(filter-out $(cmd_$(1)),$(cmd_$@)) $(filter-out $(cmd_$@),$(cmd_$(1)))), \
232 $(if $(wildcard $@), \
233 $(if $(wildcard $@.KSPLICE_pre),, \
234 $(call cmd,ksplice-cow)))))
238 define ksplice-add-cow-check
239 $(v) = $$(ksplice-cow-check)$(value $(v))
243 ksplice-cow-eval += $(foreach v,if_changed if_changed_dep if_changed_rule,$(ksplice-add-cow-check))
247 ksplice-cmd-files := $(wildcard $(foreach f,$(sort $(ksplice-targets)),$(dir $(f)).$(notdir $(f)).cmd))
248 ifneq ($(ksplice-cmd-files),)
249 $(ksplice-cmd-files): ;
250 include $(ksplice-cmd-files)
256 __ksplice: $(ksplice-deps) $(ksplice-dirs)
259 build := -f $(ksplice-makefile) obj
260 descend =$(Q)$(MAKE) $(build)=$(1) $(2)
262 PHONY += $(ksplice-dirs)
264 $(Q)$(MAKE) $(build)=$(@:_ksplice_%=%)
266 endif # skip-makefile
268 $(eval $(ksplice-cow-eval))