libwolfssl ported
authorksg <ken@mihrtec.com>
Sat, 2 Jul 2016 01:51:40 +0000 (18:51 -0700)
committerksg <ken@mihrtec.com>
Sat, 2 Jul 2016 01:51:40 +0000 (18:51 -0700)
.gitignore
src/Makefile
src/core/_rules.mk
src/core/main.c

index a9fcf01..c9ace49 100644 (file)
@@ -1,3 +1,4 @@
 *.[oad]
 *.bc
 dist/*
+extern/*
index f91e8f4..4150556 100644 (file)
@@ -5,7 +5,12 @@
 APPNAME     := the_march
 MODULES     := core
 CFLAGS      := -Wall
+
+#Additional deps and flags for the final executable file
+APP_FLAGS    :=
 APP_RULES   :=
+
+#Extra cleanup rules
 CLEAN_RULES :=
 SCRUB_RULES :=
 
@@ -14,22 +19,24 @@ ifdef EMSCRIPTEN_TOOLS
 #Emscripten build environment
 APP_RULES += move
 HTML      := index.html js/the_march.config.js js/auth.js
+EXPORTS   := '_em_main', 'auth_encrypt'
 CC        := emcc
-EXPORTS   := '_em_main', 'encrypt_password'
-EMOPTS    := --verbose --separate-asm -s ALLOW_MEMORY_GROWTH=1 -s FORCE_FILESYSTEM=1 --pre-js html/js/pre.js
-LIBS      += -s USE_SDL=2 -s USE_SDL_TTF=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]'
+EMFLAGS   := -I../extern/include
+EMFLAGS   += -s USE_SDL=2 -s USE_SDL_TTF=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]'
+APP_FLAGS += --separate-asm -s ALLOW_MEMORY_GROWTH=1 -s FORCE_FILESYSTEM=1 --pre-js html/js/pre.js
+APP_FLAGS += -s EXPORTED_FUNCTIONS="[$(EXPORTS)]"
 EXEPATH   := ../dist/bin/jasm/js
 EXE       := $(APPNAME).js
 OBJFILE   :=bc
-EMFLAGS   := $(EMOPTS) -s EXPORTED_FUNCTIONS="[$(EXPORTS)]"
-EMFLAGS   += -I/usr/include/google
+EMFLAGS   += -I/usr/include/google -I../extern/include
 BYPRODUCT := $(APPNAME).asm.js $(APPNAME).js.mem
+APP_FLAGS += $(EMFLAGS) ../extern/lib/libwolfssl.so
 else
 #Native Build Environment
 CC        := gcc
-CFLAGS    += -v
+CFLAGS    +=
 #LIBS      := -lprotobuf-c
-LIBS      += -lSDL2_ttf -lSDL2_image -lSDL2main -lSDL2
+LIBS      += SDL2_ttf SDL2_image SDL2main SDL2
 EXEPATH   := ../dist/bin/$(shell uname -m)
 #windows mingw build rules
 ifeq ($(OS), Windows_NT)
@@ -58,6 +65,8 @@ all default: clean $(APPNAME)
 #include rules from any .mk file found in a module directory
 include $(wildcard $(patsubst %,%/*.mk,$(MODULES)))
 
+CFLAGS     += $(patsubst %,-l% ,$(LIBS))
+
 #populate C objects and dependency files to generate from SRC
 COBJ       += $(patsubst %.c,%.$(OBJFILE), $(filter %.c,$(SRC)))
 CDEP       += $(COBJ:.$(OBJFILE)=.d)
@@ -67,7 +76,7 @@ include $(CDEP)
 #Build the executable
 $(APPNAME): $(APP_RULES) $(CDEP) $(COBJ)
        @mkdir -p $(EXEPATH)
-       $(CC) -o $(EXEPATH)/$(EXE) $(EMFLAGS) $(CXXFLAGS) $(CFLAGS) core/main.$(OBJFILE) $(LIBS)
+       $(CC) -o $(EXEPATH)/$(EXE) $(CXXFLAGS) $(CFLAGS) $(APP_FLAGS) core/main.$(OBJFILE)
 
 #run the game after making it
 run: $(APPNAME)
@@ -107,7 +116,7 @@ move: $(HTML)
 
 #new default .o for .c files
 %.bc %.o: %.c %.d
-       $(CC) -c $(EMFLAGS) $(CPPFLAGS) $(CFLAGS) $< -o $@ $(LIBS)
+       $(CC) -c $(EMFLAGS) $(CPPFLAGS) $(CFLAGS) $< -o $@
 
 #default for .d dependency files (output from gcc -M)
 %.d: %.c
index e69de29..f3a964c 100644 (file)
@@ -0,0 +1,27 @@
+#Core module compilation rules
+APP_RULES += wolfssl
+SCRUB_RULES += scrub_wolfssl
+
+.PHONY: wolfssl scrub_wolfssl
+wolfssl: ../extern/lib/libwolfssl.so
+       @echo "WolfSSL installed"
+
+../extern/lib/libwolfssl.so:
+       @echo "Downloading WolfSSL"
+       @mkdir -p tmp
+       @mkdir -p ../extern/include
+       @mkdir -p ../extern/lib
+       git clone git@github.com:wolfSSL/wolfssl.git tmp
+       @echo "Genearting WolfSSL Config" && cd tmp &&  emconfigure ./autogen.sh
+       @echo "Configuring WorlfSSL" && cd tmp && emconfigure ./configure --enable-singlethreaded=yes --enable-static=yes --enable-fastmath=no
+       sed -i 's/SIZEOF_LONG 0/SIZEOF_LONG 4/' tmp/config.h
+       sed -i 's/SIZEOF_LONG_LONG 0/SIZEOF_LONG_LONG 8/' tmp/config.h
+       cd tmp && emmake src/libwolfssl.la
+       cp -H tmp/src/.libs/libwolfssl.so ../extern/lib/libwolfssl.so
+       cp -r tmp/wolfssl ../extern/include
+       @rm -Rf tmp
+
+scrub_wolfssl:
+       @echo "Scrubbing WolfSSL"
+       @rm -Rf ../extern/include/wolfssl
+       @rm -f ../extern/lib/libwolfssl.so
index f067df7..6da2201 100644 (file)
 #define TRIGGERS quit_trigger
 #include <core/trigger.h>
 #include <core/engine.h>
-
-/* private functions */
-static int main_init(void);
+#include <wolfssl/wolfcrypt/sha256.h>
 
 /* exposed functions */
 void main_loop(void);
 
+/* private functions */
+static int main_init(void);
+
 /* unexposed externs *
 extern int         state_init(void);
 extern void        state_tick(uint32_t delta_ticks);
@@ -43,27 +44,34 @@ extern void        state_handle_event(SDL_Event event);
 extern int         io_init(void);
 extern const char* io_get_error(void);
 extern void        io_quit(void);*/
+
 /* main jump buffer */
 jmp_buf jmp_main;
 
-/* Main Entry
-
-   initializes subsystems and calls main_loop(void)
+/*@
+  initializes subsystems and calls main_loop(void)
 
-   main sets a jump buffer for its primary switch, which may be jumped to
-   at any time.  Jumping with a 0 return value is equivalent to calling
-   setjmp directly, which initializes the system and begins the main loop.
-   Jumping with any other value will process one of the directives associated
-   with the exit codes in core.h
-*******************************************************************************/
+  main sets a jump buffer for its primary switch, which may be jumped to
+  at any time.  Jumping with a 0 return value is equivalent to calling
+  setjmp directly, which initializes the system and begins the main loop.
+  Jumping with any other value will process one of the directives associated
+  with the exit codes in core.h
+*/
 #ifdef __EMSCRIPTEN__
 #define main_loop()\
   emscripten_set_main_loop(main_loop,0,0);\
   TRIGGER_SET(quit_trigger, emscripten_cancel_main_loop);\
   return 0;
+#endif
+
 int
 main (int argc, char** argv)
-{ switch(setjmp(jmp_main))
+{ Sha256 shstr = {0};
+  wc_InitSha256(&shstr);
+
+  printf("%d %d\n", sizeof(long), sizeof(long long));
+
+  switch(setjmp(jmp_main))
     { case 0:
         if (main_init())
           return -1;
@@ -79,8 +87,9 @@ main (int argc, char** argv)
   return 0;
 }
 
+#ifdef __EMSCRIPTEN__
 #undef main_loop
-#endif //EMSCRIPTEN
+#endif
 
 /** subsystem initializer
     Calling main_init() bootstraps the system, and may be called multiple