| @@ -1,17 +1,17 @@ | | | @@ -1,17 +1,17 @@ |
1 | Cross-compilation in pkgsrc (developer's guide) -*- outline -*- | | 1 | Cross-compilation in pkgsrc (developer's guide) -*- outline -*- |
2 | Taylor R. Campbell <riastradh@NetBSD.org> | | 2 | Taylor R. Campbell <riastradh@NetBSD.org> |
3 | | | 3 | |
4 | $NetBSD: HOWTO-dev-crosscompile,v 1.2 2013/05/11 20:15:29 riastradh Exp $ | | 4 | $NetBSD: HOWTO-dev-crosscompile,v 1.3 2013/05/11 20:24:01 riastradh Exp $ |
5 | | | 5 | |
6 | These are some notes on how to make your package cross-compilable. | | 6 | These are some notes on how to make your package cross-compilable. |
7 | There is no single recipe for it -- each package is different, and | | 7 | There is no single recipe for it -- each package is different, and |
8 | even if it follows, say, the GNU build system conventions, it may have | | 8 | even if it follows, say, the GNU build system conventions, it may have |
9 | its quirks, and the author of the software you're packaging may not | | 9 | its quirks, and the author of the software you're packaging may not |
10 | have ever thought of cross-compilation. | | 10 | have ever thought of cross-compilation. |
11 | | | 11 | |
12 | * Native and target platform | | 12 | * Native and target platform |
13 | | | 13 | |
14 | When building a package, MACHINE_ARCH, MACHINE_GNU_PLATFORM, &c., | | 14 | When building a package, MACHINE_ARCH, MACHINE_GNU_PLATFORM, &c., |
15 | describe the platform for which the package is being built. If | | 15 | describe the platform for which the package is being built. If |
16 | USE_CROSS_COMPILE=no, this is the native platform; otherwise, if | | 16 | USE_CROSS_COMPILE=no, this is the native platform; otherwise, if |
17 | USE_CROSS_COMPILE=yes, it is the target platform, and the additional | | 17 | USE_CROSS_COMPILE=yes, it is the target platform, and the additional |
| @@ -43,46 +43,65 @@ XXX And software not built following GNU | | | @@ -43,46 +43,65 @@ XXX And software not built following GNU |
43 | * Tool dependencies | | 43 | * Tool dependencies |
44 | | | 44 | |
45 | If the process of building your package requires running programs, | | 45 | If the process of building your package requires running programs, |
46 | loading libraries, using data, &c., from a native package, the native | | 46 | loading libraries, using data, &c., from a native package, the native |
47 | package is a tool dependency, not (necessarily) a build dependency or | | 47 | package is a tool dependency, not (necessarily) a build dependency or |
48 | a normal dependency. For example, if building your package entails | | 48 | a normal dependency. For example, if building your package entails |
49 | transforming some XML with XSLT, you might add: | | 49 | transforming some XML with XSLT, you might add: |
50 | | | 50 | |
51 | TOOL_DEPENDS+= libxslt>=1.1.0:../../textproc/libxslt | | 51 | TOOL_DEPENDS+= libxslt>=1.1.0:../../textproc/libxslt |
52 | | | 52 | |
53 | * Native C and C++ compilers | | 53 | * Native C and C++ compilers |
54 | | | 54 | |
55 | Some software wants build tools written in C and C++ and then execute | | 55 | Some software wants build tools written in C and C++ and then execute |
56 | them natively at build-time. Sometimes configure scripts or makefiles | | 56 | them natively at build-time. Your package probably does this if when |
57 | accept a variable named CC_FOR_BUILD or similar to supply this; in | | 57 | you try to cross-compile it, it fails with: |
58 | that case, you can pass in the pkgsrc make variables NATIVE_CC and | | | |
59 | friends: | | | |
60 | | | 58 | |
| | | 59 | sh: Cannot execute ELF binary ./foobar |
| | | 60 | |
| | | 61 | Sometimes configure scripts or makefiles accept a variable named |
| | | 62 | CC_FOR_BUILD or similar to build these tools. In that case, you can |
| | | 63 | pass in the pkgsrc make variables NATIVE_CC and friends: |
| | | 64 | |
| | | 65 | .include "../../mk/bsd.prefs.mk" |
| | | 66 | |
| | | 67 | .if !empty(USE_CROSS_COMPILE:M[yY][eE][sS]) |
61 | CONFIGURE_ENV+= CC_FOR_BUILD=${NATIVE_CC:Q} | | 68 | CONFIGURE_ENV+= CC_FOR_BUILD=${NATIVE_CC:Q} |
62 | CONFIGURE_ENV+= CXX_FOR_BUILD=${NATIVE_CXX:Q} | | 69 | CONFIGURE_ENV+= CXX_FOR_BUILD=${NATIVE_CXX:Q} |
63 | CONFIGURE_ENV+= LD_FOR_BUILD=${NATIVE_LD:Q} | | 70 | CONFIGURE_ENV+= LD_FOR_BUILD=${NATIVE_LD:Q} |
| | | 71 | .endif |
64 | | | 72 | |
65 | If the software doesn't use CC_FOR_BUILD, it may still be easy to find | | 73 | If the software doesn't use CC_FOR_BUILD, it may still be easy to find |
66 | the makefile rules that invoke $(CC) or $(LD) to build native tools | | 74 | the makefile rules that invoke $(CC) or $(LD) to build native tools |
67 | and patch them to replace that by $(CC_FOR_BUILD) and $(LD_FOR_BUILD). | | 75 | and patch them to replace that by $(CC_FOR_BUILD) and $(LD_FOR_BUILD). |
68 | | | 76 | |
69 | XXX The mechanism here is currently pretty kludgey; there is little | | 77 | XXX The mechanism here is currently pretty kludgey; there is little |
70 | principle to these NATIVE_CC/CXX/LD variables and they should be | | 78 | principle to these NATIVE_CC/CXX/LD variables and they should be |
71 | better rationalized. If you want a native Fortran compiler, for | | 79 | better rationalized. If you want a native Fortran compiler, for |
72 | instance, you'll have to hack it yourself. | | 80 | instance, you'll have to hack it yourself. |
73 | | | 81 | |
74 | * Configure-time run-tests | | 82 | * Configure-time run-tests |
75 | | | 83 | |
76 | There's a lot of autoconf-configured software out there that uses | | 84 | There's a lot of autoconf-configured software out there that uses |
77 | run-tests to learn about the environment, which doesn't work so well | | 85 | run-tests to learn about the environment, which doesn't work so well |
78 | in cross-builds. Some of these can be patched to be replaced by | | 86 | in cross-builds. Your package probably uses this if it when you try to |
79 | compile-tests; otherwise, for a particular known target environment, | | 87 | cross-compile it, it fails with: |
80 | you can pre-answer the tests for autoconf: | | 88 | |
| | | 89 | configure: error: cannot run test programs while cross-compiling |
| | | 90 | |
| | | 91 | or |
| | | 92 | |
| | | 93 | configure: error: cannot check for file existence when cross-compiling |
| | | 94 | |
| | | 95 | Some of these can be patched to be replaced by compile-tests. |
| | | 96 | Otherwise, for a particular known target environment, you can |
| | | 97 | pre-answer the tests for autoconf: |
81 | | | 98 | |
82 | .include "../../bsd.prefs.mk" | | 99 | .include "../../bsd.prefs.mk" |
83 | | | 100 | |
84 | .if ${OPSYS} == "NetBSD" | | 101 | .if !empty(USE_CROSS_COMPILE:M[yY][eE][sS]) |
| | | 102 | . if ${OPSYS} == "NetBSD" |
85 | # Configure wants to check for /dev/random but can't. We know NetBSD | | 103 | # Configure wants to check for /dev/random but can't. We know NetBSD |
86 | # always has a /dev/random, so inform autoconf of the fact. | | 104 | # always has a /dev/random, so inform autoconf of the fact. |
87 | CONFIGURE_ENV+= ac_cv_file__dev_random=yes | | 105 | CONFIGURE_ENV+= ac_cv_file__dev_random=yes |
| | | 106 | . endif |
88 | .endif | | 107 | .endif |