Skip to content

Instantly share code, notes, and snippets.

@mugwort-rc
Last active January 31, 2016 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mugwort-rc/25d1be5b81b1234417aa to your computer and use it in GitHub Desktop.
Save mugwort-rc/25d1be5b81b1234417aa to your computer and use it in GitHub Desktop.
patch for mecab-0.996 build on MinGW48_32

変更点

  • MinGW32が-municodeオプションを認識しないため、オプション削除。
  • wmainが使えないのでwinmain.hを無効化。
  • WPATHを無効化。
  • unicode版はCreateFileW時にMeCab::Utf8ToWide(filename).c_str()としたが、日本語を含むパスをUTF-8で渡しても失敗する
  • ansi版はCreateFileWCreateFileAにした。日本語を含むパスはShiftJISで渡せば成功する。

参考

diff --git a/configure b/configure
index 27ff54b..f6cf792 100644
--- a/configure
+++ b/configure
@@ -18701,8 +18701,8 @@ $as_echo "yes" >&6; }
case "$host_os" in
mingw* | os2*)
MECAB_DEFAULT_RC='c:\\\\Program Files\\\\mecab\\\\etc\\\\mecabrc'
- CFLAGS="$CFLAGS -municode -DUNICODE -D_UNICODE"
- CXXFLAGS="$CXXFLAGS -municode -DUNICODE -D_UNICODE"
+# CFLAGS="$CFLAGS -municode -DUNICODE -D_UNICODE"
+# CXXFLAGS="$CXXFLAGS -municode -DUNICODE -D_UNICODE"
;;
*)
MECAB_DEFAULT_RC="$sysconfdir/mecabrc"
diff --git a/src/common.h b/src/common.h
index 4ed43c9..ce8afec 100644
--- a/src/common.h
+++ b/src/common.h
@@ -81,7 +81,7 @@
#define EXIT_SUCCESS 0
#endif
-#if defined(_WIN32) && !defined(__CYGWIN__)
+#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__)
#define WPATH(path) (MeCab::Utf8ToWide(path).c_str())
#else
#define WPATH(path) (path)
diff --git a/src/mecab-cost-train.cpp b/src/mecab-cost-train.cpp
index f927ef3..1a17a32 100644
--- a/src/mecab-cost-train.cpp
+++ b/src/mecab-cost-train.cpp
@@ -4,7 +4,7 @@
// Copyright(C) 2001-2006 Taku Kudo <taku@chasen.org>
// Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
#include "mecab.h"
-#include "winmain.h"
+//#include "winmain.h"
int main(int argc, char **argv) {
return mecab_cost_train(argc, argv);
diff --git a/src/mecab-dict-gen.cpp b/src/mecab-dict-gen.cpp
index 62608b5..415a6eb 100644
--- a/src/mecab-dict-gen.cpp
+++ b/src/mecab-dict-gen.cpp
@@ -4,7 +4,7 @@
// Copyright(C) 2001-2006 Taku Kudo <taku@chasen.org>
// Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
#include "mecab.h"
-#include "winmain.h"
+//#include "winmain.h"
int main(int argc, char **argv) {
return mecab_dict_gen(argc, argv);
diff --git a/src/mecab-dict-index.cpp b/src/mecab-dict-index.cpp
index 7b5e68a..88e89ef 100644
--- a/src/mecab-dict-index.cpp
+++ b/src/mecab-dict-index.cpp
@@ -4,7 +4,7 @@
// Copyright(C) 2001-2006 Taku Kudo <taku@chasen.org>
// Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
#include "mecab.h"
-#include "winmain.h"
+//#include "winmain.h"
int main(int argc, char **argv) {
return mecab_dict_index(argc, argv);
diff --git a/src/mecab-system-eval.cpp b/src/mecab-system-eval.cpp
index a305153..dc92189 100644
--- a/src/mecab-system-eval.cpp
+++ b/src/mecab-system-eval.cpp
@@ -4,7 +4,7 @@
// Copyright(C) 2001-2006 Taku Kudo <taku@chasen.org>
// Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
#include "mecab.h"
-#include "winmain.h"
+//#include "winmain.h"
int main(int argc, char **argv) {
return mecab_system_eval(argc, argv);
diff --git a/src/mecab-test-gen.cpp b/src/mecab-test-gen.cpp
index 70f83a2..afb4480 100644
--- a/src/mecab-test-gen.cpp
+++ b/src/mecab-test-gen.cpp
@@ -4,7 +4,7 @@
// Copyright(C) 2001-2006 Taku Kudo <taku@chasen.org>
// Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
#include "mecab.h"
-#include "winmain.h"
+//#include "winmain.h"
int main(int argc, char **argv) {
return mecab_test_gen(argc, argv);
diff --git a/src/mecab.cpp b/src/mecab.cpp
index 1fd01e5..50cc08f 100644
--- a/src/mecab.cpp
+++ b/src/mecab.cpp
@@ -4,7 +4,7 @@
// Copyright(C) 2001-2006 Taku Kudo <taku@chasen.org>
// Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
#include "mecab.h"
-#include "winmain.h"
+//#include "winmain.h"
int main(int argc, char **argv) {
return mecab_do (argc, argv);
diff --git a/src/mmap.h b/src/mmap.h
index 4ef8003..9e96096 100644
--- a/src/mmap.h
+++ b/src/mmap.h
@@ -104,7 +104,7 @@ template <class T> class Mmap {
CHECK_FALSE(false) << "unknown open mode:" << filename;
}
- hFile = ::CreateFileW(WPATH(filename), mode1, FILE_SHARE_READ, 0,
+ hFile = ::CreateFileA(WPATH(filename), mode1, FILE_SHARE_READ, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
CHECK_FALSE(hFile != INVALID_HANDLE_VALUE)
<< "CreateFile() failed: " << filename;
diff --git a/configure b/configure
index 27ff54b..f6cf792 100644
--- a/configure
+++ b/configure
@@ -18701,8 +18701,8 @@ $as_echo "yes" >&6; }
case "$host_os" in
mingw* | os2*)
MECAB_DEFAULT_RC='c:\\\\Program Files\\\\mecab\\\\etc\\\\mecabrc'
- CFLAGS="$CFLAGS -municode -DUNICODE -D_UNICODE"
- CXXFLAGS="$CXXFLAGS -municode -DUNICODE -D_UNICODE"
+# CFLAGS="$CFLAGS -municode -DUNICODE -D_UNICODE"
+# CXXFLAGS="$CXXFLAGS -municode -DUNICODE -D_UNICODE"
;;
*)
MECAB_DEFAULT_RC="$sysconfdir/mecabrc"
diff --git a/src/common.h b/src/common.h
index 4ed43c9..ce8afec 100644
--- a/src/common.h
+++ b/src/common.h
@@ -81,7 +81,7 @@
#define EXIT_SUCCESS 0
#endif
-#if defined(_WIN32) && !defined(__CYGWIN__)
+#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__)
#define WPATH(path) (MeCab::Utf8ToWide(path).c_str())
#else
#define WPATH(path) (path)
diff --git a/src/mecab-cost-train.cpp b/src/mecab-cost-train.cpp
index f927ef3..1a17a32 100644
--- a/src/mecab-cost-train.cpp
+++ b/src/mecab-cost-train.cpp
@@ -4,7 +4,7 @@
// Copyright(C) 2001-2006 Taku Kudo <taku@chasen.org>
// Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
#include "mecab.h"
-#include "winmain.h"
+//#include "winmain.h"
int main(int argc, char **argv) {
return mecab_cost_train(argc, argv);
diff --git a/src/mecab-dict-gen.cpp b/src/mecab-dict-gen.cpp
index 62608b5..415a6eb 100644
--- a/src/mecab-dict-gen.cpp
+++ b/src/mecab-dict-gen.cpp
@@ -4,7 +4,7 @@
// Copyright(C) 2001-2006 Taku Kudo <taku@chasen.org>
// Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
#include "mecab.h"
-#include "winmain.h"
+//#include "winmain.h"
int main(int argc, char **argv) {
return mecab_dict_gen(argc, argv);
diff --git a/src/mecab-dict-index.cpp b/src/mecab-dict-index.cpp
index 7b5e68a..88e89ef 100644
--- a/src/mecab-dict-index.cpp
+++ b/src/mecab-dict-index.cpp
@@ -4,7 +4,7 @@
// Copyright(C) 2001-2006 Taku Kudo <taku@chasen.org>
// Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
#include "mecab.h"
-#include "winmain.h"
+//#include "winmain.h"
int main(int argc, char **argv) {
return mecab_dict_index(argc, argv);
diff --git a/src/mecab-system-eval.cpp b/src/mecab-system-eval.cpp
index a305153..dc92189 100644
--- a/src/mecab-system-eval.cpp
+++ b/src/mecab-system-eval.cpp
@@ -4,7 +4,7 @@
// Copyright(C) 2001-2006 Taku Kudo <taku@chasen.org>
// Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
#include "mecab.h"
-#include "winmain.h"
+//#include "winmain.h"
int main(int argc, char **argv) {
return mecab_system_eval(argc, argv);
diff --git a/src/mecab-test-gen.cpp b/src/mecab-test-gen.cpp
index 70f83a2..afb4480 100644
--- a/src/mecab-test-gen.cpp
+++ b/src/mecab-test-gen.cpp
@@ -4,7 +4,7 @@
// Copyright(C) 2001-2006 Taku Kudo <taku@chasen.org>
// Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
#include "mecab.h"
-#include "winmain.h"
+//#include "winmain.h"
int main(int argc, char **argv) {
return mecab_test_gen(argc, argv);
diff --git a/src/mecab.cpp b/src/mecab.cpp
index 1fd01e5..50cc08f 100644
--- a/src/mecab.cpp
+++ b/src/mecab.cpp
@@ -4,7 +4,7 @@
// Copyright(C) 2001-2006 Taku Kudo <taku@chasen.org>
// Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
#include "mecab.h"
-#include "winmain.h"
+//#include "winmain.h"
int main(int argc, char **argv) {
return mecab_do (argc, argv);
diff --git a/src/mmap.h b/src/mmap.h
index 4ef8003..ee5b901 100644
--- a/src/mmap.h
+++ b/src/mmap.h
@@ -104,7 +104,7 @@ template <class T> class Mmap {
CHECK_FALSE(false) << "unknown open mode:" << filename;
}
- hFile = ::CreateFileW(WPATH(filename), mode1, FILE_SHARE_READ, 0,
+ hFile = ::CreateFileW(MeCab::Utf8ToWide(filename).c_str(), mode1, FILE_SHARE_READ, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
CHECK_FALSE(hFile != INVALID_HANDLE_VALUE)
<< "CreateFile() failed: " << filename;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment