How to cross-compile Git for ARM?
Asked Answered
S

3

15

Unfortunately, I am having difficulty cross-compiling Git for the ARMv6 architecture.

But before I begin describing the steps I've taken and commands I've entered, I should briefly describe the build environment:

  • I am cross-compiling on Ubuntu 12.10 64-bit.
  • The cross compiler is installed to /home/my_name/cctoolchain (this directory contains bin/, lib/, etc.).

I began by grabbing Git 1.8.2 from here. After extracting the directory I ran:

export PATH=$PATH:/home/my_name/cctoolchain/bin

I also ran autoconf to make sure that ./configure was up to date. Then I invoked ./configure as follows:

./configure --prefix=/home/my_name/git-arm --build=x86_64-linux-gnu
  --host=arm-linux-androideabi

This ran for a couple of seconds and then aborted with:

checking whether system succeeds to read fopen'ed directory...
configure: error: in `/home/my_name/git-1.8.2':
configure: error: cannot run test program while cross compiling

I cracked open configure.ac and removed lines 806-825, disabling the test. After doing that, I also had to remove lines 806-839 for a similar reason.

At this point, the ./configure script was able to complete. I then excitedly ran make to build Git and after a few more moments, ran into this error:

fetch-pack.c: In function 'fetch_pack':
fetch-pack.c:928:16: error: 'struct stat' has no member named 'st_mtim'
make: *** [fetch-pack.o] Error 1

Somehow I get the feeling I'm "doing it wrong". This sounds like something that should be a lot easier than manually removing tests from configure.ac. What am I missing?

Seneca answered 20/3, 2013 at 5:41 Comment(1)
Thanks, your question helped me a lot! The command that finally worked for me was CC=armv7l-timesys-linux-gnueabi-gcc CFLAGS="--sysroot=/home/mmes/projects/arm-cross-sdk/tags/0.1.8" LDFLAGS="--sysroot=/home/evadeflow/projects/arm-cross-sdk/tags/0.1.8" ./configure --prefix=/home/evadeflow/git-arm --build=i386-linux-gnu --host=armv7l-timesys-linux-gnueabi. (The --sysroot= arg shouldn't be necessary for most people.) I also had to comment out some tests in configure.ac as you described (ac_cv_fread_reads_directories and ac_cv_snprintf_returns_bogus), and run make configure afterwards.Blackfellow
D
12

The macro that's failing is ST_MTIME_NSEC in git-compat-util.h. This macro is controlled by the macros USE_NSEC, NO_NSEC and USE_ST_TIMESPEC, which are provided on the build commandline or by config.mak.uname, not by configure.

It should be that if no options are provided, git doesn't attempt to use nanosecond timestamps (or st_mtim) at all, but it looks like a bug slipped through.

Try make NO_NSEC=1 and see if that resolves your problem.

Dormer answered 20/3, 2013 at 6:10 Comment(2)
It worked! After providing the extra parameter to make, the troublesome file compiled and the rest of the application seems to be building (so far, anyway).Seneca
@NathanOsman Can you provide some binaries of ARM git on a site somewhere so I can download it without having to build? Would be much appreciated!Denumerable
K
2

I just cross compiled to ARM for a more recent version of git, 2.28, and also ran into issues with tests that cannot run during a cross build.

Please note that I had previously built zlib for ARM and have it installed at /opt/arm-zlib, which appears in the paths below.

The incantation that worked for me, without touching sources, was:

./configure --build=i686-pc-linux-gnu --host=arm-linux NO_ICONV=true ac_cv_fread_reads_directories=true ac_cv_snprintf_returns_bogus=false

make LDFLAGS=-L/opt/arm-zlib/lib CFLAGS=-I/opt/arm-zlib/include NO_TCLTK=true NO_GETTEXT=true

NO_TCLTK disables the GUI, which I did not want.

The other definitions that I passed to configure and make were best guesses; I did not investigate what the best answer would be on my ARM platform.

Konrad answered 16/10, 2020 at 16:33 Comment(1)
this is gold. one thing i'd add is for --host to work, you need to either have gcc-arm-linux-gnueabihf installed (and then --host=arm-linux-gnueabihf will be matched to that compiler), or you can specify a compiler directly with CC=/path/to/gcc, eg. after downloading it from developer.arm.com/Tools%20and%20Software/GNU%20Toolchain I'm not sure how a simple "arm-linux" worked, perhaps your system had a corresponding "arm-linux-gcc" binary available, but that could correspond to several more specific arm architectures yet.Shantelleshantha
W
0

I found that ./configure supports caching the results of checks into a file. If you create that file by hand to match the behavior of your desired target, you can influence how ./configure runs (to an extent).

First, I ran ./configure --config-cache to configure for my local system. This will populate the cache file config.cache with the right variables and in the right format.

I then copied out the relevant checks into config.cache.android, cleaned, and re-ran ./configure with my modified cache.

./configure --config-cache
mv ./config.cache ../
git clean -d -f -x
grep ac_cv_fread_reads_directories ../config.cache > config.cache.android
./configure --cache-file=config.cache.android # ...
# ...
checking whether system succeeds to read fopen'ed directory... (cached) yes
# ...

To know which variables you need to grab, you need to check configure.ac. This particular cache variable refers to fread even though the API being tested is actually fopen.

AC_CACHE_CHECK([whether system succeeds to read fopen'ed directory],
 [ac_cv_fread_reads_directories],
[
AC_RUN_IFELSE(
        [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
                [[
                FILE *f = fopen(".", "r");
                return f != NULL;]])],
        [ac_cv_fread_reads_directories=no],
        [ac_cv_fread_reads_directories=yes])
])

If the author of the configure.ac didn't think to use AC_CACHE_CHECK, then you have to resort to blunter instruments.

Wagshul answered 11/10, 2020 at 5:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.