Support multiple ksplice modules in ksplice-apply.
[ksplice.git] / Makefile.ksplice
blobdfbc4c8bd6b4e7ff38d1db3924d36329af9fba80
1 ksplice-makefile := $(word $(words $(MAKEFILE_LIST)), $(MAKEFILE_LIST))
2 ksplice-script = $(dir $(ksplice-makefile))ksplice.pl
4 KSPLICE_MODE ?= diff
5 $(if $(filter_out snap diff,$(KSPLICE_MODE)), \
6   $(error Invalid KSPLICE_MODE $(KSPLICE_MODE).))
7 ksplice-mode-$(KSPLICE_MODE) = y
9 PHONY := __ksplice
10 __ksplice:
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-cow = COW     $@
19 cmd_ksplice-cow = cp -a $@ $@.KSPLICE_pre
21 ifeq ($(KERNELRELEASE),)
23 # Makefile.lib must be included before Makefile because they contain
24 # different filechk definitions in 2.6.12.
25 include scripts/Makefile.lib
26 include Makefile
27 CFLAGS_KERNEL += -ffunction-sections -fdata-sections
28 CFLAGS_MODULE += -ffunction-sections -fdata-sections
29 ksplice-deps += vmlinux.o.KSPLICE
30 ksplice-dirs += $(addprefix _ksplice_,$(vmlinux-dirs))
31 ksplice-before += prepare0 prepare scripts
33 ksplice-vmlinux-objs = $(filter-out $(head-y),$(if $(vmlinux-all),$(vmlinux-all),$(vmlinux-objs)))
34 vmlinux.o.KSPLICE: ksplice-link-deps = $(ksplice-vmlinux-objs:=.KSPLICE)
35 vmlinux.o.KSPLICE: $(ksplice-vmlinux-objs:=.KSPLICE) FORCE
36         $(call if_changed,ksplice-combine)
37 ksplice-targets += vmlinux.o.KSPLICE
38 $(ksplice-vmlinux-objs:=.KSPLICE): $(ksplice-dirs) ;
40 else    # KERNELRELEASE
42 include $(srctree)/scripts/Makefile.build
43 ksplice-deps += $(builtin-target:=.KSPLICE) $(lib-target:=.KSPLICE) $(obj-m:=.KSPLICE)
44 ksplice-dirs += $(addprefix _ksplice_,$(subdir-ym))
46 ifdef builtin-target
47 $(builtin-target:=.KSPLICE): ksplice-link-deps = $(obj-y:=.KSPLICE)
48 $(builtin-target:=.KSPLICE): $(obj-y:=.KSPLICE) FORCE
49         $(call if_changed,ksplice-combine)
50 ksplice-targets += $(builtin-target:=.KSPLICE)
51 endif
53 ifdef lib-target
54 $(lib-target:=.KSPLICE): ksplice-link-deps = $(lib-y:=.KSPLICE)
55 $(lib-target:=.KSPLICE): $(lib-y:=.KSPLICE) FORCE
56         $(call if_changed,ksplice-combine)
57 ksplice-targets += $(lib-target:=.KSPLICE)
58 endif
60 $(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)))))
61 $(sort $(multi-used-y:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(multi-objs-y:=.KSPLICE) FORCE
62         $(call if_changed,ksplice-combine)
63 $(sort $(multi-used-m:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(multi-objs-m:=.KSPLICE) FORCE
64         $(call if_changed,ksplice-combine)
65 ksplice-targets += $(sort $(multi-used-y:=.KSPLICE) $(multi-used-m:=.KSPLICE))
67 ifdef ksplice-mode-snap
68 $(obj)/%.o.KSPLICE: $(obj)/%.o FORCE
69         $(if $(strip $(wildcard $<.KSPLICE_pre) $(filter $<,$?)), \
70           $(call cmd,ksplice-snap))
71 else
72 $(obj)/%.o.KSPLICE: $(obj)/%.o
73         $(call cmd,ksplice-diff)
74 endif
76 $(sort $(subdir-obj-y:=.KSPLICE)): $(ksplice-dirs) ;
78 endif   # KERNELRELEASE
80 define ksplice-cow-check
81         $(if $(filter-out %.KSPLICE,$@), \
82           $(if $(ksplice-mode-diff), \
83             $(if $(strip $(filter-out $(PHONY),$?) $(filter-out $(cmd_$(1)),$(cmd_$@)) $(filter-out $(cmd_$@),$(cmd_$(1)))), \
84               $(if $(wildcard $@), \
85                 $(if $(wildcard $@.KSPLICE_pre),, \
86                   $(call cmd,ksplice-cow))))))
88 endef
90 $(foreach v,if_changed if_changed_dep if_changed_rule, \
91   $(eval $(v)=$$(ksplice-cow-check)$(value $(v))))
93 __ksplice: $(ksplice-deps) $(ksplice-dirs)
94         @:
96 ksplice-cmd-files := $(wildcard $(foreach f,$(sort $(ksplice-targets)),$(dir $(f)).$(notdir $(f)).cmd))
97 ifneq ($(ksplice-cmd-files),)
98 include $(ksplice-cmd-files)
99 endif
101 ksplice := -f $(ksplice-makefile) obj
103 PHONY += $(ksplice-dirs)
104 $(ksplice-dirs): $(ksplice-before)
105         $(Q)$(MAKE) $(ksplice)=$(patsubst _ksplice_%,%,$@)
107 PHONY += FORCE
108 FORCE:
110 .PHONY: $(PHONY)