diff mbox series

[137/142] meson: convert pc-bios/optionrom

Message ID 20200128175342.9066-138-pbonzini@redhat.com
State New
Headers show
Series Proof of concept for Meson integration | expand

Commit Message

Paolo Bonzini Jan. 28, 2020, 5:53 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 Makefile                      | 18 ++------
 configure                     | 20 +--------
 pc-bios/meson.build           |  4 ++
 pc-bios/optionrom/Makefile    | 77 -----------------------------------
 pc-bios/optionrom/meson.build | 72 ++++++++++++++++++++++++++++++++
 scripts/signrom.py            |  2 +
 6 files changed, 82 insertions(+), 111 deletions(-)
 delete mode 100644 pc-bios/optionrom/Makefile
 create mode 100644 pc-bios/optionrom/meson.build
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 112bae68b2..e95042fa3d 100644
--- a/Makefile
+++ b/Makefile
@@ -112,8 +112,7 @@  generated-files-y += .git-submodule-status
 Makefile: ;
 configure: ;
 
-.PHONY: all clean cscope distclean install \
-	recurse-all dist msi FORCE
+.PHONY: all clean cscope distclean install dist msi FORCE
 
 $(call set-vpath, $(SRC_PATH))
 
@@ -127,7 +126,7 @@  endif
 
 include $(SRC_PATH)/tests/Makefile.include
 
-all: recurse-all modules
+all: modules
 
 DTC_MAKE_ARGS=-I$(SRC_PATH)/dtc VPATH=$(SRC_PATH)/dtc -C dtc V="$(V)" LIBFDT_srcdir=$(SRC_PATH)/dtc/libfdt
 DTC_CFLAGS=$(CFLAGS) $(QEMU_CFLAGS)
@@ -170,20 +169,9 @@  subdir-dtc: dtc/all
 subdir-capstone: capstone/all
 subdir-slirp: slirp/all
 
-ROM_DIRS = $(addprefix pc-bios/, $(ROMS))
-ROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS)))
-# Only keep -O and -g cflags
-.PHONY: $(ROM_DIRS_RULES)
-$(ROM_DIRS_RULES):
-	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" CFLAGS="$(filter -O% -g%,$(CFLAGS))" $(notdir $@),)
-
-.PHONY: recurse-all recurse-clean
-recurse-all: $(ROM_DIRS)
-recurse-clean: $(addsuffix /clean, $(ROM_DIRS))
-
 ######################################################################
 
-clean: recurse-clean
+clean:
 # avoid old build problems by removing potentially incorrect old files
 	rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
 	find . \( -name '*.so' -o -name '*.dll' -o -name '*.mo' -o -name '*.[oda]' \) -type f \
diff --git a/configure b/configure
index 64d52fa589..ef9640344c 100755
--- a/configure
+++ b/configure
@@ -6314,23 +6314,6 @@  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
-
 # Probe for the need for relocating the user-only binary.
 if ( [ "$linux_user" = yes ] || [ "$bsd_user" = yes ] ) && [ "$pie" = no ]; then
   textseg_addr=
@@ -7497,7 +7480,6 @@  else
 fi
 QEMU_INCLUDES="-iquote ${source_path}/tcg $QEMU_INCLUDES"
 
-echo "ROMS=$roms" >> $config_host_mak
 echo "MAKE=$make" >> $config_host_mak
 echo "INSTALL=$install" >> $config_host_mak
 echo "INSTALL_DIR=$install -d -m 0755" >> $config_host_mak
@@ -8024,7 +8006,7 @@  LINKS="Makefile"
 LINKS="$LINKS tests/tcg/lm32/Makefile po/Makefile"
 LINKS="$LINKS tests/tcg/Makefile.target tests/fp/Makefile"
 LINKS="$LINKS tests/plugin/Makefile"
-LINKS="$LINKS pc-bios/optionrom/Makefile pc-bios/keymaps"
+LINKS="$LINKS pc-bios/keymaps"
 LINKS="$LINKS pc-bios/s390-ccw/Makefile"
 LINKS="$LINKS roms/seabios/Makefile roms/vgabios/Makefile"
 LINKS="$LINKS pc-bios/qemu-icon.bmp"
diff --git a/pc-bios/meson.build b/pc-bios/meson.build
index 013c75ce43..ef062457a1 100644
--- a/pc-bios/meson.build
+++ b/pc-bios/meson.build
@@ -102,6 +102,10 @@  if dtc.found()
   alias_target('update-dtb', t)
 endif
 
+if host_machine.cpu_family() in ['x86', 'x86_64']
+  subdir('optionrom')
+endif
+
 cc = meson.get_compiler('c')
 if host_machine.cpu_family() == 's390x' and cc.has_argument('-march=z900')
   subdir('s390-ccw')
diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile
deleted file mode 100644
index 51cb6ca9d8..0000000000
--- a/pc-bios/optionrom/Makefile
+++ /dev/null
@@ -1,77 +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
-
-quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 && $1, @$1))
-cc-option = $(if $(shell $(CC) $1 -S -o /dev/null -xc /dev/null >/dev/null 2>&1 && echo OK), $1, $2)
-
-# Compiling with no optimization creates ROMs that are too large
-ifeq ($(lastword $(filter -O%, -O0 $(CFLAGS))),-O0)
-override CFLAGS += -O2
-endif
-override CFLAGS += -march=i486
-
-# 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..5761736a68
--- /dev/null
+++ b/pc-bios/optionrom/meson.build
@@ -0,0 +1,72 @@ 
+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('-m32', '-Wl,-m' + e)
+    emu = e
+    break
+  endif
+endforeach
+
+if emu == ''
+  message('No suitable compiler/linker found to build optionrom')
+else
+  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 = ['-ffreestanding', '-march=i486']
+  c_args += cc.get_supported_arguments('-fno-pie', '-fno-stack-protector', '-m32')
+
+  # Compiling with no optimization creates ROMs that are too large
+  code16_c_args = ['-O2']
+  if cc.has_argument('-m16')
+    code16_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.
+    code16_c_args += cc.get_supported_arguments('-fno-toplevel-reorder', '-no-integrated-as')
+    code16_c_args += ['-m32', '-include', meson.current_source_dir() / 'code16gcc.h']
+  endif
+
+  foreach target, opt: {
+    'multiboot': {'src': ['multiboot.S'], 'cargs': ['-m32', '-g0']},
+    'linuxboot_dma': {'src': ['linuxboot_dma.c'], 'cargs': code16_c_args},
+    'linuxboot': {'src': ['linuxboot.S']},
+    'kvmvapic': {'src': ['kvmvapic.S']},
+    'pvh': {'src': ['pvh.S', 'pvh_main.c']},
+   }
+    img = executable(
+      target + '.img',
+      opt['src'],
+      c_args: [c_args, opt.get('cargs', [])],
+      include_directories: include_directories('../../include'),
+      link_args: link_args,
+    )
+
+    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
+endif
diff --git a/scripts/signrom.py b/scripts/signrom.py
index 313ee28a17..ba9ac0350e 100644
--- a/scripts/signrom.py
+++ b/scripts/signrom.py
@@ -1,3 +1,5 @@ 
+#!/usr/bin/env python
+
 from __future__ import print_function
 #
 # Option ROM signing utility