]> rtime.felk.cvut.cz Git - jailhouse.git/blob - hypervisor/Makefile
core: Add asm-defines.h generation
[jailhouse.git] / hypervisor / Makefile
1 #
2 # Jailhouse, a Linux-based partitioning hypervisor
3 #
4 # Copyright (c) Siemens AG, 2013
5 # Copyright (c) Valentine Sinitsyn, 2014
6 #
7 # Authors:
8 #  Jan Kiszka <jan.kiszka@siemens.com>
9 #  Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
10 #
11 # This work is licensed under the terms of the GNU GPL, version 2.  See
12 # the COPYING file in the top-level directory.
13 #
14
15 LINUXINCLUDE := -I$(src)/arch/$(SRCARCH)/include -I$(src)/include
16 KBUILD_CFLAGS := -g -Os -Wall -Wstrict-prototypes -Wtype-limits \
17                  -Wmissing-declarations -Wmissing-prototypes \
18                  -fno-strict-aliasing -fno-pic -fno-common \
19                  -fno-stack-protector -fno-builtin-ffsl
20
21 ifeq ($(SRCARCH),x86)
22 KBUILD_CFLAGS += -mcmodel=kernel
23 KBUILD_CPPFLAGS += -m64
24 BUILD_VARIANTS := amd intel
25 endif
26
27 ifneq ($(wildcard $(obj)/include/jailhouse/config.h),)
28 KBUILD_CFLAGS += -include $(obj)/include/jailhouse/config.h
29 endif
30
31 CORE_OBJECTS = setup.o printk.o paging.o control.o lib.o
32
33 define filechk_version
34         $(src)/../scripts/gen_version_h $(src)/..
35 endef
36
37 clean-files := $(obj)/include/jailhouse/version.h
38
39 # This derives from the Linux kernel's asm-offsets.h generation infrastructure
40
41 define sed-y
42         "/^=>/{s:=>#\(.*\):/* \1 */:; \
43         s:^=>\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
44         s:^=>\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
45         s:=>::; p;}"
46 endef
47
48 quiet_cmd_defines = GEN     $@
49 define cmd_defines
50         (set -e; \
51          echo "#ifndef _GENERATED_ASM_DEFINES_H"; \
52          echo "#define _GENERATED_ASM_DEFINES_H"; \
53          echo "/*"; \
54          echo " * This file is autogenerated. If you need to change it,"; \
55          echo " * edit arch/$(SRCARCH)/asm-defines.c instead."; \
56          echo " *"; \
57          echo " * ALL MANUAL CHANGES TO THIS FILE WILL BE LOST!"; \
58          echo " */"; \
59          echo ""; \
60          sed -ne $(sed-y) $<; \
61          echo ""; \
62          echo "#endif" ) > $@
63 endef
64
65 defines-file := include/generated/asm-defines.h
66
67 targets := $(defines-file)
68
69 $(obj)/arch/$(SRCARCH)/asm-defines.s: $(src)/arch/$(SRCARCH)/asm-defines.c
70         $(call if_changed_dep,cc_s_c)
71
72 $(obj)/$(defines-file): $(obj)/arch/$(SRCARCH)/asm-defines.s
73         $(Q)mkdir -p $(dir $@)
74         $(call cmd,defines)
75
76 $(obj)/include/jailhouse/version.h: $(src)/Makefile FORCE
77         $(call filechk,version)
78
79 $(foreach co,$(CORE_OBJECTS),\
80         $(eval $(obj)/$(co): $(obj)/$(defines-file)))
81
82 $(obj)/setup.o: $(obj)/include/jailhouse/version.h
83
84 arch-builtin: $(obj)/$(defines-file) FORCE
85         $(Q)$(MAKE) $(build)=$(obj)/arch/$(SRCARCH)
86
87 always :=
88
89 define BUILD_JAILHOUSE_template
90 always += jailhouse$(1).bin
91
92 hypervisor$(1)-y := $$(CORE_OBJECTS) arch/$$(SRCARCH)/built-in$(1).o \
93         hypervisor.lds
94 targets += $$(hypervisor$(1)-y)
95
96 # Need fake recipe here so make will consider this a volatile target
97 $$(obj)/arch/$$(SRCARCH)/built-in$(1).o: arch-builtin
98         @
99
100 HYPERVISOR$(1)_OBJS = $$(addprefix $$(obj)/,$$(hypervisor$(1)-y))
101
102 LDFLAGS_hypervisor$(1).o := -T
103
104 targets += hypervisor$(1).o
105 $$(obj)/hypervisor$(1).o: $$(src)/hypervisor.lds $$(HYPERVISOR$(1)_OBJS)
106         $$(call if_changed,ld)
107
108 OBJCOPYFLAGS_jailhouse$(1).bin := -O binary -R .eh_frame
109
110 targets += jailhouse$(1).bin
111 $$(obj)/jailhouse$(1).bin: $$(obj)/hypervisor$(1).o
112         $$(call if_changed,objcopy)
113 endef
114
115 ifneq ($(BUILD_VARIANTS),)
116 $(foreach variant,$(BUILD_VARIANTS),\
117         $(eval $(call BUILD_JAILHOUSE_template,-$(variant))))
118 else
119 $(eval $(call BUILD_JAILHOUSE_template,))
120 endif
121
122 .PHONY: arch-builtin