xref: /kvm-unit-tests/arm/Makefile.common (revision 9c92b28e6b7b504c6319dbd2110c9f9a843ea48a)
1#
2# arm common makefile
3#
4# Authors: Andrew Jones <drjones@redhat.com>
5#
6
7tests-common  = $(TEST_DIR)/selftest.$(exe)
8tests-common += $(TEST_DIR)/spinlock-test.$(exe)
9tests-common += $(TEST_DIR)/pci-test.$(exe)
10tests-common += $(TEST_DIR)/pmu.$(exe)
11tests-common += $(TEST_DIR)/gic.$(exe)
12tests-common += $(TEST_DIR)/psci.$(exe)
13tests-common += $(TEST_DIR)/sieve.$(exe)
14tests-common += $(TEST_DIR)/pl031.$(exe)
15tests-common += $(TEST_DIR)/dummy.$(exe)
16
17tests-all = $(tests-common) $(tests)
18all: directories $(tests-all)
19
20$(TEST_DIR)/sieve.elf: AUXFLAGS = 0x1
21
22##################################################################
23AUXFLAGS ?= 0x0
24
25# stack.o relies on frame pointers.
26KEEP_FRAME_POINTER := y
27
28CFLAGS += -std=gnu99
29CFLAGS += -ffreestanding
30CFLAGS += -O2
31CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib
32
33# We want to keep intermediate files
34.PRECIOUS: %.elf %.o
35
36asm-offsets = lib/$(ARCH)/asm-offsets.h
37include $(SRCDIR)/scripts/asm-offsets.mak
38
39cflatobjs += lib/util.o lib/getchar.o
40cflatobjs += lib/alloc_phys.o
41cflatobjs += lib/alloc_page.o
42cflatobjs += lib/vmalloc.o
43cflatobjs += lib/alloc.o
44cflatobjs += lib/devicetree.o
45cflatobjs += lib/migrate.o
46cflatobjs += lib/on-cpus.o
47cflatobjs += lib/pci.o
48cflatobjs += lib/pci-host-generic.o
49cflatobjs += lib/pci-testdev.o
50cflatobjs += lib/virtio.o
51cflatobjs += lib/virtio-mmio.o
52cflatobjs += lib/chr-testdev.o
53cflatobjs += lib/arm/io.o
54cflatobjs += lib/arm/setup.o
55cflatobjs += lib/arm/mmu.o
56cflatobjs += lib/arm/bitops.o
57cflatobjs += lib/arm/psci.o
58cflatobjs += lib/arm/smp.o
59cflatobjs += lib/arm/delay.o
60cflatobjs += lib/arm/gic.o lib/arm/gic-v2.o lib/arm/gic-v3.o
61cflatobjs += lib/arm/timer.o
62ifeq ($(CONFIG_EFI),y)
63cflatobjs += lib/efi.o
64endif
65
66OBJDIRS += lib/arm
67
68libeabi = lib/arm/libeabi.a
69eabiobjs = lib/arm/eabi_compat.o
70
71FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libeabi)
72
73ifeq ($(CONFIG_EFI),y)
74%.aux.o: $(SRCDIR)/lib/auxinfo.c
75	$(CC) $(CFLAGS) -c -o $@ $^ \
76		-DPROGNAME=\"$(@:.aux.o=.efi)\" -DAUXFLAGS=$(AUXFLAGS)
77
78%.so: EFI_LDFLAGS += -defsym=EFI_SUBSYSTEM=0xa --no-undefined
79%.so: %.o $(FLATLIBS) $(SRCDIR)/arm/efi/elf_aarch64_efi.lds $(cstart.o) %.aux.o
80	$(LD) $(EFI_LDFLAGS) -o $@ -T $(SRCDIR)/arm/efi/elf_aarch64_efi.lds \
81		$(filter %.o, $^) $(FLATLIBS) $(EFI_LIBS)
82
83%.efi: %.so
84	$(call arch_elf_check, $^)
85	$(OBJCOPY) --only-keep-debug $^ $@.debug
86	$(OBJCOPY) --strip-debug $^
87	$(OBJCOPY) --add-gnu-debuglink=$@.debug $^
88	$(OBJCOPY) \
89		-j .text -j .sdata -j .data -j .dynamic -j .dynsym \
90		-j .rel -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* \
91		-j .reloc \
92		-O binary $^ $@
93else
94%.aux.o: $(SRCDIR)/lib/auxinfo.c
95	$(CC) $(CFLAGS) -c -o $@ $^ \
96		-DPROGNAME=\"$(@:.aux.o=.flat)\" -DAUXFLAGS=$(AUXFLAGS)
97
98%.elf: LDFLAGS += $(arch_LDFLAGS)
99%.elf: %.o $(FLATLIBS) $(SRCDIR)/arm/flat.lds $(cstart.o) %.aux.o
100	$(LD) $(LDFLAGS) -o $@ -T $(SRCDIR)/arm/flat.lds \
101		$(filter %.o, $^) $(FLATLIBS)
102	@chmod a-x $@
103
104%.flat: %.elf
105	$(call arch_elf_check, $^)
106	$(OBJCOPY) -O binary $^ $@
107	@chmod a-x $@
108endif
109
110$(libeabi): $(eabiobjs)
111	$(AR) rcs $@ $^
112
113arm_clean: asm_offsets_clean
114	$(RM) $(TEST_DIR)/*.{o,flat,elf,so,efi,debug} $(libeabi) $(eabiobjs) \
115	      $(TEST_DIR)/.*.d $(TEST_DIR)/efi/.*.d lib/arm/.*.d
116
117generated-files = $(asm-offsets)
118$(tests-all:.$(exe)=.o) $(cstart.o) $(cflatobjs): $(generated-files)
119