Compiling FB with Emscripten

Build FB and a program on Windows for Emscripten

Prerequisites
   * git installed
   * development environment for fbc, rtlib, & gfxlib2
   * understand PATH environment variable
   * comfortable using a command prompt
   * build of latest fbc (that includes latest changes)

Install Emscripten (on Windows)
   d:/emsdk.git is assumed for installation directory

   	d:
   	cd \
   	git clone https://github.com/emscripten-core/emsdk.git emsdk.git
   	cd emsdk.git
   	emsdk install latest
   	emsdk activate latest
   	emsdk_env.bat

Build FBC libraries (on Windows)
   d:/fb.git is assumed for latest fbc checked out from repository

   	d:
   	cd \fb.git
   	
   	Rem whatever you use To set-up your fbc build environment (sets PATH)
   	Call c:\batch\setpath.bat fbgit32
   	
   	Rem Add-in the emscripten build environment (also sets PATH)
   	Call d:\emsdk.git\emsdk_env.bat
   	
   	Rem build the rtlib And gfxlib For emscripten
   	make rtlib gfxlib2 TARGET=asmjs-unknown-emscripten ENABLE_STANDALONE=1

Hook for 'emcc.bat' (on Windows)
   Here's the issue: fbc expects the supporting tools to be executable and 
   emscripten font-end on windows uses 'emcc.bat' (plus python in the 
   background) and fbc can't directly call a .BAT file.  Here's a cheap 
   hack to make it work:
   Compile the following source and copy 'emcc.exe' to 
   'd:/fb.git/bin/js-asmjs/emcc.exe'

   	'' emcc.exe to call emcc.bat and pass all arguments
   	''
   	'' tested, but not well tested...
   	''
   	Function EscapeArg( ByRef arg As Const String ) As String
   		Dim ret As String = """"
   	
   		For i As Integer = 1 To Len(arg)
   			Select Case Mid( arg, i, 1 )
   			Case """"
   				ret &= """"""
   			Case Else
   				ret &= Mid( arg, i, 1 )
   			End Select
   		Next
   	
   		ret &= """"
   	
   		Function = ret
   	
   	End Function
   	
   	Dim cmd As String = "emcc.bat"
   	
   	Dim i As Integer = 1
   	While( Command(i) > "" )
   		cmd += " " & EscapeArg( Command(i) )
   		i += 1
   	Wend
   	
   	'' assumes 'emcc.bat' is on PATH
   	
   	Var result = Shell( cmd )
   	
   	End result


   	fbc emcc.bas
   	copy emcc.exe d:\fb.git\Bin\js-asmjs\emcc.exe

Build an FBC program from fbc source
   The first time this runs, emcc takes a long time because emscripten 
   needs to build it's own runtime library and store the result.  After the 
   first time, compile times should be much quicker.  


   	Rem whatever you use To set-up your fbc build environment (sets PATH)
   	Call c:\batch\setpath.bat fbgit32
   	
   	Rem Add-in the emscripten build environment (also sets PATH)
   	Call d:\emsdk.git\emsdk_env.bat
   	
   	Rem build program.bas
   	fbc -target js-asmjs program.bas

Run 'program.html'
   In the directory where 'program.html', 'program.js' & 'program.wasm' was 
   created

   Start a server:
      > python -m http.server

   Then, browse to the directory:
      http://localhost:8000/##

   Or the program:
      http://localhost:8000/program.html##

