summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-10-17 15:51:33 +0200
committerClifford Wolf <clifford@clifford.at>2014-10-17 16:04:59 +0200
commitb3a6f8f53019d1984d4e319db459b11da0663aa3 (patch)
tree4f370d208bb86cfe681a0a054783ec7869c6ccf1 /kernel
parent468ae923748a01b2763bafa3cf5fba883fe06479 (diff)
More win32 (mxe and vs) build fixes
Diffstat (limited to 'kernel')
-rw-r--r--kernel/driver.cc30
-rw-r--r--kernel/yosys.cc36
-rw-r--r--kernel/yosys.h11
3 files changed, 65 insertions, 12 deletions
diff --git a/kernel/driver.cc b/kernel/driver.cc
index 7a3cd1a1..5e69cced 100644
--- a/kernel/driver.cc
+++ b/kernel/driver.cc
@@ -32,6 +32,36 @@
#if !defined(_WIN32) || defined(__MINGW32__)
# include <unistd.h>
+#else
+char *optarg;
+int optind = 1, optcur = 1;
+int getopt(int argc, char **argv, const char *optstring)
+{
+ if (optind >= argc || argv[optind][0] != '-')
+ return -1;
+
+ bool takes_arg = false;
+ int opt = argv[optind][optcur];
+ for (int i = 0; optstring[i]; i++)
+ if (opt == optstring[i] && optstring[i + 1] == ':')
+ takes_arg = true;
+
+ if (!takes_arg) {
+ if (argv[optind][++optcur] == 0)
+ optind++, optcur = 1;
+ return opt;
+ }
+
+ if (argv[optind][++optcur]) {
+ optarg = argv[optind++] + optcur;
+ optcur = 1;
+ return opt;
+ }
+
+ optarg = argv[++optind];
+ optind++, optcur = 1;
+ return opt;
+}
#endif
diff --git a/kernel/yosys.cc b/kernel/yosys.cc
index 26665e5b..7d1d273c 100644
--- a/kernel/yosys.cc
+++ b/kernel/yosys.cc
@@ -46,7 +46,7 @@
YOSYS_NAMESPACE_BEGIN
#if defined(_WIN32) && !defined(__MINGW32__)
-const char *yosys_version_str = "Windows";
+const char *yosys_version_str = "Yosys for Windows (Version Information Unavailable)";
#endif
int autoidx = 1;
@@ -210,9 +210,19 @@ std::string make_temp_file(std::string template_str)
{
#ifdef _WIN32
if (template_str.rfind("/tmp/", 0) == 0) {
- char path[MAX_PATH+1];
- GetTempPath(MAX_PATH+1, path);
- template_str = stringf("%s\\%s", path, template_str.c_str() + 5);
+# ifdef __MINGW32__
+ char longpath[MAX_PATH + 1];
+ char shortpath[MAX_PATH + 1];
+# else
+ WCHAR longpath[MAX_PATH + 1];
+ TCHAR shortpath[MAX_PATH + 1];
+# endif
+ if (!GetTempPath(MAX_PATH+1, longpath))
+ log_error("GetTempPath() failed.\n");
+ if (!GetShortPathName(longpath, shortpath, MAX_PATH + 1))
+ log_error("GetShortPathName() failed.\n");
+ log_assert(sizeof(TCHAR) == sizeof(char));
+ template_str = stringf("%s\\%s", shortpath, template_str.c_str() + 5);
}
size_t pos = template_str.rfind("XXXXXX");
@@ -475,14 +485,24 @@ std::string proc_self_dirname()
#elif defined(_WIN32)
std::string proc_self_dirname()
{
- char longpath[MAX_PATH+1], shortpath[MAX_PATH+1];
+ int i = 0;
+# ifdef __MINGW32__
+ char longpath[MAX_PATH + 1];
+ char shortpath[MAX_PATH + 1];
+# else
+ WCHAR longpath[MAX_PATH + 1];
+ TCHAR shortpath[MAX_PATH + 1];
+# endif
if (!GetModuleFileName(0, longpath, MAX_PATH+1))
log_error("GetModuleFileName() failed.\n");
if (!GetShortPathName(longpath, shortpath, MAX_PATH+1))
log_error("GetShortPathName() failed.\n");
- for (int i = strlen(shortpath)-1; i >= 0 && shortpath[i] != '/' && shortpath[i] != '\\' ; i--)
- shortpath[i] = 0;
- return std::string(shortpath);
+ while (shortpath[i] != 0)
+ i++;
+ while (i > 0 && shortpath[i-1] != '/' && shortpath[i-1] != '\\')
+ shortpath[--i] = 0;
+ log_assert(sizeof(TCHAR) == sizeof(char));
+ return std::string((char*)shortpath);
}
#elif defined(EMSCRIPTEN)
std::string proc_self_dirname()
diff --git a/kernel/yosys.h b/kernel/yosys.h
index a0a42be9..b9182c1d 100644
--- a/kernel/yosys.h
+++ b/kernel/yosys.h
@@ -60,9 +60,9 @@
#include <stdio.h>
#ifndef _YOSYS_
-# error It looks like you are trying to build Yosys with the config defines set. \
+# error It looks like you are trying to build Yosys without the config defines set. \
When building Yosys with a custom make system, make sure you set all the \
- defines the Yosys Makefile would set for your build configuration.
+ defines the Yosys Makefile would set for your build configuration.
#endif
#ifdef YOSYS_ENABLE_TCL
@@ -74,8 +74,6 @@
# define NOMINMAX 1
# undef YY_NO_UNISTD_H
# define YY_NO_UNISTD_H 1
-# undef _CRT_SECURE_NO_WARNINGS
-# define _CRT_SECURE_NO_WARNINGS 1
# include <windows.h>
# include <io.h>
@@ -89,6 +87,11 @@
# define popen _popen
# define pclose _pclose
# define PATH_MAX MAX_PATH
+
+# ifndef __MINGW32__
+# define isatty _isatty
+# define fileno _fileno
+# endif
#endif
#define PRIVATE_NAMESPACE_BEGIN namespace {