Skip to content

Commit

Permalink
This patch adds mingw32 cross-compilation support to HandBrake trunk to
Browse files Browse the repository at this point in the history
produce native win32 binaries. The main benefits are the binary does not have
any Cygwin runtime requirements and various host platforms can be leveraged
to build HandBrake.

Cross-compilation toolchains are complex to setup and recommended for experts
only; but once setup it can build at speeds similar to native builds,
on Darwin or Linux.

BUILD INSTRUCTIONS:
  Add mingw32 toolchain to beginning of your path and take the toolchain
  prefix from gcc (eg: i386-mingw32-gcc) and pass to configure:

    ./configure --cross=i386-ming32

PRODUCTS:
  - hb.lib (static library)
  - HandBrakeCLI.exe

DOWNLOADS:
  Contrib downloads need to be seeded with:
  - pthreads-w32-2-8-0-release.tar.gz (new)
  - xvidcore-20090311.tar.gz

SUMMARY:
  Specifically, all GUI trees are not impacted.

  configure
  - added --cross=PREFIX
  - reworked search for gcc and cross-compile related tools to use prefix

  contrib/
  - sub-patches added as needed for mingw

  contrib/xvidcore/
  - bumped from 1.1.3 -> 1.2.1+ (daily 20090311)
  - reconstituted P01-cygwin.patch
  - created new P00-darwin.patch needed for macho64 asm flag on x86_64 arch
  
  libhb/
  - uint -> uint32_t
  - remaining changes guarded by mingw32 macro.
  
  test/
  - modified to support pthread-compatibility library attach/detach.
  - all changes guarded by mingw32 macro.

BRANCHES:
  source: https://hbfork.googlecode.com/svn/branches/mingw@28
  target: svn://svn.handbrake.fr/HandBrake/trunk@2325


git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2326 b64f7644-9d1e-0410-96f1-a4d463321fa5
  • Loading branch information
KonaBlend committed Apr 14, 2009
1 parent 6a59b3b commit 16b2cd5
Show file tree
Hide file tree
Showing 38 changed files with 683 additions and 160 deletions.
1 change: 1 addition & 0 deletions contrib/bzip2/module.defs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ BZIP2.CONFIGURE = $(TOUCH.exe) $@
BZIP2.BUILD.extra = \
CC=$(BZIP2.GCC.gcc) \
CFLAGS="$(call fn.ARGS,BZIP2.GCC,*archs)" \
RANLIB="$(RANLIB.exe)"
PREFIX=$(call fn.ABSOLUTE,$(CONTRIB.build/))

BZIP2.BUILD.ntargets = libbz2.a
Expand Down
25 changes: 25 additions & 0 deletions contrib/faad2/P00-mingw-types.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff -Naur faad2.orig/common/mp4ff/mp4ff_int_types.h faad2/common/mp4ff/mp4ff_int_types.h
--- faad2.orig/common/mp4ff/mp4ff_int_types.h 2005-02-01 08:15:55.000000000 -0500
+++ faad2/common/mp4ff/mp4ff_int_types.h 2008-10-07 16:43:06.000000000 -0400
@@ -1,7 +1,7 @@
#ifndef _MP4FF_INT_TYPES_H_
#define _MP4FF_INT_TYPES_H_

-#if defined (_WIN32)
+#if defined(_WIN32) && !defined(__MINGW32__)

typedef char int8_t;
typedef unsigned char uint8_t;
diff -Naur faad2.orig/frontend/main.c faad2/frontend/main.c
--- faad2.orig/frontend/main.c 2007-11-01 08:33:29.000000000 -0400
+++ faad2/frontend/main.c 2008-10-07 16:55:49.000000000 -0400
@@ -31,7 +31,9 @@
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
+#ifndef __MINGW32__
#define off_t __int64
+#endif
#else
#include <time.h>
#endif
24 changes: 17 additions & 7 deletions contrib/ffmpeg/module.defs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ FFMPEG.EXTRACT.tarbase = ffmpeg-0.5
FFMPEG.CONFIGURE.deps =
FFMPEG.CONFIGURE.env =
FFMPEG.CONFIGURE.host =
#FFMPEG.CONFIGURE.shared =
#FFMPEG.CONFIGURE.static =

FFMPEG.CONFIGURE.extra = \
--disable-bsfs \
Expand All @@ -21,19 +23,27 @@ FFMPEG.CONFIGURE.extra = \
--enable-gpl \
--enable-libfaad \
--enable-muxer=ipod \
--enable-pthreads \
--enable-swscale \
--cc="$(GCC.gcc)" \
--extra-cflags="$(call fn.ARGS,FFMPEG.GCC,*archs ?extra) -I$(call fn.ABSOLUTE,$(CONTRIB.build/)include)" \
--extra-ldflags="$(call fn.ARGS,FFMPEG.GCC,*archs ?extra) -L$(call fn.ABSOLUTE,$(CONTRIB.build/)lib)"

ifeq ($(BUILD.cross),1)
FFMPEG.CONFIGURE.extra += --enable-cross-compile --arch=$(BUILD.machine)
endif

ifeq (cygwin,$(BUILD.system))
FFMPEG.CONFIGURE.extra += --enable-memalign-hack
## check against tuple: B-SYSTEM where B is { 0 | 1 } for cross-compiling flag
ifeq (0-cygwin,$(BUILD.cross)-$(BUILD.system))
FFMPEG.CONFIGURE.extra += --enable-pthreads --enable-memalign-hack
FFMPEG.GCC.args.extra = -fno-common
else ifeq (1-darwin,$(BUILD.cross)-$(BUILD.system))
## section for darwin-archs
FFMPEG.CONFIGURE.extra += --enable-pthreads --enable-cross-compile --arch=$(BUILD.machine)
else ifeq (1-mingw,$(BUILD.cross)-$(BUILD.system))
FFMPEG.CONFIGURE.extra += \
--enable-w32threads \
--enable-memalign-hack \
--target-os=mingw32 \
--enable-cross-compile --cross-prefix=$(BUILD.cross.prefix)
FFMPEG.GCC.args.extra += -fno-common
else
FFMPEG.CONFIGURE.extra += --enable-pthreads
endif

#
Expand Down
26 changes: 26 additions & 0 deletions contrib/libdvdread/P02-mingw-ssize_t.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff -Naur libdvdread.orig/configure libdvdread/configure
--- libdvdread.orig/configure 2006-10-06 04:14:24.000000000 -0400
+++ libdvdread/configure 2009-03-10 17:45:06.000000000 -0400
@@ -3550,9 +3550,6 @@
_ACEOF

;;
- x*mingw32* | x*cygwin*)
- CFLAGS="${CFLAGS} -Dssize_t=long"
- ;;
x*)
;;
esac
diff -Naur libdvdread.orig/configure.in libdvdread/configure.in
--- libdvdread.orig/configure.in 2006-10-06 04:12:31.000000000 -0400
+++ libdvdread/configure.in 2009-03-10 17:45:06.000000000 -0400
@@ -15,9 +15,6 @@
CFLAGS="${CFLAGS} -no-cpp-precomp"
AC_DEFINE(__DARWIN__, 1, Have a Mac OS X system)
;;
- x*mingw32* | x*cygwin*)
- CFLAGS="${CFLAGS} -Dssize_t=long"
- ;;
x*)
;;
esac
134 changes: 134 additions & 0 deletions contrib/libdvdread/P03-mingw-disable-dlopen.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
diff -Naur libdvdread.orig/configure libdvdread/configure
--- libdvdread.orig/configure 2006-10-06 04:14:24.000000000 -0400
+++ libdvdread/configure 2009-03-10 17:48:56.000000000 -0400
@@ -18889,11 +18889,6 @@
echo "${ECHO_T}$ac_cv_lib_dl_dlopen" >&6
if test $ac_cv_lib_dl_dlopen = yes; then
DL_LIBS=-ldl
-else
- { { echo "$as_me:$LINENO: error: You need libdl (dlopen)" >&5
-echo "$as_me: error: You need libdl (dlopen)" >&2;}
- { (exit 1); exit 1; }; }
-
fi


diff -Naur libdvdread.orig/dvdread/dvd_input.c libdvdread/dvdread/dvd_input.c
--- libdvdread.orig/dvdread/dvd_input.c 2005-09-19 09:43:08.000000000 -0400
+++ libdvdread/dvdread/dvd_input.c 2009-03-10 18:01:43.000000000 -0400
@@ -44,18 +44,6 @@

char * (*dvdinput_error) (dvd_input_t);

-#ifdef HAVE_DVDCSS_DVDCSS_H
-/* linking to libdvdcss */
-#include <dvdcss/dvdcss.h>
-#define DVDcss_open(a) dvdcss_open((char*)(a))
-#define DVDcss_close dvdcss_close
-#define DVDcss_seek dvdcss_seek
-#define DVDcss_title dvdcss_title
-#define DVDcss_read dvdcss_read
-#define DVDcss_error dvdcss_error
-#else
-/* dlopening libdvdcss */
-#include <dlfcn.h>
typedef struct dvdcss_s *dvdcss_handle;
static dvdcss_handle (*DVDcss_open) (const char *);
static int (*DVDcss_close) (dvdcss_handle);
@@ -63,7 +51,6 @@
static int (*DVDcss_title) (dvdcss_handle, int);
static int (*DVDcss_read) (dvdcss_handle, void *, int, int);
static char * (*DVDcss_error) (dvdcss_handle);
-#endif

/* The DVDinput handle, add stuff here for new input methods. */
struct dvd_input_s {
@@ -290,17 +277,7 @@
*/
void dvdinput_free(void)
{
-#ifdef HAVE_DVDCSS_DVDCSS_H
- /* linked statically, nothing to free */
return;
-#else
- if(dvdcss_library) {
- dlclose(dvdcss_library);
- dvdcss_library = NULL;
- }
- dvdcss_library_init = 0;
- return;
-#endif
}


@@ -324,58 +301,6 @@

verbose = get_verbose();

-#ifdef HAVE_DVDCSS_DVDCSS_H
- /* linking to libdvdcss */
- dvdcss_library = &dvdcss_library; /* Give it some value != NULL */
- /* the DVDcss_* functions have been #defined at the top */
- dvdcss_version = &dvdcss_interface_2;
-
-#else
-
- dvdcss_library = dlopen("libdvdcss.so.2", RTLD_LAZY);
-
- if(dvdcss_library != NULL) {
-#if defined(__OpenBSD__) && !defined(__ELF__)
-#define U_S "_"
-#else
-#define U_S
-#endif
- DVDcss_open = (dvdcss_handle (*)(const char*))
- dlsym(dvdcss_library, U_S "dvdcss_open");
- DVDcss_close = (int (*)(dvdcss_handle))
- dlsym(dvdcss_library, U_S "dvdcss_close");
- DVDcss_title = (int (*)(dvdcss_handle, int))
- dlsym(dvdcss_library, U_S "dvdcss_title");
- DVDcss_seek = (int (*)(dvdcss_handle, int, int))
- dlsym(dvdcss_library, U_S "dvdcss_seek");
- DVDcss_read = (int (*)(dvdcss_handle, void*, int, int))
- dlsym(dvdcss_library, U_S "dvdcss_read");
- DVDcss_error = (char* (*)(dvdcss_handle))
- dlsym(dvdcss_library, U_S "dvdcss_error");
-
- dvdcss_version = (char **)dlsym(dvdcss_library, U_S "dvdcss_interface_2");
-
- if(dlsym(dvdcss_library, U_S "dvdcss_crack")) {
- if(verbose >= 0) {
- fprintf(stderr,
- "libdvdread: Old (pre-0.0.2) version of libdvdcss found.\n"
- "libdvdread: You should get the latest version from "
- "http://www.videolan.org/\n" );
- }
- dlclose(dvdcss_library);
- dvdcss_library = NULL;
- } else if(!DVDcss_open || !DVDcss_close || !DVDcss_title || !DVDcss_seek
- || !DVDcss_read || !DVDcss_error || !dvdcss_version) {
- if(verbose >= 0) {
- fprintf(stderr, "libdvdread: Missing symbols in libdvdcss.so.2, "
- "this shouldn't happen !\n");
- }
- dlclose(dvdcss_library);
- dvdcss_library = NULL;
- }
- }
-#endif /* HAVE_DVDCSS_DVDCSS_H */
-
dvdcss_library_init = 1;

if(dvdcss_library) {
diff -Naur libdvdread.orig/dvdread/dvd_reader.c libdvdread/dvdread/dvd_reader.c
--- libdvdread.orig/dvdread/dvd_reader.c 2006-10-06 03:58:03.000000000 -0400
+++ libdvdread/dvdread/dvd_reader.c 2009-03-10 17:51:22.000000000 -0400
@@ -183,7 +183,7 @@
dev->align = align;
}

-#ifdef WIN32 /* replacement gettimeofday implementation */
+#if defined(WIN32) && !defined(__MINGW32__) /* replacement gettimeofday implementation */
#include <sys/timeb.h>
static int gettimeofday( struct timeval *tv, void *tz )
{
29 changes: 29 additions & 0 deletions contrib/libdvdread/P04-mingw-endian-macros.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff -Naur libdvdread.orig/dvdread/bswap.h libdvdread/dvdread/bswap.h
--- libdvdread.orig/dvdread/bswap.h 2006-06-06 16:03:37.000000000 -0400
+++ libdvdread/dvdread/bswap.h 2009-03-13 21:05:23.000000000 -0400
@@ -83,6 +83,25 @@
#define B2N_32(x) x = OSSwapBigToHostConstInt32(x)
#define B2N_64(x) x = OSSwapBigToHostConstInt64(x)

+#elif defined(__MINGW32__)
+#define B2N_16(x) \
+ x = ((((x) & 0xff00) >> 8) | \
+ (((x) & 0x00ff) << 8))
+#define B2N_32(x) \
+ x = ((((x) & 0xff000000) >> 24) | \
+ (((x) & 0x00ff0000) >> 8) | \
+ (((x) & 0x0000ff00) << 8) | \
+ (((x) & 0x000000ff) << 24))
+#define B2N_64(x) \
+ x = ((((x) & 0xff00000000000000ULL) >> 56) | \
+ (((x) & 0x00ff000000000000ULL) >> 40) | \
+ (((x) & 0x0000ff0000000000ULL) >> 24) | \
+ (((x) & 0x000000ff00000000ULL) >> 8) | \
+ (((x) & 0x00000000ff000000ULL) << 8) | \
+ (((x) & 0x0000000000ff0000ULL) << 24) | \
+ (((x) & 0x000000000000ff00ULL) << 40) | \
+ (((x) & 0x00000000000000ffULL) << 56))
+
#else
#if defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) || defined(WIN32) || defined(__BEOS__) || defined(__INTERIX)
/* These systems don't have swap macros */
28 changes: 28 additions & 0 deletions contrib/libdvdread/P05-mingw-large-file.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--- libdvdread.orig/dvdread/dvd_input.h 2005-09-06 12:23:00.000000000 -0700
+++ libdvdread/dvdread/dvd_input.h 2009-03-25 15:01:39.000000000 -0700
@@ -28,6 +28,24 @@

#define DVDINPUT_READ_DECRYPT (1 << 0)

+#if defined( __MINGW32__ )
+# undef lseek
+# define lseek _lseeki64
+# undef fseeko
+# define fseeko fseeko64
+# undef ftello
+# define ftello ftello64
+# define flockfile(...)
+# define funlockfile(...)
+# define getc_unlocked getc
+# undef off_t
+# define off_t off64_t
+# undef stat
+# define stat _stati64
+# define fstat _fstati64
+# define wstat _wstati64
+#endif
+
typedef struct dvd_input_s *dvd_input_t;

/**

24 changes: 24 additions & 0 deletions contrib/libmkv/P00-mingw-large-file.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--- libmkv.orig/src/matroska.c 2009-01-12 23:14:26.000000000 -0800
+++ libmkv/src/matroska.c 2009-03-25 15:22:30.000000000 -0700
@@ -27,6 +27,11 @@

#include <sys/time.h>

+#if defined( __MINGW32__ )
+#undef fseeko
+#define fseeko fseeko64
+#endif
+
#define RESERVED_SEEKHEAD 0x100
/* 256 bytes should be enough room for our Seek entries. */
#define RESERVED_CHAPTERS 0x800
@@ -34,7 +39,7 @@

int mk_seekFile(mk_Writer *w, uint64_t pos)
{
- if (fseek(w->fp, pos, SEEK_SET))
+ if (fseeko(w->fp, pos, SEEK_SET))
return -1;

w->f_pos = pos;

16 changes: 16 additions & 0 deletions contrib/libmp4v2/P00-mingw-static.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Index: mp4v2/include/mp4v2/platform.h
===================================================================
--- mp4v2/include/mp4v2/platform.h (revision 272)
+++ mp4v2/include/mp4v2/platform.h (working copy)
@@ -24,8 +24,10 @@
#if defined( _WIN32 ) || defined( __MINGW32__ )
# if defined( _WINDLL ) || defined( DLL_EXPORT )
# define MP4V2_EXPORT __declspec(dllexport)
+# elif defined( _DLL ) || defined( DLL_IMPORT )
+# define MP4V2_EXPORT __declspec(dllimport)
# else
-# define MP4V2_EXPORT __declspec(dllimport)
+# define MP4V2_EXPORT
# endif
#else
# define MP4V2_EXPORT __attribute__((visibility("default")))
31 changes: 31 additions & 0 deletions contrib/libmp4v2/P01-mingw-msvcrt-lower.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
diff -Naur libmp4v2.orig/libplatform/io/File_win32.cpp libmp4v2/libplatform/io/File_win32.cpp
--- libmp4v2.orig/libplatform/io/File_win32.cpp 2008-11-16 02:50:26.000000000 -0500
+++ libmp4v2/libplatform/io/File_win32.cpp 2009-03-13 02:00:09.000000000 -0400
@@ -8,7 +8,8 @@
bool
StdioFile::getPosition( Size& pos_ )
{
- pos_ = _ftelli64( _handle );
+ fflush( _handle ); // must flush because we're using _fileno routines
+ pos_ = _telli64( _fileno( _handle ));
return pos_ == -1;
}

@@ -17,6 +18,7 @@
bool
StdioFile::getSize( Size& size_ )
{
+ fflush( _handle ); // must flush because we're using _fileno routines
LARGE_INTEGER n;
if( !GetFileSizeEx( (HANDLE)_get_osfhandle( _fileno( _handle )), &n ))
return true;
@@ -29,7 +31,8 @@
bool
StdioFile::setPosition( Size pos_ )
{
- return _fseeki64( _handle, pos_, SEEK_SET ) != 0;
+ fflush( _handle ); // must flush because we're using _fileno routines
+ return _lseeki64( _fileno( _handle ), pos_, SEEK_SET ) == -1;
}

///////////////////////////////////////////////////////////////////////////////
26 changes: 26 additions & 0 deletions contrib/libmp4v2/P02-mingw-configure.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff -Naur libmp4v2.orig/configure.ac libmp4v2/configure.ac
--- libmp4v2.orig/configure.ac 2009-01-10 12:44:40.000000000 -0500
+++ libmp4v2/configure.ac 2009-03-13 18:18:38.000000000 -0400
@@ -103,11 +103,11 @@
X_CXX_ARCH="$X_CXX_ARCH -mwin32"
fi
;;
-*-*-mingw32)
+*-*-mingw*)
# do not support shared
enable_shared=no
X_PLATFORM=win32
- X_MINGW_LIBS="$X_MINGW_LIBS -lmsvcr80"
+ X_MINGW_LIBS="$X_MINGW_LIBS"
X_CXX_W="$X_CXX_W -Wno-format"
if test "$enable_mingw_threads" = "yes"; then
X_CXX_ARCH="$X_CXX_ARCH -mthreads"
@@ -197,7 +197,7 @@
case ${host} in
*-*-cygwin)
;;
- *-*-mingw32)
+ *-*-mingw*)
;;
*)
AC_LANG(C++)
Loading

0 comments on commit 16b2cd5

Please sign in to comment.