From 68513521ef1d9f854f945235ea983bbfb0fcb9ea Mon Sep 17 00:00:00 2001 From: Frank Jacobs Date: Fri, 10 Oct 2008 08:06:31 -0600 Subject: [PATCH 01/12] 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. --- classpath/java-nio.cpp | 3 +-- makefile | 41 +++++++++++++++++++++++++++++++++++++---- readme.txt | 18 +++++++++++++++++- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/classpath/java-nio.cpp b/classpath/java-nio.cpp index e82f34f0dd..88d0afb195 100644 --- a/classpath/java-nio.cpp +++ b/classpath/java-nio.cpp @@ -14,6 +14,7 @@ #include #include +#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 diff --git a/makefile b/makefile index dad63c0512..73da99af9d 100644 --- a/makefile +++ b/makefile @@ -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 $(@) diff --git a/readme.txt b/readme.txt index 2efc5b8c84..e349bf0e88 100644 --- a/readme.txt +++ b/readme.txt @@ -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 From e2c04b276199024543ca8b03517fd884690ac917 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 10 Oct 2008 11:43:40 -0600 Subject: [PATCH 02/12] various makefile refinements for better supporting native Windows builds --- makefile | 77 ++++++++++++++++---------------------------------------- 1 file changed, 22 insertions(+), 55 deletions(-) diff --git a/makefile b/makefile index 73da99af9d..ff5e3869cd 100644 --- a/makefile +++ b/makefile @@ -3,15 +3,10 @@ MAKEFLAGS = -s name = avian version = 0.1.1 -build-arch = $(shell uname -m) -ifeq ($(build-arch),i586) - build-arch = i386 -endif -ifeq ($(build-arch),i686) - build-arch = i386 -endif +build-arch = $(shell uname -m | sed 's/^i.86$$/i386/') -build-platform = $(shell uname -s | tr [:upper:] [:lower:]) +build-platform = \ + $(shell uname -s | tr [:upper:] [:lower:] | sed 's/^mingw32.*$$/windows/') arch = $(build-arch) platform = $(build-platform) @@ -41,11 +36,12 @@ cxx = $(build-cxx) cc = $(build-cc) ar = ar ranlib = ranlib +dlltool = dlltool objcopy = objcopy vg = nice valgrind --num-callers=32 --db-attach=yes --freelist-vol=100000000 vg += --leak-check=full --suppressions=valgrind.supp db = gdb --args -javac = javac +javac = "$(JAVA_HOME)/bin/javac" jar = jar strip = : strip-all = --strip-all @@ -55,12 +51,12 @@ rdynamic = -rdynamic warnings = -Wall -Wextra -Werror -Wunused-parameter -Winit-self common-cflags = $(warnings) -fno-rtti -fno-exceptions \ - -I$(JAVA_HOME)/include -idirafter $(src) -I$(native-build) \ + "-I$(JAVA_HOME)/include" -idirafter $(src) -I$(native-build) \ -D__STDC_LIMIT_MACROS -D_JNI_IMPLEMENTATION_ -DAVIAN_VERSION=\"$(version)\" \ -DBOOT_CLASSPATH=\"[classpathJar]\" build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \ - -I$(JAVA_HOME)/include/linux -I$(src) -pthread + "-I$(JAVA_HOME)/include/linux" -I$(src) -pthread cflags = $(build-cflags) @@ -77,8 +73,6 @@ pointer-size = 8 so-prefix = lib so-suffix = .so -exe-suffix = - shared = -shared @@ -89,8 +83,7 @@ ifeq ($(arch),i386) endif ifeq ($(platform),darwin) - build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \ - -I$(JAVA_HOME)/include/linux -I$(src) + build-cflags = $(common-cflags) -fPIC -fvisibility=hidden -I$(src) lflags = $(common-lflags) -ldl -framework CoreFoundation rdynamic = strip-all = -S -x @@ -99,35 +92,7 @@ ifeq ($(platform),darwin) shared = -dynamiclib endif -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 - - system = windows - object-format = pe-i386 - - 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 @@ -138,14 +103,18 @@ ifeq ($(platform),windows) so-suffix = .dll exe-suffix = .exe - cxx = i586-mingw32msvc-g++ - cc = i586-mingw32msvc-gcc - dlltool = i586-mingw32msvc-dlltool - ar = i586-mingw32msvc-ar - ranlib = i586-mingw32msvc-ranlib - objcopy = i586-mingw32msvc-objcopy + ifeq ($(build-platform),windows) + build-cflags = $(common-cflags) \ + "-I$(JAVA_HOME)/include/win32" -I$(src) -mthreads + else + cxx = i586-mingw32msvc-g++ + cc = i586-mingw32msvc-gcc + dlltool = i586-mingw32msvc-dlltool + ar = i586-mingw32msvc-ar + ranlib = i586-mingw32msvc-ranlib + objcopy = i586-mingw32msvc-objcopy + endif - rdynamic = -Wl,--export-dynamic lflags = -L$(lib) $(common-lflags) -lws2_32 -mwindows -mconsole cflags = $(common-cflags) -I$(inc) endif @@ -324,7 +293,7 @@ $(classpath-dep): $(classpath-sources) @echo "compiling classpath classes" @mkdir -p $(dir $(@)) $(javac) -d $(dir $(@)) -bootclasspath $(classpath-build) \ - $(shell make -s --no-print-directory $(classpath-classes)) + $(shell $(MAKE) -s --no-print-directory $(classpath-classes)) @touch $(@) $(test-build)/%.class: $(test)/%.java @@ -334,7 +303,7 @@ $(test-dep): $(test-sources) @echo "compiling test classes" @mkdir -p $(dir $(@)) $(javac) -d $(dir $(@)) -bootclasspath $(classpath-build) \ - $(shell make -s --no-print-directory $(test-classes)) + $(shell $(MAKE) -s --no-print-directory $(test-classes)) @touch $(@) define compile-object @@ -400,9 +369,7 @@ $(executable): \ $(vm-objects) $(classpath-object) $(jni-objects) $(driver-object) \ $(boot-object) @echo "linking $(@)" - -ifneq (,$(filter $(platform),windows mingw32_nt-6.0)) - # This is either cross-compiled or native Windows build +ifeq ($(platform),windows) $(dlltool) -z $(@).def $(^) $(dlltool) -k -d $(@).def -e $(@).exp $(cc) $(@).exp $(^) $(lflags) -o $(@) From 88828e7a021b93c4165b586b15037608a7518712 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 10 Oct 2008 11:47:31 -0600 Subject: [PATCH 03/12] update readme.txt windows build instructions --- readme.txt | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/readme.txt b/readme.txt index e349bf0e88..a7cd7b2c12 100644 --- a/readme.txt +++ b/readme.txt @@ -12,15 +12,21 @@ on Mac OS X: $ 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 +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 +download page. Extract the tarball into your MSYS installation +directory. Open the MSYS shell and: + + $ export JAVA_HOME="C:/Program Files/Java/jdk1.6.0_07" $ make - $ build/mingw32_nt-6.0-i386-compile-fast/avian -cp build/test Hello + $ build/windows-i386-compile-fast/avian -cp build/test Hello + +Adjust JAVA_HOME according to your system, but be sure to use forward +slashes in the path. + Introduction ------------ @@ -50,10 +56,6 @@ Avian can currently target the following platforms: Win32 (i386) Mac OS X (i386) -The Win32 port may be built on Linux using a MinGW cross compiler and -build environment. Builds on MSYS or Cygwin are not yet supported, -but patches to enable them are welcome. - Building -------- @@ -83,7 +85,7 @@ The build is directed by a single makefile and may be influenced via certain flags described below. $ make platform={linux,windows,darwin} arch={i386,x86_64} \ - process={compile,interpret} mode={debug,debug-fast,fast} + process={compile,interpret} mode={debug,debug-fast,fast,small} * platform - the target platform default: output of $(uname -s | tr [:upper:] [:lower:]) @@ -233,7 +235,7 @@ main(int ac, const char** av) return exitCode; } EOF - $ g++ -I$JAVA_HOME/include -c main.cpp -o main.o + $ g++ -I$JAVA_HOME/include -D_JNI_IMPLEMENTATION_ -c main.cpp -o main.o Step 5: Link the objects produced above to produce the final @@ -248,8 +250,8 @@ on Mac OS X: $ 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 + $ g++ hello.exp *.o -L../../win32/lib -lmingwthrd -lm -lz -lws2_32 \ + -mwindows -mconsole -o hello $ strip --strip-all hello.exe From f423d39b256fbd3ec532e2417ef5a2169cc4472e Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 10 Oct 2008 11:49:07 -0600 Subject: [PATCH 04/12] explicitly include stdint.h in java-nio.cpp --- classpath/java-nio.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/classpath/java-nio.cpp b/classpath/java-nio.cpp index 88d0afb195..86eb9aa6c5 100644 --- a/classpath/java-nio.cpp +++ b/classpath/java-nio.cpp @@ -12,9 +12,9 @@ #include #include #include +#include #include -#include "machine.h" #include "jni.h" #include "jni-util.h" @@ -36,6 +36,8 @@ typedef int socklen_t; #endif +inline void* operator new(size_t, void* p) throw() { return p; } + namespace { inline jbyteArray From 96d7bf571d0190962647b4d4d313986e34a2f0b4 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 10 Oct 2008 11:49:28 -0600 Subject: [PATCH 05/12] implement a few methods to make SWT 3.4 happy --- classpath/java/lang/StringBuffer.java | 5 +++++ classpath/java/lang/StringBuilder.java | 4 ++++ classpath/java/util/Calendar.java | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/classpath/java/lang/StringBuffer.java b/classpath/java/lang/StringBuffer.java index 5c3929c31e..cc494a7496 100644 --- a/classpath/java/lang/StringBuffer.java +++ b/classpath/java/lang/StringBuffer.java @@ -93,6 +93,11 @@ public class StringBuffer implements CharSequence { return this; } + public synchronized StringBuffer insert(int i, int v) { + sb.insert(i, v); + return this; + } + public synchronized StringBuffer delete(int start, int end) { sb.delete(start, end); return this; diff --git a/classpath/java/lang/StringBuilder.java b/classpath/java/lang/StringBuilder.java index cc1c681de4..47b58134d1 100644 --- a/classpath/java/lang/StringBuilder.java +++ b/classpath/java/lang/StringBuilder.java @@ -154,6 +154,10 @@ public class StringBuilder implements CharSequence { return insert(i, new String(new char[] { c }, 0, 1, false)); } + public StringBuilder insert(int i, int v) { + return insert(i, String.valueOf(v)); + } + public StringBuilder delete(int start, int end) { if (start >= end) { return this; diff --git a/classpath/java/util/Calendar.java b/classpath/java/util/Calendar.java index 8d81716253..d39b8a1438 100644 --- a/classpath/java/util/Calendar.java +++ b/classpath/java/util/Calendar.java @@ -45,6 +45,12 @@ public abstract class Calendar { fields[field] = value; } + public void set(int year, int month, int date) { + set(YEAR, year); + set(MONTH, month); + set(DAY_OF_MONTH, date); + } + public void setTime(Date date) { time = date.getTime(); } From e3a5c7e03fc6b4a0dab85d888f6f07408ff26afc Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 10 Oct 2008 17:01:33 -0600 Subject: [PATCH 06/12] look for jar under $JAVA_HOME/bin --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index ff5e3869cd..10ca344844 100644 --- a/makefile +++ b/makefile @@ -42,7 +42,7 @@ vg = nice valgrind --num-callers=32 --db-attach=yes --freelist-vol=100000000 vg += --leak-check=full --suppressions=valgrind.supp db = gdb --args javac = "$(JAVA_HOME)/bin/javac" -jar = jar +jar = "$(JAVA_HOME)/bin/jar" strip = : strip-all = --strip-all From 5c04c19e293441aee44552c35deb51adaddc72a7 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 10 Oct 2008 17:37:36 -0600 Subject: [PATCH 07/12] look for %s@%d format symbols when resolving native methods on Windows, which obviates the need for -k flag to dlltool --- makefile | 2 +- readme.txt | 2 +- src/process.cpp | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/makefile b/makefile index 10ca344844..61b9089d97 100644 --- a/makefile +++ b/makefile @@ -371,7 +371,7 @@ $(executable): \ @echo "linking $(@)" ifeq ($(platform),windows) $(dlltool) -z $(@).def $(^) - $(dlltool) -k -d $(@).def -e $(@).exp + $(dlltool) -d $(@).def -e $(@).exp $(cc) $(@).exp $(^) $(lflags) -o $(@) else $(cc) $(^) $(rdynamic) $(lflags) -o $(@) diff --git a/readme.txt b/readme.txt index a7cd7b2c12..a1f6a1dff9 100644 --- a/readme.txt +++ b/readme.txt @@ -251,7 +251,7 @@ on Mac OS X: on Windows: $ dlltool -z hello.def *.o - $ dlltool -k -d hello.def -e hello.exp + $ dlltool -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 diff --git a/src/process.cpp b/src/process.cpp index ecfac1f2d8..c2693d0281 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -167,8 +167,7 @@ resolveNativeMethod2(Thread* t, object method) } #ifdef __MINGW32__ - // on windows, we also try the _%s@%d variant, since the SWT - // libraries use it. + // on windows, we also try the _%s@%d and %s@%d variants unsigned footprint = methodParameterFootprint(t, method) + 1; if (methodFlags(t, method) & ACC_STATIC) { ++ footprint; @@ -186,6 +185,12 @@ resolveNativeMethod2(Thread* t, object method) if (p) { return p; } + + // one more try without the leading underscore + p = ::resolveNativeMethod(t, undecorated + 1, decorated + 1); + if (p) { + return p; + } #endif return 0; From 7a1522e94e9da5fb6f0ed5867acabba40c55bd93 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 10 Oct 2008 17:53:51 -0600 Subject: [PATCH 08/12] readme.txt clarifications for building on Windows --- readme.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index a1f6a1dff9..65ac99ce70 100644 --- a/readme.txt +++ b/readme.txt @@ -237,6 +237,8 @@ main(int ac, const char** av) EOF $ g++ -I$JAVA_HOME/include -D_JNI_IMPLEMENTATION_ -c main.cpp -o main.o +Add -I$JAVA_HOME/include/win32 to the above when building on Windows. + Step 5: Link the objects produced above to produce the final executable, and optionally strip its symbols. @@ -253,5 +255,5 @@ on Windows: $ dlltool -z hello.def *.o $ dlltool -d hello.def -e hello.exp $ g++ hello.exp *.o -L../../win32/lib -lmingwthrd -lm -lz -lws2_32 \ - -mwindows -mconsole -o hello + -mwindows -mconsole -o hello.exe $ strip --strip-all hello.exe From a6f1b92b6387b9246149e4cc78714b71f80106aa Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 10 Oct 2008 18:08:01 -0600 Subject: [PATCH 09/12] additional readme.txt embedding example clarification --- readme.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 65ac99ce70..d31022e1f0 100644 --- a/readme.txt +++ b/readme.txt @@ -235,9 +235,17 @@ main(int ac, const char** av) return exitCode; } EOF + +on Linux: + $ g++ -I$JAVA_HOME/include -I$JAVA_HOME/include/linux \ + -D_JNI_IMPLEMENTATION_ -c main.cpp -o main.o + +on Mac OS X: $ g++ -I$JAVA_HOME/include -D_JNI_IMPLEMENTATION_ -c main.cpp -o main.o -Add -I$JAVA_HOME/include/win32 to the above when building on Windows. +on Windows: + $ g++ -I$JAVA_HOME/include -I$JAVA_HOME/include/win32 \ + -D_JNI_IMPLEMENTATION_ -c main.cpp -o main.o Step 5: Link the objects produced above to produce the final From 471ac4d960271e45b651a501079de431c9d53d20 Mon Sep 17 00:00:00 2001 From: Frank Jacobs Date: Sat, 11 Oct 2008 10:10:11 -0600 Subject: [PATCH 10/12] support building from a directory with spaces in its name --- makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/makefile b/makefile index 61b9089d97..0393f5f2a5 100644 --- a/makefile +++ b/makefile @@ -93,8 +93,8 @@ ifeq ($(platform),darwin) endif ifeq ($(platform),windows) - inc = $(root)/win32/include - lib = $(root)/win32/lib + inc = "$(root)/win32/include" + lib = "$(root)/win32/lib" system = windows object-format = pe-i386 @@ -333,7 +333,7 @@ $(boot-object): $(boot-source) $(build)/classpath.jar: $(classpath-dep) (wd=$$(pwd); \ cd $(classpath-build); \ - $(jar) c0f $${wd}/$(@) $$(find . -name '*.class')) + $(jar) c0f "$${wd}/$(@)" $$(find . -name '*.class')) $(binaryToMacho): $(src)/binaryToMacho.cpp $(cxx) $(^) -o $(@) @@ -347,7 +347,7 @@ else (wd=$$(pwd); \ cd $(build); \ $(objcopy) -I binary classpath.jar \ - -O $(object-format) -B $(object-arch) $${wd}/$(@)) + -O $(object-format) -B $(object-arch) "$${wd}/$(@)") endif $(generator-objects): $(native-build)/%.o: $(src)/%.cpp From 54e618847adb25408ed3301842bc4ee4bd63ec85 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 11 Oct 2008 11:59:18 -0600 Subject: [PATCH 11/12] use /bin/sh instead of /bin/bash to run test.sh, since MSYS does not have /bin/bash (although /bin/sh is bash) --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 0393f5f2a5..250fc58e5a 100644 --- a/makefile +++ b/makefile @@ -255,7 +255,7 @@ vg: build .PHONY: test test: build - /bin/bash $(test)/test.sh 2>/dev/null \ + /bin/sh $(test)/test.sh 2>/dev/null \ $(executable) $(mode) "$(flags)" \ $(call class-names,$(test-build),$(test-classes)) From 1a39012002f30653468ef13a26c840e9d1dfc689 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 11 Oct 2008 14:46:20 -0600 Subject: [PATCH 12/12] support building on Cygwin --- makefile | 35 ++++++++++++++++++++++++----------- readme.txt | 54 +++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 61 insertions(+), 28 deletions(-) diff --git a/makefile b/makefile index 250fc58e5a..f06074bdcb 100644 --- a/makefile +++ b/makefile @@ -6,10 +6,12 @@ version = 0.1.1 build-arch = $(shell uname -m | sed 's/^i.86$$/i386/') build-platform = \ - $(shell uname -s | tr [:upper:] [:lower:] | sed 's/^mingw32.*$$/windows/') + $(shell uname -s | tr [:upper:] [:lower:] \ + | sed 's/^mingw32.*$$/mingw32/' \ + | sed 's/^cygwin.*$$/cygwin/') arch = $(build-arch) -platform = $(build-platform) +platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))) ifeq ($(platform),windows) arch = i386 @@ -62,6 +64,8 @@ cflags = $(build-cflags) common-lflags = -lm -lz +build-lflags = + lflags = $(common-lflags) -lpthread -ldl system = posix @@ -76,6 +80,8 @@ so-suffix = .so shared = -shared +native-path = echo + ifeq ($(arch),i386) object-arch = i386 object-format = elf32-i386 @@ -103,20 +109,27 @@ ifeq ($(platform),windows) so-suffix = .dll exe-suffix = .exe - ifeq ($(build-platform),windows) - build-cflags = $(common-cflags) \ - "-I$(JAVA_HOME)/include/win32" -I$(src) -mthreads - else + lflags = -L$(lib) $(common-lflags) -lws2_32 -mwindows -mconsole + cflags = $(common-cflags) -I$(inc) + + ifeq (,$(filter mingw32 cygwin,$(build-platform))) cxx = i586-mingw32msvc-g++ cc = i586-mingw32msvc-gcc dlltool = i586-mingw32msvc-dlltool ar = i586-mingw32msvc-ar ranlib = i586-mingw32msvc-ranlib objcopy = i586-mingw32msvc-objcopy + else + build-cflags = $(common-cflags) \ + "-I$(JAVA_HOME)/include/win32" -I$(src) -mthreads + ifeq ($(build-platform),cygwin) + build-lflags += -mno-cygwin + build-cflags += -mno-cygwin + lflags += -mno-cygwin + cflags += -mno-cygwin + native-path = cygpath -m + endif endif - - lflags = -L$(lib) $(common-lflags) -lws2_32 -mwindows -mconsole - cflags = $(common-cflags) -I$(inc) endif ifeq ($(mode),debug) @@ -333,7 +346,7 @@ $(boot-object): $(boot-source) $(build)/classpath.jar: $(classpath-dep) (wd=$$(pwd); \ cd $(classpath-build); \ - $(jar) c0f "$${wd}/$(@)" $$(find . -name '*.class')) + $(jar) c0f "$$($(native-path) "$${wd}/$(@)")" $$(find . -name '*.class')) $(binaryToMacho): $(src)/binaryToMacho.cpp $(cxx) $(^) -o $(@) @@ -392,5 +405,5 @@ $(executable-dynamic): $(driver-dynamic-object) $(dynamic-library) $(generator): $(generator-objects) @echo "linking $(@)" - $(build-cc) $(^) -o $(@) + $(build-cc) $(^) $(build-lflags) -o $(@) diff --git a/readme.txt b/readme.txt index d31022e1f0..c4e80a3cfd 100644 --- a/readme.txt +++ b/readme.txt @@ -11,19 +11,18 @@ on Mac OS X: $ 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: +on Windows (MSYS): $ export JAVA_HOME="C:/Program Files/Java/jdk1.6.0_07" $ make $ build/windows-i386-compile-fast/avian -cp build/test Hello +on Windows (Cygwin): + + $ export JAVA_HOME="/cygdrive/c/Program Files/Java/jdk1.6.0_07" + $ make + $ build/windows-i386-compile-fast/avian -cp build/test Hello + Adjust JAVA_HOME according to your system, but be sure to use forward slashes in the path. @@ -72,15 +71,6 @@ Build requirements include: Earlier versions of some of these packages may also work but have not been tested. -If you are cross-compiling for Windows, you may find it useful to use -our win32 repository: (run this from the directory containing the -avian directory) - - $ git clone git://oss.readytalk.com/win32.git - -This gives you the Windows JNI headers, zlib headers and library, and -a few other useful libraries like OpenSSL and libjpeg. - The build is directed by a single makefile and may be influenced via certain flags described below. @@ -101,6 +91,33 @@ certain flags described below. * process - choice between pure interpreter or JIT compiler default: compile +If you are compiling for Windows, you may either cross-compile using +MinGW or build natively on Windows under MSYS or Cygwin. + +Installing MSYS: + + 1. Download and install the current MinGW and MSYS packages from + mingw.org, selecting the C and C++ compilers when prompted. Use the + post-install script to create the filesystem link to the compiler. + + 2. Download GNU Make 3.81 from the MSYS download page + (make-3.81-MSYS-1.0.11-2.tar.bz2) and extract the tar file into + e.g. c:/msys/1.0. + +Installing Cygwin: + + 1. Download and run setup.exe from cygwin.com, installing the base + system and these packages: make, gcc-mingw-g++, and (optionally) + git. + +You may also find our win32 repository useful: (run this from the +directory containing the avian directory) + + $ git clone git://oss.readytalk.com/win32.git + +This gives you the Windows JNI headers, zlib headers and library, and +a few other useful libraries like OpenSSL and libjpeg. + Installing ---------- @@ -114,6 +131,9 @@ Embedding The following series of commands illustrates how to produce a stand-alone executable out of a Java application using Avian. +Note: if you are building on Cygwin, add -mno-cygwin to each of the +compile and link commands below. + Step 1: Build Avian, create a new directory, and populate it with the VM object files and bootstrap classpath jar.