How to compile rsync for Android in Ubuntu

My situation

My machine

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04 LTS
Release:    14.04
Codename:   trusty

The latest rsync version to compile (for me it was rsync-3.1.0.tar.gz)

$ curl -s http://rsync.samba.org/ftp/rsync/ \
    | sed -r 's/^.*href="([^"]*)".*$/\1/' | grep 'rsync-[0-9].*\.tar\.gz$'

Procedure

  1. save the tarball name in a variable
    $ RSYNCTGZ="rsync-3.1.0.tar.gz"
    
  2. install needed software
    $ sudo aptitude install gcc-arm-linux-gnueabi
    
  3. download sources
    $ wget http://rsync.samba.org/ftp/rsync/$RSYNCTGZ
    $ tar xzf $RSYNCTGZ
    $ cd rsync-[0-9]*
    
  4. compile
    $ ./configure --host=arm-linux-gnueabi CFLAGS=-static
    $ make
    
  5. install on the device
    $ adb push rsync /data/local/tmp && adb shell chmod 775 /data/local/tmp/rsync
    
  6. test execution
    $ adb shell /data/local/tmp/rsync
    

References