Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Support building with newest Mingw64 cross-toolchain.
Browse files Browse the repository at this point in the history
This modifies android-configure.sh to detect the new Mingw64-based
cross toolchain (i.e. x86_64-w64-mingw32-gcc) and use it when it
is in the user's path.

Note that this only builds a 32-bit Windows binary, it just uses
a different toolchain to do it. A future patch will add support
for building both Win32 and Win64 binaries at the same time
(which the new toolchain supports).

Since this switches from GCC 4.2 to 4.8, this introduces a ton of
new warnings that require some cleanups in the sources too.

Only the most important warnings are fixed here.

Change-Id: Iec8c9b8332d4a38a2cb8acf368c8aa5341cf77be
  • Loading branch information
digit-android committed Apr 28, 2014
1 parent 52ffef3 commit 7891dd3
Show file tree
Hide file tree
Showing 32 changed files with 89 additions and 49 deletions.
9 changes: 8 additions & 1 deletion Makefile.android
Expand Up @@ -151,6 +151,13 @@ ifneq ($(combo_target)$(TARGET_SIMULATOR),HOST_true)
endif
endif

ifeq ($(HOST_OS)-$(BUILD_STANDALONE_EMULATOR),windows-true)
# Ensure that printf() et al use GNU printf format specifiers as required
# by QEMU. This is important when using the newer Mingw64 cross-toolchain.
# See http://sourceforge.net/apps/trac/mingw-w64/wiki/gnu%20printf
MY_CFLAGS += -D__USE_MINGW_ANSI_STDIO=1
endif

# Enable warning, except those related to missing field initializers
# (the QEMU coding style loves using these).
#
Expand Down Expand Up @@ -218,7 +225,7 @@ endef
#
QEMU_SYSTEM_LDLIBS := -lm
ifeq ($(HOST_OS),windows)
QEMU_SYSTEM_LDLIBS += -mno-cygwin -mwindows -mconsole
QEMU_SYSTEM_LDLIBS += -mwindows -mconsole
endif

ifeq ($(HOST_OS),freebsd)
Expand Down
11 changes: 11 additions & 0 deletions android-configure.sh
Expand Up @@ -487,6 +487,16 @@ feature_check_header HAVE_BYTESWAP_H "<byteswap.h>"
feature_check_header HAVE_MACHINE_BSWAP_H "<machine/bswap.h>"
feature_check_header HAVE_FNMATCH_H "<fnmatch.h>"

# check for Mingw version.
MINGW_VERSION=
if [ "$TARGET_OS" = "windows" ]; then
log "Mingw : Probing for GCC version."
GCC_VERSION=$($CC -v 2>&1 | awk '$1 == "gcc" && $2 == "version" { print $3; }')
GCC_MAJOR=$(echo "$GCC_VERSION" | cut -f1 -d.)
GCC_MINOR=$(echo "$GCC_VERSION" | cut -f2 -d.)
log "Mingw : Found GCC version $GCC_MAJOR.$GCC_MINOR [$GCC_VERSION]"
MINGW_GCC_VERSION=$(( $GCC_MAJOR * 100 + $GCC_MINOR ))
fi
# Build the config.make file
#

Expand Down Expand Up @@ -583,6 +593,7 @@ if [ "$OPTION_MINGW" = "yes" ] ; then
echo "" >> $config_mk
echo "USE_MINGW := 1" >> $config_mk
echo "HOST_OS := windows" >> $config_mk
echo "HOST_MINGW_VERSION := $MINGW_GCC_VERSION" >> $config_mk
fi

if [ "$HOST_OS" = "darwin" ]; then
Expand Down
22 changes: 16 additions & 6 deletions android/build/common.sh
Expand Up @@ -204,19 +204,29 @@ enable_linux_mingw ()
exit 1
fi
# Do we have the binaries installed
log "Mingw64 : Checking for mingw64 installation"
MINGW64_PREFIX=x86_64-w64-mingw32
find_program MINGW64_CC $MINGW64_PREFIX-gcc
if [ -n "$MINGW64_CC" ]; then
MINGW_CC=$MINGW64_CC
MINGW_PREFIX=$MINGW64_PREFIX
else
log "Mingw : Checking for mingw32 installation"
MINGW32_PREFIX=i586-mingw32msvc
find_program MINGW32_CC $MINGW32_PREFIX-gcc
if [ -z "$MINGW32_CC" ] ; then
echo "ERROR: It looks like $MINGW32_PREFIX-gcc is not in your path"
echo "Please install the mingw32 package !"
echo "ERROR: It looks like neither $MINGW64_PREFIX-cc nor $MINGW32_PREFIX-gcc"
echo "are in your path. Please install the mingw32 package !"
exit 1
fi
MINGW_CC=$MINGW32_CC
MINGW_PREFIX=$MINGW32_PREFIX
FORCE_32BIT=no
fi
log2 "Mingw : Found $MINGW32_CC"
CC=$MINGW32_CC
LD=$MINGW32_CC
AR=$MINGW32_PREFIX-ar
FORCE_32BIT=no
CC=$MINGW_CC
LD=$MINGW_CC
AR=$MINGW_PREFIX-ar
}

# Cygwin is normally not supported, unless you call this function
Expand Down
5 changes: 3 additions & 2 deletions android/main-emulator.c
Expand Up @@ -24,6 +24,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <android/utils/compiler.h>
#include <android/utils/panic.h>
#include <android/utils/path.h>
#include <android/utils/bufprint.h>
Expand Down Expand Up @@ -68,14 +69,14 @@ static char* getTargetEmulatorPath(const char* progName, const char* avdArch, co
static char* getSharedLibraryPath(const char* progName, const char* libName);
static void prependSharedLibraryPath(const char* prefix);

/* The execv() definition in mingw is slightly bogus.
/* The execv() definition in older mingw is slightly bogus.
* It takes a second argument of type 'const char* const*'
* while POSIX mandates char** instead.
*
* To avoid compiler warnings, define the safe_execv macro
* to perform an explicit cast with mingw.
*/
#ifdef _WIN32
#if defined(_WIN32) && !ANDROID_GCC_PREREQ(4,4)
# define safe_execv(_filepath,_argv) execv((_filepath),(const char* const*)(_argv))
#else
# define safe_execv(_filepath,_argv) execv((_filepath),(_argv))
Expand Down
4 changes: 2 additions & 2 deletions android/sockets.c
Expand Up @@ -1210,11 +1210,11 @@ static void socket_cleanup(void)
int socket_init(void)
{
WSADATA Data;
int ret, err;
int ret;

ret = WSAStartup(MAKEWORD(2,2), &Data);
if (ret != 0) {
err = WSAGetLastError();
(void) WSAGetLastError();
return -1;
}
atexit(socket_cleanup);
Expand Down
9 changes: 9 additions & 0 deletions android/utils/compiler.h
Expand Up @@ -20,4 +20,13 @@
#define ANDROID_END_HEADER /* nothing */
#endif

// ANDROID_GCC_PREREQ(<major>,<minor>) will evaluate to true
// iff the current version of GCC is <major>.<minor> or higher.
#if defined(__GNUC__) && defined(__GNUC_MINOR__)
# define ANDROID_GCC_PREREQ(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
# define ANDROID_GCC_PREREQ(maj, min) 0
#endif

#endif // ANDROID_UTILS_COMPILER_H
4 changes: 2 additions & 2 deletions android/utils/filelock.c
Expand Up @@ -91,13 +91,13 @@ filelock_lock( FileLock* lock )
#ifdef _WIN32
int pidfile_fd = -1;

ret = _mkdir( lock->lock );
ret = mkdir( lock->lock );
if (ret < 0) {
if (errno == ENOENT) {
D( "could not access directory '%s', check path elements", lock->lock );
return -1;
} else if (errno != EEXIST) {
D( "_mkdir(%s): %s", lock->lock, strerror(errno) );
D( "mkdir(%s): %s", lock->lock, strerror(errno) );
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion android/utils/path.c
Expand Up @@ -284,7 +284,7 @@ path_mkdir( const char* path, int mode )
{
#ifdef _WIN32
(void)mode;
return _mkdir(path);
return mkdir(path);
#else
return HANDLE_EINTR(mkdir(path, mode));
#endif
Expand Down
3 changes: 2 additions & 1 deletion android/utils/system.c
Expand Up @@ -67,7 +67,8 @@ android_realloc( void* block, size_t size )
if (block2 != NULL)
return block2;

fprintf(stderr, "PANIC: not enough memory to reallocate %zu bytes\n", size);
fprintf(stderr, "PANIC: not enough memory to reallocate %u bytes\n",
(unsigned)size);
exit(1);
return NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions android/utils/system.h
Expand Up @@ -103,9 +103,9 @@ typedef int ABool;
extern char* win32_strsep(char** pline, const char* delim);
#endif

/** Handle strcasecmp on Windows
/** Handle strcasecmp on Windows (and older Mingw32 toolchain)
**/
#ifdef _WIN32
#if defined(_WIN32) && !ANDROID_GCC_PREREQ(4,4)
# define strcasecmp stricmp
#endif

Expand Down
2 changes: 1 addition & 1 deletion audio/mixeng.c
Expand Up @@ -301,7 +301,7 @@ void *st_rate_start (int inrate, int outrate)
struct rate *rate = audio_calloc (AUDIO_FUNC, 1, sizeof (*rate));

if (!rate) {
dolog ("Could not allocate resampler (%zu bytes)\n", sizeof (*rate));
dolog ("Could not allocate resampler (%u bytes)\n", (int)sizeof (*rate));
return NULL;
}

Expand Down
2 changes: 1 addition & 1 deletion distrib/elff/elff/elff_map_file.h
Expand Up @@ -16,4 +16,4 @@
// TODO(digit): Provide standalone implementation for the library.
#include "android/utils/mapfile.h"

#endif // ELFF_MAP_FILE_H
#endif // ELFF_MAP_FILE_H
2 changes: 1 addition & 1 deletion distrib/sdl-1.2.15/include/SDL_opengl.h
Expand Up @@ -27,7 +27,7 @@
#include "SDL_config.h"

#ifdef __WIN32__
#define WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#ifndef NOMINMAX
#define NOMINMAX /* Don't defined min() and max() */
#endif
Expand Down
2 changes: 1 addition & 1 deletion distrib/sdl-1.2.15/include/SDL_syswm.h
Expand Up @@ -129,7 +129,7 @@ typedef struct SDL_SysWMinfo {
} SDL_SysWMinfo;

#elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW) || defined(SDL_VIDEO_DRIVER_GAPI)
#define WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>

/** The windows custom event structure */
Expand Down
2 changes: 1 addition & 1 deletion distrib/sdl-1.2.15/src/thread/win32/SDL_systhread.c
Expand Up @@ -23,7 +23,7 @@

/* Win32 thread management routines for SDL */

#define WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>

#include "SDL_thread.h"
Expand Down
2 changes: 1 addition & 1 deletion distrib/sdl-1.2.15/src/thread/win32/SDL_systhread_c.h
Expand Up @@ -21,7 +21,7 @@
*/
#include "SDL_config.h"

#define WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>

typedef HANDLE SYS_ThreadHandle;
Expand Down
2 changes: 1 addition & 1 deletion distrib/sdl-1.2.15/src/video/wincommon/SDL_lowvideo.h
Expand Up @@ -24,7 +24,7 @@
#ifndef _SDL_lowvideo_h
#define _SDL_lowvideo_h

#define WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>

#ifndef SetClassLongPtr
Expand Down
2 changes: 1 addition & 1 deletion distrib/sdl-1.2.15/src/video/wincommon/SDL_sysevents.c
Expand Up @@ -21,7 +21,7 @@
*/
#include "SDL_config.h"

#define WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>

/* Make sure XBUTTON stuff is defined that isn't in older Platform SDKs... */
Expand Down
2 changes: 1 addition & 1 deletion distrib/sdl-1.2.15/src/video/wincommon/SDL_sysmouse.c
Expand Up @@ -21,7 +21,7 @@
*/
#include "SDL_config.h"

#define WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>

#include "SDL_mouse.h"
Expand Down
2 changes: 1 addition & 1 deletion distrib/sdl-1.2.15/src/video/wincommon/SDL_syswm.c
Expand Up @@ -21,7 +21,7 @@
*/
#include "SDL_config.h"

#define WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>

#include "SDL_version.h"
Expand Down
2 changes: 1 addition & 1 deletion distrib/sdl-1.2.15/src/video/windib/SDL_dibevents.c
Expand Up @@ -21,7 +21,7 @@
*/
#include "SDL_config.h"

#define WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>

#include "SDL_main.h"
Expand Down
2 changes: 1 addition & 1 deletion distrib/sdl-1.2.15/src/video/windib/SDL_dibvideo.c
Expand Up @@ -21,7 +21,7 @@
*/
#include "SDL_config.h"

#define WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>

/* Not yet in the mingw32 cross-compile headers */
Expand Down
2 changes: 1 addition & 1 deletion distrib/sdl-1.2.15/src/video/windib/SDL_dibvideo.h
Expand Up @@ -24,7 +24,7 @@
#ifndef _SDL_dibvideo_h
#define _SDL_dibvideo_h

#define WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>


Expand Down
2 changes: 1 addition & 1 deletion distrib/sdl-1.2.15/src/video/windib/SDL_gapidibvideo.h
Expand Up @@ -24,7 +24,7 @@
#ifndef _SDL_gapidibvideo_h
#define _SDL_gapidibvideo_h

#define WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>

/* Hidden "this" pointer for the video functions */
Expand Down
2 changes: 1 addition & 1 deletion exec.c
Expand Up @@ -1174,7 +1174,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
0xff, size >> TARGET_PAGE_BITS);
//cpu_physical_memory_set_dirty_range(new_block->offset, size, 0xff);

//qemu_ram_setup_dump(new_block->host, size);
qemu_ram_setup_dump(new_block->host, size);
//qemu_madvise(new_block->host, size, QEMU_MADV_HUGEPAGE);
//qemu_madvise(new_block->host, size, QEMU_MADV_DONTFORK);

Expand Down
9 changes: 7 additions & 2 deletions hw/android/goldfish/mmc.c
Expand Up @@ -10,6 +10,7 @@
** GNU General Public License for more details.
*/
#include "cpu.h"
#include "qemu-common.h"
#include "migration/qemu-file.h"
#include "hw/android/goldfish/device.h"
#include "hw/hw.h"
Expand Down Expand Up @@ -266,7 +267,9 @@ static void goldfish_mmc_do_command(struct goldfish_mmc_state *s, uint32_t cmd,
m = (uint32_t)(capacity / (512*1024)) - 1;
// m must fit into 22 bits
if (m & 0xFFC00000) {
fprintf(stderr, "SD card too big (%lld bytes). Maximum SDHC card size is 128 gigabytes.\n", (long long)capacity);
fprintf(stderr, "SD card too big (%" PRId64 " bytes). "
"Maximum SDHC card size is 128 gigabytes.\n",
capacity);
abort();
}

Expand All @@ -292,7 +295,9 @@ static void goldfish_mmc_do_command(struct goldfish_mmc_state *s, uint32_t cmd,
exponent = 0;
capacity = sector_count * 512;
if (capacity > 2147483648U) {
fprintf(stderr, "SD card too big (%lld bytes). Maximum SD card size is 2 gigabytes.\n", (long long)capacity);
fprintf(stderr, "SD card too big (%" PRIu64 " bytes). "
"Maximum SD card size is 2 gigabytes.\n",
capacity);
abort();
}
capacity >>= 10; // convert to Kbytes
Expand Down
2 changes: 1 addition & 1 deletion include/exec/cpu-all.h
Expand Up @@ -325,7 +325,7 @@ extern unsigned long reserved_va;
#define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1)
#define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK)
#ifdef TARGET_X86_64
#define TARGET_PTE_MASK 0x7fffffffffff
#define TARGET_PTE_MASK 0x7fffffffffffULL
#endif

/* ??? These should be the larger of uintptr_t and target_ulong. */
Expand Down
8 changes: 2 additions & 6 deletions include/qemu-common.h
Expand Up @@ -12,6 +12,7 @@
#ifndef QEMU_COMMON_H
#define QEMU_COMMON_H

#include <inttypes.h>
#include <setjmp.h>

#include "qemu/compiler.h"
Expand Down Expand Up @@ -107,12 +108,7 @@ static inline char *realpath(const char *path, char *resolved_path)
_fullpath(resolved_path, path, _MAX_PATH);
return resolved_path;
}

#define PRId64 "I64d"
#define PRIx64 "I64x"
#define PRIu64 "I64u"
#define PRIo64 "I64o"
#endif
#endif /* _WIN32 */

/* bottom halves */
typedef void QEMUBHFunc(void *opaque);
Expand Down
5 changes: 2 additions & 3 deletions tap-win32.c
Expand Up @@ -576,7 +576,6 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle,
} version;
DWORD version_len;
DWORD idThread;
HANDLE hThread;

if (prefered_name != NULL)
snprintf(name_buffer, sizeof(name_buffer), "%s", prefered_name);
Expand Down Expand Up @@ -620,8 +619,8 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle,

*phandle = &tap_overlapped;

hThread = CreateThread(NULL, 0, tap_win32_thread_entry,
(LPVOID)&tap_overlapped, 0, &idThread);
(void) CreateThread(NULL, 0, tap_win32_thread_entry,
(LPVOID)&tap_overlapped, 0, &idThread);
return 0;
}

Expand Down

0 comments on commit 7891dd3

Please sign in to comment.