Difference between revisions of "Compile Software for the Humax"

From hummy.tv Wiki
Jump to: navigation, search
(Fix cross-compiler link and other grammar/punctuation)
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
== Compiling on-box ==
 
== Compiling on-box ==
  
It is possible to compile some software directly on the Humax itself, however due to the limited amount of CPU horsepower available, this is only recommended for fairly small packages.
+
It is possible to compile some software directly on the Humax itself, however, due to the limited amount of CPU horsepower available, this is only recommended for fairly small packages.
  
First you need to install the ''gcc'' and ''gawk'' packages. ''gcc'' is the compiler itself and automatically pulls in dependant packages, ''gawk'' is needed to properly support packages which use GNU autoconf, which most do.
+
First you need to install the ''gcc'' and ''gawk'' packages. ''gcc'' is the compiler itself and automatically pulls in dependant packages. ''gawk'' is needed to properly support packages which use GNU autoconf, which most do.
  
 
<pre>
 
<pre>
humax# opkg install gcc gawk
+
humax# opkg install gcc gawk gmake
 
</pre>
 
</pre>
  
After this, close your telnet session and create a new one to properly set up the environment, and you are ready to compile your first piece of software on the Humax.
+
After this, close your telnet session, open a new one to set up the environment properly, and you are ready to compile your first piece of software on the Humax.
  
== Cross compiling on an external host ==
+
=== Warning: Problems with floating-point numbers ===
  
== Recommended ''configure'' parameters ==
+
Whilst programs that use floating-point number functions such as rint() may compile OK on the Humax box, they may not produce the correct results on execution.
  
<pre>
+
This appears to be because the on-box compilers are configured to use software floating-point libraries rather than hardware floating-point.
CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" \
+
You can use compiler option ''-mhard-float'' to overcome the problem, but this does generate warning messages from the compiler.
./configure \
 
        --prefix=/mod \
 
        --host=mipsel-linux \
 
        --target=mipsel-linux \
 
        --disable-nls
 
</pre>
 
  
== Test ==
+
Until this problem is resolved it is best to use the cross-compiler (see below) for code that requires floating-point numbers.
  
<syntaxhighlight lang='bash'>
+
=== Example - compiling the GNU zip (gzip) program ===
#!/bin/sh
 
  
tar="gtar --owner=root --group=root"
+
<pre>
ar="/opt/GNUbinutils/bin/ar"
+
humax# cd /mod/tmp
 +
humax# wget http://ftp.gnu.org/gnu/gzip/gzip-1.4.tar.gz
 +
--2011-08-18 16:39:58-- http://ftp.gnu.org/gnu/gzip/gzip-1.4.tar.gz
 +
Resolving ftp.gnu.org... 140.186.70.20
 +
Connecting to ftp.gnu.org|140.186.70.20|:80... connected.
 +
HTTP request sent, awaiting response... 200 OK
 +
Length: 907411 (886K) [application/x-gzip]
 +
Saving to: `gzip-1.4.tar.gz'
  
pkg=${1:?"No package specified"}
+
100%[======================================>] 907,411      225K/s  in 4.2s   
dst=${2:-"base"}
 
force=0
 
[ "$3" = "-f" ] && force=1
 
  
srcdir="src/$pkg"
+
2011-08-18 16:40:03 (210 KB/s) - `gzip-1.4.tar.gz' saved [907411/907411]
dstdir="`pwd`/pkg/$dst"
 
  
[ ! -d "$srcdir" ] && echo "$srcdir does not exist here." && exit 1
+
humax# tar -xvf gzip-1.4.tar.gz
[ ! -d "$dstdir" ] && echo "$dstdir does not exist here." && exit 1
+
gzip-1.4/
 +
gzip-1.4/zgrep.1
 +
gzip-1.4/configure.ac
 +
...
  
param()
+
humax# cd gzip-1.4
{
+
humax# CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" \
        grep "^$1:" $srcdir/CONTROL/control | cut -d: -f2 | sed 's/^  *//'
+
    ./configure --prefix=/mod --build=mipsel-linux
}
+
checking for a BSD-compatible install... /mod/bin/busybox/install -c
 +
checking whether build environment is sane... yes
 +
...
  
version=`param Version`
+
humax# make
arch=`param Architecture`
+
Making all in lib
 +
make[1]: Entering directory `/mnt/hd2/mod/tmp/gzip-1.4/lib'
 +
  GEN      alloca.h
 +
  GEN      arg-nonnull.h
 +
...
 +
 
 +
humax# ./gzip -V
 +
gzip 1.4
 +
Copyright (C) 2007 Free Software Foundation, Inc.
 +
</pre>
  
pkgfile="$dstdir/${pkg}_${version}_${arch}.opk"
+
== Cross-compiling on an external host ==
  
if [ -f "$pkgfile" ]; then
+
To cross-compile code to run on the Humax you need another Linux system on which to run the compiler. If you don't have another spare Linux box lying around, you can run it on a standard Windows system using VirtualBox.  Oracle provide a number of [http://www.oracle.com/technetwork/server-storage/linux/downloads/vm-for-hol-1896500.html pre-configured Linux systems] which can be downloaded to prevent the need for a full Linux install. You may need to update BIOS settings to enable the virtual machine to run (on HP System Configuration -> Device Configurations Enable Virtualization technology VT-x)
        echo "$pkgfile already exists."
 
        [ $force -eq 0 ] && exit 1
 
fi
 
  
tmpdir=pkg/OPKG_BUILD.$$
+
The actual cross-compiler is available from the [https://uk.humaxdigital.com/open-source/ HUMAX open source download site] with the specific package needed being entitled '''crosstools_hf-linux-2.6.18.0_gcc-4.2-11ts_uclibc-nptl-0.9.29-20070423_20090508.tar.bz2'''
[ -d "$tmpdir" ] && echo "Temporary directory already exists." && exit 1
 
mkdir $tmpdir
 
  
(cd $srcdir && $tar -czf - * --exclude=CONTROL) > $tmpdir/data.tar.gz
+
Once downloaded to your Linux system, the file needs to be extracted under ''/opt/toolchains/'' and your path set up appropriately.
(cd $srcdir/CONTROL && $tar -czf - *) > $tmpdir/control.tar.gz
 
echo "2.0" > $tmpdir/debian-binary
 
  
(cd $tmpdir && $ar -crf $pkgfile debian-binary data.tar.gz control.tar.gz)
+
Hint: due to the excessively long path and file names, use symlinks to create shortcuts.
rm -rf $tmpdir
 
  
echo "Packaged contents of $srcdir into $pkgfile"
+
To reduce the hassle of building software libraries such as ''libsndfile'', copy the relevant headers and libraries across from the Humax box.
  
</syntaxhighlight>
+
If running on a 64 bit Linux system you may experience error messages when compiling such as "bad ELF interpreter: No such file or directory" due to missing 32 bit libraries. See [http://www.howtodoityourself.org/how-to-fix-libld-linux-so-2-bad-elf-interpreter-no-such-file-or-directory.html here] for how to fix.

Latest revision as of 23:23, 12 June 2023

Compiling on-box

It is possible to compile some software directly on the Humax itself, however, due to the limited amount of CPU horsepower available, this is only recommended for fairly small packages.

First you need to install the gcc and gawk packages. gcc is the compiler itself and automatically pulls in dependant packages. gawk is needed to properly support packages which use GNU autoconf, which most do.

humax# opkg install gcc gawk gmake

After this, close your telnet session, open a new one to set up the environment properly, and you are ready to compile your first piece of software on the Humax.

Warning: Problems with floating-point numbers

Whilst programs that use floating-point number functions such as rint() may compile OK on the Humax box, they may not produce the correct results on execution.

This appears to be because the on-box compilers are configured to use software floating-point libraries rather than hardware floating-point. You can use compiler option -mhard-float to overcome the problem, but this does generate warning messages from the compiler.

Until this problem is resolved it is best to use the cross-compiler (see below) for code that requires floating-point numbers.

Example - compiling the GNU zip (gzip) program

humax# cd /mod/tmp
humax# wget http://ftp.gnu.org/gnu/gzip/gzip-1.4.tar.gz
--2011-08-18 16:39:58--  http://ftp.gnu.org/gnu/gzip/gzip-1.4.tar.gz
Resolving ftp.gnu.org... 140.186.70.20
Connecting to ftp.gnu.org|140.186.70.20|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 907411 (886K) [application/x-gzip]
Saving to: `gzip-1.4.tar.gz'

100%[======================================>] 907,411      225K/s   in 4.2s    

2011-08-18 16:40:03 (210 KB/s) - `gzip-1.4.tar.gz' saved [907411/907411]

humax# tar -xvf gzip-1.4.tar.gz 
gzip-1.4/
gzip-1.4/zgrep.1
gzip-1.4/configure.ac
...

humax# cd gzip-1.4
humax# CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" \
    ./configure --prefix=/mod --build=mipsel-linux
checking for a BSD-compatible install... /mod/bin/busybox/install -c
checking whether build environment is sane... yes
...

humax# make
Making all in lib
make[1]: Entering directory `/mnt/hd2/mod/tmp/gzip-1.4/lib'
  GEN      alloca.h
  GEN      arg-nonnull.h
...

humax# ./gzip -V
gzip 1.4
Copyright (C) 2007 Free Software Foundation, Inc.

Cross-compiling on an external host

To cross-compile code to run on the Humax you need another Linux system on which to run the compiler. If you don't have another spare Linux box lying around, you can run it on a standard Windows system using VirtualBox. Oracle provide a number of pre-configured Linux systems which can be downloaded to prevent the need for a full Linux install. You may need to update BIOS settings to enable the virtual machine to run (on HP System Configuration -> Device Configurations Enable Virtualization technology VT-x)

The actual cross-compiler is available from the HUMAX open source download site with the specific package needed being entitled crosstools_hf-linux-2.6.18.0_gcc-4.2-11ts_uclibc-nptl-0.9.29-20070423_20090508.tar.bz2

Once downloaded to your Linux system, the file needs to be extracted under /opt/toolchains/ and your path set up appropriately.

Hint: due to the excessively long path and file names, use symlinks to create shortcuts.

To reduce the hassle of building software libraries such as libsndfile, copy the relevant headers and libraries across from the Humax box.

If running on a 64 bit Linux system you may experience error messages when compiling such as "bad ELF interpreter: No such file or directory" due to missing 32 bit libraries. See here for how to fix.