|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# X11 include dest /opt/python-wasm-sdk/./emsdk/upstream/emscripten/cache/sysroot/include/X11 |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +. ${CONFIG:-config} |
| 8 | + |
| 9 | + |
| 10 | +cd ${ROOT}/src |
| 11 | + |
| 12 | +PKG=microwindows |
| 13 | + |
| 14 | + |
| 15 | +if [ -f ${PKG}.patched ] |
| 16 | +then |
| 17 | + echo " |
| 18 | + ${PKG} already prepared |
| 19 | + " |
| 20 | +else |
| 21 | + git clone --recursive https://github.com/pmp-p/${PKG} |
| 22 | + pushd ${PKG} |
| 23 | + popd |
| 24 | + touch ${PKG}.patched |
| 25 | +fi |
| 26 | + |
| 27 | + |
| 28 | +if [ -f $PREFIX/lib/libX11.a ] |
| 29 | +then |
| 30 | + echo " |
| 31 | + already built in $PREFIX/lib/libX11.a |
| 32 | + " |
| 33 | +else |
| 34 | + . ${SDKROOT}/scripts/emsdk-fetch.sh |
| 35 | + |
| 36 | + |
| 37 | + # mkdir -p $ROOT/build/${PKG} |
| 38 | + cp -rf $ROOT/src/${PKG} $ROOT/build/ |
| 39 | + |
| 40 | + pushd $ROOT/build/${PKG} |
| 41 | + |
| 42 | +patch -p1 <<END |
| 43 | +diff --git a/src/nanox/client.c b/src/nanox/client.c |
| 44 | +index 5c44e26..1fbe424 100644 |
| 45 | +--- a/src/nanox/client.c |
| 46 | ++++ b/src/nanox/client.c |
| 47 | +@@ -77,6 +77,19 @@ |
| 48 | + */ |
| 49 | + #define SHM_BLOCK_SIZE 4096 |
| 50 | +
|
| 51 | ++ |
| 52 | ++#if defined(__EMSCRIPTEN__) || defined(__wasi__) |
| 53 | ++int nxGlobalLock = 0; |
| 54 | ++#undef LOCK_DECLARE |
| 55 | ++#undef LOCK |
| 56 | ++#undef UNLOCK |
| 57 | ++#undef LOCK_FREE |
| 58 | ++#define LOCK_DECLARE(x) |
| 59 | ++#define LOCK(l) |
| 60 | ++#define UNLOCK(l) |
| 61 | ++#define LOCK_FREE(l) |
| 62 | ++#endif |
| 63 | ++ |
| 64 | + #if !__ECOS |
| 65 | + /* exported global data */ |
| 66 | + int nxSocket = -1; /* The network socket descriptor */ |
| 67 | +diff --git a/src/nanox/serv.h b/src/nanox/serv.h |
| 68 | +index d7379a0..e1968b4 100644 |
| 69 | +--- a/src/nanox/serv.h |
| 70 | ++++ b/src/nanox/serv.h |
| 71 | +@@ -134,6 +134,15 @@ |
| 72 | + * in lock.h) for linked-in mode, or a no-op for client/server mode. |
| 73 | + */ |
| 74 | +
|
| 75 | ++ |
| 76 | ++#if defined(__EMSCRIPTEN__) || defined(__wasi__) |
| 77 | ++//static int gr_server_mutex = 0; |
| 78 | ++#define SERVER_LOCK_DECLARE |
| 79 | ++#define SERVER_LOCK_INIT() |
| 80 | ++#define SERVER_LOCK() |
| 81 | ++#define SERVER_UNLOCK() |
| 82 | ++#else |
| 83 | ++ |
| 84 | + #if NONETWORK |
| 85 | + /* Use a server-side mutex. */ |
| 86 | +
|
| 87 | +@@ -153,6 +162,7 @@ LOCK_EXTERN(gr_server_mutex); |
| 88 | + #define SERVER_LOCK() do {} while(0) /* no-op, but require a ";" */ |
| 89 | + #define SERVER_UNLOCK() do {} while(0) /* no-op, but require a ";" */ |
| 90 | + #endif /* !NONETWORK*/ |
| 91 | ++#endif /* __EMSCRIPTEN__ __wasi__ */ |
| 92 | +
|
| 93 | + /* |
| 94 | + * Drawing types. |
| 95 | +END |
| 96 | + |
| 97 | +# FIXME: use pkg config !!! |
| 98 | + |
| 99 | + EMCC_CFLAGS="-I${SDKROOT}/emsdk/upstream/emscripten/cache/sysroot/include/freetype2" \ |
| 100 | + CC=emcc CXX=emc++ emmake make -C src NX11=Y NANOX=Y ARCH=EMSCRIPTEN LINK_APP_INTO_SERVER=Y NANOXDEMO=N |
| 101 | + |
| 102 | + |
| 103 | + if [ -f /pp ] |
| 104 | + then |
| 105 | + emcc -sASYNCIFY -o xhello.html -I./src/nx11/X11-local ./src/contrib/nx11-test/xhello.c -L./src/lib -lNX11 -lnano-X -lz -lfreetype -lSDL2; mv xhello.* /srv/www/html/wasm/x11/ |
| 106 | + fi |
| 107 | + cp ./src/lib/{libNX11.a,libnano-X.a} $PREFIX/lib/ |
| 108 | + cp -r ./src/nx11/X11-local/X11 $PREFIX/include/ |
| 109 | + popd |
| 110 | +fi |
| 111 | + |
| 112 | +# for fltk build |
| 113 | + |
| 114 | +cat <<END > ${SDKROOT}/emsdk/upstream/emscripten/cache/sysroot/include/X11/Xlocale.h |
| 115 | +#define LC_CTYPE "C" |
| 116 | +#define setlocale(ct0,ct1) |
| 117 | +END |
| 118 | + |
| 119 | + |
0 commit comments