mirror of
https://github.com/janet-lang/janet
synced 2024-11-24 17:27:18 +00:00
Initial Mingw support with Makefile.
Also add a macro JANET_MSVC to distinguish between a windows build (JANET_WINDOWS) and a build with msvc.
This commit is contained in:
parent
d8d1de2dcb
commit
93b469885a
6
Makefile
6
Makefile
@ -77,6 +77,12 @@ ifeq ($(shell uname -o), Android)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Mingw
|
||||||
|
ifeq ($(findstring MINGW,$(UNAME)), MINGW)
|
||||||
|
CLIBS:=-lws2_32 -lpsapi -lwsock32
|
||||||
|
LDFLAGS:=
|
||||||
|
endif
|
||||||
|
|
||||||
$(shell mkdir -p build/core build/c build/boot)
|
$(shell mkdir -p build/core build/c build/boot)
|
||||||
all: $(JANET_TARGET) $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY) build/janet.h
|
all: $(JANET_TARGET) $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY) build/janet.h
|
||||||
|
|
||||||
|
@ -98,11 +98,11 @@ size_t janet_os_rwlock_size(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int32_t janet_incref(JanetAbstractHead *ab) {
|
static int32_t janet_incref(JanetAbstractHead *ab) {
|
||||||
return InterlockedIncrement(&ab->gc.data.refcount);
|
return InterlockedIncrement((LONG volatile *) &ab->gc.data.refcount);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t janet_decref(JanetAbstractHead *ab) {
|
static int32_t janet_decref(JanetAbstractHead *ab) {
|
||||||
return InterlockedDecrement(&ab->gc.data.refcount);
|
return InterlockedDecrement((LONG volatile *) &ab->gc.data.refcount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void janet_os_mutex_init(JanetOSMutex *mutex) {
|
void janet_os_mutex_init(JanetOSMutex *mutex) {
|
||||||
|
@ -2273,7 +2273,7 @@ JanetAsyncStatus ev_machine_read(JanetListenerState *s, JanetAsyncEvent event) {
|
|||||||
#ifdef JANET_NET
|
#ifdef JANET_NET
|
||||||
if (state->mode == JANET_ASYNC_READMODE_RECVFROM) {
|
if (state->mode == JANET_ASYNC_READMODE_RECVFROM) {
|
||||||
state->wbuf.len = (ULONG) chunk_size;
|
state->wbuf.len = (ULONG) chunk_size;
|
||||||
state->wbuf.buf = state->chunk_buf;
|
state->wbuf.buf = (char *) state->chunk_buf;
|
||||||
status = WSARecvFrom((SOCKET) s->stream->handle, &state->wbuf, 1,
|
status = WSARecvFrom((SOCKET) s->stream->handle, &state->wbuf, 1,
|
||||||
NULL, &state->flags, &state->from, &state->fromlen, &state->overlapped, NULL);
|
NULL, &state->flags, &state->from, &state->fromlen, &state->overlapped, NULL);
|
||||||
if (status && (WSA_IO_PENDING != WSAGetLastError())) {
|
if (status && (WSA_IO_PENDING != WSAGetLastError())) {
|
||||||
@ -2664,15 +2664,15 @@ int janet_make_pipe(JanetHandle handles[2], int mode) {
|
|||||||
* so we lift from the windows source code and modify for our own version.
|
* so we lift from the windows source code and modify for our own version.
|
||||||
*/
|
*/
|
||||||
JanetHandle shandle, chandle;
|
JanetHandle shandle, chandle;
|
||||||
UCHAR PipeNameBuffer[MAX_PATH];
|
CHAR PipeNameBuffer[MAX_PATH];
|
||||||
SECURITY_ATTRIBUTES saAttr;
|
SECURITY_ATTRIBUTES saAttr;
|
||||||
memset(&saAttr, 0, sizeof(saAttr));
|
memset(&saAttr, 0, sizeof(saAttr));
|
||||||
saAttr.nLength = sizeof(saAttr);
|
saAttr.nLength = sizeof(saAttr);
|
||||||
saAttr.bInheritHandle = TRUE;
|
saAttr.bInheritHandle = TRUE;
|
||||||
sprintf(PipeNameBuffer,
|
sprintf(PipeNameBuffer,
|
||||||
"\\\\.\\Pipe\\JanetPipeFile.%08x.%08x",
|
"\\\\.\\Pipe\\JanetPipeFile.%08x.%08x",
|
||||||
GetCurrentProcessId(),
|
(unsigned int) GetCurrentProcessId(),
|
||||||
InterlockedIncrement(&PipeSerialNumber));
|
(unsigned int) InterlockedIncrement(&PipeSerialNumber));
|
||||||
|
|
||||||
/* server handle goes to subprocess */
|
/* server handle goes to subprocess */
|
||||||
shandle = CreateNamedPipeA(
|
shandle = CreateNamedPipeA(
|
||||||
|
@ -838,7 +838,6 @@ JANET_CORE_FN(cfun_ffi_signature,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Add reference items */
|
/* Add reference items */
|
||||||
size_t old_stack_count = stack_count;
|
|
||||||
stack_count += 2 * ref_stack_count;
|
stack_count += 2 * ref_stack_count;
|
||||||
if (stack_count & 0x1) {
|
if (stack_count & 0x1) {
|
||||||
stack_count++;
|
stack_count++;
|
||||||
|
@ -34,9 +34,11 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#include <mswsock.h>
|
#include <mswsock.h>
|
||||||
|
#ifdef JANET_MSVC
|
||||||
#pragma comment (lib, "Ws2_32.lib")
|
#pragma comment (lib, "Ws2_32.lib")
|
||||||
#pragma comment (lib, "Mswsock.lib")
|
#pragma comment (lib, "Mswsock.lib")
|
||||||
#pragma comment (lib, "Advapi32.lib")
|
#pragma comment (lib, "Advapi32.lib")
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -173,7 +175,6 @@ JanetAsyncStatus net_machine_accept(JanetListenerState *s, JanetAsyncEvent event
|
|||||||
|
|
||||||
JANET_NO_RETURN static void janet_sched_accept(JanetStream *stream, JanetFunction *fun) {
|
JANET_NO_RETURN static void janet_sched_accept(JanetStream *stream, JanetFunction *fun) {
|
||||||
Janet err;
|
Janet err;
|
||||||
SOCKET lsock = (SOCKET) stream->handle;
|
|
||||||
JanetListenerState *s = janet_listen(stream, net_machine_accept, JANET_ASYNC_LISTEN_READ, sizeof(NetStateAccept), NULL);
|
JanetListenerState *s = janet_listen(stream, net_machine_accept, JANET_ASYNC_LISTEN_READ, sizeof(NetStateAccept), NULL);
|
||||||
NetStateAccept *state = (NetStateAccept *)s;
|
NetStateAccept *state = (NetStateAccept *)s;
|
||||||
memset(&state->overlapped, 0, sizeof(WSAOVERLAPPED));
|
memset(&state->overlapped, 0, sizeof(WSAOVERLAPPED));
|
||||||
@ -706,7 +707,7 @@ JANET_CORE_FN(cfun_net_getsockname,
|
|||||||
if (getsockname((JSock)js->handle, (struct sockaddr *) &ss, &slen)) {
|
if (getsockname((JSock)js->handle, (struct sockaddr *) &ss, &slen)) {
|
||||||
janet_panicf("Failed to get localname on %v: %V", argv[0], janet_ev_lasterr());
|
janet_panicf("Failed to get localname on %v: %V", argv[0], janet_ev_lasterr());
|
||||||
}
|
}
|
||||||
janet_assert(slen <= sizeof(ss), "socket address truncated");
|
janet_assert(slen <= (socklen_t) sizeof(ss), "socket address truncated");
|
||||||
return janet_so_getname(&ss);
|
return janet_so_getname(&ss);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -722,7 +723,7 @@ JANET_CORE_FN(cfun_net_getpeername,
|
|||||||
if (getpeername((JSock)js->handle, (struct sockaddr *)&ss, &slen)) {
|
if (getpeername((JSock)js->handle, (struct sockaddr *)&ss, &slen)) {
|
||||||
janet_panicf("Failed to get peername on %v: %V", argv[0], janet_ev_lasterr());
|
janet_panicf("Failed to get peername on %v: %V", argv[0], janet_ev_lasterr());
|
||||||
}
|
}
|
||||||
janet_assert(slen <= sizeof(ss), "socket address truncated");
|
janet_assert(slen <= (socklen_t) sizeof(ss), "socket address truncated");
|
||||||
return janet_so_getname(&ss);
|
return janet_so_getname(&ss);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,7 +445,7 @@ typedef struct {
|
|||||||
static JanetEVGenericMessage janet_proc_wait_subr(JanetEVGenericMessage args) {
|
static JanetEVGenericMessage janet_proc_wait_subr(JanetEVGenericMessage args) {
|
||||||
JanetProc *proc = (JanetProc *) args.argp;
|
JanetProc *proc = (JanetProc *) args.argp;
|
||||||
WaitForSingleObject(proc->pHandle, INFINITE);
|
WaitForSingleObject(proc->pHandle, INFINITE);
|
||||||
GetExitCodeProcess(proc->pHandle, &args.tag);
|
GetExitCodeProcess(proc->pHandle, (LPDWORD) &args.tag);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -902,9 +902,6 @@ static Janet os_execute_impl(int32_t argc, Janet *argv, int is_spawn) {
|
|||||||
janet_panic("failed to create pipes");
|
janet_panic("failed to create pipes");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Result */
|
|
||||||
int status = 0;
|
|
||||||
|
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef JANET_WINDOWS
|
||||||
|
|
||||||
HANDLE pHandle, tHandle;
|
HANDLE pHandle, tHandle;
|
||||||
@ -983,6 +980,9 @@ static Janet os_execute_impl(int32_t argc, Janet *argv, int is_spawn) {
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
/* Result */
|
||||||
|
int status = 0;
|
||||||
|
|
||||||
const char **child_argv = janet_smalloc(sizeof(char *) * ((size_t) exargs.len + 1));
|
const char **child_argv = janet_smalloc(sizeof(char *) * ((size_t) exargs.len + 1));
|
||||||
for (int32_t i = 0; i < exargs.len; i++)
|
for (int32_t i = 0; i < exargs.len; i++)
|
||||||
child_argv[i] = janet_getcstring(exargs.items, i);
|
child_argv[i] = janet_getcstring(exargs.items, i);
|
||||||
@ -1769,9 +1769,11 @@ static Janet os_stat_changed(jstat_t *st) {
|
|||||||
}
|
}
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef JANET_WINDOWS
|
||||||
static Janet os_stat_blocks(jstat_t *st) {
|
static Janet os_stat_blocks(jstat_t *st) {
|
||||||
|
(void) st;
|
||||||
return janet_wrap_number(0);
|
return janet_wrap_number(0);
|
||||||
}
|
}
|
||||||
static Janet os_stat_blocksize(jstat_t *st) {
|
static Janet os_stat_blocksize(jstat_t *st) {
|
||||||
|
(void) st;
|
||||||
return janet_wrap_number(0);
|
return janet_wrap_number(0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -2047,6 +2049,7 @@ JANET_CORE_FN(os_open,
|
|||||||
uint32_t stream_flags = 0;
|
uint32_t stream_flags = 0;
|
||||||
JanetHandle fd;
|
JanetHandle fd;
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef JANET_WINDOWS
|
||||||
|
(void) mode;
|
||||||
DWORD desiredAccess = 0;
|
DWORD desiredAccess = 0;
|
||||||
DWORD shareMode = 0;
|
DWORD shareMode = 0;
|
||||||
DWORD creationDisp = 0;
|
DWORD creationDisp = 0;
|
||||||
|
@ -39,9 +39,11 @@
|
|||||||
#ifdef JANET_WINDOWS
|
#ifdef JANET_WINDOWS
|
||||||
#ifdef JANET_DYNAMIC_MODULES
|
#ifdef JANET_DYNAMIC_MODULES
|
||||||
#include <psapi.h>
|
#include <psapi.h>
|
||||||
|
#ifdef JANET_MSVC
|
||||||
#pragma comment (lib, "Psapi.lib")
|
#pragma comment (lib, "Psapi.lib")
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef JANET_APPLE
|
#ifdef JANET_APPLE
|
||||||
#include <AvailabilityMacros.h>
|
#include <AvailabilityMacros.h>
|
||||||
@ -863,7 +865,7 @@ int janet_cryptorand(uint8_t *out, size_t n) {
|
|||||||
unsigned int v;
|
unsigned int v;
|
||||||
if (rand_s(&v))
|
if (rand_s(&v))
|
||||||
return -1;
|
return -1;
|
||||||
for (int32_t j = 0; (j < sizeof(unsigned int)) && (i + j < n); j++) {
|
for (int32_t j = 0; (j < (int32_t) sizeof(unsigned int)) && (i + j < n); j++) {
|
||||||
out[i + j] = v & 0xff;
|
out[i + j] = v & 0xff;
|
||||||
v = v >> 8;
|
v = v >> 8;
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,11 @@ extern "C" {
|
|||||||
#define JANET_WINDOWS 1
|
#define JANET_WINDOWS 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Check if compiling with MSVC - else assume a GCC-like compiler by default */
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define JANET_MSVC
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Check 64-bit vs 32-bit */
|
/* Check 64-bit vs 32-bit */
|
||||||
#if ((defined(__x86_64__) || defined(_M_X64)) \
|
#if ((defined(__x86_64__) || defined(_M_X64)) \
|
||||||
&& (defined(JANET_POSIX) || defined(JANET_WINDOWS))) \
|
&& (defined(JANET_POSIX) || defined(JANET_WINDOWS))) \
|
||||||
|
@ -296,6 +296,7 @@ static char *sdup(const char *s) {
|
|||||||
return memcpy(mem, s, len);
|
return memcpy(mem, s, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
static int curpos(void) {
|
static int curpos(void) {
|
||||||
char buf[32];
|
char buf[32];
|
||||||
int cols, rows;
|
int cols, rows;
|
||||||
@ -311,6 +312,7 @@ static int curpos(void) {
|
|||||||
if (sscanf(buf + 2, "%d;%d", &rows, &cols) != 2) return -1;
|
if (sscanf(buf + 2, "%d;%d", &rows, &cols) != 2) return -1;
|
||||||
return cols;
|
return cols;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int getcols(void) {
|
static int getcols(void) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
0
tools/format.sh
Executable file → Normal file
0
tools/format.sh
Executable file → Normal file
Loading…
Reference in New Issue
Block a user