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 <e...@ozhiker.com>
Date: Sun, 21 Aug 2016 17:27:46 +0100
Subject: [PATCH 1/2] Add support for building on Windows in MSYS2
Signed-off-by: Evan Hunter <e...@ozhiker.com>
---
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(-)
diff --git a/block.c b/block.c
index 30d64e6..534039d 100644
--- a/block.c
+++ b/block.c
@@ -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
diff --git a/configure b/configure
index 4b808f9..11ba495 100755
--- a/configure
+++ b/configure
@@ -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
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index c506ac3..de68d67 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -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;
diff --git a/os-posix.c b/os-posix.c
index c6ddb7d..af86512 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -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;
}
diff --git a/qga/channel-posix.c b/qga/channel-posix.c
index bb65d8b..aa58fec 100644
--- a/qga/channel-posix.c
+++ b/qga/channel-posix.c
@@ -130,7 +130,7 @@ static gboolean ga_channel_open(GAChannel *c, const
gchar *path, GAChannelMethod
switch (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
);
diff --git a/slirp/slirp.h b/slirp/slirp.h
index a1f3139..0dc6dfa 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -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
diff --git a/util/compatfd.c b/util/compatfd.c
index 9a43042..0cf4afd 100644
--- a/util/compatfd.c
+++ b/util/compatfd.c
@@ -18,7 +18,9 @@
#include "qemu/compatfd.h"
#include "qemu/thread.h"
+#ifndef __MSYS__
#include <sys/syscall.h>
+#endif
struct sigfd_compat_info
{
diff --git a/util/qemu-openpty.c b/util/qemu-openpty.c
index 2e8b43b..99e6a5b 100644
--- a/util/qemu-openpty.c
+++ b/util/qemu-openpty.c
@@ -35,7 +35,7 @@
#include "qemu/osdep.h"
#include "qemu-common.h"
-#if defined(__GLIBC__)
+#if defined(__GLIBC__) || defined(__MSYS__)
# include <pty.h>
#elif defined CONFIG_BSD
# include <termios.h>
--
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"