2 # Define WERROR=0 to disable -Werror.
19 include config/utilities.mak
20 include config/feature-tests.mak
22 CC := $(CROSS_COMPILE)$(CC)
23 LD := $(CROSS_COMPILE)$(LD)
32 bindir = $(prefix)/$(bindir_relative)
34 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
35 bindir_SQ = $(subst ','\'',$(bindir))
40 GUEST_INIT := guest/init
42 OBJS += builtin-balloon.o
43 OBJS += builtin-debug.o
44 OBJS += builtin-help.o
45 OBJS += builtin-list.o
46 OBJS += builtin-stat.o
47 OBJS += builtin-pause.o
48 OBJS += builtin-resume.o
50 OBJS += builtin-setup.o
51 OBJS += builtin-stop.o
52 OBJS += builtin-version.o
55 OBJS += guest_compat.o
67 OBJS += virtio/console.o
71 OBJS += virtio/balloon.o
77 OBJS += net/uip/core.o
79 OBJS += net/uip/icmp.o
80 OBJS += net/uip/ipv4.o
84 OBJS += net/uip/csum.o
85 OBJS += net/uip/dhcp.o
89 OBJS += util/threadpool.o
90 OBJS += util/parse-options.o
91 OBJS += util/rbtree-interval.o
93 OBJS += util/read-write.o
96 OBJS += virtio/9p-pdu.o
98 OBJS += hw/pci-shmem.o
100 OBJS += builtin-sandbox.o
101 OBJS += virtio/mmio.o
103 # Translate uname -m into ARCH string
104 ARCH ?= $(shell uname -m | sed -e s/i.86/i386/ -e s/ppc.*/powerpc/)
108 DEFINES += -DCONFIG_X86_32
110 ifeq ($(ARCH),x86_64)
112 DEFINES += -DCONFIG_X86_64
115 LIBFDT_SRC = fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o fdt_strerror.o
116 LIBFDT_OBJS = $(patsubst %,../../scripts/dtc/libfdt/%,$(LIBFDT_SRC))
118 ### Arch-specific stuff
122 DEFINES += -DCONFIG_X86
125 OBJS += x86/interrupt.o
129 OBJS += x86/kvm-cpu.o
130 OBJS += x86/mptable.o
132 # Exclude BIOS object files from header dependencies.
133 OTHEROBJS += x86/bios.o
134 OTHEROBJS += x86/bios/bios-rom.o
135 ARCH_INCLUDE := x86/include
137 # POWER/ppc: Actually only support ppc64 currently.
138 ifeq ($(ARCH), powerpc)
139 DEFINES += -DCONFIG_PPC
140 OBJS += powerpc/boot.o
141 OBJS += powerpc/ioport.o
142 OBJS += powerpc/irq.o
143 OBJS += powerpc/kvm.o
144 OBJS += powerpc/cpu_info.o
145 OBJS += powerpc/kvm-cpu.o
146 OBJS += powerpc/spapr_hcall.o
147 OBJS += powerpc/spapr_rtas.o
148 OBJS += powerpc/spapr_hvcons.o
149 OBJS += powerpc/spapr_pci.o
150 OBJS += powerpc/xics.o
151 # We use libfdt, but it's sometimes not packaged 64bit. It's small too,
152 # so just build it in:
153 CFLAGS += -I../../scripts/dtc/libfdt
154 OTHEROBJS += $(LIBFDT_OBJS)
155 ARCH_INCLUDE := powerpc/include
161 ifeq (,$(ARCH_INCLUDE))
162 UNSUPP_ERR = @echo "This architecture is not supported in kvmtool." && exit 1
169 # Detect optional features.
170 # On a given system, some libs may link statically, some may not; so, check
171 # both and only build those that link!
173 FLAGS_BFD := $(CFLAGS) -lbfd
174 ifeq ($(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD)),y)
175 CFLAGS_DYNOPT += -DCONFIG_HAS_BFD
176 OBJS_DYNOPT += symbol.o
179 ifeq ($(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD) -static),y)
180 CFLAGS_STATOPT += -DCONFIG_HAS_BFD
181 OBJS_STATOPT += symbol.o
182 LIBS_STATOPT += -lbfd
185 FLAGS_VNCSERVER := $(CFLAGS) -lvncserver
186 ifeq ($(call try-cc,$(SOURCE_VNCSERVER),$(FLAGS_VNCSERVER)),y)
187 OBJS_DYNOPT += ui/vnc.o
188 CFLAGS_DYNOPT += -DCONFIG_HAS_VNCSERVER
189 LIBS_DYNOPT += -lvncserver
191 ifeq ($(call try-cc,$(SOURCE_VNCSERVER),$(FLAGS_VNCSERVER) -static),y)
192 OBJS_STATOPT += ui/vnc.o
193 CFLAGS_STATOPT += -DCONFIG_HAS_VNCSERVER
194 LIBS_STATOPT += -lvncserver
197 FLAGS_SDL := $(CFLAGS) -lSDL
198 ifeq ($(call try-cc,$(SOURCE_SDL),$(FLAGS_SDL)),y)
199 OBJS_DYNOPT += ui/sdl.o
200 CFLAGS_DYNOPT += -DCONFIG_HAS_SDL
203 ifeq ($(call try-cc,$(SOURCE_SDL),$(FLAGS_SDL) -static), y)
204 OBJS_STATOPT += ui/sdl.o
205 CFLAGS_STATOPT += -DCONFIG_HAS_SDL
206 LIBS_STATOPT += -lSDL
209 FLAGS_ZLIB := $(CFLAGS) -lz
210 ifeq ($(call try-cc,$(SOURCE_ZLIB),$(FLAGS_ZLIB)),y)
211 CFLAGS_DYNOPT += -DCONFIG_HAS_ZLIB
214 ifeq ($(call try-cc,$(SOURCE_ZLIB),$(FLAGS_ZLIB) -static),y)
215 CFLAGS_STATOPT += -DCONFIG_HAS_ZLIB
219 FLAGS_AIO := $(CFLAGS) -laio
220 ifeq ($(call try-cc,$(SOURCE_AIO),$(FLAGS_AIO)),y)
221 CFLAGS_DYNOPT += -DCONFIG_HAS_AIO
224 ifeq ($(call try-cc,$(SOURCE_AIO),$(FLAGS_AIO) -static),y)
225 CFLAGS_STATOPT += -DCONFIG_HAS_AIO
226 LIBS_STATOPT += -laio
229 ifneq ($(call try-build,$(SOURCE_STATIC),-static,),y)
230 $(error No static libc found. Please install glibc-static package.)
239 DEPS := $(patsubst %.o,%.d,$(OBJS))
241 DEFINES += -D_FILE_OFFSET_BITS=64
242 DEFINES += -D_GNU_SOURCE
243 DEFINES += -DKVMTOOLS_VERSION='"$(KVMTOOLS_VERSION)"'
244 DEFINES += -DBUILD_ARCH='"$(ARCH)"'
246 KVM_INCLUDE := include
247 CFLAGS += $(CPPFLAGS) $(DEFINES) -I$(KVM_INCLUDE) -I$(ARCH_INCLUDE) -I$(KINCL_PATH)/include/uapi -I$(KINCL_PATH)/include -I$(KINCL_PATH)/arch/$(ARCH)/include/ -O2 -fno-strict-aliasing -g -flto
250 WARNINGS += -Wcast-align
251 WARNINGS += -Wformat=2
252 WARNINGS += -Winit-self
253 WARNINGS += -Wmissing-declarations
254 WARNINGS += -Wmissing-prototypes
255 WARNINGS += -Wnested-externs
256 WARNINGS += -Wno-system-headers
257 WARNINGS += -Wold-style-definition
258 WARNINGS += -Wredundant-decls
259 WARNINGS += -Wsign-compare
260 WARNINGS += -Wstrict-prototypes
262 WARNINGS += -Wvolatile-register-var
263 WARNINGS += -Wwrite-strings
265 CFLAGS += $(WARNINGS)
267 # Some targets may use 'external' sources that don't build totally cleanly.
268 CFLAGS_EASYGOING := $(CFLAGS)
274 all: arch_support_check $(PROGRAM) $(PROGRAM_ALIAS) $(GUEST_INIT)
279 KVMTOOLS-VERSION-FILE:
280 @$(SHELL_PATH) util/KVMTOOLS-VERSION-GEN $(OUTPUT)
281 -include $(OUTPUT)KVMTOOLS-VERSION-FILE
283 # When building -static all objects are built with appropriate flags, which
284 # may differ between static & dynamic .o. The objects are separated into
285 # .o and .static.o. See the %.o: %.c rules below.
287 # $(OTHEROBJS) are things that do not get substituted like this.
289 STATIC_OBJS = $(patsubst %.o,%.static.o,$(OBJS) $(OBJS_STATOPT))
290 GUEST_OBJS = guest/guest_init.o
292 $(PROGRAM)-static: $(DEPS) $(STATIC_OBJS) $(OTHEROBJS) $(GUEST_INIT)
294 $(Q) $(CC) -static $(CFLAGS) $(STATIC_OBJS) $(OTHEROBJS) $(GUEST_OBJS) $(LIBS) $(LIBS_STATOPT) -o $@
296 $(PROGRAM): $(DEPS) $(OBJS) $(OBJS_DYNOPT) $(OTHEROBJS) $(GUEST_INIT)
298 $(Q) $(CC) $(CFLAGS) $(OBJS) $(OBJS_DYNOPT) $(OTHEROBJS) $(GUEST_OBJS) $(LIBS) $(LIBS_DYNOPT) -o $@
300 $(PROGRAM_ALIAS): $(PROGRAM)
302 $(Q) ln -f $(PROGRAM) $@
304 $(GUEST_INIT): guest/init.c
306 $(Q) $(CC) -static guest/init.c -o $@
307 $(Q) $(LD) -r -b binary -o guest/guest_init.o $(GUEST_INIT)
311 util/rbtree.d: ../../lib/rbtree.c
312 $(Q) $(CC) -M -MT util/rbtree.o $(CFLAGS) $< -o $@
315 $(Q) $(CC) -M -MT $(patsubst %.d,%.o,$@) $(CFLAGS) $< -o $@
318 $(Q) $(CC) -o $@ -S $(CFLAGS) -fverbose-asm $<
320 # The header file common-cmds.h is needed for compilation of builtin-help.c.
321 builtin-help.d: $(KVM_INCLUDE)/common-cmds.h
325 # This rule relaxes the -Werror on libfdt, since for now it still has
326 # a bunch of warnings. :(
327 ../../scripts/dtc/libfdt/%.o: ../../scripts/dtc/libfdt/%.c
330 $(Q) $(CHECK) -c $(CFLAGS_EASYGOING) $< -o $@
333 $(Q) $(CC) -c $(CFLAGS_EASYGOING) $< -o $@
335 util/rbtree.static.o util/rbtree.o: ../../lib/rbtree.c
338 $(Q) $(CHECK) -c $(CFLAGS) $< -o $@
341 $(Q) $(CC) -c $(CFLAGS) $< -o $@
346 $(Q) $(CHECK) -c $(CFLAGS) $(CFLAGS_STATOPT) $< -o $@
349 $(Q) $(CC) -c $(CFLAGS) $(CFLAGS_STATOPT) $< -o $@
354 $(Q) $(CHECK) -c $(CFLAGS) $(CFLAGS_DYNOPT) $< -o $@
357 $(Q) $(CC) -c $(CFLAGS) $(CFLAGS_DYNOPT) $< -o $@
360 $(KVM_INCLUDE)/common-cmds.h: util/generate-cmdlist.sh command-list.txt
362 $(KVM_INCLUDE)/common-cmds.h: $(wildcard Documentation/kvm-*.txt)
364 $(Q) util/generate-cmdlist.sh > $@+ && mv $@+ $@
367 # BIOS assembly weirdness
370 BIOS_CFLAGS += -march=i386
371 BIOS_CFLAGS += -mregparm=3
373 BIOS_CFLAGS += -fno-stack-protector
374 BIOS_CFLAGS += -I../../arch/$(ARCH)
376 x86/bios.o: x86/bios/bios.bin x86/bios/bios-rom.h
378 x86/bios/bios.bin.elf: x86/bios/entry.S x86/bios/e820.c x86/bios/int10.c x86/bios/int15.c x86/bios/rom.ld.S
379 $(E) " CC x86/bios/memcpy.o"
380 $(Q) $(CC) -include code16gcc.h $(CFLAGS) $(BIOS_CFLAGS) -c -s x86/bios/memcpy.c -o x86/bios/memcpy.o
381 $(E) " CC x86/bios/e820.o"
382 $(Q) $(CC) -include code16gcc.h $(CFLAGS) $(BIOS_CFLAGS) -c -s x86/bios/e820.c -o x86/bios/e820.o
383 $(E) " CC x86/bios/int10.o"
384 $(Q) $(CC) -include code16gcc.h $(CFLAGS) $(BIOS_CFLAGS) -c -s x86/bios/int10.c -o x86/bios/int10.o
385 $(E) " CC x86/bios/int15.o"
386 $(Q) $(CC) -include code16gcc.h $(CFLAGS) $(BIOS_CFLAGS) -c -s x86/bios/int15.c -o x86/bios/int15.o
387 $(E) " CC x86/bios/entry.o"
388 $(Q) $(CC) $(CFLAGS) $(BIOS_CFLAGS) -c -s x86/bios/entry.S -o x86/bios/entry.o
390 $(Q) $(LD) -T x86/bios/rom.ld.S -o x86/bios/bios.bin.elf x86/bios/memcpy.o x86/bios/entry.o x86/bios/e820.o x86/bios/int10.o x86/bios/int15.o
392 x86/bios/bios.bin: x86/bios/bios.bin.elf
394 $(Q) objcopy -O binary -j .text x86/bios/bios.bin.elf x86/bios/bios.bin
396 x86/bios/bios-rom.o: x86/bios/bios-rom.S x86/bios/bios.bin x86/bios/bios-rom.h
398 $(Q) $(CC) -c $(CFLAGS) x86/bios/bios-rom.S -o x86/bios/bios-rom.o
400 x86/bios/bios-rom.h: x86/bios/bios.bin.elf
402 $(Q) cd x86/bios && sh gen-offsets.sh > bios-rom.h && cd ..
406 ./$(PROGRAM) run tests/pit/tick.bin
407 ./$(PROGRAM) run -d tests/boot/boot_test.iso -p "init=init"
412 $(Q) $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
413 $(Q) $(INSTALL) $(PROGRAM) '$(DESTDIR_SQ)$(bindir_SQ)'
418 $(Q) rm -f x86/bios/*.bin
419 $(Q) rm -f x86/bios/*.elf
420 $(Q) rm -f x86/bios/*.o
421 $(Q) rm -f x86/bios/bios-rom.h
422 $(Q) rm -f tests/boot/boot_test.iso
423 $(Q) rm -rf tests/boot/rootfs/
424 $(Q) rm -f $(DEPS) $(OBJS) $(OTHEROBJS) $(OBJS_DYNOPT) $(STATIC_OBJS) $(PROGRAM) $(PROGRAM_ALIAS) $(PROGRAM)-static $(GUEST_INIT) $(GUEST_OBJS)
428 $(Q) rm -f $(KVM_INCLUDE)/common-cmds.h
429 $(Q) rm -f KVMTOOLS-VERSION-FILE
436 $(Q) mknod $@ char 10 232
444 $(Q) $(FIND) . -name '*.[hcS]' -print | xargs etags -a
450 $(Q) $(FIND) . -name '*.[hcS]' -print | xargs ctags -a
455 $(Q) $(FIND) . -name '*.[hcS]' -print > cscope.files