<!doctype linuxdoc system>
<linuxdoc><article>
<titlepag>
  <title>Cross compiling VLC for ARM-Linux based platforms</title>
  <author>Marc Ariberti <tt><htmlurl url="mailto:marcari@videolan.org" name="<marcari@videolan.org>"></tt></author>
  <date>v0.0.1, 13 march 2003</date>
  <abstract>
    This document describes all the steps to cross compile vlc for ARM based
    platforms. It describes how to build a cross compilation toolchain, how to
    build the libraries needed by vlc and the compilation of the vlc itself.
  </abstract>
</titlepag>

<toc>

<sect>
  <heading>Introduction</heading>
  <sect1>
    <heading>Which platforms are targeted ?</heading>
    <p>
      I will describe here how to compile vlc for an ARM based
      PDA running linux. It includes for example :
      <itemize>
      <item>Compaq - iPaq (H36xx, H38xx,...), using
        <itemize>
          <item>Familiar linux
          <item>Opie
        </itemize>
      </item>
      <item>YOPY/Linupy</item>
      <item>Zaurus</item>
      </itemize>
    </p>
  </sect1> 
  <sect1>
    <heading>Requirements for cross-compilation</heading>
  </sect1>
  <sect1>
    <heading>Why cross-compiling ?</heading>
    <p>
      It is of course possible to compile directly on the targeted platform.
      But there are a lot of great advantages to cross-compile :
      <itemize>
      <item>The most important one is probably the speed, because a
        desktop computer is most of the time faster than a PDA for
        compilation.</item>
      <item>Another big problem is that a complete compilation toolchain
        does take a great amount of disk space. And this space is usually
        very limited on embedded systems.</item>
      <item>And there also may not be enough memory to compile big files.</item>
      </itemize>
    </p>
  </sect1>
</sect>

<sect>
  <heading>Building the toolchain</heading>
  <sect1>
    <heading>Prerequisite</heading>
    <sect2>
      <heading></heading>
      <p>
        During this section, we will use the following variables :
        <itemize>
          <item><bf>${PREFIX}</bf> will designate where you want to install 
            your toolchain (eg: <tt>/usr/local/arm/2.95.3</tt>).</item>
          <item><bf>${SRCDIR}</bf> will designate the directory where 
            sources will be uncompressed 
            (eg: <tt>/usr/src</tt> or <tt>/home/foobar/cross-arm</tt>).</item>
        </itemize>
      </p>
    </sect2>
    <sect2>
      <heading>Files needed</heading>
      <p>Download the following files and put them in the <bf>${SRCDIR}</bf> :
        <itemize>
          <item><tt>binutils-2.11.2.tar.gz</tt></item>
          <item><tt>linux-2.4.19.tar.bz2</tt></item>
          <item><tt>patch-2.4.19-rmk4.bz2</tt></item>
        </itemize>
      </p>
    </sect2>
  </sect1>
  <sect1>
    <heading>Binutils</heading>
    <p>Compiling binutils is pretty simple :
    <tscreen><verb>
% tar xzf binutils-2.11.2.tar.gz
% cd binutils-2.11.2
% ./configure --target=arm-linux --prefix=/usr/local/arm/2.95.3
% make
% su 
# make install
    </verb></tscreen>
    </p>
  </sect1>
  <sect1>
    <heading>Preparing linux kernel</heading>
    <p>
    <tscreen><verb>
        % tar xzf linux-2.4.19.tar.bz2
        % bunzip2 patch-2.4.19-rmk4.bz2
        % cd linux-2.4.19
        % patch -p1 &lt; ../patch-2.4.19-rmk4.bz2
        % make clean ARCH=arm CROSS_COMPILE=arm-linux-
        % make ARCH=arm h3600_config
        !!! don't forget to save the configuration even if no changes are made
        % make ARCH=arm menuconfig
        % make symlinks ARCH=arm CROSS_COMPILE=arm-linux-
        % mkdir -p /usr/local/arm/2.95.3/arm-linux/include
        % cp -Rf include/asm include/asm-arm include/linux /usr/local/arm/2.95.3/arm-linux/include
        % cd /usr/local/arm/2.95.3/arm-linux
        % ln -s include sys-linux

    </verb></tscreen>
    </p>
  </sect1>
  <sect1>
    <heading>Basic cross compiler (gcc)</heading>
    <p>
    tar xvzf gcc-2.95.3.tar.gz
    bunzip2 gcc-2.95.3.diff.bz2
    bunzip2 gcc-2.95.3.diffbis.bz2
    patch -p1 -d gcc-2.95.3 &lt; gcc-2.95.3.diff
    patch -p1 -d gcc-2.95.3 &lt; gcc-2.95.3.diffbis
    cd gcc-2.95.3
    ./configure --target=arm-linux --disable-threads --enable-languages=c --prefix=/usr/local/arm/2.95.3 --with-headers=linux-2.4.19/include
    make
    make install
    </p>

  </sect1>
  <sect1>
    <heading>Compiling glibc</heading>
    <p>
    Depending on your target, you may choose another glibc version (eg: 2.1.3 for linupy 1.4)
    tar xvzf glibc-2.2.5.tar.gz
    cd glibc-2.2.5
    tar xvzf ../glibc-linuxthreads-2.2.5.tar.gz
    CC=arm-linux-gcc ./configure arm-linux --target=arm-linux --prefix=/usr/local/arm/2.95.3/arm-linux --enable-add-ons
    
    The following step is quite long !
    
    CC=arm-linux-gcc make

    If you have problems compiling glibc due to pread/pwrite, edit sysdeps/unix/sysv/linux/kernel-features.h
    and turn  __ASSUME_PREAD_SYSCALL and __ASSUME_PWRITE_SYSCALL from 1 to 0.
    
    CC=arm-linux-gcc make install
    </p>
  </sect1>
  <sect1>
    <heading>Full cross compiler (gcc)</heading>
    rm -Rf gcc-2.95.3
    tar xvzf gcc-2.95.3.tar.gz
    patch -p1 -d gcc-2.95.3 &lt; gcc-2.95.3.diff
    patch -p1 -d gcc-2.95.3 &lt; gcc-2.95.3.diff2
    cd gcc-2.95.3
    ./configure --target=arm-linux --prefix=/usr/local/arm/2.95.3
    make
    make install
  </sect1>
  <sect1>
    <heading>Misc</heading>
    Add  /usr/local/arm/2.95.3/bin to your PATH. Add the following line (depends on your shell)
    to your shell's configuration file :
    export PATH=/usr/local/arm/2.95.3/bin:$PATH

    cp libgcc_s.so.1 /usr/local/arm/2.95.3-new/arm-linux/lib                         
    
    Install theses packages on your compiler box in /usr/local/arm/2.95.3/arm-linux
     xlibs_4.1-5_arm.ipk
     xlibs-dev_4.1.0-16_arm.ipk
     zlib1g_1.1.4-3_arm.ipk
     zlib1g-dev_1.1.3-fam1_arm.ipk
  </sect1>
</sect>





<sect>
  <heading>Cross compiling libraries needed by vlc</heading>
  Download <tt>ipaq-config.site</tt> to ${SOURCES}.
  When downloading source tarballs copy them to your ${SOURCES} directory.
  Each section is supposed to begin with <tt>cd ${SOURCES}</tt>.
  <sect1>
    <heading>SDL</heading>
    !!!! beurk but did not found a better working method กกกก
    tar xvzf SDL-1.2.5.tar.gz
    cd SDL-1.2.5
./configure --enable-release --target=arm-linux --host=arm-linux \
    --disable-esd \
    --prefix=/usr/local/arm/2.95.3/arm-linux/usr \
    --x-includes=/usr/local/arm/2.95.3/arm-linux/usr/X11R6/include \
    --x-libraries=/usr/local/arm/2.95.3/arm-linux/usr/X11R6/lib \
    --disable-video-opengl
export PATH=/usr/local/arm/2.95.3/arm-linux/bin:$PATH

  
make && make install
    
  </sect1>
  <sect1>
    <heading>Glib/GTK+</heading>
    tar xvzf glib-1.2.10.tar.gz
    cd glib-1.2.10
    CONFIG_SITE=../ipaq-config.site ./configure --prefix=/usr/local/arm/2.95.3/arm-linux/usr
    make
    make install
    cd ..
    tar xvzf gtk+-1.2.10.tar.gz
    cd gtk+-1.2.10
    CONFIG_SITE=../ipaq-config.site ./configure --prefix=/usr/local/arm/2.95.3/arm-linux/usr --with-glib=../glib-1.2.10
    make 
    make install
  </sect1>
  <sect1>
    <heading>ffmpeg</heading>
    tar xvzf ffmpeg.tar.gz
    cd ffmpeg
    ./configure --cpu=armv4l --cc=arm-linux-gcc --disable-mmx --prefix=/usr/local/arm/2.95.3/arm-linux/usr --enable-shared
    cd libavcodec
    make

    Vlc does not require that you install ffmpeg.
  </sect1>
  <sect1>
    <heading>mad</heading>
    tar xvzf mad-0.14.2b.tar.gz
    cd mad-0.14.2b
./configure --enable-release --target=arm-linux --host=arm-linux \
    --disable-esd \
    --prefix=/usr/local/arm/2.95.3/arm-linux/usr \
    --x-includes=/usr/local/arm/2.95.3/arm-linux/usr/X11R6/include \
    --x-libraries=/usr/local/arm/2.95.3/arm-linux/usr/X11R6/lib \
    --disable-video-opengl
export PATH=/usr/local/arm/2.95.3/arm-linux/bin:$PATH
    make
    
  </sect1>
  <sect1>
    <heading>gpe</heading>
  </sect1>
  %%%%%%%%%%%%%%%%%%%%%%%
  First get Tremor and ogg sources from xiph.org (through CVS for example).       
Then for each them, do :                                                        
% ./configure  --enable-release --prefix=/usr/local/arm/2.95.3/arm-linux        
% export PATH=/usr/local/arm/2.95.3/arm-linux/bin:$PATH                         
% make                                                                          
% su                                                                            
# make install                                                                  
                                                                                
I know it is not clean, but --host or --target switches does not work.          
The PATH I include, contains all the gcc utils for cross compilation            
without the arm-linux- prefix.                                                  
                                                                                
If you want to link them statically : edit the libvorbisidec.a and remove       
from the archive bitwise.o and framing.o (conflict with libogg.a)               
                                                                                
For flac, get the source tarball (from the videolan website for example)        
% ./configure --enable-release --host=arm-linux --target=arm-linux              
--prefix=/usr/local/arm/2.95.3/arm-linux                                        
% make                                                                          
-> will fail (xmms plugin), but not a problem, continue installation by hand    
% su                                                                            
# cp -Rf include/FLAC /usr/local/arm/2.95.3/arm-linux/include                   
# cd src/libFLAC                                                                
# make install                                                                  
                                                                                
When compiling vlc, add to the ./configure :                                    
        --enable-ogg                                                            
        --enable-tremor                                                         
        --enable-flac                                                           
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
  <sect1>
    <heading>tremor</heading>
  </sect1>
  <sect1>
    <heading>ogg</heading>
  </sect1>
  <sect1>
    <heading>flac</heading>
  </sect1>
  <sect1>
    <heading>libdvbpsi</heading>
    tar xvzf libdvbpsi-0.1.2.tar.gz
    cd libdvbpsi-0.1.2
    ./bootstrap
    ./configure --target=arm-linux --host=arm-linux
    make
    
  </sect1>
  <sect1>
    <heading>a52</heading>
    tar xvzf a52dec-0.7.4.tar.gz
    cd a52dec-0.7.4
    ./configure --enable-release --host=arm-linux --target=arm-linux --prefix=/usr/local/arm/2.95.3/arm-linux
    make && make install

  </sect1>
</sect>

<sect>
  <heading>Cross compiling vlc itself</heading>
  have a look เ rules.* in the ipkg directory.
</sect>

</article></linuxdoc>
