support building on Windows using MinGW

Here is a patch for getting Avian to build in Windows. I used MinGW
and MSYS for the build environment. The patch has the following
changes:

1. java-nio.cpp: Had to add an include and remove a function
declaration that was reported as duplicate.
2. readme.txt: Updated the instructions to include notes about
building on Windows.
3. makefile: Added a conditional for MinGW. I left the existing "ifeq
($(platform),windows)" conditional alone so as to not break
cross-compiled Windows builds. There are some similarities between the
two, so it might be possible to combine portions of them in an elegant
manner. Since I'm not sure how the cross-compiled builds have been
done, I didn't want to mess with that portion of the makefile.
This commit is contained in:
Frank Jacobs 2008-10-10 08:06:31 -06:00 committed by Joel Dice
parent f9426f084f
commit 68513521ef
3 changed files with 55 additions and 7 deletions

View File

@ -14,6 +14,7 @@
#include <stdlib.h>
#include <unistd.h>
#include "machine.h"
#include "jni.h"
#include "jni-util.h"
@ -35,8 +36,6 @@
typedef int socklen_t;
#endif
inline void* operator new(size_t, void* p) throw() { return p; }
namespace {
inline jbyteArray

View File

@ -77,6 +77,8 @@ pointer-size = 8
so-prefix = lib
so-suffix = .so
exe-suffix =
shared = -shared
@ -97,7 +99,11 @@ ifeq ($(platform),darwin)
shared = -dynamiclib
endif
ifeq ($(platform),windows)
ifeq ($(platform),mingw32_nt-6.0)
# A native Windows build (i.e. not cross-compiled).
build-cflags = $(common-cflags) \
-I$(JAVA_HOME)/include/win32 -I$(src) -mthreads
lflags = $(common-lflags) -lmthreads -ldl
inc = $(root)/win32/include
lib = $(root)/win32/lib
@ -106,6 +112,31 @@ ifeq ($(platform),windows)
so-prefix =
so-suffix = .dll
exe-suffix = .exe
cxx = g++
cc = gcc
dlltool = dlltool
ar = ar
ranlib = ranlib
objcopy = objcopy
rdynamic = -Wl,--export-dynamic
lflags = -L$(lib) $(common-lflags) -lws2_32 -mwindows -mconsole
cflags = $(common-cflags) -I$(inc)
endif
ifeq ($(platform),windows)
# A Windows cross-compiled build
inc = $(root)/win32/include
lib = $(root)/win32/lib
system = windows
object-format = pe-i386
so-prefix =
so-suffix = .dll
exe-suffix = .exe
cxx = i586-mingw32msvc-g++
cc = i586-mingw32msvc-gcc
@ -214,9 +245,9 @@ generator-objects = \
generator = $(native-build)/generator
static-library = $(native-build)/lib$(name).a
executable = $(native-build)/$(name)
executable = $(native-build)/$(name)${exe-suffix}
dynamic-library = $(native-build)/$(so-prefix)$(name)$(so-suffix)
executable-dynamic = $(native-build)/$(name)-dynamic
executable-dynamic = $(native-build)/$(name)-dynamic${exe-suffix}
classpath-sources = $(shell find $(classpath) -name '*.java')
classpath-classes = \
@ -369,7 +400,9 @@ $(executable): \
$(vm-objects) $(classpath-object) $(jni-objects) $(driver-object) \
$(boot-object)
@echo "linking $(@)"
ifeq ($(platform),windows)
ifneq (,$(filter $(platform),windows mingw32_nt-6.0))
# This is either cross-compiled or native Windows build
$(dlltool) -z $(@).def $(^)
$(dlltool) -k -d $(@).def -e $(@).exp
$(cc) $(@).exp $(^) $(lflags) -o $(@)

View File

@ -10,7 +10,17 @@ on Mac OS X:
$ export JAVA_HOME=/Library/Java/Home
$ make
$ build/darwin-i386-compile-fast/avian -cp build/test Hello
on Windows:
Install the current MSYS from the MinGW page (selecting the C and C++
compilers). Follow the post-install options to create the file system
link to the compiler. Upgrade to GNU make 3.81 by downloading the
current release of GNU make from the same download page as the MSYS
download page. Extract the tarball into your MSYS installation
directory. Open the MSYS shell and:
$ export JAVA_HOME=C:/my/java/install # be sure to use forward slashes
$ make
$ build/mingw32_nt-6.0-i386-compile-fast/avian -cp build/test Hello
Introduction
------------
@ -237,3 +247,9 @@ on Mac OS X:
$ g++ -rdynamic *.o -ldl -lpthread -lz -o hello -framework CoreFoundation
$ strip -S -x hello
on Windows:
$ g++ -I$JAVA_HOME/include -I../../win32/include -D_JNI_IMPLEMENTATION_ -c main.cpp -o main.o
$ dlltool -z hello.def *.o
$ dlltool -k -d hello.def -e hello.exp
$ g++ hello.exp *.o -L../../win32/lib -lmingwthrd -lm -lz -lws2_32 -mwindows -mconsole -o hello
$ strip --strip-all hello.exe