11

Which path should I pass to the --prefix option when doing cross compiling: should I specify the path on my build machine or the path on the target platform?

Suppose I build the code into /home/me/arm/build/target_fs/usr, after that I copy the files into my target platform where they will be located at /usr. Should I use --prefix=/home/me/arm/build/target_fs/usr or just --prefix=/usr and then make install DESTDIR=/home/me/arm/build/target_fs?

I thought that the --prefix is not the path for build but the path for running environment (i.e. the path on target platform). The answers here makes me think that I'm right. But there are many pages out there (for example, Cross-compiling FFmpeg for Raspbian: --prefix=/my/path/were/i/keep/built/) where people use the path on build machine for the --prefix. So I'm confused.

anton_rh
  • 8,226
  • 7
  • 45
  • 73

2 Answers2

6

Yes you are right, --prefix is the path for working environment. Just use --prefix=/usr. You can check in which folder path make install command will install your binary by installing in DESTDIR. For example if you use --prefix=/usr and make install DESTDIR=/home/me/arm/build/target_fs, then the binaries will be installed in the folder /home/me/arm/build/target_fs/usr. And If you just run make install, then the binary will be installed in your prefix i.e. in "/usr".

As you are cross-compiling, I think it doesn't matter which prefix you use, because anyways you will be installing in DESTDIR and then copying the binary files manually to your target.

Sami
  • 311
  • 2
  • 8
  • I heard that the prefix may be used by the compiled program for looking for some files (like configs). So if I use `/home/me/arm/build/target_fs/usr` for prefix then the compiled program may try to look files in `/home/me/arm/build/target_fs/usr` which is a path on my build machine, not on the target platform where the program runs. So I think that prefix may matter in some cases. – anton_rh Oct 29 '15 at 11:01
  • 1
    For installation it doesn't matter.But yes, at run time it matters. your binary may look for some config files in prefix at run time. Just use standard path for example --prefix=/usr – Sami Oct 29 '15 at 11:07
  • Thank you, I understood. – anton_rh Oct 29 '15 at 11:17
-1

As you may found:

--prefix=dirname Specify the toplevel installation directory. This is the recommended way to install the tools into a directory other than the default. The toplevel installation directory defaults to /usr/local.

As far as I understand you are trying to compile a compiler for some target.

In this case prefix will specify directory when the compiler will be installed after make install command on build machine. After it you can take a compiler there.

. Should I use --prefix=/home/me/arm/build/target_fs/usr or just --prefix=/usr and then make install DESTDIR=/home/me/arm/build/target_fs?

In your case prefix command have no sense. Because you are copy binaries by hands.

Also you can find all other info on GCC official site: https://gcc.gnu.org/install/finalinstall.html

Laser
  • 6,652
  • 8
  • 54
  • 85
  • No, I don't compile a compiler, I cross compile ordinary packages (like ffmpeg) that will be run on ARM CPU. The "copy" in my case is not just `cp`, it's a script that makes filesystem image for burning into target board. – anton_rh Oct 29 '15 at 10:47
  • Then seems you have to use `DESTDIR` https://www.gnu.org/prep/standards/html_node/DESTDIR.html – Laser Oct 29 '15 at 10:53
  • 1
    prefix certainly can have a big impact, it's often used to hard code paths in binaries themselves, or e.g. in generated config files. You want --prefix to be the installation path that's used at runtime. – nos Oct 29 '15 at 11:07
  • @Arseniy, thanks, your link clarifies some questions: "Prepending the variable DESTDIR to each target in this way provides for staged installs, where the installed files are not placed directly into their expected location but are instead copied into a temporary location (DESTDIR). However, installed files maintain their relative directory structure and any embedded file names will not be modified." – anton_rh Oct 29 '15 at 11:16