win32 build fixes

This commit is contained in:
K Lange 2021-02-26 22:18:40 +09:00
parent adfd8a6492
commit 4c94aab5c1
2 changed files with 19 additions and 5 deletions

View File

@ -29,6 +29,7 @@ ifndef KRK_ENABLE_STATIC
CFLAGS += -Wno-format
# And we need to link this by name with extension because I don't want
# to actually rename it to kuroko.dll or whatever.
MODLIBS = libkuroko.so
endif
all: ${TARGET} ${MODULES} ${TOOLS}
KUROKO_LIBS = libkuroko.so
@ -96,13 +97,13 @@ libkuroko.so: ${OBJS}
# Modules are built as shared objects. We link them with LDLIBS
# as well, but this probably isn't necessary?
modules/%.so: src/module_%.c libkuroko.so
${CC} ${CFLAGS} ${LDFLAGS} -shared -o $@ $< ${LDLIBS}
${CC} ${CFLAGS} ${LDFLAGS} -shared -o $@ $< ${LDLIBS} ${MODLIBS}
# A module can have dependencies that didn't exist in the main lib,
# like how the math library pulls in libm but we kept references
# to that out of the main interpreter.
modules/math.so: src/module_math.c libkuroko.so
${CC} ${CFLAGS} ${LDFLAGS} -shared -o $@ $< -lm ${LDLIBS}
${CC} ${CFLAGS} ${LDFLAGS} -shared -o $@ $< -lm ${LDLIBS} ${MODLIBS}
.PHONY: clean
clean:

View File

@ -5,10 +5,10 @@
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#ifndef _WIN32
#include <sys/utsname.h>
#include <sys/stat.h>
#include <sys/types.h>
#ifndef _WIN32
#include <sys/utsname.h>
#else
#include <windows.h>
#endif
@ -304,6 +304,9 @@ KRK_FUNC(close,{
}
})
#ifdef _WIN32
#define mkdir(p,m) mkdir(p); (void)m
#endif
KRK_FUNC(mkdir,{
FUNCTION_TAKES_AT_LEAST(1);
FUNCTION_TAKES_AT_MOST(2);
@ -502,10 +505,16 @@ KRK_FUNC(execvp,{
})
#define SET(thing) krk_attachNamedValue(&out->fields, #thing, INTEGER_VAL(buf. thing))
#ifdef _WIN32
#define STAT_STRUCT struct __stat64
#define stat _stat64
#else
#define STAT_STRUCT struct stat
#endif
KRK_FUNC(stat,{
FUNCTION_TAKES_EXACTLY(1);
CHECK_ARG(0,str,KrkString*,path);
struct stat buf;
STAT_STRUCT buf;
int result = stat(path->chars, &buf);
if (result == -1) {
return krk_runtimeError(OSError, strerror(errno));
@ -595,6 +604,7 @@ KRK_FUNC(S_ISREG,{
CHECK_ARG(0,int,krk_integer_type,mode);
return INTEGER_VAL(S_ISREG(mode));
})
#ifndef _WIN32
KRK_FUNC(S_ISLNK,{
FUNCTION_TAKES_EXACTLY(1);
CHECK_ARG(0,int,krk_integer_type,mode);
@ -605,6 +615,7 @@ KRK_FUNC(S_ISSOCK,{
CHECK_ARG(0,int,krk_integer_type,mode);
return INTEGER_VAL(S_ISSOCK(mode));
})
#endif
_noexport
void _createAndBind_osMod(void) {
@ -813,8 +824,10 @@ void _createAndBind_osMod(void) {
BIND_FUNC(module,S_ISDIR);
BIND_FUNC(module,S_ISFIFO);
BIND_FUNC(module,S_ISREG);
#ifndef _WIN32
BIND_FUNC(module,S_ISLNK);
BIND_FUNC(module,S_ISSOCK);
#endif
}