1include $(XEN_ROOT)/Config.mk
2
3ifneq ($(CONFIG_COMPAT),)
4
5compat-arch-$(CONFIG_X86) := x86_32
6
7headers-y := \
8    compat/callback.h \
9    compat/elfnote.h \
10    compat/event_channel.h \
11    compat/features.h \
12    compat/grant_table.h \
13    compat/kexec.h \
14    compat/memory.h \
15    compat/nmi.h \
16    compat/physdev.h \
17    compat/platform.h \
18    compat/sched.h \
19    compat/tmem.h \
20    compat/trace.h \
21    compat/vcpu.h \
22    compat/version.h \
23    compat/xen.h \
24    compat/xenoprof.h
25headers-$(CONFIG_X86)     += compat/arch-x86/pmu.h
26headers-$(CONFIG_X86)     += compat/arch-x86/xen-mca.h
27headers-$(CONFIG_X86)     += compat/arch-x86/xen.h
28headers-$(CONFIG_X86)     += compat/arch-x86/xen-$(compat-arch-y).h
29headers-$(CONFIG_X86)     += compat/hvm/hvm_vcpu.h
30headers-$(CONFIG_X86)     += compat/hvm/dm_op.h
31headers-y                 += compat/arch-$(compat-arch-y).h compat/pmu.h compat/xlat.h
32headers-$(CONFIG_FLASK)   += compat/xsm/flask_op.h
33
34cppflags-y                := -include public/xen-compat.h -DXEN_GENERATING_COMPAT_HEADERS
35cppflags-$(CONFIG_X86)    += -m32
36
37# 8-byte types are 4-byte aligned on x86_32 ...
38prefix-$(CONFIG_X86)      := \#pragma pack(4)
39suffix-$(CONFIG_X86)      := \#pragma pack()
40
41endif
42
43public-$(CONFIG_X86) := $(wildcard public/arch-x86/*.h public/arch-x86/*/*.h)
44public-$(CONFIG_ARM) := $(wildcard public/arch-arm/*.h public/arch-arm/*/*.h)
45
46.PHONY: all
47all: $(headers-y)
48
49compat/%.h: compat/%.i Makefile $(BASEDIR)/tools/compat-build-header.py
50	set -e; id=_$$(echo $@ | tr '[:lower:]-/.' '[:upper:]___'); \
51	echo "#ifndef $$id" >$@.new; \
52	echo "#define $$id" >>$@.new; \
53	echo "#include <xen/compat.h>" >>$@.new; \
54	$(if $(filter-out compat/arch-%.h,$@),echo "#include <$(patsubst compat/%,public/%,$@)>" >>$@.new;) \
55	$(if $(prefix-y),echo "$(prefix-y)" >>$@.new;) \
56	grep -v '^# [0-9]' $< | \
57	$(PYTHON) $(BASEDIR)/tools/compat-build-header.py | uniq >>$@.new; \
58	$(if $(suffix-y),echo "$(suffix-y)" >>$@.new;) \
59	echo "#endif /* $$id */" >>$@.new
60	mv -f $@.new $@
61
62compat/%.i: compat/%.c Makefile
63	$(CPP) $(filter-out -M% %.d -include %/include/xen/config.h,$(CFLAGS)) $(cppflags-y) -o $@ $<
64
65compat/%.c: public/%.h xlat.lst Makefile $(BASEDIR)/tools/compat-build-source.py
66	mkdir -p $(@D)
67	grep -v 'DEFINE_XEN_GUEST_HANDLE(long)' $< | \
68	$(PYTHON) $(BASEDIR)/tools/compat-build-source.py >$@.new
69	mv -f $@.new $@
70
71compat/.xlat/%.h: compat/%.h compat/.xlat/%.lst $(BASEDIR)/tools/get-fields.sh Makefile
72	export PYTHON=$(PYTHON); \
73	while read what name; do \
74		$(SHELL) $(BASEDIR)/tools/get-fields.sh "$$what" compat_$$name $< || exit $$?; \
75	done <$(patsubst compat/%,compat/.xlat/%,$(basename $<)).lst >$@.new
76	mv -f $@.new $@
77
78.PRECIOUS: compat/.xlat/%.lst
79compat/.xlat/%.lst: xlat.lst Makefile
80	mkdir -p $(@D)
81	grep -v '^[[:blank:]]*#' $< | sed -ne 's,@arch@,$(compat-arch-y),g' -re 's,[[:blank:]]+$*\.h[[:blank:]]*$$,,p' >$@.new
82	$(call move-if-changed,$@.new,$@)
83
84xlat-y := $(shell sed -ne 's,@arch@,$(compat-arch-y),g' -re 's,^[?!][[:blank:]]+[^[:blank:]]+[[:blank:]]+,,p' xlat.lst | uniq)
85xlat-y := $(filter $(patsubst compat/%,%,$(headers-y)),$(xlat-y))
86
87compat/xlat.h: $(addprefix compat/.xlat/,$(xlat-y)) Makefile
88	cat $(filter %.h,$^) >$@.new
89	mv -f $@.new $@
90
91ifeq ($(XEN_TARGET_ARCH),$(XEN_COMPILE_ARCH))
92
93all: headers.chk headers99.chk headers++.chk
94
95PUBLIC_HEADERS := $(filter-out public/arch-% public/dom0_ops.h, $(wildcard public/*.h public/*/*.h) $(public-y))
96
97PUBLIC_C99_HEADERS := public/io/9pfs.h public/io/pvcalls.h
98PUBLIC_ANSI_HEADERS := $(filter-out public/%ctl.h public/xsm/% public/%hvm/save.h $(PUBLIC_C99_HEADERS), $(PUBLIC_HEADERS))
99
100public/io/9pfs.h-prereq := string
101public/io/pvcalls.h-prereq := string
102
103headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile
104	for i in $(filter %.h,$^); do \
105	    $(CC) -x c -ansi -Wall -Werror -include stdint.h \
106	          -S -o /dev/null $$i || exit 1; \
107	    echo $$i; \
108	done >$@.new
109	mv $@.new $@
110
111headers99.chk: $(PUBLIC_C99_HEADERS) Makefile
112	rm -f $@.new
113	$(foreach i, $(filter %.h,$^),                                        \
114	    echo "#include "\"$(i)\"                                          \
115	    | $(CC) -x c -std=c99 -Wall -Werror                               \
116	      -include stdint.h $(foreach j, $($(i)-prereq), -include $(j).h) \
117	      -S -o /dev/null -                                               \
118	    || exit $$?; echo $(i) >> $@.new;)
119	mv $@.new $@
120
121headers++.chk: $(PUBLIC_HEADERS) Makefile
122	rm -f $@.new
123	if ! $(CXX) -v >/dev/null 2>&1; then                                  \
124	    touch $@.new;                                                     \
125	    exit 0;                                                           \
126	fi;                                                                   \
127	$(foreach i, $(filter %.h,$^),                                        \
128	    echo "#include "\"$(i)\"                                          \
129	    | $(CXX) -x c++ -std=gnu++98 -Wall -Werror -D__XEN_TOOLS__        \
130	      -include stdint.h -include public/xen.h                         \
131	      $(foreach j, $($(i)-prereq), -include c$(j)) -S -o /dev/null -  \
132	    || exit $$?; echo $(i) >> $@.new;)
133	mv $@.new $@
134
135endif
136
137ifeq ($(XEN_TARGET_ARCH),x86_64)
138
139$(BASEDIR)/include/asm-x86/cpuid-autogen.h: $(BASEDIR)/include/public/arch-x86/cpufeatureset.h $(BASEDIR)/tools/gen-cpuid.py FORCE
140	$(PYTHON) $(BASEDIR)/tools/gen-cpuid.py -i $^ -o $@.new
141	$(call move-if-changed,$@.new,$@)
142
143all: $(BASEDIR)/include/asm-x86/cpuid-autogen.h
144endif
145
146clean::
147	rm -rf compat config generated headers*.chk
148	rm -f $(BASEDIR)/include/asm-x86/cpuid-autogen.h
149