Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ endif()
# test_big_endian(WORDS_BIGENDIAN)
#endif()

if (EMSCRIPTEN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEMSCRIPTEN")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DEMSCRIPTEN")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --memory-init-file 0")
endif()

#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_STANDARD 11)
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,11 @@ scripts\speck\build_win.bat

dll library is outputted to `libs/windows` directory.

## emscripten

```
./scripts/speck/build_emscripten.sh
```

# License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2FNaruto%2Fsimon-speck-c.svg?type=large)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2FNaruto%2Fsimon-speck-c?ref=badge_large)
5 changes: 5 additions & 0 deletions include/speck/speck.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@
#define SPECK_H

#include <stdint.h>
#if EMSCRIPTEN
#include <emscripten/emscripten.h>
#endif

#ifdef SPECKAPI
#undef SPECKAPI
#endif

#if _WIN32
#define SPECKAPI __declspec(dllexport)
#elif EMSCRIPTEN
#define SPECKAPI EMSCRIPTEN_KEEPALIVE
#else
#ifdef __GNUC__
#if __GNUC__ >= 4
Expand Down
29 changes: 29 additions & 0 deletions scripts/speck/build_emscripten.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash -xe

SCRIPTDIR=`dirname $0`
SCRIPTDIR=`cd $SCRIPTDIR && pwd -P`
BASEDIR=${SCRIPTDIR}/../..
BASEDIR=`cd ${BASEDIR} && pwd -P`

pushd ${BASEDIR} > /dev/null
/bin/rm -rf build
/bin/mkdir build
# build
pushd build > /dev/null
emcmake cmake -DENABLE_STATIC=ON -DCMAKE_BUILD_TYPE=Release ..
cmake --build .

# rename .c.o to .bc
ar x libspeck.a
for f in *.c.o; do
mv $f ${f%.c.o}.bc
done
zip libspeck.zip *.bc

popd > /dev/null

/bin/rm -rf libs/emscripten
/bin/mkdir -p libs/emscripten
/bin/cp ./build/libspeck.zip libs/emscripten

popd > /dev/null