From f79f32085972bbc7000994ea515d3b7983082503 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 5 Dec 2012 15:30:49 -0700 Subject: [PATCH] fix MSVC build regression --- makefile | 30 ++++++++++++++++++++++-------- src/embed.cpp | 8 +++++--- src/embed.h | 2 +- src/embedded-loader.cpp | 13 +++++++++---- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/makefile b/makefile index c1a2fb2b7b..f006ba0bf9 100755 --- a/makefile +++ b/makefile @@ -568,7 +568,10 @@ as := $(cc) ld := $(cc) build-ld := $(build-cc) +static = -static + ifdef msvc + static = no-error = windows-path = $(native-path) windows-java-home := $(shell $(windows-path) "$(JAVA_HOME)") @@ -591,7 +594,7 @@ ifdef msvc shared = -dll lflags = -nologo -LIBPATH:"$(zlib)/lib" -DEFAULTLIB:ws2_32 \ - -DEFAULTLIB:zlib -MANIFEST -debug + -DEFAULTLIB:zlib -DEFAULTLIB:user32 -MANIFEST -debug output = -Fo$(1) ifeq ($(mode),debug) @@ -1021,12 +1024,18 @@ endif ifdef embed $(embed): $(embed-objects) $(embed-loader-o) @echo "building $(embed)" - $(cxx) $(^) -mwindows -mconsole -static -o $(@) +ifdef msvc + $(ld) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ + -IMPLIB:$(@).lib -MANIFESTFILE:$(@).manifest + $(mt) -manifest $(@).manifest -outputresource:"$(@);1" +else + $(cxx) $(^) $(lflags) $(static) $(call output,$(@)) +endif $(build-embed)/%.o: $(src)/%.cpp @echo "compiling $(@)" @mkdir -p $(dir $(@)) - $(cxx) -D_UNICODE -DUNICODE -c $(<) -o $(@) + $(cxx) $(cflags) -c $(<) $(call output,$(@)) $(embed-loader-o): $(embed-loader) $(converter) @mkdir -p $(dir $(@)) @@ -1036,17 +1045,22 @@ $(embed-loader-o): $(embed-loader) $(converter) $(embed-loader): $(embed-loader-objects) $(static-library) @mkdir -p $(dir $(@)) cd $(dir $(@)) && $(ar) x ../../../$(static-library) +ifdef msvc + $(ld) $(lflags) $(dir $(@))/*.o -out:$(@) -PDB:$(@).pdb \ + -IMPLIB:$(@).lib -MANIFESTFILE:$(@).manifest + $(mt) -manifest $(@).manifest -outputresource:"$(@);1" +else $(dlltool) -z $(addsuffix .def,$(basename $(@))) $(dir $(@))/*.o $(dlltool) -d $(addsuffix .def,$(basename $(@))) -e $(addsuffix .exp,$(basename $(@))) - $(cxx) $(addsuffix .exp,$(basename $(@))) $(dir $(@))/*.o -L../win32/lib -lmingwthrd -lm -lz -lws2_32 -liphlpapi \ - -mwindows -mconsole -static -o $(@) - strip --strip-all $(@) + $(ld) $(addsuffix .exp,$(basename $(@))) $(dir $(@))/*.o \ + $(lflags) $(bootimage-lflags) -o $(@) +endif + $(strip) $(strip-all) $(@) $(build-embed-loader)/%.o: $(src)/%.cpp @echo "compiling $(@)" @mkdir -p $(dir $(@)) - $(cxx) -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/win32 \ - -D_JNI_IMPLEMENTATION_ -c $(<) -o $(@) + $(cxx) $(cflags) -c $(<) $(call output,$(@)) endif $(build)/%.o: $(lzma)/C/%.c diff --git a/src/embed.cpp b/src/embed.cpp index d47e4e98a9..a4a32bb6d7 100644 --- a/src/embed.cpp +++ b/src/embed.cpp @@ -74,12 +74,12 @@ bool mkStringSection(std::vector* stringSection, const std::vector& strings) { - for(int i = 0; i < strings.size(); i += 16) + for(unsigned i = 0; i < strings.size(); i += 16) { std::vector stringSection; if(mkStringSection(&stringSection, strings, i, std::min(i + 15, strings.size() - 1))) - UpdateResourceW(hDest, RT_STRING, MAKEINTRESOURCE((i >> 4) + 1), LANG_NEUTRAL, &stringSection.at(0), sizeof(wchar_t) * stringSection.size()); + UpdateResourceW(hDest, reinterpret_cast(RT_STRING), reinterpret_cast(MAKEINTRESOURCE((i >> 4) + 1)), LANG_NEUTRAL, &stringSection.at(0), sizeof(wchar_t) * stringSection.size()); } } @@ -104,7 +104,7 @@ int wmain(int argc, wchar_t* argv[]) std::vector jarFile; readFile(&jarFile, classesName); - UpdateResourceW(hDest, RT_RCDATA, _T(RESID_BOOT_JAR), LANG_NEUTRAL, &jarFile.at(0), jarFile.size()); + UpdateResourceW(hDest, reinterpret_cast(RT_RCDATA), RESID_BOOT_JAR, LANG_NEUTRAL, &jarFile.at(0), jarFile.size()); EndUpdateResource(hDest, FALSE); } @@ -113,6 +113,7 @@ int wmain(int argc, wchar_t* argv[]) return 0; } +#ifndef _MSC_VER extern "C" int _CRT_glob; extern "C" void __wgetmainargs(int*, wchar_t***, wchar_t***, int, int*); @@ -123,3 +124,4 @@ int main() __wgetmainargs(&argc, &argv, &enpv, _CRT_glob, &si); return wmain(argc, argv); } +#endif diff --git a/src/embed.h b/src/embed.h index a38108e64b..2f5b5f14ef 100644 --- a/src/embed.h +++ b/src/embed.h @@ -12,6 +12,6 @@ #define EMBED_H #define RESID_MAIN_CLASS 100 -#define RESID_BOOT_JAR "BOOT.JAR" +#define RESID_BOOT_JAR L"BOOT.JAR" #endif diff --git a/src/embedded-loader.cpp b/src/embedded-loader.cpp index 0b0a2c90ab..eb5b26f359 100644 --- a/src/embedded-loader.cpp +++ b/src/embedded-loader.cpp @@ -15,20 +15,25 @@ #include "embed.h" #include "jni.h" - #if (defined __MINGW32__) || (defined _MSC_VER) # define EXPORT __declspec(dllexport) +# ifdef _MSC_VER +# define not ! +# endif #else # define EXPORT __attribute__ ((visibility("default"))) \ __attribute__ ((used)) #endif extern "C" { + // since we aren't linking against libstdc++, we must implement this + // ourselves: + void __cxa_pure_virtual(void) { abort(); } EXPORT const uint8_t* bootJar(unsigned* size) { - if(HRSRC hResInfo = FindResource(NULL, _T(RESID_BOOT_JAR), RT_RCDATA)) + if(HRSRC hResInfo = FindResourceW(NULL, RESID_BOOT_JAR, reinterpret_cast(RT_RCDATA))) { if(HGLOBAL hRes = LoadResource(NULL, hResInfo)) { @@ -44,7 +49,7 @@ extern "C" { } } // extern "C" -static bool getMainClass(char* pName, int maxLen) +static void getMainClass(char* pName, int maxLen) { if(0 == LoadString(NULL, RESID_MAIN_CLASS, pName, maxLen)) { @@ -61,7 +66,7 @@ main(int ac, const char** av) vmArgs.nOptions = 1; vmArgs.ignoreUnrecognized = JNI_TRUE; - JavaVMOption options[vmArgs.nOptions]; + JavaVMOption options[1]; vmArgs.options = options; options[0].optionString = const_cast("-Xbootclasspath:[bootJar]");