| From 3157e53522e3fa5232c56fdbba378ebdf2f3ef4f Mon Sep 17 00:00:00 2001 |
| From: Andrew Hsieh <andrewhsieh@google.com> |
| Date: Tue, 19 Mar 2013 10:38:57 -0700 |
| Subject: [PATCH 3/5] Fix mingw build |
| |
| Change-Id: I8d1669bf1d89cad60e8b49a946feee52734c4a23 |
| --- |
| include/mcld/Support/Path.h | 6 ++++-- |
| lib/Support/Directory.cpp | 2 +- |
| lib/Support/Path.cpp | 4 ++-- |
| lib/Support/Windows/FileSystem.inc | 19 +++++++++++++++++++ |
| lib/Support/Windows/PathV3.inc | 15 +++++++++++++-- |
| lib/Support/Windows/System.inc | 5 +++++ |
| lib/Support/raw_ostream.cpp | 2 +- |
| lib/Target/GNULDBackend.cpp | 4 ++++ |
| lib/Target/Mips/MipsLDBackend.cpp | 4 ++++ |
| tools/llvm-mcld/llvm-mcld.cpp | 13 +++++++++++++ |
| 10 files changed, 66 insertions(+), 8 deletions(-) |
| |
| diff --git a/include/mcld/Support/Path.h b/include/mcld/Support/Path.h |
| index 399c56d..b84d55a 100644 |
| --- a/include/mcld/Support/Path.h |
| +++ b/include/mcld/Support/Path.h |
| @@ -28,7 +28,7 @@ namespace mcld { |
| namespace sys { |
| namespace fs { |
| |
| -#if defined(MCLD_ON_WIN32) |
| +#if defined(MCLD_ON_WIN32) && !defined(__MINGW32__) |
| const wchar_t preferred_separator = L'\\'; |
| const wchar_t separator = L'\\'; |
| const wchar_t colon = L':'; |
| @@ -50,7 +50,7 @@ const char dot = L'.'; |
| class Path |
| { |
| public: |
| -#if defined(MCLD_ON_WIN32) |
| +#if defined(MCLD_ON_WIN32) && !defined(__MINGW32__) |
| typedef wchar_t ValueType; |
| typedef std::wstring StringType; |
| #else |
| @@ -93,7 +93,9 @@ public: |
| { return m_PathName.c_str(); } |
| |
| std::string string() const; |
| +#if !defined(__MINGW32__) |
| std::wstring wstring() const; |
| +#endif |
| |
| // ----- decomposition ----- // |
| Path parent_path() const; |
| diff --git a/lib/Support/Directory.cpp b/lib/Support/Directory.cpp |
| index 827df59..d19d6a0 100644 |
| --- a/lib/Support/Directory.cpp |
| +++ b/lib/Support/Directory.cpp |
| @@ -24,7 +24,7 @@ bool is_symlink(FileStatus f) |
| return f.type() == SymlinkFile; |
| } |
| |
| -#if defined(MCLD_ON_WIN32) |
| +#if defined(MCLD_ON_WIN32) && !defined(__MINGW32__) |
| const Path dot_path(L"."); |
| const Path dot_dot_path(L".."); |
| |
| diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp |
| index 9989c1a..4a2e28e 100644 |
| --- a/lib/Support/Path.cpp |
| +++ b/lib/Support/Path.cpp |
| @@ -23,7 +23,7 @@ using namespace mcld::sys::fs; |
| // Helper |
| //===--------------------------------------------------------------------===// |
| namespace { |
| -#if defined(MCLD_ON_WIN32) |
| +#if defined(MCLD_ON_WIN32) && !defined(__MINGW32__) |
| bool is_separator(wchar_t value) |
| { |
| return (value == separator || value == preferred_separator); |
| @@ -104,7 +104,7 @@ Path& Path::append(const Path& pPath) |
| unsigned int new_size = old_size + pPath.native().size(); |
| |
| m_PathName.resize(new_size); |
| -#if defined(MCLD_ON_WIN32) |
| +#if defined(MCLD_ON_WIN32) && !defined(__MINGW32__) |
| wcscpy(const_cast<ValueType*>(m_PathName.data()+old_size), pPath.native().data()); |
| #else |
| strcpy(const_cast<ValueType*>(m_PathName.data()+old_size), pPath.native().data()); |
| diff --git a/lib/Support/Windows/FileSystem.inc b/lib/Support/Windows/FileSystem.inc |
| index 7ccb958..0708aff 100644 |
| --- a/lib/Support/Windows/FileSystem.inc |
| +++ b/lib/Support/Windows/FileSystem.inc |
| @@ -8,8 +8,10 @@ |
| //===----------------------------------------------------------------------===// |
| #include <string> |
| #include <io.h> |
| +#include <stdio.h> |
| #include <fcntl.h> |
| #include <cstdlib> |
| +#include <sys/stat.h> |
| #include <mcld/Support/FileHandle.h> |
| |
| #ifndef STDIN_FILENO |
| @@ -27,16 +29,29 @@ namespace sys{ |
| namespace fs{ |
| namespace detail{ |
| |
| +#if !defined(__MINGW32__) |
| Path::StringType static_library_extension = L".lib"; |
| Path::StringType shared_library_extension = L".dll"; |
| Path::StringType executable_extension = L".exe"; |
| Path::StringType relocatable_extension = L".obj"; |
| Path::StringType assembly_extension = L".s"; |
| Path::StringType bitcode_extension = L".bc"; |
| +#else |
| +Path::StringType static_library_extension = ".lib"; |
| +Path::StringType shared_library_extension = ".dll"; |
| +Path::StringType executable_extension = ".exe"; |
| +Path::StringType relocatable_extension = ".obj"; |
| +Path::StringType assembly_extension = ".s"; |
| +Path::StringType bitcode_extension = ".bc"; |
| +#endif |
| |
| int open(const Path& pPath, int pOFlag) |
| { |
| +#if !defined(__MINGW32__) |
| return ::_wopen(pPath.native().c_str(), pOFlag); |
| +#else |
| + return ::open(pPath.native().c_str(), pOFlag); |
| +#endif |
| } |
| |
| int open(const Path& pPath, int pOFlag, int pPerm) |
| @@ -52,7 +67,11 @@ int open(const Path& pPath, int pOFlag, int pPerm) |
| pPerm & FileHandle::WriteOther) |
| perm |= _S_IWRITE; |
| |
| +#if !defined(__MINGW32__) |
| return ::_wopen(pPath.native().c_str(), pOFlag, perm); |
| +#else |
| + return ::open(pPath.native().c_str(), pOFlag, perm); |
| +#endif |
| } |
| |
| ssize_t pread(int pFD, void* pBuf, size_t pCount, size_t pOffset) |
| diff --git a/lib/Support/Windows/PathV3.inc b/lib/Support/Windows/PathV3.inc |
| index db577c0..ed0e712 100644 |
| --- a/lib/Support/Windows/PathV3.inc |
| +++ b/lib/Support/Windows/PathV3.inc |
| @@ -8,7 +8,7 @@ |
| //===----------------------------------------------------------------------===// |
| #include <mcld/Support/Path.h> |
| #include <mcld/Support/Directory.h> |
| -#include <Windows.h> |
| +#include <windows.h> |
| #include <sys/types.h> |
| #include <sys/stat.h> |
| #include <limits.h> |
| @@ -30,10 +30,12 @@ std::string Path::string() const |
| return result; |
| } |
| |
| +#if !defined(__MINGW32__) |
| std::wstring Path::wstring() const |
| { |
| return m_PathName; |
| } |
| +#endif |
| |
| //===----------------------------------------------------------------------===// |
| // mcld::sys::fs::detail |
| @@ -150,7 +152,11 @@ bool not_found_error(int perrno) |
| void status(const Path& p, FileStatus& pFileStatus) |
| { |
| struct ::_stat path_stat; |
| +#if !defined(__MINGW32__) |
| if(::_wstat(p.c_str(), &path_stat)!= 0) |
| +#else |
| + if(::_stat(p.c_str(), &path_stat)!= 0) |
| +#endif |
| { |
| if(not_found_error(errno)) |
| { |
| @@ -200,8 +206,13 @@ void close_dir(Directory& pDir) |
| |
| void get_pwd(Path& pPWD) |
| { |
| - wchar_t* pwd = (wchar_t*)malloc(PATH_MAX); |
| +#if !defined(__MINGW32__) |
| + wchar_t* pwd = (wchar_t*)malloc(PATH_MAX*sizeof(wchar_t)); |
| pPWD.assign(_wgetcwd(pwd, PATH_MAX)); |
| +#else |
| + char* pwd = (char*)malloc(PATH_MAX); |
| + pPWD.assign(pwd); |
| +#endif |
| free(pwd); |
| } |
| |
| diff --git a/lib/Support/Windows/System.inc b/lib/Support/Windows/System.inc |
| index 8b64c40..ba91105 100644 |
| --- a/lib/Support/Windows/System.inc |
| +++ b/lib/Support/Windows/System.inc |
| @@ -16,6 +16,11 @@ |
| namespace mcld{ |
| namespace sys{ |
| |
| +char *strerror(int errnum) |
| +{ |
| + return strerror(errnum); |
| +} |
| + |
| std::string getDefaultTargetTriple() |
| { |
| return MCLD_DEFAULT_TARGET_TRIPLE; |
| diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp |
| index 57213ed..4797245 100644 |
| --- a/lib/Support/raw_ostream.cpp |
| +++ b/lib/Support/raw_ostream.cpp |
| @@ -17,7 +17,7 @@ |
| #include <io.h> |
| #endif |
| |
| -#if defined(_MSC_VER) |
| +#if defined(_MSC_VER) || defined(__MINGW32__) |
| #include <io.h> |
| #ifndef STDIN_FILENO |
| # define STDIN_FILENO 0 |
| diff --git a/lib/Target/GNULDBackend.cpp b/lib/Target/GNULDBackend.cpp |
| index 12a2100..3e00c12 100644 |
| --- a/lib/Target/GNULDBackend.cpp |
| +++ b/lib/Target/GNULDBackend.cpp |
| @@ -37,6 +37,10 @@ |
| #include <mcld/LD/StubFactory.h> |
| #include <mcld/Object/ObjectBuilder.h> |
| |
| +#if defined(_WIN32) |
| + #define bzero(b,l) (memset((b), 0, (l)), (void)0) |
| +#endif |
| + |
| using namespace mcld; |
| |
| //===--------------------------------------------------------------------===// |
| diff --git a/lib/Target/Mips/MipsLDBackend.cpp b/lib/Target/Mips/MipsLDBackend.cpp |
| index 3db1c47..ae34f50 100644 |
| --- a/lib/Target/Mips/MipsLDBackend.cpp |
| +++ b/lib/Target/Mips/MipsLDBackend.cpp |
| @@ -27,6 +27,10 @@ |
| #include <mcld/Target/OutputRelocSection.h> |
| #include <mcld/Object/ObjectBuilder.h> |
| |
| +#if defined(_WIN32) |
| + #define bzero(b,l) (memset((b), 0, (l)), (void)0) |
| +#endif |
| + |
| using namespace mcld; |
| |
| //===----------------------------------------------------------------------===// |
| diff --git a/tools/llvm-mcld/llvm-mcld.cpp b/tools/llvm-mcld/llvm-mcld.cpp |
| index 98bdcad..81a7f55 100644 |
| --- a/tools/llvm-mcld/llvm-mcld.cpp |
| +++ b/tools/llvm-mcld/llvm-mcld.cpp |
| @@ -47,6 +47,19 @@ |
| # include <unistd.h> |
| #endif |
| |
| +#if defined(_MSC_VER) || defined(__MINGW32__) |
| +#include <io.h> |
| +#ifndef STDIN_FILENO |
| +# define STDIN_FILENO 0 |
| +#endif |
| +#ifndef STDOUT_FILENO |
| +# define STDOUT_FILENO 1 |
| +#endif |
| +#ifndef STDERR_FILENO |
| +# define STDERR_FILENO 2 |
| +#endif |
| +#endif |
| + |
| using namespace llvm; |
| |
| #ifdef ENABLE_UNITTEST |
| -- |
| 1.8.1.3 |
| |