Add canonical_symbol helper function.
[ksplice.git] / Makefile.ksplice
blob7678dcdf1b7aee6c6b8ceb6bf24e976909a5acaf
1 ksplice-makefile := $(word $(words $(MAKEFILE_LIST)), $(MAKEFILE_LIST))
2 ksplice-script = $(dir $(ksplice-makefile))ksplice-obj.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-ignore = IGNORE  $(@:.KSPLICE=)
19 cmd_ksplice-ignore = touch $@
20 quiet_cmd_ksplice-cow = COW     $@
21 cmd_ksplice-cow = cp -a $@ $@.KSPLICE_pre
22 rule_ksplice-mod = $(Q)if [ -s $< ]; then echo $(<:.o.KSPLICE=) > $@; elif [ -e $@ ]; then rm -f $@; fi
24 ifeq ($(KERNELRELEASE),)
26 # Makefile.lib must be included before Makefile because they contain
27 # different filechk definitions in 2.6.12.
28 include scripts/Makefile.lib
29 include Makefile
30 CFLAGS_KERNEL += -ffunction-sections -fdata-sections
31 CFLAGS_MODULE += -ffunction-sections -fdata-sections
32 ksplice-deps += $(MODVERDIR)/vmlinux.mod.KSPLICE
33 ksplice-dirs += $(addprefix _ksplice_,$(vmlinux-dirs))
34 ifdef ksplice-mode-snap
35 ksplice-before += prepare0 prepare scripts
36 endif
38 ksplice-vmlinux-objs = $(filter-out $(head-y),$(if $(vmlinux-all),$(vmlinux-all),$(vmlinux-objs)))
39 vmlinux.o.KSPLICE: ksplice-link-deps = $(ksplice-vmlinux-objs:=.KSPLICE)
40 vmlinux.o.KSPLICE: $(ksplice-vmlinux-objs:=.KSPLICE) FORCE
41         $(call if_changed,ksplice-combine)
42 ksplice-targets += vmlinux.o.KSPLICE
43 $(ksplice-vmlinux-objs:=.KSPLICE): $(ksplice-dirs) ;
45 $(MODVERDIR)/vmlinux.mod.KSPLICE: vmlinux.o.KSPLICE
46         $(rule_ksplice-mod)
48 else    # KERNELRELEASE
50 include $(srctree)/scripts/Makefile.build
51 ksplice-deps += $(builtin-target:=.KSPLICE) $(lib-target:=.KSPLICE) $(addprefix $(MODVERDIR)/,$(notdir $(obj-m:.o=.mod.KSPLICE)))
52 ksplice-dirs += $(addprefix _ksplice_,$(subdir-ym))
54 ifdef builtin-target
55 $(builtin-target:=.KSPLICE): ksplice-link-deps = $(obj-y:=.KSPLICE)
56 $(builtin-target:=.KSPLICE): $(obj-y:=.KSPLICE) FORCE
57         $(call if_changed,ksplice-combine)
58 ksplice-targets += $(builtin-target:=.KSPLICE)
59 endif
61 ifdef lib-target
62 $(lib-target:=.KSPLICE): ksplice-link-deps = $(lib-y:=.KSPLICE)
63 $(lib-target:=.KSPLICE): $(lib-y:=.KSPLICE) FORCE
64         $(call if_changed,ksplice-combine)
65 ksplice-targets += $(lib-target:=.KSPLICE)
66 endif
68 $(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)))))
69 $(sort $(multi-used-y:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(multi-objs-y:=.KSPLICE) FORCE
70         $(call if_changed,ksplice-combine)
71 $(sort $(multi-used-m:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(multi-objs-m:=.KSPLICE) FORCE
72         $(call if_changed,ksplice-combine)
73 ksplice-targets += $(sort $(multi-used-y:=.KSPLICE) $(multi-used-m:=.KSPLICE))
75 ifdef ksplice-mode-snap
76 $(obj)/%.o.KSPLICE: $(obj)/%.o FORCE
77         $(if $(strip $(wildcard $<.KSPLICE_pre) $(filter $<,$?)), \
78           $(call cmd,ksplice-snap))
79 else
80 $(obj)/%.o.KSPLICE: $(obj)/%.o
81         $(call cmd,ksplice-diff)
82 endif
84 $(obj)/%.lds.KSPLICE:
85         $(call cmd,ksplice-ignore)
87 $(sort $(subdir-obj-y:=.KSPLICE)): $(ksplice-dirs) ;
89 $(MODVERDIR)/%.mod.KSPLICE: $(obj)/%.o.KSPLICE
90         $(rule_ksplice-mod)
91 .PRECIOUS: $(obj)/%.o.KSPLICE
93 endif   # KERNELRELEASE
95 define ksplice-cow-check
96         $(if $(filter-out %.KSPLICE,$@), \
97           $(if $(ksplice-mode-diff), \
98             $(if $(strip $(filter-out $(PHONY),$?) $(filter-out $(cmd_$(1)),$(cmd_$@)) $(filter-out $(cmd_$@),$(cmd_$(1)))), \
99               $(if $(wildcard $@), \
100                 $(if $(wildcard $@.KSPLICE_pre),, \
101                   $(call cmd,ksplice-cow))))))
103 endef
105 $(foreach v,if_changed if_changed_dep if_changed_rule, \
106   $(eval $(v)=$$(ksplice-cow-check)$(value $(v))))
108 __ksplice: $(ksplice-deps) $(ksplice-dirs)
109         @:
111 ksplice-cmd-files := $(wildcard $(foreach f,$(sort $(ksplice-targets)),$(dir $(f)).$(notdir $(f)).cmd))
112 ifneq ($(ksplice-cmd-files),)
113 include $(ksplice-cmd-files)
114 endif
116 ksplice := -f $(ksplice-makefile) obj
118 PHONY += $(ksplice-dirs)
119 $(ksplice-dirs): $(ksplice-before)
120         $(Q)$(MAKE) $(ksplice)=$(patsubst _ksplice_%,%,$@)
122 PHONY += FORCE
123 FORCE:
125 .PHONY: $(PHONY)