Skip to content
Browse files

Allow building with MSVC on windows

Signed-off-by: Steve Bennett <steveb@workware.net.au>
  • Loading branch information...
1 parent 5fe0bb5 commit 05e51ed5447b83badfd8ed550c7386b68eb94919 @msteveb committed Nov 7, 2011
Showing with 98 additions and 43 deletions.
  1. +3 −3 auto.def
  2. +6 −3 jim-aio.c
  3. +0 −1 jim-array.c
  4. +4 −1 jim-clock.c
  5. +6 −3 jim-exec.c
  6. +34 −9 jim-file.c
  7. +6 −1 jim-package.c
  8. +4 −1 jim-readdir.c
  9. +11 −0 jim-win32compat.c
  10. +4 −8 jim-win32compat.h
  11. +4 −6 jim.c
  12. +15 −6 make-bootstrap-jim
  13. +1 −1 stdlib.tcl
View
6 auto.def
@@ -62,8 +62,8 @@ options {
cc-check-types "long long"
-cc-check-includes sys/socket.h netinet/in.h arpa/inet.h netdb.h
-cc-check-includes sys/un.h dlfcn.h unistd.h crt_externs.h
+cc-check-includes sys/time.h sys/socket.h netinet/in.h arpa/inet.h netdb.h
+cc-check-includes sys/un.h dlfcn.h unistd.h dirent.h crt_externs.h
define LDLIBS ""
@@ -79,7 +79,7 @@ if {[cc-check-function-in-lib socket socket]} {
}
cc-check-functions ualarm lstat fork vfork system select
-cc-check-functions backtrace geteuid mkstemp realpath strptime gettimeofday
+cc-check-functions backtrace geteuid mkstemp realpath strptime
cc-check-functions regcomp waitpid sigaction sys_signame sys_siglist
cc-check-functions syslog opendir readlink sleep usleep pipe getaddrinfo utimes
if {[cc-check-functions sysinfo]} {
View
9 jim-aio.c
@@ -38,7 +38,6 @@
* official policies, either expressed or implied, of the Jim Tcl Project.
**/
-#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
@@ -52,6 +51,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
+#include <unistd.h>
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
@@ -973,14 +973,15 @@ static int JimAioOpenCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
const char *mode;
+ const char *filename;
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "filename ?mode?");
return JIM_ERR;
}
mode = (argc == 3) ? Jim_String(argv[2]) : "r";
- const char *filename = Jim_String(argv[1]);
+ filename = Jim_String(argv[1]);
#ifdef jim_ext_tclcompat
/* If the filename starts with '|', use popen instead */
@@ -1036,7 +1037,9 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam
if (fh == NULL) {
JimAioSetError(interp, filename);
- close(fd);
+ if (fd >= 0) {
+ close(fd);
+ }
Jim_DecrRefCount(interp, filename);
return JIM_ERR;
}
View
1 jim-array.c
@@ -48,7 +48,6 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include <unistd.h>
#include <errno.h>
#include "jim.h"
View
5 jim-clock.c
@@ -14,12 +14,15 @@
#include <string.h>
#include <stdio.h>
#include <time.h>
-#include <sys/time.h>
#include "jim.h"
#include "jimautoconf.h"
#include "jim-subcmd.h"
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+
static int clock_cmd_format(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
/* How big is big enough? */
View
9 jim-exec.c
@@ -90,10 +90,13 @@ int Jim_execInit(Jim_Interp *interp)
#include <errno.h>
#include <signal.h>
-#define XXX printf("@%s:%d\n", __FILE__, __LINE__); fflush(stdout);
-
#if defined(__MINGW32__)
- /* XXX: Should we use this implementation for cygwin too? */
+ /* XXX: Should we use this implementation for cygwin too? msvc? */
+ #ifndef STRICT
+ #define STRICT
+ #endif
+ #define WIN32_LEAN_AND_MEAN
+ #include <windows.h>
#include <fcntl.h>
typedef HANDLE fdtype;
View
43 jim-file.c
@@ -47,16 +47,27 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
-#include <sys/param.h>
-#include <sys/time.h>
#include "jim.h"
#include "jimautoconf.h"
#include "jim-subcmd.h"
+#ifdef HAVE_UTIMES
+#include <sys/time.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#elif defined(_MSC_VER)
+#include <direct.h>
+#define F_OK 0
+#define W_OK 2
+#define R_OK 4
+#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
+#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+#endif
+
# ifndef MAXPATHLEN
# define MAXPATHLEN JIM_PATH_LEN
# endif
@@ -86,25 +97,31 @@ static const char *JimGetFileType(int mode)
else if (S_ISDIR(mode)) {
return "directory";
}
+#ifdef S_ISCHR
else if (S_ISCHR(mode)) {
return "characterSpecial";
}
+#endif
+#ifdef S_ISBLK
else if (S_ISBLK(mode)) {
return "blockSpecial";
}
+#endif
+#ifdef S_ISFIFO
else if (S_ISFIFO(mode)) {
return "fifo";
-#ifdef S_ISLNK
}
+#endif
+#ifdef S_ISLNK
else if (S_ISLNK(mode)) {
return "link";
+ }
#endif
#ifdef S_ISSOCK
- }
else if (S_ISSOCK(mode)) {
return "socket";
-#endif
}
+#endif
return "unknown";
}
@@ -189,7 +206,7 @@ static int file_cmd_dirname(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
else if (p == path) {
Jim_SetResultString(interp, "/", -1);
}
-#if defined(__MINGW32__)
+#if defined(__MINGW32__) || defined(_MSC_VER)
else if (p[-1] == ':') {
/* z:/dir => z:/ */
Jim_SetResultString(interp, path, p - path + 1);
@@ -280,7 +297,7 @@ static int file_cmd_join(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
/* Absolute component, so go back to the start */
last = newname;
}
-#if defined(__MINGW32__)
+#if defined(__MINGW32__) || defined(_MSC_VER)
else if (strchr(part, ':')) {
/* Absolute compontent on mingw, so go back to the start */
last = newname;
@@ -349,7 +366,15 @@ static int file_cmd_writable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
static int file_cmd_executable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
+#ifdef X_OK
return file_access(interp, argv[0], X_OK);
+#else
+ /* XXX: X_OK doesn't work under Windows.
+ * In any case, may need to add .exe, etc. so just lie!
+ */
+ Jim_SetResultBool(interp, 1);
+ return JIM_OK;
+#endif
}
static int file_cmd_exists(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -901,7 +926,7 @@ static int Jim_PwdCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Jim_SetResultString(interp, "Failed to get pwd", -1);
return JIM_ERR;
}
-#if defined(__MINGW32__)
+#if defined(__MINGW32__) || defined(_MSC_VER)
{
/* Try to keep backlashes out of paths */
char *p = cwd;
View
7 jim-package.c
@@ -1,10 +1,15 @@
-#include <unistd.h>
#include <string.h>
#include "jim.h"
#include "jimautoconf.h"
#include "jim-subcmd.h"
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#else
+#define R_OK 4
+#endif
+
/* -----------------------------------------------------------------------------
* Packages handling
* ---------------------------------------------------------------------------*/
View
5 jim-readdir.c
@@ -48,11 +48,14 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
-#include <dirent.h>
#include "jim.h"
#include "jimautoconf.h"
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+#endif
+
/*
*-----------------------------------------------------------------------------
*
View
11 jim-win32compat.c
@@ -1,6 +1,13 @@
#include "jim.h"
#include "jimautoconf.h"
+#if defined(_WIN32) || defined(WIN32)
+#ifndef STRICT
+#define STRICT
+#endif
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
#if defined(HAVE_DLOPEN_COMPAT)
void *dlopen(const char *path, int mode)
{
@@ -30,6 +37,9 @@ char *dlerror(void)
#endif
#ifdef _MSC_VER
+
+#include <sys/timeb.h>
+
/* POSIX gettimeofday() compatibility for WIN32 */
int gettimeofday(struct timeval *tv, void *unused)
{
@@ -119,3 +129,4 @@ struct dirent *readdir(DIR * dir)
return result;
}
#endif
+#endif
View
12 jim-win32compat.h
@@ -5,11 +5,6 @@
/* Note that at this point we don't yet have access to jimautoconf.h */
#if defined(_WIN32) || defined(WIN32)
-#ifndef STRICT
- #define STRICT
-#endif
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
#define HAVE_DLOPEN
void *dlopen(const char *path, int mode);
@@ -24,8 +19,7 @@ char *dlerror(void);
#pragma warning(disable:4146)
#endif
-#define strcasecmp _stricmp
-
+#include <limits.h>
#define jim_wide _int64
#ifndef LLONG_MAX
#define LLONG_MAX 9223372036854775807I64
@@ -36,10 +30,12 @@ char *dlerror(void);
#define JIM_WIDE_MIN LLONG_MIN
#define JIM_WIDE_MAX LLONG_MAX
#define JIM_WIDE_MODIFIER "I64d"
+#define strcasecmp _stricmp
+#define strtoull _strtoui64
+#define snprintf _snprintf
#include <io.h>
-#define HAVE_GETTIMEOFDAY
struct timeval {
long tv_sec;
long tv_usec;
View
10 jim.c
@@ -55,13 +55,13 @@
#include <time.h>
#include <setjmp.h>
-#include <unistd.h>
-#include <sys/time.h>
-
#include "jim.h"
#include "jimautoconf.h"
#include "utf8.h"
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
#ifdef HAVE_BACKTRACE
#include <execinfo.h>
#endif
@@ -13406,10 +13406,8 @@ static int Jim_DictCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg
objPtr = Jim_NewDictObj(interp, argv + 2, argc - 2);
Jim_SetResult(interp, objPtr);
return JIM_OK;
-
- default:
- abort();
}
+ return JIM_ERR;
}
/* [subst] */
View
21 make-bootstrap-jim
@@ -58,22 +58,31 @@ for i in $allexts; do
echo "#define jim_ext_$i"
done
-# Can we make a bootstrap jimsh work even on mingw32?
cat <<EOF
-#if defined(__MINGW32__)
+#if defined(_MSC_VER)
+#define TCL_PLATFORM_OS "windows"
+#define TCL_PLATFORM_PLATFORM "windows"
+#define TCL_PLATFORM_PATH_SEPARATOR ";"
+#define HAVE_MKDIR_ONE_ARG
+#define HAVE_SYSTEM
+#elif defined(__MINGW32__)
#define TCL_PLATFORM_OS "mingw"
#define TCL_PLATFORM_PLATFORM "windows"
#define TCL_PLATFORM_PATH_SEPARATOR ";"
#define HAVE_MKDIR_ONE_ARG
#define HAVE_SYSTEM
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
+#define HAVE_SYS_TIME_H
+#define HAVE_DIRENT_H
+#define HAVE_UNISTD_H
#else
#define TCL_PLATFORM_OS "unknown"
#define TCL_PLATFORM_PLATFORM "unix"
#define TCL_PLATFORM_PATH_SEPARATOR ":"
#define HAVE_VFORK
#define HAVE_WAITPID
+#define HAVE_SYS_TIME_H
+#define HAVE_DIRENT_H
+#define HAVE_UNISTD_H
#endif
EOF
@@ -85,7 +94,7 @@ outputsource()
}
# Now output header files, removing references to jim header files
-for i in utf8.h jim.h jim-subcmd.h jimregexp.h ; do
+for i in jim-win32compat.h utf8.h jim.h jim-subcmd.h jimregexp.h ; do
outputsource $i
done
@@ -99,7 +108,7 @@ done
makeloadexts $allexts
# And finally the core source code
-for i in jim.c jim-subcmd.c utf8.c jim-format.c jimregexp.c; do
+for i in jim.c jim-subcmd.c utf8.c jim-format.c jimregexp.c jim-win32compat.c; do
outputsource $i
done
echo "#ifndef JIM_BOOTSTRAP_LIB_ONLY"
View
2 stdlib.tcl
@@ -105,7 +105,7 @@ proc {info nameofexecutable} {} {
return [file join [pwd] $::jim_argv0]
}
foreach path [split [env PATH ""] $::tcl_platform(pathSeparator)] {
- set exec [file join [pwd] $path $::jim_argv0]
+ set exec [file join [pwd] [string map {\\ /} $path] $::jim_argv0]
if {[file executable $exec]} {
return $exec
}

0 comments on commit 05e51ed

Please sign in to comment.
Something went wrong with that request. Please try again.