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) $(real-objs-m) $(real-objs-y))
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 ifneq ($(wildcard include/linux/compile.h),)
34 MAKE += --old-file=include/linux/compile.h
36 # Makefile.lib must be included before Makefile because they contain
37 # different filechk definitions in 2.6.12.
38 include scripts/Makefile.lib
40 CC := ksplice-cc.pl $(CC)
41 CFLAGS_KSPLICE = -ffunction-sections -fdata-sections -ksplice-cflags-api=1
42 CFLAGS_KERNEL += $(CFLAGS_KSPLICE)
43 CFLAGS_MODULE += $(CFLAGS_KSPLICE)
44 ksplice-mods += vmlinux
45 ifdef KSPLICE_BUILD_MODULES
46 ksplice-deps += ksplice_modpost
48 ksplice-dirs += $(vmlinux-dirs:%=_ksplice_%)
49 ifdef ksplice-mode-snap
50 ksplice-before += prepare0 prepare scripts
53 ksplice-vmlinux-objs = $(filter-out $(head-y),$(if $(vmlinux-all),$(vmlinux-all),$(vmlinux-objs)))
54 $(obj)/vmlinux.o.KSPLICE: ksplice-link-deps = $(ksplice-vmlinux-objs)
55 $(obj)/vmlinux.o.KSPLICE: $(call ksplice-objs,$(ksplice-vmlinux-objs)) FORCE
56 $(call if_changed,ksplice-combine)
57 ksplice-targets += $(obj)/vmlinux.o.KSPLICE
58 $(ksplice-vmlinux-objs:=.KSPLICE): $(ksplice-dirs) ;
60 PHONY += ksplice_modpost ksplice_modinst
61 ksplice_modpost: $(ksplice-dirs)
62 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
63 ksplice_modinst: $(ksplice-dirs)
64 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
68 ifdef KSPLICE_BUILD_MODULES
72 include $(srctree)/scripts/Makefile.build
73 ksplice-mods += $(obj-m:.o=)
74 ksplice-deps += $(if $(filter $(KSPLICE_ONLY_TARGETS),vmlinux),$(builtin-target:=.KSPLICE) $(lib-target:=.KSPLICE))
75 ifdef KSPLICE_BUILD_MODULES
76 ksplice-deps += $(obj-m)
78 ksplice-dirs += $(subdir-ym:%=_ksplice_%)
81 $(builtin-target:=.KSPLICE): ksplice-link-deps = $(obj-y)
82 $(builtin-target:=.KSPLICE): $(call ksplice-objs,$(obj-y)) FORCE
83 $(call if_changed,ksplice-combine)
84 ksplice-targets += $(builtin-target:=.KSPLICE)
88 $(lib-target:=.KSPLICE): ksplice-link-deps = $(lib-y)
89 $(lib-target:=.KSPLICE): $(call ksplice-objs,$(lib-y)) FORCE
90 $(call if_changed,ksplice-combine)
91 ksplice-targets += $(lib-target:=.KSPLICE)
94 $(sort $(multi-used-y:=.KSPLICE) $(multi-used-m:=.KSPLICE)): ksplice-link-deps = $($(@:$(obj)/%.o.KSPLICE=%-objs):%=$(obj)/%) $($(@:$(obj)/%.o.KSPLICE=%-y):%=$(obj)/%)
95 $(sort $(multi-used-y:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(call ksplice-objs,$(multi-objs-y)) FORCE
96 $(call if_changed,ksplice-combine)
97 $(sort $(multi-used-m:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(call ksplice-objs,$(multi-objs-m)) FORCE
98 $(call if_changed,ksplice-combine)
99 ksplice-targets += $(sort $(multi-used-y:=.KSPLICE) $(multi-used-m:=.KSPLICE))
101 ifdef ksplice-mode-snap
102 $(obj)/%.o.KSPLICE: $(obj)/%.o FORCE
103 $(if $(strip $(wildcard $<.KSPLICE_pre) $(filter $<,$?)), \
104 $(call cmd,ksplice-snap))
106 $(obj)/%.o.KSPLICE: $(obj)/%.o
107 $(call cmd,ksplice-diff)
110 $(obj)/%.lds.KSPLICE:
111 $(call cmd,ksplice-ignore)
113 $(sort $(subdir-obj-y:=.KSPLICE)): $(ksplice-dirs) ;
115 endif # KERNELRELEASE
117 ksplice-modnames = $(filter $(KSPLICE_ONLY_TARGETS),$(notdir $(ksplice-mods)))
118 ksplice-deps += $(ksplice-modnames:%=$(MODVERDIR)/%.mod.KSPLICE)
119 $(MODVERDIR)/%.mod.KSPLICE: $(obj)/%.o.KSPLICE
121 .PRECIOUS: $(obj)/%.o.KSPLICE
123 $(obj)/%.o.KSPLICE_helper: $(obj)/%.o.KSPLICE
124 $(call cmd,ksplice-helper)
126 ifdef ksplice-mode-diff
128 define ksplice-cow-check
129 $(if $(filter-out %.KSPLICE,$@), \
130 $(if $(strip $(filter-out $(PHONY),$?) $(filter-out $(cmd_$(1)),$(cmd_$@)) $(filter-out $(cmd_$@),$(cmd_$(1)))), \
131 $(if $(wildcard $@), \
132 $(if $(wildcard $@.KSPLICE_pre),, \
133 $(call cmd,ksplice-cow)))))
137 define ksplice-add-cow-check
138 $(v) = $$(ksplice-cow-check)$(value $(v))
142 ksplice-cow-eval += $(foreach v,if_changed if_changed_dep if_changed_rule,$(ksplice-add-cow-check))
144 endif # ksplice-mode-diff
146 __ksplice: $(ksplice-deps) $(ksplice-dirs)
149 ksplice-cmd-files := $(wildcard $(foreach f,$(sort $(ksplice-targets)),$(dir $(f)).$(notdir $(f)).cmd))
150 ifneq ($(ksplice-cmd-files),)
151 $(ksplice-cmd-files): ;
152 include $(ksplice-cmd-files)
155 PHONY += $(ksplice-dirs)
156 $(ksplice-dirs): $(ksplice-before)
157 $(Q)$(MAKE) -f $(ksplice-makefile) obj=$(@:_ksplice_%=%)
159 $(eval $(ksplice-cow-eval))