But I don’t want to go on the cart!


Is LTIB really the right choice for cross-compiling for the Raspberry Pi?  I mean, it’s designed to create an entire board support package for an embedded Linux system:  a kernel, bootloader, root file system, binutils, do memory allocation, system init, etc., etc., etc.

At first glance, that seems a bit like killing a horsefly with a flamethrower if all you want to do is cross-compile.  I was definitely of this opinion before I started making LTIB support the Pi.  I resisted doing the work.  I wanted to do things with my Pi, not futz around with things that were much like my day job.  This was supposed to be fun, right?  So I set out to manually cross-compile MAME for the Pi.

How’d it go?  Well, let’s take a look at my project notebook from a couple of weeks ago.

Image

God, my handwriting is atrocious.

Since I was compiling and linking for the ARM, all the libraries needed by MAME also needed to be compiled for ARM and installed on my build system.  And they needed to be installed in places other than /lib and /usr/lib, so I was going to have to pass in those locations to all the config scripts for all the packages.  Some of the software packages required that other packages be installed on the build system in order to work properly, so those needed to be compiled for x86 so that they could make ARM binaries.

And you can see a partial list of libraries needed just for MAME:  gtk+, gconf, pango, cairo, fontconfig, glib, gdk-pixbuf, atk, pkg-config, libivconv, libffi...

I was starting to feel like I was looking for metal so that I could make a shovel so that I could mine for iron that I needed to make the tool necessary to do the job that I wanted to do.

Ugh!

But these frustrations are exactly the problems that LTIB was designed to solve.  The fastest path through the woods, it turned out, was to make a tool that I was familiar with support my favorite new platform.

I knew that once I got basic support for the Pi working in LTIB, getting it to cross-compile AdvanceMAME would be pretty straightforward.  I could then grab the resulting RPM and install it on Raspian with no trouble at all.

More importantly, because it would cross-compile so quickly compared to a native compilation, I could easily try out different compilers, settings, etc. to see which combination produced the best binaries. [ Or which setup produced binaries at all. I ran into situations where I had to upgrade gcc from 4.6 to 4.7 when I was compiling advanceMAME inside QEMU or natively on the Pi; gcc-4.6 generated bad object files. It was painful to have a compilation fail like this after an hour. I was sold; cross-compiling in 5-10 minutes was for me! ]

Walkthrough for advanceMAME

To build advancemame-0.106, I did the following.

I put the source tarball into a direction mentioned in the lpp section of .ltibrc. /opt/freescale/pkgs, in my case.

In dist/lfs-5.1 I created advancemame/advancemame.spec as follows:

%define pfx /opt/freescale/rootfs/%{_target_cpu}

Summary   : Advance MAME Arcade Machine Emulator
Name      : advancemame
Version   : 0.106.1
Release   : 1
License   : MAME License
Vendor    : http:/advancemame.org
Packager  : Midnight Yell
Group     : Applications/Entertainment
Source    : %{name}-%{version}.tar.gz
BuildRoot : %{_tmppath}/%{name}
Prefix    : %{pfx}

%Description
%{summary}

%Prep
%setup

%Build
if [ ! -e obj/mame/linux/blend/cpu/m68000/m68kmake ] ; then
  # m68kmake must be built natively and advancemame doesn't handle
  # native building & spoofed paths well, so un-spoof the paths and
  # make it.
  ORIG_PATH=$PATH
  export PATH=$UNSPOOF_PATH
  ./configure
  mkdir -p obj/mame/linux/blend/cpu/m68000/
  make obj/mame/linux/blend/cpu/m68000/m68kmake
  export PATH=$ORIG_PATH
fi

./configure --prefix=$RPM_BUILD_ROOT/%{pfx}/%{_prefix} --host=$CFGHOST --build=%{_build} --mandir=%{pfx}/%{_mandir}
CFLAGS="-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard" \
make%Install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT/%{pfx}%Clean
rm -rf $RPM_BUILD_ROOT

%Files
%defattr(-,root,root)
%{pfx}/*

And note that AdvanceMAME is one of those packages that builds a tool that needs to be run natively so that it can build other files that run on the ARM — most packages will have simpler .spec files.

To add advmame to the menu system you have to modify 2 files in config/userspace.  pkg_map:

PKG_ADVMAME = advancemame

And extra_packages.lkc:

config PKG_ADVMAME
bool "advmame" 
help
  This package is a MAME emulator. It contains no ROMs.

That was it!  The next ./ltib -c had advMAME as a menu item under Packages, and when finished, LTIB left an RPM in rpm/RPMS/arm/advancemame-0.106.1-1.arm.rpm

Installing the rpm on Raspian is easy, though slightly non-standard in that you have to specify –relocate because the paths in the rpm include /path/to/ltib/dir/rootfs/usr/bin and you want to actually install to /usr/bin.

After I got AdvanceMAME and AdvanceMESS working, I made similar spec files for xtailpocketsphinx, and a few others.

Next, I want to get LTIB’s version of X up-to-date.  I have something special in mind for my Pi running a low-resource version of X.   Something special indeed…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s