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 = touch -r ksplice-revert-stamp $(@:_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-revert-dirs = $(vmlinux-alldirs:%=_ksplice_%)
75 ksplice-dirs += $(ksplice-revert-dirs)
77 .INTERMEDIATE $(ksplice-revert-dirs): ksplice-revert-stamp
78 ksplice-revert-stamp: FORCE
83 ifneq ($(filter snap diff,$(KSPLICE_MODE)),)
85 ksplice-mods += vmlinux
86 ifdef KSPLICE_BUILD_MODULES
87 ksplice-deps += ksplice_modpost
89 ksplice-deps += $(vmlinux-dirs)
91 ksplice-vmlinux-objs = $(if $(vmlinux-all),$(vmlinux-all),$(vmlinux-objs))
92 $(obj)/vmlinux.o.KSPLICE: ksplice-link-deps = $(ksplice-vmlinux-objs)
93 $(obj)/vmlinux.o.KSPLICE: $(call ksplice-objs,$(ksplice-vmlinux-objs)) FORCE
94 $(call if_changed,ksplice-combine)
95 ksplice-targets += $(obj)/vmlinux.o.KSPLICE
96 $(ksplice-vmlinux-objs:=.KSPLICE): $(vmlinux-dirs) ;
98 PHONY += ksplice_modpost
99 ksplice_modpost: $(vmlinux-dirs) vmlinux
100 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
104 ifeq ($(KSPLICE_MODE),modinst)
106 ksplice-deps += ksplice_modinst
107 PHONY += ksplice_modinst
109 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
113 endif # skip-makefile
117 ifeq ($(KSPLICE_MODE),revert)
119 -include .config # workaround for missing obj- = subdir/ declarations
120 include $(srctree)/scripts/Makefile.clean
121 ksplice-dirs += $(subdir-ymn:%=_ksplice_%)
125 ifneq ($(filter snap diff,$(KSPLICE_MODE)),)
127 ifdef KSPLICE_BUILD_MODULES
131 include $(srctree)/scripts/Makefile.build
132 ksplice-mods += $(obj-m:.o=)
133 ksplice-deps += $(if $(filter $(KSPLICE_ONLY_TARGETS),vmlinux),$(builtin-target:=.KSPLICE) $(lib-target:=.KSPLICE))
134 ifdef KSPLICE_BUILD_MODULES
135 ksplice-deps += __build
137 ksplice-deps += $(subdir-ym) $(always)
140 $(builtin-target:=.KSPLICE): ksplice-link-deps = $(obj-y)
141 $(builtin-target:=.KSPLICE): $(call ksplice-objs,$(obj-y)) FORCE
142 $(call if_changed,ksplice-combine)
143 ksplice-targets += $(builtin-target:=.KSPLICE)
147 $(lib-target:=.KSPLICE): ksplice-link-deps = $(lib-y)
148 $(lib-target:=.KSPLICE): $(call ksplice-objs,$(lib-y)) FORCE
149 $(call if_changed,ksplice-combine)
150 ksplice-targets += $(lib-target:=.KSPLICE)
153 $(sort $(multi-used-y:=.KSPLICE) $(multi-used-m:=.KSPLICE)): ksplice-link-deps = $($(@:$(obj)/%.o.KSPLICE=%-objs):%=$(obj)/%) $($(@:$(obj)/%.o.KSPLICE=%-y):%=$(obj)/%)
154 $(sort $(multi-used-y:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(call ksplice-objs,$(multi-objs-y)) FORCE
155 $(call if_changed,ksplice-combine)
156 $(sort $(multi-used-m:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(call ksplice-objs,$(multi-objs-m)) FORCE
157 $(call if_changed,ksplice-combine)
158 ksplice-targets += $(sort $(multi-used-y:=.KSPLICE) $(multi-used-m:=.KSPLICE))
160 ifeq ($(KSPLICE_MODE),snap)
161 $(obj)/%.o.KSPLICE: $(obj)/%.o FORCE
162 $(if $(strip $(wildcard $<.KSPLICE_pre) $(filter $<,$?)), \
163 $(call cmd,ksplice-snap))
165 $(obj)/%.o.KSPLICE: $(obj)/%.o
166 $(call cmd,ksplice-diff)
169 $(obj)/%.lds.KSPLICE:
170 $(call cmd,ksplice-ignore)
172 $(sort $(subdir-obj-y:=.KSPLICE)): $(subdir-ym) ;
174 ifeq ($(MAKECMDGOALS),missing-syscalls)
182 ifeq ($(skip-makefile),)
184 ifeq ($(KSPLICE_MODE),revert)
186 ksplice-revert-obj := $(wildcard $(obj)/*.KSPLICE_pre)
187 ksplice-revert-files := $(ksplice-revert-obj)
188 ifneq ($(obj),$(src))
189 ksplice-revert-files += $(wildcard $(src)/*.KSPLICE_pre)
191 ksplice-revert-deps := $(ksplice-revert-files:%=_ksplice-revert_%)
192 ksplice-deps += $(ksplice-revert-deps)
193 PHONY += $(ksplice-revert-deps)
194 $(ksplice-revert-deps): FORCE
196 $(call cmd,ksplice-freeze)
198 $(call cmd,ksplice-revert)
201 ksplice-revert-snap-files := $(wildcard $(ksplice-revert-obj:.KSPLICE_pre=.KSPLICE))
202 ksplice-revert-snap-deps := $(ksplice-revert-snap-files:%=_ksplice-revert-snap_%)
203 ksplice-deps += $(ksplice-revert-snap-deps)
204 PHONY += $(ksplice-revert-snap-deps)
205 $(ksplice-revert-snap-deps): $(ksplice-revert-snap-files:%.KSPLICE=_ksplice-revert_%.KSPLICE_pre) FORCE
206 $(call cmd,ksplice-revert-snap)
208 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))
209 ksplice-clean-deps = $(ksplice-clean-files:%=_ksplice-clean_%)
210 ksplice-deps += $(ksplice-clean-deps)
211 PHONY += $(ksplice-clean-deps)
212 $(ksplice-clean-deps): FORCE
213 $(call cmd,ksplice-clean)
217 ifneq ($(filter snap diff,$(KSPLICE_MODE)),)
219 ksplice-modnames = $(filter $(KSPLICE_ONLY_TARGETS),$(notdir $(ksplice-mods)))
220 ifdef KSPLICE_KMODSRC
221 ksplice-deps += $(ksplice-modnames:%=$(KSPLICE_KMODSRC)/%.mod.KSPLICE)
222 $(KSPLICE_KMODSRC)/%.mod.KSPLICE: $(obj)/%.o.KSPLICE
223 $(Q)$(call rule_ksplice-mod,ksplice-mod)
225 ksplice-deps += $(ksplice-modnames:%=$(obj)/%.o.KSPLICE)
227 .SECONDARY: $(obj)/%.o.KSPLICE
229 $(obj)/%.o.KSPLICE_helper: $(obj)/%.o.KSPLICE
230 $(call cmd,ksplice-helper)
232 ifeq ($(KSPLICE_MODE),diff)
234 define ksplice-cow-check
235 $(if $(filter-out %.KSPLICE,$@), \
236 $(if $(strip $(filter-out $(PHONY),$?) $(filter-out $(cmd_$(1)),$(cmd_$@)) $(filter-out $(cmd_$@),$(cmd_$(1)))), \
237 $(if $(wildcard $@), \
238 $(if $(wildcard $@.KSPLICE_pre),, \
239 $(call cmd,ksplice-cow)))))
243 define ksplice-add-cow-check
244 $(v) = $$(ksplice-cow-check)$(value $(v))
248 ksplice-cow-eval += $(foreach v,if_changed if_changed_dep if_changed_rule,$(ksplice-add-cow-check))
252 ksplice-cmd-files := $(wildcard $(foreach f,$(sort $(ksplice-targets)),$(dir $(f)).$(notdir $(f)).cmd))
253 ifneq ($(ksplice-cmd-files),)
254 $(ksplice-cmd-files): ;
255 include $(ksplice-cmd-files)
261 __ksplice: $(ksplice-deps) $(ksplice-dirs)
264 build := -f $(ksplice-makefile) obj
265 descend =$(Q)$(MAKE) $(build)=$(1) $(2)
267 PHONY += $(ksplice-dirs)
269 $(Q)$(MAKE) $(build)=$(@:_ksplice_%=%)
271 endif # skip-makefile
273 $(eval $(ksplice-cow-eval))