Patch to add support for building in MSYS2 on Windows
Hi,
I noticed that QEMU would not compile on Windows in the MSYS2 environment.
Here is a patch that adds a check for it to the configure script and amended some ifdefs so it now builds.
At the bottom of this email is a build script I made for building under MSYS2, however I am not sure if it is suitable merging nor where it should go.
Regards,
Evan Hunter
-----------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------
MSYS2 Patch:
From 81eee3b9c0722b054852d002b605d55b0530a4ce Mon Sep 17 00:00:00 2001
From: Evan Hunter <[email protected]>
Date: Sun, 21 Aug 2016 17:27:46 +0100
Subject: [PATCH 1/2] Add support for building on Windows in MSYS2
--- block.c | 2 +- configure | 12 +++++++++++- net/tap-bsd.c | 4 ++-- os-posix.c | 6 +++--- qga/channel-posix.c | 2 +- slirp/slirp.h | 2 +- util/compatfd.c | 2 ++ util/qemu-openpty.c | 2 +- 8 files changed, 22 insertions(+), 10 deletions(-)
block.c +1 -1
@@ -44,7 +44,7 @@#ifdef CONFIG_BSD #include <sys/ioctl.h> #include <sys/queue.h> -#ifndef __DragonFly__ +#if !defined(__DragonFly__) && !defined(__MSYS__)#include <sys/disk.h> #endif #endif
configure +11 -1
@@ -566,6 +566,10 @@ MINGW32*) audio_drv_list="" fi ;; +MSYS_NT-*) + bsd="yes" + audio_drv_list="dsound" +;; GNU/kFreeBSD) bsd="yes" audio_drv_list="oss"
@@ -680,7 +684,13 @@ esac if [ "$bsd" = "yes" ] ; then if [ "$darwin" != "yes" ] ; then - bsd_user="yes" + case $targetos in + MSYS_NT-*) + ;; + *) + bsd_user="yes" + ;; + esac fi fi
net/tap-bsd.c +2 -2
@@ -42,7 +42,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,int fd;#ifdef TAPGIFNAME struct ifreq ifr; -#else +#elif !defined(__MSYS__)char *dev;struct stat s;#endif
@@ -83,7 +83,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, return -1; }pstrcpy (ifname, ifname_size, ifr.ifr_name); -#else +#elif !defined(__MSYS__)if (fstat (fd, &s) <0 ) {error_setg_errno (errp, errno,"could not stat %s" , dname);return -1 ;
os-posix.c +3 -3
@@ -329,12 +329,12 @@ bool is_daemonized(void)int os_mlock (void ) { -int ret =0 ; - +int ret = -ENOSYS ;; +#ifndef __MSYS__ ret =mlockall (MCL_CURRENT |MCL_FUTURE );if (ret <0 ) {perror ("mlockall" ); } - +#endif return ret; }
qga/channel-posix.c +1 -1
@@ -130,7 +130,7 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, GAChannelMethodswitch (c->method) {case GA_CHANNEL_VIRTIO_SERIAL : { int fd = qemu_open(path, O_RDWR | O_NONBLOCK -#ifndef CONFIG_SOLARIS +#if !defined(CONFIG_SOLARIS) && !defined(__MSYS__) |O_ASYNC #endif );
slirp/slirp.h +1 -1
@@ -15,7 +15,7 @@ typedef char *caddr_t;# include <iphlpapi.h> #else -# if !defined(__HAIKU__) +# if !defined(__HAIKU__) && !defined(__MSYS__)# define O_BINARY 0# endif #endif
util/compatfd.c +2 -0
@@ -18,7 +18,9 @@#include "qemu/compatfd.h" #include "qemu/thread.h" +#ifndef __MSYS__#include <sys/syscall.h> +#endif struct sigfd_compat_info {
util/qemu-openpty.c +1 -1
@@ -35,7 +35,7 @@#include "qemu/osdep.h" #include "qemu-common.h" -#if defined(__GLIBC__) +#if defined(__GLIBC__) || defined(__MSYS__)# include <pty.h> #elif definedCONFIG_BSD # include <termios.h>
Signature · 49 lines
1.9.5.msysgit.0 ----------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------- MSYS2 Build Script: #!/bin/bash # # Script for building QEMU on Windows in MSYS2 environment # set -e uname_output=`uname` if [ $uname_output != MSYS_NT-6.1 ]; then echo "This script is only for building under MSYS2" exit 1 fi package_list="python2 make pkg-config gcc zlib-devel glib2-devel autoconf bison automake1.10 libtool libutil-linux-devel" if ! pacman -Q $package_list > /dev/null; then echo "Missing dependencies. Please run:" echo "pacman -S $package_list" exit 1 fi echo "Configuring..." mkdir -p build cd build CC=/usr/bin/gcc ../configure --python=/usr/bin/python2 2>&1 | tee build.log echo "Building..." make -j6 2>&1 | tee -a build.log echo "Done"
Quoted 6 lines · Evan Hunter
Hi,
I noticed that QEMU would not compile on Windows in the MSYS2 environment. Here is a patch that adds a check for it to the configure script and amended some ifdefs so it now builds.
Quoted 7 lines
At the bottom of this email is a build script I made for building under MSYS2, however I am
not sure if it is suitable merging nor where it should go.Regards,
Evan Hunter
Hi Evan,
I'm not sure whether adding support for MSYS2 builds is a good idea or not. Supporting several build environments for QEMU for Windows requires a lot of time. Currently we only support MinGW-w64. It has several advantages:
* 32 and 64 bit builds supported
* cross builds on Linux (Redhat, Debian, others) supported
* cross builds on Windows with Cygwin supported
* native builds on Windows supported
AFAIK Redhat includes all packages needed for the cross builds. Cygwin also has excellent package support.
Debian only includes the build tools, but can use Cygwin packages.
In most cases it is sufficient to test QEMU builds with MinGW-w64 on one platform, and all others will work, too. Usually QEMU developers will run their tests using Linux (me too).
For MSYS2, we'd need additional build tests running on Windows (please correct me if I am wrong - I have no own experience with MSYS2). What would be the advantages of supporting MSYS2?
Maybe you could start with documenting the MSYS2 based build process on http://wiki.qemu.org/Hosts/W32 and refer to a QEMU git clone which includes the necessary modifications.
More feedback also from other contributors whether MSYS2 support is wanted or not would be helpful.
Kind regards,
Stefan Weil
Quoted 6 lines · Stefan Weil
Maybe you could start with documenting the MSYS2 based build process on
http://wiki.qemu.org/Hosts/W32 and refer to a QEMU git clone which includes the necessary modifications.More feedback also from other contributors whether MSYS2 support is wanted or not would be helpful.
You could reduce the delta between stock QEMU and one which builds on MSYS2 by converting some of these "ifdef MSYS2" changes to instead by "ifdef <some property of the host>". For instance, instead of guarding a #include of <pty.h> with "#if defined(__GLIBC__) || defined(__MSYS__)"
we could guard it with "#ifdef CONFIG_HAVE_PTY_H".
In general I think that per-host-OS-ifdefs are not a great idea, though they are the easy expedient way to handle things and so we have a fair number at the moment. Converting a per-host-ifdef setup to a "check for existence of feature" setup is a cleanup I think we'd be happy to accept even if we don't want to care about MSYS2 build support.
thanks
-- PMM