Skip to content
Snippets Groups Projects
Commit 3933f666 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Start of Emscripten support.

Not at all approaching functional yet.
parent 4985797d
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #4260 passed
...@@ -249,6 +249,9 @@ ifeq ($(machine_uname),mac68k) ...@@ -249,6 +249,9 @@ ifeq ($(machine_uname),mac68k)
endif endif
ifeq ($(machine_uname),) ifeq ($(machine_uname),)
machine := $(os) machine := $(os)
endif
ifeq ($(os),emscripten)
machine := webassembly
else else
machine := $(os).$(machine_uname) machine := $(os).$(machine_uname)
CFLAGS += -DUNAME_ARCHITECTURE_DESC=$(machine_uname) CFLAGS += -DUNAME_ARCHITECTURE_DESC=$(machine_uname)
...@@ -382,6 +385,9 @@ else ...@@ -382,6 +385,9 @@ else
ifeq ($(os),win32) # Windows ifeq ($(os),win32) # Windows
CFLAGS += -U__STRICT_ANSI__ -D_WIN32 -D_WIN32_WINNT=0x0501 -DWINVER=0x0501 -D_WIN32_IE=0x0500 CFLAGS += -U__STRICT_ANSI__ -D_WIN32 -D_WIN32_WINNT=0x0501 -DWINVER=0x0501 -D_WIN32_IE=0x0500
MT_CFLAGS += -D_WIN32 MT_CFLAGS += -D_WIN32
else
ifeq ($(os),emscripten)
CFLAGS += -D_BSD_SOURCE -D__STDC_NO_ATOMICS__
else # Linux / Other UNIX else # Linux / Other UNIX
XP_SEM := 1 XP_SEM := 1
MT_CFLAGS += -DUSE_XP_SEMAPHORES MT_CFLAGS += -DUSE_XP_SEMAPHORES
...@@ -392,6 +398,7 @@ else ...@@ -392,6 +398,7 @@ else
endif endif
endif endif
endif endif
endif
SHLIBOPTS := -shared SHLIBOPTS := -shared
ifeq ($(os),darwin) ifeq ($(os),darwin)
......
...@@ -48,5 +48,8 @@ hdiutil convert ~/Desktop/SyncTERM.dmg -format UDRO -o /Volumes/Synchronet/sbbs/ ...@@ -48,5 +48,8 @@ hdiutil convert ~/Desktop/SyncTERM.dmg -format UDRO -o /Volumes/Synchronet/sbbs/
Release builds for Win32 using MinGW32 use the following command line: Release builds for Win32 using MinGW32 use the following command line:
gmake CC=mingw32-gcc VERBOSE=please AR=mingw32-ar AS=mingw32-as RANLIB=mingw32-ranlib RELEASE=1 CXX=mingw32-g++ WINDRES=mingw32-windres gmake CC=mingw32-gcc VERBOSE=please AR=mingw32-ar AS=mingw32-as RANLIB=mingw32-ranlib RELEASE=1 CXX=mingw32-g++ WINDRES=mingw32-windres
Release builds for Emscripten use the following command line:
gmake CC=emcc VERBOSE=please AR=emar RANLIB=emranlib RELEASE=1 CXX=emc++ os=emscripten
Release builds of jsdoor (not related at all) Release builds of jsdoor (not related at all)
gmake jsdoor NO_LD_RUN_PATH=dumbass CC=mingw32-gcc VERBOSE=please AR=mingw32-ar AS=mingw32-as RANLIB=mingw32-ranlib RELEASE=1 CXX=mingw32-g++ WINDRES=mingw32-windres JSLIBDIR=../../3rdp/win32.release/mozjs/bin/ JSINCLUDE=../../3rdp/win32.release/mozjs/include/ JSLIB=mozjs gmake jsdoor NO_LD_RUN_PATH=dumbass CC=mingw32-gcc VERBOSE=please AR=mingw32-ar AS=mingw32-as RANLIB=mingw32-ranlib RELEASE=1 CXX=mingw32-g++ WINDRES=mingw32-windres JSLIBDIR=../../3rdp/win32.release/mozjs/bin/ JSINCLUDE=../../3rdp/win32.release/mozjs/include/ JSLIB=mozjs
...@@ -65,6 +65,7 @@ void _termios_reset(void) ...@@ -65,6 +65,7 @@ void _termios_reset(void)
#if defined(__BORLANDC__) #if defined(__BORLANDC__)
#pragma argsused #pragma argsused
#endif #endif
#ifndef __EMSCRIPTEN_major__
void _sighandler_stop(int sig) void _sighandler_stop(int sig)
{ {
/* clean up the terminal */ /* clean up the terminal */
...@@ -73,6 +74,7 @@ void _sighandler_stop(int sig) ...@@ -73,6 +74,7 @@ void _sighandler_stop(int sig)
/* ... and stop */ /* ... and stop */
kill(getpid(), SIGSTOP); kill(getpid(), SIGSTOP);
} }
#endif
#if defined(__BORLANDC__) #if defined(__BORLANDC__)
#pragma argsused #pragma argsused
#endif #endif
...@@ -103,7 +105,9 @@ void _termios_setup(void) ...@@ -103,7 +105,9 @@ void _termios_setup(void)
atexit(_termios_reset); atexit(_termios_reset);
/* install the Ctrl-Z handler */ /* install the Ctrl-Z handler */
#ifndef __EMSCRIPTEN_major__
signal(SIGTSTP, _sighandler_stop); signal(SIGTSTP, _sighandler_stop);
#endif
signal(SIGCONT, _sighandler_cont); signal(SIGCONT, _sighandler_cont);
} }
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "genwrap.h" /* lastchar */ #include "genwrap.h" /* lastchar */
#include "filewrap.h" /* chsize */ #include "filewrap.h" /* chsize */
#include <stdlib.h> /* malloc */ #include <stdlib.h> /* malloc */
#include <string.h> /* strdup */ #include "strwrap.h" /* strdup */
/***********************************/ /***********************************/
/* CSV (Comma Separated Value) API */ /* CSV (Comma Separated Value) API */
...@@ -206,6 +206,10 @@ str_list_t dataCreateList(const str_list_t records[], const str_list_t columns, ...@@ -206,6 +206,10 @@ str_list_t dataCreateList(const str_list_t records[], const str_list_t columns,
BOOL dataWriteFile(FILE* fp, const str_list_t records[], const str_list_t columns, const char* separator BOOL dataWriteFile(FILE* fp, const str_list_t records[], const str_list_t columns, const char* separator
,dataLineCreator_t lineCreator) ,dataLineCreator_t lineCreator)
{ {
#ifdef __EMSCRIPTEN_major__
fprintf(stderr, "%s not implemented.\n", __func__);
return FALSE;
#else
size_t count,total; size_t count,total;
str_list_t list; str_list_t list;
...@@ -222,6 +226,7 @@ BOOL dataWriteFile(FILE* fp, const str_list_t records[], const str_list_t column ...@@ -222,6 +226,7 @@ BOOL dataWriteFile(FILE* fp, const str_list_t records[], const str_list_t column
strListFree(&list); strListFree(&list);
return(count == total); return(count == total);
#endif
} }
str_list_t* dataParseList(const str_list_t records, str_list_t* columns, dataLineParser_t lineParser) str_list_t* dataParseList(const str_list_t records, str_list_t* columns, dataLineParser_t lineParser)
......
...@@ -157,7 +157,7 @@ void gettime(struct time* nyt) ...@@ -157,7 +157,7 @@ void gettime(struct time* nyt)
#endif /* !Borland */ #endif /* !Borland */
#if !defined(__unix__) #if (!defined(__unix__)) || defined(__EMSCRIPTEN_major__)
/****************************************************************************/ /****************************************************************************/
/* Win32 implementations of the recursive (thread-safe) versions of std C */ /* Win32 implementations of the recursive (thread-safe) versions of std C */
......
...@@ -44,7 +44,7 @@ DLLEXPORT struct tm* localtime32(const time32_t* t, struct tm* tm); ...@@ -44,7 +44,7 @@ DLLEXPORT struct tm* localtime32(const time32_t* t, struct tm* tm);
/* Win32 implementations of recursive (thread-safe) std C time functions on Unix */ /* Win32 implementations of recursive (thread-safe) std C time functions on Unix */
/*********************************************************************************/ /*********************************************************************************/
#if !defined(__unix__) #if (!defined(__unix__)) || defined(__EMSCRIPTEN_major__)
#include <time.h> /* time_t, etc. */ #include <time.h> /* time_t, etc. */
...@@ -60,6 +60,10 @@ DLLEXPORT struct tm* localtime32(const time32_t* t, struct tm* tm); ...@@ -60,6 +60,10 @@ DLLEXPORT struct tm* localtime32(const time32_t* t, struct tm* tm);
#define timegm _mkgmtime #define timegm _mkgmtime
#endif #endif
#if defined(__EMSCRIPTEN_major__)
#define timegm mktime
#endif
/***********************************/ /***********************************/
/* Borland DOS date/time functions */ /* Borland DOS date/time functions */
/***********************************/ /***********************************/
......
...@@ -814,7 +814,9 @@ int delfiles(const char *inpath, const char *spec, size_t keep) ...@@ -814,7 +814,9 @@ int delfiles(const char *inpath, const char *spec, size_t keep)
errors++; errors++;
continue; continue;
} }
#ifndef __EMSCRIPTEN_major__
(void)CHMOD(fpath, S_IWRITE); /* In case it's been marked RDONLY */ (void)CHMOD(fpath, S_IWRITE); /* In case it's been marked RDONLY */
#endif
if(remove(fpath)==0) if(remove(fpath)==0)
files++; files++;
else else
...@@ -1218,6 +1220,10 @@ int mkpath(const char* path) ...@@ -1218,6 +1220,10 @@ int mkpath(const char* path)
#if !defined _WIN32 #if !defined _WIN32
BOOL CopyFile(const char* src, const char* dest, BOOL failIfExists) BOOL CopyFile(const char* src, const char* dest, BOOL failIfExists)
{ {
#ifdef __EMSCRIPTEN_major__
fprintf(stderr, "%s not implemented\n", __func__);
return FALSE;
#else
uint8_t buf[256 * 1024]; uint8_t buf[256 * 1024];
FILE* in; FILE* in;
FILE* out; FILE* out;
...@@ -1249,5 +1255,6 @@ BOOL CopyFile(const char* src, const char* dest, BOOL failIfExists) ...@@ -1249,5 +1255,6 @@ BOOL CopyFile(const char* src, const char* dest, BOOL failIfExists)
setfdate(dest,ftime); setfdate(dest,ftime);
return success; return success;
#endif
} }
#endif #endif
...@@ -194,7 +194,11 @@ int unlock(int fd, off_t pos, off_t len) ...@@ -194,7 +194,11 @@ int unlock(int fd, off_t pos, off_t len)
int sopen(const char *fn, int sh_access, int share, ...) int sopen(const char *fn, int sh_access, int share, ...)
{ {
int fd; int fd;
#ifdef S_IREAD
int pmode=S_IREAD; int pmode=S_IREAD;
#else
int pmode=0;
#endif
#ifndef F_SANEWRLCKNO #ifndef F_SANEWRLCKNO
int flock_op=LOCK_NB; /* non-blocking */ int flock_op=LOCK_NB; /* non-blocking */
#endif #endif
...@@ -367,6 +371,10 @@ long getdelim(char **linep, size_t *linecapp, int delimiter, FILE *stream) ...@@ -367,6 +371,10 @@ long getdelim(char **linep, size_t *linecapp, int delimiter, FILE *stream)
#ifdef __unix__ #ifdef __unix__
FILE *_fsopen(const char *pszFilename, const char *pszMode, int shmode) FILE *_fsopen(const char *pszFilename, const char *pszMode, int shmode)
{ {
#ifdef __EMSCRIPTEN_major__
fprintf(stderr, "%s not implemented\n", __func__);
return NULL;
#else
int file; int file;
int Mode=0; int Mode=0;
const char *p; const char *p;
...@@ -423,5 +431,6 @@ FILE *_fsopen(const char *pszFilename, const char *pszMode, int shmode) ...@@ -423,5 +431,6 @@ FILE *_fsopen(const char *pszFilename, const char *pszMode, int shmode)
if(file==-1) if(file==-1)
return(NULL); return(NULL);
return(fdopen(file,pszMode)); return(fdopen(file,pszMode));
#endif
} }
#endif #endif
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <limits.h> /* CHAR_BIT */ #include <limits.h> /* CHAR_BIT */
#include <math.h> /* fmod */ #include <math.h> /* fmod */
#include "strwrap.h" /* strdup */
#include "ini_file.h" #include "ini_file.h"
#if defined(__unix__) #if defined(__unix__)
...@@ -982,6 +983,10 @@ uint64_t xp_timer64(void) ...@@ -982,6 +983,10 @@ uint64_t xp_timer64(void)
/* Returns TRUE if specified process is running */ /* Returns TRUE if specified process is running */
BOOL check_pid(pid_t pid) BOOL check_pid(pid_t pid)
{ {
#ifdef __EMSCRIPTEN_major__
fprintf(stderr, "%s not implemented", __func__);
return FALSE;
#else
#if defined(__unix__) #if defined(__unix__)
return(kill(pid,0)==0); return(kill(pid,0)==0);
#elif defined(_WIN32) #elif defined(_WIN32)
...@@ -998,11 +1003,16 @@ BOOL check_pid(pid_t pid) ...@@ -998,11 +1003,16 @@ BOOL check_pid(pid_t pid)
#else #else
return FALSE; /* Need check_pid() definition! */ return FALSE; /* Need check_pid() definition! */
#endif #endif
#endif
} }
/* Terminate (unconditionally) the specified process */ /* Terminate (unconditionally) the specified process */
BOOL terminate_pid(pid_t pid) BOOL terminate_pid(pid_t pid)
{ {
#ifdef __EMSCRIPTEN_major__
fprintf(stderr, "%s not implemented", __func__);
return FALSE;
#else
#if defined(__unix__) #if defined(__unix__)
return(kill(pid,SIGKILL)==0); return(kill(pid,SIGKILL)==0);
#elif defined(_WIN32) #elif defined(_WIN32)
...@@ -1018,6 +1028,7 @@ BOOL terminate_pid(pid_t pid) ...@@ -1018,6 +1028,7 @@ BOOL terminate_pid(pid_t pid)
#else #else
return FALSE; /* Need check_pid() definition! */ return FALSE; /* Need check_pid() definition! */
#endif #endif
#endif
} }
/****************************************************************************/ /****************************************************************************/
...@@ -1031,7 +1042,7 @@ char* safe_strerror(int errnum, char *buf, size_t buflen) ...@@ -1031,7 +1042,7 @@ char* safe_strerror(int errnum, char *buf, size_t buflen)
#if defined(_MSC_VER) #if defined(_MSC_VER)
strerror_s(buf, buflen, errnum); strerror_s(buf, buflen, errnum);
#elif defined(_WIN32) #elif defined(_WIN32) || defined(__EMSCRIPTEN_major__)
strncpy(buf, strerror(errnum), buflen); strncpy(buf, strerror(errnum), buflen);
buf[buflen - 1] = 0; buf[buflen - 1] = 0;
#elif defined(_GNU_SOURCE) #elif defined(_GNU_SOURCE)
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#if defined(__unix__) #if defined(__unix__)
#include <sched.h> /* sched_yield */ #include <sched.h> /* sched_yield */
#include <time.h> /* clock_t */
#include <sys/time.h> /* struct timeval */ #include <sys/time.h> /* struct timeval */
#include <strings.h> /* strcasecmp() */ #include <strings.h> /* strcasecmp() */
#include <unistd.h> /* usleep */ #include <unistd.h> /* usleep */
...@@ -202,6 +201,8 @@ extern "C" { ...@@ -202,6 +201,8 @@ extern "C" {
#define ARCHITECTURE_DESC "ppc" #define ARCHITECTURE_DESC "ppc"
#elif defined(_M_IA64) || defined(__ia64__) #elif defined(_M_IA64) || defined(__ia64__)
#define ARCHITECTURE_DESC "ia64" #define ARCHITECTURE_DESC "ia64"
#elif defined(__EMSCRIPTEN_major__)
#define ARCHITECTURE_DESC "wasm"
#else #else
#ifdef UNAME_ARCHITECTURE_DESC #ifdef UNAME_ARCHITECTURE_DESC
#define ARCHITECTURE_DESC UNAME_ARCHITECTURE_DESC #define ARCHITECTURE_DESC UNAME_ARCHITECTURE_DESC
......
...@@ -75,3 +75,39 @@ strndup(const char *str, size_t maxlen) ...@@ -75,3 +75,39 @@ strndup(const char *str, size_t maxlen)
return copy; return copy;
} }
#endif #endif
#if defined(__EMSCRIPTEN_major__)
char *
strdup(const char *str)
{
if (str == NULL)
return NULL;
char *ret = malloc(strlen(str) + 1);
if (ret != NULL)
strcpy(ret, str);
return ret;
}
char *
strtok_r(char *str, const char *delim, char **saveptr)
{
char *ret;
char *end;
if (str == NULL)
str = *saveptr;
if (str == NULL)
return NULL;
end = strchr(str, '\0');
ret = strtok(str, delim);
if (ret == NULL) {
*saveptr = NULL;
}
else {
*saveptr = strchr(ret, '\0') + 1;
if (*saveptr > end)
*saveptr = NULL;
}
return ret;
}
#endif
...@@ -33,4 +33,15 @@ size_t strnlen(const char *s, size_t maxlen); ...@@ -33,4 +33,15 @@ size_t strnlen(const char *s, size_t maxlen);
#endif #endif
#endif #endif
#if defined(__cplusplus)
extern "C" {
#endif
#if defined(__EMSCRIPTEN_major__)
char * strdup(const char *str);
char * strtok_r(char *str, const char *delim, char **saveptr);
#endif
#if defined(__cplusplus)
}
#endif
#endif #endif
...@@ -56,7 +56,7 @@ int main() ...@@ -56,7 +56,7 @@ int main()
/* Show platform details */ /* Show platform details */
DESCRIBE_COMPILER(compiler); DESCRIBE_COMPILER(compiler);
printf("%-15s: %s\n","Platform",PLATFORM_DESC); printf("%-15s: %s\n","Platform",PLATFORM_DESC);
printf("%-15s: %s\n","Version",os_version(str)); printf("%-15s: %s\n","Version",os_version(str, sizeof(str)));
printf("%-15s: %s\n","Compiler" ,compiler); printf("%-15s: %s\n","Compiler" ,compiler);
printf("%-15s: %ld\n","Random Number",xp_random(1000)); printf("%-15s: %ld\n","Random Number",xp_random(1000));
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#elif defined(__unix__) #elif defined(__unix__)
#include <fcntl.h> #include <fcntl.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#ifndef __EMSCRIPTEN_major__
#if SOUNDCARD_H_IN==1 #if SOUNDCARD_H_IN==1
#include <sys/soundcard.h> #include <sys/soundcard.h>
#elif SOUNDCARD_H_IN==2 #elif SOUNDCARD_H_IN==2
...@@ -47,6 +48,7 @@ ...@@ -47,6 +48,7 @@
#endif #endif
#endif #endif
#endif #endif
#endif
/* xpdev headers */ /* xpdev headers */
#ifdef WITH_PORTAUDIO #ifdef WITH_PORTAUDIO
...@@ -1196,7 +1198,7 @@ void unix_beep(int freq, int dur) ...@@ -1196,7 +1198,7 @@ void unix_beep(int freq, int dur)
} }
#endif #endif
#if !defined(__GNU__) && !defined(__QNX__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__APPLE__) && !defined(__CYGWIN__) && !defined(__HAIKU__) #if !defined(__GNU__) && !defined(__QNX__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__APPLE__) && !defined(__CYGWIN__) && !defined(__HAIKU__) && !defined(__EMSCRIPTEN_major__)
if(console_fd == -1) if(console_fd == -1)
console_fd = open("/dev/console", O_NOCTTY); console_fd = open("/dev/console", O_NOCTTY);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment