Convert symbol tables to vector interface.
[ksplice.git] / Makefile.ksplice
blobdcddd1a3f7ef51568ab8f59837acf8ed86d4b256
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-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 ksplice-before += prepare0 prepare scripts
36 ksplice-vmlinux-objs = $(filter-out $(head-y),$(if $(vmlinux-all),$(vmlinux-all),$(vmlinux-objs)))
37 vmlinux.o.KSPLICE: ksplice-link-deps = $(ksplice-vmlinux-objs:=.KSPLICE)
38 vmlinux.o.KSPLICE: $(ksplice-vmlinux-objs:=.KSPLICE) FORCE
39         $(call if_changed,ksplice-combine)
40 ksplice-targets += vmlinux.o.KSPLICE
41 $(ksplice-vmlinux-objs:=.KSPLICE): $(ksplice-dirs) ;
43 $(MODVERDIR)/vmlinux.mod.KSPLICE: vmlinux.o.KSPLICE
44         $(rule_ksplice-mod)
46 else    # KERNELRELEASE
48 include $(srctree)/scripts/Makefile.build
49 ksplice-deps += $(builtin-target:=.KSPLICE) $(lib-target:=.KSPLICE) $(addprefix $(MODVERDIR)/,$(notdir $(obj-m:.o=.mod.KSPLICE)))
50 ksplice-dirs += $(addprefix _ksplice_,$(subdir-ym))
52 ifdef builtin-target
53 $(builtin-target:=.KSPLICE): ksplice-link-deps = $(obj-y:=.KSPLICE)
54 $(builtin-target:=.KSPLICE): $(obj-y:=.KSPLICE) FORCE
55         $(call if_changed,ksplice-combine)
56 ksplice-targets += $(builtin-target:=.KSPLICE)
57 endif
59 ifdef lib-target
60 $(lib-target:=.KSPLICE): ksplice-link-deps = $(lib-y:=.KSPLICE)
61 $(lib-target:=.KSPLICE): $(lib-y:=.KSPLICE) FORCE
62         $(call if_changed,ksplice-combine)
63 ksplice-targets += $(lib-target:=.KSPLICE)
64 endif
66 $(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)))))
67 $(sort $(multi-used-y:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(multi-objs-y:=.KSPLICE) FORCE
68         $(call if_changed,ksplice-combine)
69 $(sort $(multi-used-m:=.KSPLICE)): $(obj)/%.o.KSPLICE: $(multi-objs-m:=.KSPLICE) FORCE
70         $(call if_changed,ksplice-combine)
71 ksplice-targets += $(sort $(multi-used-y:=.KSPLICE) $(multi-used-m:=.KSPLICE))
73 ifdef ksplice-mode-snap
74 $(obj)/%.o.KSPLICE: $(obj)/%.o FORCE
75         $(if $(strip $(wildcard $<.KSPLICE_pre) $(filter $<,$?)), \
76           $(call cmd,ksplice-snap))
77 else
78 $(obj)/%.o.KSPLICE: $(obj)/%.o
79         $(call cmd,ksplice-diff)
80 endif
82 $(obj)/%.lds.KSPLICE:
83         $(call cmd,ksplice-ignore)
85 $(sort $(subdir-obj-y:=.KSPLICE)): $(ksplice-dirs) ;
87 $(MODVERDIR)/%.mod.KSPLICE: $(obj)/%.o.KSPLICE
88         $(rule_ksplice-mod)
89 .PRECIOUS: $(obj)/%.o.KSPLICE
91 endif   # KERNELRELEASE
93 define ksplice-cow-check
94         $(if $(filter-out %.KSPLICE,$@), \
95           $(if $(ksplice-mode-diff), \
96             $(if $(strip $(filter-out $(PHONY),$?) $(filter-out $(cmd_$(1)),$(cmd_$@)) $(filter-out $(cmd_$@),$(cmd_$(1)))), \
97               $(if $(wildcard $@), \
98                 $(if $(wildcard $@.KSPLICE_pre),, \
99                   $(call cmd,ksplice-cow))))))
101 endef
103 $(foreach v,if_changed if_changed_dep if_changed_rule, \
104   $(eval $(v)=$$(ksplice-cow-check)$(value $(v))))
106 __ksplice: $(ksplice-deps) $(ksplice-dirs)
107         @:
109 ksplice-cmd-files := $(wildcard $(foreach f,$(sort $(ksplice-targets)),$(dir $(f)).$(notdir $(f)).cmd))
110 ifneq ($(ksplice-cmd-files),)
111 include $(ksplice-cmd-files)
112 endif
114 ksplice := -f $(ksplice-makefile) obj
116 PHONY += $(ksplice-dirs)
117 $(ksplice-dirs): $(ksplice-before)
118         $(Q)$(MAKE) $(ksplice)=$(patsubst _ksplice_%,%,$@)
120 PHONY += FORCE
121 FORCE:
123 .PHONY: $(PHONY)