[udis86] Add xgetbv and xsetbv instructions.
[ksplice.git] / Makefile.ksplice
blob9a22026d4179f7ae635d321b41a3ee776b56ea38
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 revert modinst,$(KSPLICE_MODE)), \
6   $(error Invalid KSPLICE_MODE $(KSPLICE_MODE).))
8 KSPLICE_ONLY_TARGETS ?= %
10 PHONY :=
12 __ksplice:
14 ksplice-extra = $(filter-out $(KSPLICE_EXCLUDE_MATCH),$(filter $(KSPLICE_EXTRA_MATCH),$(lib-y) $(real-objs-m) $(real-objs-y)))
15 ksplice-objs = $(foreach o,$(1),$(o:=.KSPLICE) $(addsuffix .KSPLICE_old_code,$(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_new_code) $(<:.KSPLICE=.KSPLICE_old_code) $(KSPLICE_KMODSRC)/
32 rule_ksplice-mod = if [ -s $< ]; then $(echo-cmd) $(cmd_$(1)); fi
33 quiet_cmd_ksplice-old-code = OLDCODE $(@:.KSPLICE_old_code=)
34 cmd_ksplice-old-code = $(ksplice-script) old_code $@
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_%=%)
44 ifeq ($(obj),)
46 ifneq ($(wildcard include/linux/compile.h),)
47 MAKE += --old-file=include/linux/compile.h
48 endif
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
53 endif
54 include $(if $(KBUILD_SRC),$(KBUILD_SRC)/)Makefile
56 ifneq ($(skip-makefile),)
58 PHONY += __ksplice
59 __ksplice: FORCE
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)
65 else    # skip-makefile
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
79         $(Q)touch $@
81 endif   # KSPLICE_MODE
83 ifneq ($(filter snap diff,$(KSPLICE_MODE)),)
85 ksplice-mods += vmlinux
86 ifdef KSPLICE_BUILD_MODULES
87 ksplice-deps += ksplice_modpost
88 endif
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
102 endif   # KSPLICE_MODE
104 ifeq ($(KSPLICE_MODE),modinst)
106 ksplice-deps += ksplice_modinst
107 PHONY += ksplice_modinst
108 ksplice_modinst:
109         $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
111 endif   # KSPLICE_MODE
113 endif   # skip-makefile
115 else    # obj
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_%)
123 endif   # KSPLICE_MODE
125 ifneq ($(filter snap diff,$(KSPLICE_MODE)),)
127 ifdef KSPLICE_BUILD_MODULES
128 KBUILD_MODULES = 1
129 endif
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
136 endif
137 ksplice-deps += $(subdir-ym) $(always)
139 ifdef builtin-target
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)
144 endif
146 ifdef lib-target
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)
151 endif
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))
164 else
165 $(obj)/%.o.KSPLICE: $(obj)/%.o
166         $(call cmd,ksplice-diff)
167 endif
169 $(obj)/%.lds.KSPLICE:
170         $(call cmd,ksplice-ignore)
172 $(sort $(subdir-obj-y:=.KSPLICE)): $(subdir-ym) ;
174 ifeq ($(MAKECMDGOALS),missing-syscalls)
175 cmd = @:
176 endif
178 endif   # KSPLICE_MODE
180 endif   # obj
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)
190 endif
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
195 ifdef KSPLICE_SERIES
196         $(call cmd,ksplice-freeze)
197 else
198         $(call cmd,ksplice-revert)
199 endif
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_new_code) $(ksplice-revert-snap-files:.KSPLICE_pre=.KSPLICE_old_code),$(wildcard $(obj)/*.KSPLICE_new_code $(obj)/*.KSPLICE_old_code))
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)
215 endif   # KSPLICE_MODE
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)
224 else
225 ksplice-deps += $(ksplice-modnames:%=$(obj)/%.o.KSPLICE)
226 endif
227 .SECONDARY: $(obj)/%.o.KSPLICE
229 $(obj)/%.o.KSPLICE_old_code: $(obj)/%.o.KSPLICE
230         $(call cmd,ksplice-old-code)
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)))))
241 endef
243 define ksplice-add-cow-check
244 $(v) = $$(ksplice-cow-check)$(value $(v))
246 endef
248 ksplice-cow-eval += $(foreach v,if_changed if_changed_dep if_changed_rule,$(ksplice-add-cow-check))
250 endif   # KSPLICE_MODE
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)
256 endif
258 endif   # KSPLICE_MODE
260 PHONY += __ksplice
261 __ksplice: $(ksplice-deps) $(ksplice-dirs)
262         @:
264 build := -f $(ksplice-makefile) obj
265 descend =$(Q)$(MAKE) $(build)=$(1) $(2)
267 PHONY += $(ksplice-dirs)
268 $(ksplice-dirs):
269         $(Q)$(MAKE) $(build)=$(@:_ksplice_%=%)
271 endif   # skip-makefile
273 $(eval $(ksplice-cow-eval))
275 PHONY += FORCE
276 FORCE:
278 .PHONY: $(PHONY)