Monday, October 11, 2010

CMake and Clang/LLVM fun.

I have been using CMake in more projects lately, and have had some fun working around the kinks with alternative compilers (like using mingw from Linux to compile windows executables).

Recently wanted to build a software graphics renderer with Clang, and see if there was any speedup.
The major problem I encountered was getting CMake to let me use clang with its cool -O4 mode (yes, there really is an optimization beyond -O3 for clang). The first problem was -O4 outputs bytecode enhanced o files, ld had no clue, and I didn't want to use gold with plugins to use llvm plugin for ld, and it kept using gcc as the linker. The second problem was cmake forces -rdynamic in the flags to the linker, which the llvm-ld linker couldn't handle.

Here is my working toolchain_llvm.cmake file I use to make CMake work:
#include using cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake
INCLUDE(CMakeForceCompiler) #Disables checks
SET(CMAKE_SYSTEM_NAME Generic)
#Generic removes -rdynamic from linker, which llvm-ld doesn't support

CMAKE_FORCE_C_COMPILER( /usr/bin/clang CLang )
CMAKE_FORCE_CXX_COMPILER ( /usr/bin/clang++ CLang )
SET(CMAKE_RANLIB "/usr/bin/llvm-ranlib" CACHE INTERNAL STRING)
SET(CMAKE_AR "/usr/bin/llvm-ar" CACHE INTERNAL STRING)

SET(CMAKE_LINKER "/usr/bin/llvm-ld" CACHE INTERNAL STRING)
#SET(CMAKE_C_LINKER "/usr/bin/llvm-ld")
#SET(CMAKE_CXX_LINKER "/usr/bin/llvm-ld")

SET(CMAKE_C_LINK_EXECUTABLE "/usr/bin/llvm-ld <OBJECTS> -o <TARGET> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>")
SET(CMAKE_CXX_LINK_EXECUTABLE "/usr/bin/llvm-ld <OBJECTS> -o <TARGET> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>")

SET(CMAKE_FIND_ROOT_PATH /usr/bin)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Yeah, kind of a mouthful, but worth it. Now I can use it with any cmake projects I have, just by running cmake -DCMAKE_TOOLCHAIN_FILE=toolchain_llvm.cmake .

Will get around to posting this in the cmake forums later this week.

Sunday, May 9, 2010

Compiled Opposite Lock Racing for J2ME

Found a neat GPL J2ME racing game : http://code.google.com/p/oppositelock/
Wanted to package it with PhoneMe on the GP2X, but had to compile it first to get the resolution right for 320x240.
Ended up setting up Eclipse, EclipseME and Sun JWT (Java WirelessToolkit) to build the thing. Had to do it on a 32-bit virtual machine, as Sun JWT doesn't have a 64-bit version, and getting everything 32-bit on a 64-bit Linux is a hassle.



Finished packaging it for the GP2x (Gamepark) with PhoneME for j2ME and uploaded it to: GP2X_Archive



Saturday, May 1, 2010

GP2X: phoneME (j2me) updates

I had updated phoneME(j2me opensource version) for the gp2x a while back, and just sat on the updates. Currently I have it compiling against the latest version of open2x libs, and a fix for clipping in draw2d for software rastered 3d racing games.

You can see the bug here. The big blue, white, red and yellow triangles coming from the left and right.





























And here is how it should look, pretty cool rastered 3d effect (no 3d hardware, everything is drawn in software).





























Disneyland kart racer has a demo at http://www.disneylandwap.com/game.jsp.
I uploaded a copy of the last build before my updates with the fun (beta) game mister hachi on archive.gp2x.de

Sunday, November 22, 2009

Google O3D plugin on Linux AMD64

Couldn't sleep, so I tried the new O3D plugin from Google for Ubuntu AMD64 (from the PPAs on Launchpad), didn't work. Ended up building it from source... lots of snags, like 3 new build tools from Google (why can't they just use pre-existing tools).
I am using Chromium on Ubuntu, installed from the PPAs on Launchpad.

Here are the steps I used to build O3D on my 64-bit Linux:
 sudo apt-get install devscripts libglu1-mesa-dev cdbs libgtk2.0-dev libgconf2-dev
tar -xvf depot_tools.tar.gz
export PATH="$HOME/depot_tools:$PATH"
mkdir o3d_chromium_src; cd o3d_chromium_src
gclient config http://src.chromium.org/svn/trunk/src/o3d
gclient sync
export GYP_DEFINES="target_arch=x64"
gclient runhooks --force
cd o3d/build/
hammer -f o3d_main.scons
cd sconsbuild/Debug/
sudo cp libnpo3dautoplugin.so /usr/lib/chromium-browser/plugins/
sudo cp lib* /usr/lib/chromium-browser/















Played Infinite Journey at http://blog.largeanimal.com/demo/
It was cute, looked great, and showed that 3d games in the browser are coming.

No luck with 3d acceleration though, all the games run quite slow, but it looks interesting.

Saturday, September 12, 2009

A Good Start

Most things (like Linux) need setup or are missing some simple piece (Batteries not included). I decided to start a blog about Linux, GP2X and other fun tech and the missing steps.