Sat May 11 20:24:01 2013 UTC ()
Add some more notes on cross-compilation for developers.


(riastradh)
diff -r1.2 -r1.3 pkgsrc/doc/HOWTO-dev-crosscompile

cvs diff -r1.2 -r1.3 pkgsrc/doc/HOWTO-dev-crosscompile (expand / switch to unified diff)

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