Skip to content

Commit

Permalink
fix: substitute LIBC_MINGW32 define with _WIN32
Browse files Browse the repository at this point in the history
WIN32 is natively present on all windows build for both 32 and 64 bit
windows platforms.
jaromil committed Dec 16, 2024
1 parent b554248 commit e4315c1
Showing 12 changed files with 35 additions and 116 deletions.
81 changes: 0 additions & 81 deletions build/embed-headers.sh

This file was deleted.

10 changes: 5 additions & 5 deletions build/embed-path.sh
Original file line number Diff line number Diff line change
@@ -23,16 +23,16 @@ command -v xxd > /dev/null || {
exit 1
}

>&2 echo "parent: $parent"
>&2 echo "name: $name"
>&2 echo "pathname: $pathname"
>&2 echo "dest: $dst"
# >&2 echo "parent: $parent"
# >&2 echo "name: $name"
# >&2 echo "pathname: $pathname"
# >&2 echo "dest: $dst"

rm -f ${name}.tar.gz
prevpwd=`pwd`
cd ${parent}
[ "$pathname" != "$name" ] && cp -ra "$pathname" "$name"
tar --format ustar -czf ${prevpwd}/${name}.tar.gz "$name"
tar --format ustar -cvzf ${prevpwd}/${name}.tar.gz "$name"
[ "$pathname" != "$name" ] && rm -rf "$name"
cd -

2 changes: 1 addition & 1 deletion build/win-native.mk
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ SHELL := C:\Program Files\Git\bin\bash.exe
# redefine compilation flags
cc := gcc
cflags := -O2 -fomit-frame-pointer -Isrc -Ilib/tinycc
cflags += -DLIBC_MINGW32 -DCJIT_BUILD_WIN
cflags += -DCJIT_BUILD_WIN
ldflags := -static-libgcc
ldadd := lib/tinycc/libtcc.a -lshlwapi

2 changes: 1 addition & 1 deletion build/win-wsl.mk
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ include build/init.mk

cc := x86_64-w64-mingw32-gcc
ar := x86_64-w64-mingw32-ar
cflags += -DLIBC_MINGW32 -DCJIT_BUILD_WIN
cflags += -DCJIT_BUILD_WIN

ldadd += -lrpcrt4 -lshlwapi

2 changes: 1 addition & 1 deletion examples/nuklear.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// CJIT library loading for SDL2+OpenGL
#pragma comment(lib, "SDL2")
#ifdef WINDOWS
#ifdef _WIN32
#pragma comment(lib, "opengl32")
#elif LINUX
#pragma comment(lib, "OpenGL")
2 changes: 1 addition & 1 deletion examples/opengl.c
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@

#pragma comment(lib, "SDL2")

#ifdef WINDOWS
#ifdef _WIN32
#pragma comment(lib, "opengl32")
#elif LINUX
#pragma comment(lib, "OpenGL")
14 changes: 7 additions & 7 deletions src/cjit.c
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@
#include <ctype.h>
#include <unistd.h>

#ifndef LIBC_MINGW32
#if !defined(_WIN32)
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -195,7 +195,7 @@ int main(int argc, char **argv) {
CJIT.write_pid = malloc(strlen(opt.arg)+1);
strcpy(CJIT.write_pid,opt.arg);
} else if (c == 301) {
#ifdef LIBC_MINGW32
#if defined(_WIN32)
_err("Live mode not supported in Windows");
#else
if(!quiet)_err("Live mode activated");
@@ -243,7 +243,7 @@ int main(int argc, char **argv) {
// where is libtcc1.a found
tcc_add_library_path(TCC, CJIT.tmpdir);

#ifdef LIBC_MINGW32
#if defined(_WIN32)
tcc_add_library_path(TCC, "C:\\Windows\\System32");
#endif
// tcc_set_lib_path(TCC,tmpdir); // this overrides all?
@@ -277,7 +277,7 @@ int main(int argc, char **argv) {

char *stdin_code = NULL;
if(opt.ind >= argc) {
#ifdef LIBC_MINGW32
#if defined(_WIN32)
_err("No files specified on commandline");
goto endgame;
#endif
@@ -300,7 +300,7 @@ int main(int argc, char **argv) {
if(!quiet)_err("%c %s",(*code_path=='-'?'|':'+'),
(*code_path=='-'?"standard input":code_path));
if(*code_path=='-') { // stdin explicit
#ifdef LIBC_MINGW32
#if defined(_WIN32)
_err("Code from standard input not supported on Windows");
goto endgame;
#endif
@@ -337,7 +337,7 @@ int main(int argc, char **argv) {
// error handler callback for TCC
tcc_set_error_func(TCC, stderr, handle_error);

#ifdef LIBC_MINGW32
#if defined(_WIN32)
// add symbols for windows compatibility
tcc_add_symbol(TCC, "usleep", &win_compat_usleep);
tcc_add_symbol(TCC, "getline", &win_compat_getline);
@@ -352,7 +352,7 @@ int main(int argc, char **argv) {
// number of args at the left hand of arg separator, or all of them
int right_args = argc-left_args+1;//arg_separator? argc-arg_separator : 0;
char **right_argv = &argv[left_args-1];//arg_separator?&argv[arg_separator]:0
#ifndef LIBC_MINGW32
#if !defined(_WIN32)
res = cjit_exec_fork(TCC, &CJIT, entry, right_args, right_argv);
#else
res = cjit_exec_win(TCC, &CJIT, entry, right_args, right_argv);
4 changes: 2 additions & 2 deletions src/cjit.h
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ extern char* dir_load(const char *path);
extern bool write_to_file(const char *path, const char *filename,
const char *buf, unsigned int len);

#ifdef LIBC_MINGW32
#if defined(_WIN32)
bool win32_mkdtemp(CJITState *CJIT);
// from win-compat.c
extern void win_compat_usleep(unsigned int microseconds);
@@ -41,7 +41,7 @@ bool posix_mkdtemp(CJITState *CJIT);
extern void _out(const char *fmt, ...);
extern void _err(const char *fmt, ...);
// from repl.c
#ifdef LIBC_MINGW32
#if defined(_WIN32)
extern int cjit_exec_win(TCCState *TCC, CJITState *CJIT,
const char *ep, int argc, char **argv);
#else
2 changes: 1 addition & 1 deletion src/exec-headers.c
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ bool gen_exec_headers(char *tmpdir) {
if(!write_to_file(tmpdir,"tccdefs.h",(char*)&lib_tinycc_include_tccdefs_h,lib_tinycc_include_tccdefs_h_len)) return(false);
if(!write_to_file(tmpdir,"tgmath.h",(char*)&lib_tinycc_include_tgmath_h,lib_tinycc_include_tgmath_h_len)) return(false);
if(!write_to_file(tmpdir,"varargs.h",(char*)&lib_tinycc_include_varargs_h,lib_tinycc_include_varargs_h_len)) return(false);
#if defined(LIBC_MINGW32)
#if defined(_WIN32)
if(!write_to_file(tmpdir,"assert.h",(char*)&lib_tinycc_win32_include_assert_h,lib_tinycc_win32_include_assert_h_len)) return(false);
if(!write_to_file(tmpdir,"conio.h",(char*)&lib_tinycc_win32_include_conio_h,lib_tinycc_win32_include_conio_h_len)) return(false);
if(!write_to_file(tmpdir,"ctype.h",(char*)&lib_tinycc_win32_include_ctype_h,lib_tinycc_win32_include_ctype_h_len)) return(false);
10 changes: 5 additions & 5 deletions src/file.c
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@

#include <ftw.h> // _GNU_SOURCE

#ifdef LIBC_MINGW32
#if defined(_WIN32)
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
@@ -169,7 +169,7 @@ char* file_load(const char *filename) {
}

char *load_stdin() {
#ifdef LIBC_MINGW32
#if defined(_WIN32)
return NULL;
#else
char *code = NULL;
@@ -202,7 +202,7 @@ bool write_to_file(const char *path, const char *filename, const char *buf, unsi
FILE *fd;
size_t written;
char fullpath[256];
#if defined(LIBC_MINGW32)
#if defined(_WIN32)
snprintf(fullpath,255,"%s\\%s",path,filename);
#else
snprintf(fullpath,255,"%s/%s",path,filename);
@@ -226,7 +226,7 @@ bool write_to_file(const char *path, const char *filename, const char *buf, unsi
static int rm_ftw(const char *pathname,
const struct stat *sbuf,
int type, struct FTW *ftwb) {
#ifndef LIBC_MINGW32
#if !defined(_WIN32)
if(remove(pathname) < 0) {
_err("Error: remove path %s",pathname);
_err("%s",strerror(errno));
@@ -258,7 +258,7 @@ bool rm_recursive(char *path) {
return true;
}

#ifndef LIBC_MINGW32
#if !defined(_WIN32)

static char *full_content = NULL;

2 changes: 1 addition & 1 deletion src/libtcc1.h
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ extern char *lib_tinycc_include_tgmath_h;
extern unsigned int lib_tinycc_include_tgmath_h_len;
extern char *lib_tinycc_include_varargs_h;
extern unsigned int lib_tinycc_include_varargs_h_len;
#if defined(LIBC_MINGW32)
#if defined(_WIN32)
extern char *lib_tinycc_win32_include_assert_h;
extern unsigned int lib_tinycc_win32_include_assert_h_len;
extern char *lib_tinycc_win32_include_conio_h;
20 changes: 10 additions & 10 deletions src/repl.c
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@

#include <cjit.h>

#ifndef LIBC_MINGW32
#if !defined(_WIN32)
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -36,7 +36,7 @@
extern void _out(const char *fmt, ...);
extern void _err(const char *fmt, ...);

#ifdef LIBC_MINGW32
#if defined(_WIN32)
int cjit_exec_win(TCCState *TCC, CJITState *CJIT, const char *ep, int argc, char **argv) {
int res = 1;
int (*_ep)(int, char**);
@@ -61,7 +61,7 @@ int cjit_exec_win(TCCState *TCC, CJITState *CJIT, const char *ep, int argc, char
return(res);
}

#else // LIBC_MINGW32
#else // _WIN32
int cjit_exec_fork(TCCState *TCC, CJITState *CJIT, const char *ep, int argc, char **argv) {
pid_t pid;
int res = 1;
@@ -111,7 +111,7 @@ int cjit_exec_fork(TCCState *TCC, CJITState *CJIT, const char *ep, int argc, cha
}
return res;
}
#endif // LIBC_MINGW32
#endif // _WIN32

#ifdef KILO_SUPPORTED

@@ -356,9 +356,9 @@ int cjit_cli_tty(TCCState *TCC) {
return 2;
}
strcpy(code, intro);
#ifdef LIBC_MINGW32
#if defined(_WIN32)
_err("Missing source code argument");
#else // LIBC_MINGW32
#else // _WIN32
while (1) {
printf("cjit> ");
fflush(stdout);
@@ -395,11 +395,11 @@ int cjit_cli_tty(TCCState *TCC) {
_err("Running code\n");
_err("-----------------------------------\n");
#endif // VERBOSE_CLI
#ifndef LIBC_MINGW32
#if !defined(_WIN32)
res = cjit_exec_fork(TCC, NULL, "main", 0, NULL);
#else // LIBC_MINGW32
#else // _WIN32
res = cjit_exec_win(TCC, NULL, "main", 0, NULL);
#endif // LIBC_MINGW32
#endif // _WIN32
free(code);
code = NULL;
break;
@@ -414,6 +414,6 @@ int cjit_cli_tty(TCCState *TCC) {
free(line);
line = NULL;
}
#endif // LIBC_MINGW32
#endif // _WIN32
return res;
}

0 comments on commit e4315c1

Please sign in to comment.