xref: /kvm-unit-tests/x86/Makefile.common (revision d74708246bd9a593e03ecca476a5f1ed36e47288)
1#This is a make file with common rules for both x86 & x86-64
2
3all: directories test_cases
4
5cflatobjs += lib/pci.o
6cflatobjs += lib/pci-edu.o
7cflatobjs += lib/alloc.o
8cflatobjs += lib/auxinfo.o
9cflatobjs += lib/vmalloc.o
10cflatobjs += lib/alloc_page.o
11cflatobjs += lib/alloc_phys.o
12cflatobjs += lib/x86/setup.o
13cflatobjs += lib/x86/io.o
14cflatobjs += lib/x86/smp.o
15cflatobjs += lib/x86/vm.o
16cflatobjs += lib/x86/fwcfg.o
17cflatobjs += lib/x86/apic.o
18cflatobjs += lib/x86/atomic.o
19cflatobjs += lib/x86/desc.o
20cflatobjs += lib/x86/isr.o
21cflatobjs += lib/x86/acpi.o
22cflatobjs += lib/x86/stack.o
23cflatobjs += lib/x86/fault_test.o
24cflatobjs += lib/x86/delay.o
25
26OBJDIRS += lib/x86
27
28$(libcflat): LDFLAGS += -nostdlib
29$(libcflat): CFLAGS += -ffreestanding -I $(SRCDIR)/lib -I lib
30
31COMMON_CFLAGS += -m$(bits)
32ifneq ($(WA_DIVIDE),)
33COMMON_CFLAGS += -Wa,--divide
34endif
35COMMON_CFLAGS += -O1
36
37# stack.o relies on frame pointers.
38KEEP_FRAME_POINTER := y
39
40libgcc := $(shell $(CC) -m$(bits) --print-libgcc-file-name)
41
42# We want to keep intermediate file: %.elf and %.o
43.PRECIOUS: %.elf %.o
44
45FLATLIBS = lib/libcflat.a $(libgcc)
46%.elf: %.o $(FLATLIBS) $(SRCDIR)/x86/flat.lds $(cstart.o)
47	$(CC) $(CFLAGS) -nostdlib -o $@ -Wl,-T,$(SRCDIR)/x86/flat.lds \
48		$(filter %.o, $^) $(FLATLIBS)
49	@chmod a-x $@
50
51%.flat: %.elf
52	$(OBJCOPY) -O elf32-i386 $^ $@
53	@chmod a-x $@
54
55tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \
56               $(TEST_DIR)/smptest.flat  \
57               $(TEST_DIR)/realmode.flat $(TEST_DIR)/msr.flat \
58               $(TEST_DIR)/hypercall.flat $(TEST_DIR)/sieve.flat \
59               $(TEST_DIR)/kvmclock_test.flat  $(TEST_DIR)/eventinj.flat \
60               $(TEST_DIR)/s3.flat $(TEST_DIR)/pmu.flat $(TEST_DIR)/setjmp.flat \
61               $(TEST_DIR)/tsc_adjust.flat $(TEST_DIR)/asyncpf.flat \
62               $(TEST_DIR)/init.flat $(TEST_DIR)/smap.flat \
63               $(TEST_DIR)/hyperv_synic.flat $(TEST_DIR)/hyperv_stimer.flat \
64               $(TEST_DIR)/hyperv_connections.flat \
65               $(TEST_DIR)/umip.flat $(TEST_DIR)/tsx-ctrl.flat
66
67test_cases: $(tests-common) $(tests)
68
69$(TEST_DIR)/%.o: CFLAGS += -std=gnu99 -ffreestanding -I $(SRCDIR)/lib -I $(SRCDIR)/lib/x86 -I lib
70
71$(TEST_DIR)/realmode.elf: $(TEST_DIR)/realmode.o
72	$(CC) -m32 -nostdlib -o $@ -Wl,-m,elf_i386 \
73	      -Wl,-T,$(SRCDIR)/$(TEST_DIR)/realmode.lds $^
74
75$(TEST_DIR)/realmode.o: bits = $(if $(call cc-option,-m16,""),16,32)
76
77$(TEST_DIR)/kvmclock_test.elf: $(TEST_DIR)/kvmclock.o
78
79$(TEST_DIR)/hyperv_synic.elf: $(TEST_DIR)/hyperv.o
80
81$(TEST_DIR)/hyperv_stimer.elf: $(TEST_DIR)/hyperv.o
82
83$(TEST_DIR)/hyperv_connections.elf: $(TEST_DIR)/hyperv.o
84
85arch_clean:
86	$(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \
87	$(TEST_DIR)/.*.d lib/x86/.*.d \
88