emscripten – openSUSE Lizards https://lizards.opensuse.org Blogs and Ramblings of the openSUSE Members Fri, 06 Mar 2020 11:29:40 +0000 en-US hourly 1 Emscripten and openSUSE: Hands on.. Hands up! https://lizards.opensuse.org/2014/03/24/emscripten-and-opensuse-hands-on-hands-up/ Mon, 24 Mar 2014 08:09:43 +0000 http://lizards.opensuse.org/?p=10686 Emscripten logo
I can code with javascript and I’m fairly good at it (not marvelous just brialiant!). If you have read some of my resent blog post I think in C/C++/Perl or Bash. I also have some kind of a hobby to help out with UnReal world RPG game. Mostly my part is to make it work with *nix platform (mainly Linux and Mac OS X).
As we have seen world is moving fast forward towards web. It’s the-place-to-be for everyone. There is huge potential for players just wandering around and yelling for pleasure to play UrW! So I thought let’s see if we could port SDL to javascript/Flash or something straight from same source. after tiny amount of searching I popped up Emscripten.

Emscripten in nutshell

Emscripten is stated in their Github page (which seems to be only place to reach this project) like this:

Emscripten is an LLVM-to-JavaScript compiler. It takes LLVM bitcode - which can be generated from C/C++, using llvm-gcc or clang, or any other language that can be converted into LLVM - and compiles that into JavaScript, which can be run on the web (or anywhere else JavaScript can run).

So in other words you can your existing C++ or C source code and compile it (with minor changes) to javascript pseudocode with LLVM back-end. I thought it can’t be working and started digging further.

How to test it on openSUSE

If you have openSUSE 12.3 or above you are good to go or you need to install LLVM 3.2 or above from OBS. You can do it with zypper like this:

zypper install llvm llvm-devel llvm-clang llvm-clang-devel git nodejs

Ain’t Clang just another C-compiler? So why not use GCC? Answer is LLVM is very flexible system (GCC is kinda married to C/C++. even there is many other backends) that turns code to Abstract syntax tree and then back-end compiles it to binary (which can anything from machine code to some of your favorite byte code like Java/C#). So in other words you have parser (clang) and you write back-end to generate code (javascript) quite easily (in theory). I think it was kind idea behind GCC in version 3.0 but as said it doesn’t work as seamlessly as it works in LLVM. Another strong point with LLVM is license. (L)GPL is fine license but if you have compiler you license should be as free as it gets.

So HOW TO TEST IT?

I haven’t got time to make rpm-package from Emscripten because I’m still learning by myself but I’ll share now what I have learned:

Ok now you have read Emscripten documentation and you have clang, nodejs and git installed. Clone the Emscripten Git-repo

git clone https://github.com/kripken/emscripten.git

If you just want to test something you can follow this tutorial: http://sol.gfxile.net/emscripten/ so you get the idea. This how far I’ll take you this time. I’ll figure out some SDL examples to be ported (since UnReal World RPG uses SDL) in near future so stay tuned.

]]>