Various MXE build fixes

This commit is contained in:
Clifford Wolf 2014-10-17 12:04:40 +02:00
parent 31267a1ae8
commit 4df902637a
4 changed files with 30 additions and 15 deletions

View File

@ -30,7 +30,7 @@
#include <limits.h> #include <limits.h>
#include <errno.h> #include <errno.h>
#ifndef _WIN32 #if !defined(_WIN32) || defined(__MINGW32__)
# include <unistd.h> # include <unistd.h>
#endif #endif

View File

@ -30,6 +30,7 @@
#ifdef _WIN32 #ifdef _WIN32
# include <windows.h> # include <windows.h>
# include <io.h>
#elif defined(__APPLE__) #elif defined(__APPLE__)
# include <mach-o/dyld.h> # include <mach-o/dyld.h>
#else #else
@ -44,7 +45,7 @@
YOSYS_NAMESPACE_BEGIN YOSYS_NAMESPACE_BEGIN
#ifdef _WIN32 #if defined(_WIN32) && !defined(__MINGW32__)
const char *yosys_version_str = "Windows"; const char *yosys_version_str = "Windows";
#endif #endif
@ -224,7 +225,7 @@ std::string make_temp_file(std::string template_str)
x ^= x << 13, x ^= x >> 17, x ^= x << 5; x ^= x << 13, x ^= x >> 17, x ^= x << 5;
template_str[pos+i] = y[x % y.size()]; template_str[pos+i] = y[x % y.size()];
} }
if (access(template_str.c_str(), F_OK) != 0) if (_access(template_str.c_str(), 0) != 0)
break; break;
} }
#else #else
@ -265,6 +266,18 @@ std::string make_temp_dir(std::string template_str)
#endif #endif
} }
#ifdef _WIN32
bool check_file_exists(std::string filename, bool)
{
return _access(filename.c_str(), 0);
}
#else
bool check_file_exists(std::string filename, bool is_exec)
{
return access(filename.c_str(), is_exec ? X_OK : F_OK);
}
#endif
void remove_directory(std::string dirname) void remove_directory(std::string dirname)
{ {
#ifdef _WIN32 #ifdef _WIN32
@ -484,10 +497,10 @@ std::string proc_share_dirname()
{ {
std::string proc_self_path = proc_self_dirname(); std::string proc_self_path = proc_self_dirname();
std::string proc_share_path = proc_self_path + "share/"; std::string proc_share_path = proc_self_path + "share/";
if (access(proc_share_path.c_str(), X_OK) == 0) if (check_file_exists(proc_share_path, true) == 0)
return proc_share_path; return proc_share_path;
proc_share_path = proc_self_path + "../share/yosys/"; proc_share_path = proc_self_path + "../share/yosys/";
if (access(proc_share_path.c_str(), X_OK) == 0) if (check_file_exists(proc_share_path, true) == 0)
return proc_share_path; return proc_share_path;
log_error("proc_share_dirname: unable to determine share/ directory!\n"); log_error("proc_share_dirname: unable to determine share/ directory!\n");
} }

View File

@ -70,8 +70,10 @@
// a few platform specific things // a few platform specific things
#ifdef _WIN32 #ifdef _WIN32
# define NOMINMAX # ifndef NOMINMAX
# include <Windows.h> # define NOMINMAX 1
# endif
# include <windows.h>
# include <stdint.h> // takes care of a number of typedefs # include <stdint.h> // takes care of a number of typedefs
# include <io.h> # include <io.h>
# include <direct.h> # include <direct.h>
@ -80,15 +82,11 @@
# define strtok_r strtok_s # define strtok_r strtok_s
# define strdup _strdup # define strdup _strdup
# define snprintf _snprintf # define snprintf _snprintf
# define access _access
# define getcwd _getcwd # define getcwd _getcwd
# define mkdir _mkdir # define mkdir _mkdir
# define popen _popen # define popen _popen
# define pclose _pclose # define pclose _pclose
# define PATH_MAX MAX_PATH # define PATH_MAX MAX_PATH
# define F_OK 00
# define X_OK 00 // note this is NOT correct as there is no execute flag in Windows
#endif #endif
@ -130,6 +128,7 @@ bool patmatch(const char *pattern, const char *string);
int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>()); int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());
std::string make_temp_file(std::string template_str = "/tmp/yosys_XXXXXX"); std::string make_temp_file(std::string template_str = "/tmp/yosys_XXXXXX");
std::string make_temp_dir(std::string template_str = "/tmp/yosys_XXXXXX"); std::string make_temp_dir(std::string template_str = "/tmp/yosys_XXXXXX");
bool check_file(std::string filename, bool is_exec = false);
void remove_directory(std::string dirname); void remove_directory(std::string dirname);
template<typename T> int GetSize(const T &obj) { return obj.size(); } template<typename T> int GetSize(const T &obj) { return obj.size(); }

View File

@ -28,9 +28,9 @@ YOSYS_NAMESPACE_BEGIN
std::map<std::string, void*> loaded_plugins; std::map<std::string, void*> loaded_plugins;
std::map<std::string, std::string> loaded_plugin_aliases; std::map<std::string, std::string> loaded_plugin_aliases;
#ifdef YOSYS_ENABLE_PLUGINS
void load_plugin(std::string filename, std::vector<std::string> aliases) void load_plugin(std::string filename, std::vector<std::string> aliases)
{ {
#ifdef YOSYS_ENABLE_PLUGINS
if (filename.find('/') == std::string::npos) if (filename.find('/') == std::string::npos)
filename = "./" + filename; filename = "./" + filename;
@ -44,10 +44,13 @@ void load_plugin(std::string filename, std::vector<std::string> aliases)
for (auto &alias : aliases) for (auto &alias : aliases)
loaded_plugin_aliases[alias] = filename; loaded_plugin_aliases[alias] = filename;
#else
log_error("This version of yosys is built without plugin support.\n");
#endif
} }
#else
void load_plugin(std::string, std::vector<std::string>)
{
log_error("This version of yosys is built without plugin support.\n");
}
#endif
struct PluginPass : public Pass { struct PluginPass : public Pass {
PluginPass() : Pass("plugin", "load and list loaded plugins") { } PluginPass() : Pass("plugin", "load and list loaded plugins") { }