meson: target
[qemu/ar7.git] / pc-bios / optionrom / Makefile
blob51cb6ca9d89099700ac0b9f1a18c9c630d7afeb6
1 CURRENT_MAKEFILE := $(realpath $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
2 SRC_DIR := $(dir $(CURRENT_MAKEFILE))
3 TOPSRC_DIR := $(SRC_DIR)/../..
4 VPATH = $(SRC_DIR)
6 all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin
7 # Dummy command so that make thinks it has done something
8 @true
10 include ../../config-host.mak
12 quiet-command = $(if $(V),$1,$(if $(2),@printf " %-7s %s\n" $2 $3 && $1, @$1))
13 cc-option = $(if $(shell $(CC) $1 -S -o /dev/null -xc /dev/null >/dev/null 2>&1 && echo OK), $1, $2)
15 # Compiling with no optimization creates ROMs that are too large
16 ifeq ($(lastword $(filter -O%, -O0 $(CFLAGS))),-O0)
17 override CFLAGS += -O2
18 endif
19 override CFLAGS += -march=i486
21 # Flags for dependency generation
22 override CPPFLAGS += -MMD -MP -MT $@ -MF $(@D)/$(*F).d
24 override CFLAGS += $(filter -W%, $(QEMU_CFLAGS))
25 override CFLAGS += $(CFLAGS_NOPIE) -ffreestanding -I$(TOPSRC_DIR)/include
26 override CFLAGS += $(call cc-option, -fno-stack-protector)
27 override CFLAGS += $(call cc-option, -m16)
29 ifeq ($(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.
36 override CFLAGS += $(call cc-option, -fno-toplevel-reorder)
37 override CFLAGS += $(call cc-option, -no-integrated-as)
38 override CFLAGS += -m32 -include $(SRC_DIR)/code16gcc.h
39 endif
41 Wa = -Wa,
42 override ASFLAGS += -32
43 override CFLAGS += $(call cc-option, $(Wa)-32)
46 LD_I386_EMULATION ?= elf_i386
47 override LDFLAGS = -m $(LD_I386_EMULATION) -T $(SRC_DIR)/flat.lds
48 override LDFLAGS += $(LDFLAGS_NOPIE)
50 all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin
52 pvh.img: pvh.o pvh_main.o
54 %.o: %.S
55 $(call quiet-command,$(CPP) $(CPPFLAGS) -c -o - $< | $(AS) $(ASFLAGS) -o $@,"AS","$@")
57 %.o: %.c
58 $(call quiet-command,$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@,"CC","$@")
60 %.img: %.o
61 $(call quiet-command,$(LD) $(LDFLAGS) -s -o $@ $^,"BUILD","$@")
63 %.raw: %.img
64 $(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@,"BUILD","$@")
66 %.bin: %.raw
67 $(call quiet-command,$(PYTHON) $(TOPSRC_DIR)/scripts/signrom.py $< $@,"SIGN","$@")
69 include $(wildcard *.d)
71 clean:
72 rm -f *.o *.d *.raw *.img *.bin *~
74 # suppress auto-removal of intermediate files
75 .SECONDARY:
77 .PHONY: all clean