diff mbox series

[1/6] meson: convert pc-bios/s390-ccw

Message ID 20200918204759.225810-2-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>

Use a fake 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                    |   2 -
 pc-bios/meson.build          |   4 +
 pc-bios/s390-ccw/Makefile    |  62 ------------
 pc-bios/s390-ccw/meson.build | 177 +++++++++++++++++++++++++++++++++++
 pc-bios/s390-ccw/netboot.mak |  62 ------------
 subprojects/s390-ccw         |   1 +
 6 files changed, 182 insertions(+), 126 deletions(-)
 delete mode 100644 pc-bios/s390-ccw/Makefile
 create mode 100644 pc-bios/s390-ccw/meson.build
 delete mode 100644 pc-bios/s390-ccw/netboot.mak
 create mode 120000 subprojects/s390-ccw
diff mbox series

Patch

diff --git a/configure b/configure
index 7564479008..3a8733c9be 100755
--- a/configure
+++ b/configure
@@ -6462,7 +6462,6 @@  fi
 if test "$cpu" = "s390x" ; then
   write_c_skeleton
   if compile_prog "-march=z900" ""; then
-    roms="$roms s390-ccw"
     # SLOF is required for building the s390-ccw firmware on s390x,
     # since it is using the libnet code from SLOF for network booting.
     if test -e "${source_path}/.git" ; then
@@ -7863,7 +7862,6 @@  LINKS="Makefile"
 LINKS="$LINKS tests/tcg/lm32/Makefile"
 LINKS="$LINKS tests/tcg/Makefile.target"
 LINKS="$LINKS pc-bios/optionrom/Makefile"
-LINKS="$LINKS pc-bios/s390-ccw/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 a0d21be432..e5139b3ef5 100644
--- a/pc-bios/meson.build
+++ b/pc-bios/meson.build
@@ -91,3 +91,7 @@  endif
 
 subdir('descriptors')
 subdir('keymaps')
+
+if host_machine.cpu_family() == 's390x' and cc.has_argument('-march=z900')
+  subproject('s390-ccw')
+endif
diff --git a/pc-bios/s390-ccw/Makefile b/pc-bios/s390-ccw/Makefile
deleted file mode 100644
index 3eb785048a..0000000000
--- a/pc-bios/s390-ccw/Makefile
+++ /dev/null
@@ -1,62 +0,0 @@ 
-all: build-all
-# 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 -S -o /dev/null -xc /dev/null > /dev/null \
-	      2>&1 && echo OK), $1, $2)
-
-VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.sh %.rc Kconfig% %.json.in
-set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
-$(call set-vpath, $(SRC_PATH)/pc-bios/s390-ccw)
-
-# Flags for dependency generation
-QEMU_DGFLAGS = -MMD -MP -MT $@ -MF $(@D)/$(*F).d
-
-%.o: %.c
-	$(call quiet-command,$(CC) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) \
-	       -c -o $@ $<,"CC","$(TARGET_DIR)$@")
-
-%.o: %.S
-	$(call quiet-command,$(CCAS) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) \
-	       -c -o $@ $<,"CCAS","$(TARGET_DIR)$@")
-
-.PHONY : all clean build-all
-
-OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o \
-	  virtio.o virtio-scsi.o virtio-blkdev.o libc.o cio.o dasd-ipl.o
-
-QEMU_CFLAGS := -Wall $(filter -W%, $(QEMU_CFLAGS))
-QEMU_CFLAGS += -ffreestanding -fno-delete-null-pointer-checks -msoft-float
-QEMU_CFLAGS += -march=z900 -fPIE -fno-strict-aliasing
-QEMU_CFLAGS += -fno-asynchronous-unwind-tables
-QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), -fno-stack-protector)
-LDFLAGS += -Wl,-pie -nostdlib
-
-build-all: s390-ccw.img s390-netboot.img
-
-s390-ccw.elf: $(OBJECTS)
-	$(call quiet-command,$(CC) $(LDFLAGS) -o $@ $(OBJECTS),"BUILD","$(TARGET_DIR)$@")
-
-STRIP ?= strip
-
-s390-ccw.img: s390-ccw.elf
-	$(call quiet-command,$(STRIP) --strip-unneeded $< -o $@,"STRIP","$(TARGET_DIR)$@")
-
-$(OBJECTS): Makefile
-
-ifneq ($(wildcard $(SRC_PATH)/roms/SLOF/lib/libnet),)
-include $(SRC_PATH)/pc-bios/s390-ccw/netboot.mak
-else
-s390-netboot.img:
-	@echo "s390-netboot.img not built since roms/SLOF/ is not available."
-endif
-
-ALL_OBJS = $(sort $(OBJECTS) $(NETOBJS) $(LIBCOBJS) $(LIBNETOBJS))
--include $(ALL_OBJS:%.o=%.d)
-
-clean:
-	rm -f *.o *.d *.img *.elf *~ *.a
diff --git a/pc-bios/s390-ccw/meson.build b/pc-bios/s390-ccw/meson.build
new file mode 100644
index 0000000000..0de5400287
--- /dev/null
+++ b/pc-bios/s390-ccw/meson.build
@@ -0,0 +1,177 @@ 
+project('s390-ccw')
+
+strip = find_program('strip')
+cc = meson.get_compiler('c')
+link_args = ['-Wl,-pie', '-nostdlib']
+
+# FIXME: find a better way to check/enable slof
+slof = '../../roms/SLOF'
+has_slof = cc.has_header('libnet/tftp.h', args: '-I' + meson.current_source_dir() / slof / 'lib')
+
+s390_cargs = [
+  '-ffreestanding',
+  '-fno-delete-null-pointer-checks',
+  '-msoft-float',
+  '-march=z900',
+  '-fPIE',
+  '-fno-strict-aliasing',
+  '-fno-asynchronous-unwind-tables',
+  cc.get_supported_arguments('-fno-stack-protector')
+]
+
+s390_incs = []
+
+s390_srcs = [
+  'bootmap.c',
+  'cio.c',
+  'dasd-ipl.c',
+  'jump2ipl.c',
+  'libc.c',
+  'main.c',
+  'menu.c',
+  'sclp.c',
+  'start.S',
+  'virtio-blkdev.c',
+  'virtio-scsi.c',
+  'virtio.c',
+]
+
+if has_slof
+  s390_srcs += [
+    'netmain.c',
+    'virtio-net.c',
+  ]
+  s390_incs += include_directories(slof / 'lib/libnet')
+  s390_incs += include_directories(slof / 'lib/libc/include')
+  s390_cargs += '-nostdinc'
+endif
+
+s390_lib = static_library(
+  's390', s390_srcs,
+  c_args: s390_cargs,
+  include_directories: s390_incs,
+)
+
+s390_ccw_elf = executable(
+  's390-ccw.elf',
+  link_args: link_args,
+  objects: s390_lib.extract_objects([
+    'bootmap.c',
+    'cio.c',
+    'dasd-ipl.c',
+    'jump2ipl.c',
+    'libc.c',
+    'main.c',
+    'menu.c',
+    'sclp.c',
+    'start.S',
+    'virtio-blkdev.c',
+    'virtio-scsi.c',
+    'virtio.c',
+  ]),
+)
+
+custom_target(
+  's390-ccw.img',
+  output: 's390-ccw.img',
+  input: s390_ccw_elf,
+  command: [strip, '--strip-unneeded', '@INPUT@', '-o', '@OUTPUT@'],
+  build_by_default: true,
+)
+
+if has_slof
+  slof_ctype = slof / 'lib/libc/ctype'
+  slof_str = slof / 'lib/libc/string'
+  slof_stdlib = slof / 'lib/libc/stdlib'
+  slof_stdio = slof / 'lib/libc/stdio'
+
+  s390_libc = static_library(
+    's390-libc', files(
+      slof_ctype / 'isdigit.c',
+      slof_ctype / 'isxdigit.c',
+      slof_ctype / 'toupper.c',
+      slof_str / 'strcat.c',
+      slof_str / 'strchr.c',
+      slof_str / 'strrchr.c',
+      slof_str / 'strcpy.c',
+      slof_str / 'strlen.c',
+      slof_str / 'strncpy.c',
+      slof_str / 'strcmp.c',
+      slof_str / 'strncmp.c',
+      slof_str / 'strcasecmp.c',
+      slof_str / 'strncasecmp.c',
+      slof_str / 'strstr.c',
+      slof_str / 'memset.c',
+      slof_str / 'memcpy.c',
+      slof_str / 'memmove.c',
+      slof_str / 'memcmp.c',
+      slof_stdlib / 'atoi.c',
+      slof_stdlib / 'atol.c',
+      slof_stdlib / 'strtoul.c',
+      slof_stdlib / 'strtol.c',
+      slof_stdlib / 'rand.c',
+      slof_stdlib / 'malloc.c',
+      slof_stdlib / 'free.c',
+      slof_stdio / 'sprintf.c',
+      slof_stdio / 'snprintf.c',
+      slof_stdio / 'vfprintf.c',
+      slof_stdio / 'vsnprintf.c',
+      slof_stdio / 'vsprintf.c',
+      slof_stdio / 'fprintf.c',
+      slof_stdio / 'printf.c',
+      slof_stdio / 'putc.c',
+      slof_stdio / 'puts.c',
+      slof_stdio / 'putchar.c',
+      slof_stdio / 'stdchnls.c',
+      slof_stdio / 'fileno.c',
+      slof / 'slof/sbrk.c',
+    ),
+    c_args: s390_cargs,
+    include_directories: s390_incs,
+  )
+
+  slof_libnet = slof / 'lib/libnet'
+  s390_libnet = static_library(
+    's390-libnet', files(
+      slof_libnet / 'args.c',
+      slof_libnet / 'dhcp.c',
+      slof_libnet / 'dns.c',
+      slof_libnet / 'icmpv6.c',
+      slof_libnet / 'ipv6.c',
+      slof_libnet / 'tcp.c',
+      slof_libnet / 'udp.c',
+      slof_libnet / 'bootp.c',
+      slof_libnet / 'dhcpv6.c',
+      slof_libnet / 'ethernet.c',
+      slof_libnet / 'ipv4.c',
+      slof_libnet / 'ndp.c',
+      slof_libnet / 'tftp.c',
+      slof_libnet / 'pxelinux.c',
+    ),
+    c_args: [s390_cargs, '-DDHCPARCH=0x1F'],
+    include_directories: s390_incs,
+  )
+
+  s390_netboot_elf = executable(
+    's390-netboot.elf',
+    link_with: [s390_libc, s390_libnet],
+    link_args: [link_args, '-Ttext=0x7800000'],
+    objects: s390_lib.extract_objects([
+      'cio.c',
+      'jump2ipl.c',
+      'netmain.c',
+      'sclp.c',
+      'start.S',
+      'virtio-net.c',
+      'virtio.c',
+    ]),
+  )
+
+  custom_target(
+    's390-netboot.img',
+    output: 's390-netboot.img',
+    input: s390_netboot_elf,
+    command: [strip, '--strip-unneeded', '@INPUT@', '-o', '@OUTPUT@'],
+    build_by_default: true,
+  )
+endif
diff --git a/pc-bios/s390-ccw/netboot.mak b/pc-bios/s390-ccw/netboot.mak
deleted file mode 100644
index 577c023afe..0000000000
--- a/pc-bios/s390-ccw/netboot.mak
+++ /dev/null
@@ -1,62 +0,0 @@ 
-
-SLOF_DIR := $(SRC_PATH)/roms/SLOF
-
-NETOBJS := start.o sclp.o cio.o virtio.o virtio-net.o jump2ipl.o netmain.o
-
-LIBC_INC := -nostdinc -I$(SLOF_DIR)/lib/libc/include
-LIBNET_INC := -I$(SLOF_DIR)/lib/libnet
-
-NETLDFLAGS := $(LDFLAGS) -Ttext=0x7800000
-
-$(NETOBJS): QEMU_CFLAGS += $(LIBC_INC) $(LIBNET_INC)
-
-s390-netboot.elf: $(NETOBJS) libnet.a libc.a
-	$(call quiet-command,$(CC) $(NETLDFLAGS) -o $@ $^,"BUILD","$(TARGET_DIR)$@")
-
-s390-netboot.img: s390-netboot.elf
-	$(call quiet-command,$(STRIP) --strip-unneeded $< -o $@,"STRIP","$(TARGET_DIR)$@")
-
-# libc files:
-
-LIBC_CFLAGS = $(QEMU_CFLAGS) $(CFLAGS) $(LIBC_INC) $(LIBNET_INC) \
-	      -MMD -MP -MT $@ -MF $(@:%.o=%.d)
-
-CTYPE_OBJS = isdigit.o isxdigit.o toupper.o
-%.o : $(SLOF_DIR)/lib/libc/ctype/%.c
-	$(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,"CC","$(TARGET_DIR)$@")
-
-STRING_OBJS = strcat.o strchr.o strrchr.o strcpy.o strlen.o strncpy.o \
-	      strcmp.o strncmp.o strcasecmp.o strncasecmp.o strstr.o \
-	      memset.o memcpy.o memmove.o memcmp.o
-%.o : $(SLOF_DIR)/lib/libc/string/%.c
-	$(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,"CC","$(TARGET_DIR)$@")
-
-STDLIB_OBJS = atoi.o atol.o strtoul.o strtol.o rand.o malloc.o free.o
-%.o : $(SLOF_DIR)/lib/libc/stdlib/%.c
-	$(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,"CC","$(TARGET_DIR)$@")
-
-STDIO_OBJS = sprintf.o snprintf.o vfprintf.o vsnprintf.o vsprintf.o fprintf.o \
-	     printf.o putc.o puts.o putchar.o stdchnls.o fileno.o
-%.o : $(SLOF_DIR)/lib/libc/stdio/%.c
-	$(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,"CC","$(TARGET_DIR)$@")
-
-sbrk.o: $(SLOF_DIR)/slof/sbrk.c
-	$(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,"CC","$(TARGET_DIR)$@")
-
-LIBCOBJS := $(STRING_OBJS) $(CTYPE_OBJS) $(STDLIB_OBJS) $(STDIO_OBJS) sbrk.o
-
-libc.a: $(LIBCOBJS)
-	$(call quiet-command,$(AR) -rc $@ $^,"AR","$(TARGET_DIR)$@")
-
-# libnet files:
-
-LIBNETOBJS := args.o dhcp.o dns.o icmpv6.o ipv6.o tcp.o udp.o bootp.o \
-	      dhcpv6.o ethernet.o ipv4.o ndp.o tftp.o pxelinux.o
-LIBNETCFLAGS = $(QEMU_CFLAGS) $(CFLAGS) $(LIBC_INC) $(LIBNET_INC) \
-	       -DDHCPARCH=0x1F -MMD -MP -MT $@ -MF $(@:%.o=%.d)
-
-%.o : $(SLOF_DIR)/lib/libnet/%.c
-	$(call quiet-command,$(CC) $(LIBNETCFLAGS) -c -o $@ $<,"CC","$(TARGET_DIR)$@")
-
-libnet.a: $(LIBNETOBJS)
-	$(call quiet-command,$(AR) -rc $@ $^,"AR","$(TARGET_DIR)$@")
diff --git a/subprojects/s390-ccw b/subprojects/s390-ccw
new file mode 120000
index 0000000000..8a3120224b
--- /dev/null
+++ b/subprojects/s390-ccw
@@ -0,0 +1 @@ 
+../pc-bios/s390-ccw
\ No newline at end of file