xref: /openbmc/qemu/pc-bios/optionrom/Makefile (revision 64ed6f92)
1CURRENT_MAKEFILE := $(realpath $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
2SRC_DIR := $(dir $(CURRENT_MAKEFILE))
3TOPSRC_DIR := $(SRC_DIR)/../..
4VPATH = $(SRC_DIR)
5
6all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin
7# Dummy command so that make thinks it has done something
8	@true
9
10include ../../config-host.mak
11
12quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 && $1, @$1))
13cc-option = $(if $(shell $(CC) $1 -S -o /dev/null -xc /dev/null >/dev/null 2>&1 && echo OK), $1, $2)
14
15# Compiling with no optimization creates ROMs that are too large
16ifeq ($(lastword $(filter -O%, -O0 $(CFLAGS))),-O0)
17override CFLAGS += -O2
18endif
19override CFLAGS += -march=i486
20
21# Flags for dependency generation
22override CPPFLAGS += -MMD -MP -MT $@ -MF $(@D)/$(*F).d
23
24override CFLAGS += $(filter -W%, $(QEMU_CFLAGS))
25override CFLAGS += $(CFLAGS_NOPIE) -ffreestanding -I$(TOPSRC_DIR)/include
26override CFLAGS += $(call cc-option, -fno-stack-protector)
27override CFLAGS += $(call cc-option, -m16)
28
29ifeq ($(filter -m16, $(CFLAGS)),)
30# Attempt to work around compilers that lack -m16 (GCC <= 4.8, clang <= ??)
31# On GCC we add -fno-toplevel-reorder to keep the order of asm blocks with
32# respect to the rest of the code.  clang does not have -fno-toplevel-reorder,
33# but it places all asm blocks at the beginning and we're relying on it for
34# the option ROM header.  So just force clang not to use the integrated
35# assembler, which doesn't support .code16gcc.
36override CFLAGS += $(call cc-option, -fno-toplevel-reorder)
37override CFLAGS += $(call cc-option, -no-integrated-as)
38override CFLAGS += -m32 -include $(SRC_DIR)/code16gcc.h
39endif
40
41Wa = -Wa,
42override ASFLAGS += -32
43override CFLAGS += $(call cc-option, $(Wa)-32)
44
45
46LD_I386_EMULATION ?= elf_i386
47override LDFLAGS = -m $(LD_I386_EMULATION) -T $(SRC_DIR)/flat.lds
48override LDFLAGS += $(LDFLAGS_NOPIE)
49
50all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin
51
52pvh.img: pvh.o pvh_main.o
53
54%.o: %.S
55	$(call quiet-command,$(CPP) $(CPPFLAGS) -c -o - $< | $(AS) $(ASFLAGS) -o $@,"AS","$@")
56
57%.o: %.c
58	$(call quiet-command,$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@,"CC","$@")
59
60%.img: %.o
61	$(call quiet-command,$(LD) $(LDFLAGS) -s -o $@ $^,"BUILD","$@")
62
63%.raw: %.img
64	$(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@,"BUILD","$@")
65
66%.bin: %.raw
67	$(call quiet-command,$(PYTHON) $(TOPSRC_DIR)/scripts/signrom.py $< $@,"SIGN","$@")
68
69include $(wildcard *.d)
70
71clean:
72	rm -f *.o *.d *.raw *.img *.bin *~
73
74# suppress auto-removal of intermediate files
75.SECONDARY:
76
77.PHONY: all clean
78