Although an article was written a while ago regarding this topic, I have decided to rewrite it based on the amount of changes that have occurred over these years and adapt it to some majority distribution. More specifically, this tutorial is intended for those developers eager to make their own programs, or compile existing ones, under Ubuntu 9.10 (Koala Karmic).

Preparing the environment

    The first thing we must do is install the necessary packages to compile the SDKs, we do this using a package manager, either from the graphical environments or from the command line. Before this, there is an item that we cannot forget, since gcc 4.4 has become the default compiler, it presents us with a problem, since the SDKs are prepared to be compiled using gcc 3.4. But no problem, because everything is solvable, first we will add an old repository to our /etc/apt/sources.list, more specifically Jaunty.

_deb http://es.archive.ubuntu.com/ubuntu/ jaunty main universe
_

 We update the repositories

sudo apt-get update 

 We install the relevant packages

_sudo apt-get install gcc-3.4 g++ binutils patch bzip2 flex bison make gettext pkg-config unzip libz-dev

We change the default compiler 4.4 to 3.4

sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc-3.4 /usr/bin/gcc

NOTE: When finished, if we want, we can restore the gcc version:

sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc-4.4 /usr/bin/gcc

Compiling the SDKs

   Congratulations, you almost have it in your hand, now let’s download the SDKs and compile them. First we change the directory and obtain the code:

cd /usr/src/

sudo mkdir /usr/src/fonera

_cd fonera
_

wget http://download.fon.com/firmware/fonera/latest/fonera.tar.bz2

   Now we unzip the downloaded file:

tar jxvf /another/where/fonera.tar.bz2

   And we proceed to compile it:

make V=99

   This process can take several minutes, as soon as we launch the command we will get a configuration menu, if we want a specific one we can modify and readapt it, if not, we can directly exit and the default configuration will remain. After a while the compilation should finish successfully.

  To make everything easier to work with, you can put the path where we have compiled the SDKs, as an environment variable, and thus not have to go to the aforementioned directory every time we want to compile

PATH=$PATH:/usr/src/fonera/staging_dir_mips/bin

export PATH

Compiling our first program

At this point we already have the compiler available, to check it run:

mips-linux-uclibc-gcc  -v

And we will get something similar to:

Configured with: /usr/src/fonera/toolchain_build_mips/gcc-3.4.6/configure –prefix=/usr/src/fonera/staging_dir_mips –build=i386-pc-linux-gnu –host=i386-pc-linux-gnu –target=mips-linux-uclibc –enable-languages=c,c++ –enable-shared –disable-__cxa_atexit –enable-target-optspace –with-gnu-ld –disable-nls
Thread model: posix
gcc version 3.4.6 (OpenWrt-2.0)

 You can now start your developments, as an example we will do the mythical “hello world”

nano test.c

We introduce the following source code:

_#include <stdio.h>

int main(int argc, char *argv[])
{
     printf(“Hello World !\n”);
}
_

And we compile them:

mips-linux-uclibc-gcc test.c -o test

 You can now pass it to the fonera, for example through scp, and execute it.