diff mbox series

[3/6] meson: convert pc-bios/optionrom

Message ID 20200918204759.225810-4-marcandre.lureau@redhat.com
State New
Headers show
Series Convert pc-bios Makefiles to meson | expand

Commit Message

Marc-André Lureau Sept. 18, 2020, 8:47 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Checking for linker emulation is a bit tricky with meson, since it
actually tries to compile a file with a main().

I didn't bother to port the Darwin or SunOS check, as they are
quite old, and not very specific to the compiler version/issue, so they
might be outdated.

Use a subproject: this is a simple workaround to avoid the incompatible
flags (such as gprof) that are set globally for the rest of QEMU.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 configure                     | 16 --------
 pc-bios/meson.build           |  4 ++
 pc-bios/optionrom/Makefile    | 73 -----------------------------------
 pc-bios/optionrom/meson.build | 73 +++++++++++++++++++++++++++++++++++
 subprojects/optionrom         |  1 +
 5 files changed, 78 insertions(+), 89 deletions(-)
 delete mode 100644 pc-bios/optionrom/Makefile
 create mode 100644 pc-bios/optionrom/meson.build
 create mode 120000 subprojects/optionrom
diff mbox series

Patch

diff --git a/configure b/configure
index 3a8733c9be..4e56edc70c 100755
--- a/configure
+++ b/configure
@@ -6441,22 +6441,7 @@  if test "$guest_agent_msi" = "yes"; then
   esac
 fi
 
-# Mac OS X ships with a broken assembler
 roms=
-if { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \
-        test "$targetos" != "Darwin" && test "$targetos" != "SunOS" && \
-        test "$softmmu" = yes ; then
-    # Different host OS linkers have different ideas about the name of the ELF
-    # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd
-    # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe.
-    for emu in elf_i386 elf_i386_fbsd elf_i386_obsd i386pe; do
-        if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
-            ld_i386_emulation="$emu"
-            roms="optionrom"
-            break
-        fi
-    done
-fi
 
 # Only build s390-ccw bios if we're on s390x and the compiler has -march=z900
 if test "$cpu" = "s390x" ; then
@@ -7861,7 +7846,6 @@  DIRS="$DIRS contrib/plugins/"
 LINKS="Makefile"
 LINKS="$LINKS tests/tcg/lm32/Makefile"
 LINKS="$LINKS tests/tcg/Makefile.target"
-LINKS="$LINKS pc-bios/optionrom/Makefile"
 LINKS="$LINKS roms/seabios/Makefile"
 LINKS="$LINKS pc-bios/qemu-icon.bmp"
 LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
diff --git a/pc-bios/meson.build b/pc-bios/meson.build
index e5139b3ef5..d25585ca97 100644
--- a/pc-bios/meson.build
+++ b/pc-bios/meson.build
@@ -92,6 +92,10 @@  endif
 subdir('descriptors')
 subdir('keymaps')
 
+if host_machine.cpu_family() in ['x86', 'x86_64']
+  subproject('optionrom')
+endif
+
 if host_machine.cpu_family() == 's390x' and cc.has_argument('-march=z900')
   subproject('s390-ccw')
 endif
diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile
deleted file mode 100644
index 084fc10f05..0000000000
--- a/pc-bios/optionrom/Makefile
+++ /dev/null
@@ -1,73 +0,0 @@ 
-CURRENT_MAKEFILE := $(realpath $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
-SRC_DIR := $(dir $(CURRENT_MAKEFILE))
-TOPSRC_DIR := $(SRC_DIR)/../..
-VPATH = $(SRC_DIR)
-
-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin
-# Dummy command so that make thinks it has done something
-	@true
-
-include ../../config-host.mak
-CFLAGS = -O2 -g
-
-quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 && $1, @$1))
-cc-option = $(if $(shell $(CC) $1 -c -o /dev/null -xc /dev/null >/dev/null 2>&1 && echo OK), $1, $2)
-
-override CFLAGS += -march=i486 -Wall
-
-# Flags for dependency generation
-override CPPFLAGS += -MMD -MP -MT $@ -MF $(@D)/$(*F).d
-
-override CFLAGS += $(filter -W%, $(QEMU_CFLAGS))
-override CFLAGS += $(CFLAGS_NOPIE) -ffreestanding -I$(TOPSRC_DIR)/include
-override CFLAGS += $(call cc-option, -fno-stack-protector)
-override CFLAGS += $(call cc-option, -m16)
-
-ifeq ($(filter -m16, $(CFLAGS)),)
-# Attempt to work around compilers that lack -m16 (GCC <= 4.8, clang <= ??)
-# On GCC we add -fno-toplevel-reorder to keep the order of asm blocks with
-# respect to the rest of the code.  clang does not have -fno-toplevel-reorder,
-# but it places all asm blocks at the beginning and we're relying on it for
-# the option ROM header.  So just force clang not to use the integrated
-# assembler, which doesn't support .code16gcc.
-override CFLAGS += $(call cc-option, -fno-toplevel-reorder)
-override CFLAGS += $(call cc-option, -no-integrated-as)
-override CFLAGS += -m32 -include $(SRC_DIR)/code16gcc.h
-endif
-
-Wa = -Wa,
-override ASFLAGS += -32
-override CFLAGS += $(call cc-option, $(Wa)-32)
-
-LD_I386_EMULATION ?= elf_i386
-override LDFLAGS = -m $(LD_I386_EMULATION) -T $(SRC_DIR)/flat.lds
-override LDFLAGS += $(LDFLAGS_NOPIE)
-
-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin
-
-pvh.img: pvh.o pvh_main.o
-
-%.o: %.S
-	$(call quiet-command,$(CPP) $(CPPFLAGS) -c -o - $< | $(AS) $(ASFLAGS) -o $@,"AS","$@")
-
-%.o: %.c
-	$(call quiet-command,$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@,"CC","$@")
-
-%.img: %.o
-	$(call quiet-command,$(LD) $(LDFLAGS) -s -o $@ $^,"BUILD","$@")
-
-%.raw: %.img
-	$(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@,"BUILD","$@")
-
-%.bin: %.raw
-	$(call quiet-command,$(PYTHON) $(TOPSRC_DIR)/scripts/signrom.py $< $@,"SIGN","$@")
-
-include $(wildcard *.d)
-
-clean:
-	rm -f *.o *.d *.raw *.img *.bin *~
-
-# suppress auto-removal of intermediate files
-.SECONDARY:
-
-.PHONY: all clean
diff --git a/pc-bios/optionrom/meson.build b/pc-bios/optionrom/meson.build
new file mode 100644
index 0000000000..7d5314cd80
--- /dev/null
+++ b/pc-bios/optionrom/meson.build
@@ -0,0 +1,73 @@ 
+project('optionrom')
+
+cc = meson.get_compiler('c')
+objcopy = find_program('objcopy')
+signrom = find_program(meson.current_source_dir() / '../../scripts/signrom.py')
+
+emu = ''
+foreach e: ['elf_i386', 'elf_i386_fbsd', 'elf_i386_obsd', 'i386pe']
+  if cc.has_multi_link_arguments('-nostdlib', '-Wl,-emain', '-m32', '-Wl,-m' + e)
+    emu = e
+    break
+  endif
+endforeach
+
+if emu == ''
+  message('No suitable compiler/linker found to build optionrom')
+  subdir_done()
+endif
+
+link_args = ['-nostdlib', '-m32', '-Wl,-m' + e]
+link_args += cc.get_supported_link_arguments('-Wl,--build-id=none')
+if cc.has_multi_link_arguments('-fno-pie', '-no-pie')
+  link_args += ['-no-pie']
+endif
+
+link_args += '-Wl,-T' + meson.current_source_dir() / 'flat.lds'
+
+c_args = ['-O2', '-ffreestanding', '-march=i486']
+c_args += cc.get_supported_arguments('-fno-pie', '-fno-stack-protector', '-Wa,-32')
+if cc.has_argument('-m16')
+  c_args += '-m16'
+else
+  # Attempt to work around compilers that lack -m16 (GCC <= 4.8, clang <= ??)
+  # On GCC we add -fno-toplevel-reorder to keep the order of asm blocks with
+  # respect to the rest of the code.  clang does not have -fno-toplevel-reorder,
+  # but it places all asm blocks at the beginning and we're relying on it for
+  # the option ROM header.  So just force clang not to use the integrated
+  # assembler, which doesn't support .code16gcc.
+  c_args += cc.get_supported_arguments('-fno-toplevel-reorder', '-no-integrated-as')
+  c_args += ['-m32', '-include', meson.current_source_dir() / 'code16gcc.h']
+endif
+
+foreach target, src: {
+  'multiboot': ['multiboot.S'],
+  'linuxboot_dma': ['linuxboot_dma.c'],
+  'linuxboot': ['linuxboot.S'],
+  'kvmvapic': ['kvmvapic.S'],
+  'pvh': ['pvh.S', 'pvh_main.c'],
+ }
+  img = executable(
+    target + '.img',
+    src,
+    c_args: c_args,
+    include_directories: include_directories('../../include'),
+    link_args: link_args,
+    override_options: ['b_coverage=false'],
+  )
+
+  raw = custom_target(
+    target + '.raw',
+    output: target + '.raw',
+    input: img,
+    command: [objcopy, '-O', 'binary', '-j', '.text', '@INPUT@', '@OUTPUT@'],
+  )
+
+  bin = custom_target(
+    target + '.bin',
+    output: target + '.bin',
+    input: raw,
+    command: [signrom, '@INPUT@', '@OUTPUT@'],
+    build_by_default: true,
+  )
+endforeach
diff --git a/subprojects/optionrom b/subprojects/optionrom
new file mode 120000
index 0000000000..0bd7ed1798
--- /dev/null
+++ b/subprojects/optionrom
@@ -0,0 +1 @@ 
+../pc-bios/optionrom
\ No newline at end of file