2

I understand the basic concept of using a cross compiler to compile code on one architecture and then copying the executable to another architecture to run it. But I can't figure out the last step of the typical ./configure; make; make install sequence in the context of cross compiling.

For example, I want to cross-compile libusb for an ARM device using my Ubuntu PC. I downloaded the libusb source code, ran configure and make:

> ./configure --disable-udev --host=arm-linux-gnueabihf CC=/usr/bin/arm-linux-gnueabi-gcc
> make

At this point, I have a bunch of libusb compiled binaries for the ARM architecture. Ideally, I want to copy those binaries over to the ARM device and run make install so that I don't have to manually copy them into their destination directories. But that would mean I'd have to copy over the entire build environment from the Ubuntu computer, which seems like a waste of time and disk space. Or I could gather just the binaries and the appropriate Makefiles and copy them over, but that seems clunky.

Is there a more elegant way to take advantage of make install on the destination architecture?

4

Yes, at least for Autotools-based build systems, as used here (and probably some others); these support a DESTDIR variable which can be used to install somewhere other than /.

mkdir destdir
make DESTDIR="${PWD}/destdir" install

This will give you the target binaries (and accompanying files) in destdir; you can then copy that to the target device's /.

  • So I would never run make on the destination computer. Just copy the directory of binaries over to the destination computer and do one big copy to /? – Dan Laks Dec 8 '16 at 2:32
  • Yes, that's it! – Stephen Kitt Dec 8 '16 at 2:34
2

OK, As @Stephen Kitt mentioned you can pass DESTDIR to make install. Here I will provide one more possible option you can try,

  • Run configure script with --prefix=/your/custom/install/dir/path

You can pass --prefix along with your custom path to configure script. So that whenever you run make install it will install to the prefix directory.

Example:

./configure --disable-udev --host=arm-linux-gnueabihf CC=/usr/bin/arm-linux-gnueabi-gcc --prefix=/your/custom/path
  • Run make install with DESTDIR

make install supports DESTDIR variable which will be prepended to installed target file.

Example:

make DESTDIR=`pwd`/DESTDIR install
  • When you specify --prefix, you need to use the target directory that you want to use on the target system; you can't use --prefix to install somewhere handy that's not the real installation directory. (Well, you can in some cases, but you can't rely on that.) – Stephen Kitt Dec 9 '16 at 10:57
  • @StephenKitt Well, It completely depends on the build rules but most of the standard packages will have the support. At least it is recommended to use standard Directory Variables. For instance, bindir will have /prefix/bin/* – Thushi Dec 9 '16 at 12:01
  • I agree --prefix is widely supported; what I'm saying is it's not intended for the use you're putting it to here (unless I'm misunderstanding your intentions). DESTDIR is designed for the kinds of scenarios the OP is interested in. – Stephen Kitt Dec 9 '16 at 12:15
  • @StephenKitt : Nod :) – Thushi Dec 20 '16 at 5:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.