Skip to content

Commit 084404d

Browse files
committed
NUKLEAR: refactor backend for windows build
1 parent a74bd55 commit 084404d

File tree

8 files changed

+187
-117
lines changed

8 files changed

+187
-117
lines changed

clipboard/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Download the GNU Public License (GPL) from www.gnu.org
66
#
77

8+
AM_CXXFLAGS=-fno-rtti -std=c++14
89
AM_CPPFLAGS = -I../include -Wall -I./libclipboard/include
910
lib_LTLIBRARIES = libclipboard.la
1011
libclipboard_la_SOURCES = ../include/param.cpp ../include/hashmap.cpp clipboard.c main.cpp

clipboard/clipboard.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "config.h"
22

3-
#if defined(WIN32)
3+
#if defined(_WIN32)
44
#define LIBCLIPBOARD_BUILD_WIN32 1
55
#include "libclipboard/src/clipboard_win32.c"
66
#else

configure.ac

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,21 @@ AC_ARG_WITH(static-include,
3939
case "${host_os}" in
4040
*mingw*)
4141
AC_DEFINE(_WIN32, 1, [building for win32])
42-
PLATFORM_LDFLAGS="-no-undefined -Wc,-static"
42+
PLATFORM_LDFLAGS="-no-undefined -Wl,-static"
4343
RAYLIB_LDFLAGS="-pthread -lgdi32 -mwindows"
4444
CLIPBOARD_LDFLAGS=""
45+
NUKLEAR_LDFLAGS=""
46+
NUKLEAR_CPPFLAGS=""
47+
WEBSOCKET_LDFLAGS="-lwsock32"
4548
STATIC_INCLUDE="yes"
4649
;;
4750

4851
*)
4952
PLATFORM_LDFLAGS="-Wl,--no-undefined"
5053
CLIPBOARD_LDFLAGS="`pkg-config xcb --libs` -lpthread"
54+
NUKLEAR_LDFLAGS="-lGL `sdl2-config --libs`"
55+
NUKLEAR_CPPFLAGS="`sdl2-config --cflags`"
56+
WEBSOCKET_LDFLAGS=""
5157
if test "${STATIC_INCLUDE}" = "yes"
5258
then
5359
RAYLIB_LDFLAGS="-lGL -lm -lpthread -ldl -lrt -lX11"
@@ -59,6 +65,9 @@ esac
5965
AM_CONDITIONAL(WITH_STATIC_INCLUDE, test "${STATIC_INCLUDE}" = "yes")
6066
AC_SUBST(CLIPBOARD_LDFLAGS)
6167
AC_SUBST(RAYLIB_LDFLAGS)
68+
AC_SUBST(NUKLEAR_CPPFLAGS)
69+
AC_SUBST(NUKLEAR_LDFLAGS)
70+
AC_SUBST(WEBSOCKET_LDFLAGS)
6271
AC_SUBST(PLATFORM_LDFLAGS)
6372

6473
# checks for nuklear

include/param.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,26 @@ void v_setreal(var_t *var, var_num_t n) {
111111
}
112112

113113
void v_setstr(var_t *var, const char *str) {
114-
assert(var->type == V_INT);
115-
116-
int length = strlen(str == nullptr ? 0 : str);
117-
var->type = V_STR;
118-
var->v.p.ptr = (char *)malloc(length + 1);
119-
var->v.p.ptr[0] = '\0';
120-
var->v.p.length = length + 1;
121-
var->v.p.owner = 1;
122-
strcpy(var->v.p.ptr, str);
114+
assert(var->type == V_INT || var->type == V_STR);
115+
116+
bool isSet = false;
117+
if (var->type == V_STR) {
118+
if (strcmp(str, var->v.p.ptr) == 0) {
119+
// already set
120+
isSet = true;
121+
} else if (var->v.p.owner) {
122+
free(var->v.p.ptr);
123+
}
124+
}
125+
if (!isSet) {
126+
int length = strlen(str == nullptr ? 0 : str);
127+
var->type = V_STR;
128+
var->v.p.ptr = (char *)malloc(length + 1);
129+
var->v.p.ptr[0] = '\0';
130+
var->v.p.length = length + 1;
131+
var->v.p.owner = 1;
132+
strcpy(var->v.p.ptr, str);
133+
}
123134
}
124135

125136
int v_strlen(const var_t *v) {

nuklear/Makefile.am

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55
# Download the GNU Public License (GPL) from www.gnu.org
66
#
77

8-
AM_CPPFLAGS = -I../include `sdl2-config --cflags` -fno-exceptions -pedantic -O2
8+
#
9+
# cross-compile sdl: ./configure --host=x86_64-w64-mingw32 --prefix=/home/chrisws/mingw64 --disable-static
10+
# use built sdl2-config: export PATH=~/mingw64/bin:${PATH}
11+
#
12+
13+
AM_CXXFLAGS=-fno-rtti -std=c++14
14+
AM_CPPFLAGS = -I../include @NUKLEAR_CPPFLAGS@
915
lib_LTLIBRARIES = libnuklear.la
1016
libnuklear_la_SOURCES = ../include/param.cpp ../include/hashmap.cpp main.cpp
11-
libnuklear_la_LDFLAGS = -module -rpath '$(libdir)' `sdl2-config --libs` -lGL @PLATFORM_LDFLAGS@
17+
libnuklear_la_LDFLAGS = -module -rpath '$(libdir)' @NUKLEAR_LDFLAGS@ @PLATFORM_LDFLAGS@
1218

0 commit comments

Comments
 (0)