autotools.bbclass 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. def autotools_dep_prepend(d):
  2. if d.getVar('INHIBIT_AUTOTOOLS_DEPS', True):
  3. return ''
  4. pn = d.getVar('PN', True)
  5. deps = ''
  6. if pn in ['autoconf-native', 'automake-native', 'help2man-native']:
  7. return deps
  8. deps += 'autoconf-native automake-native '
  9. if not pn in ['libtool', 'libtool-native'] and not pn.endswith("libtool-cross"):
  10. deps += 'libtool-native '
  11. if not bb.data.inherits_class('native', d) \
  12. and not bb.data.inherits_class('nativesdk', d) \
  13. and not bb.data.inherits_class('cross', d) \
  14. and not d.getVar('INHIBIT_DEFAULT_DEPS', True):
  15. deps += 'libtool-cross '
  16. return deps + 'gnu-config-native '
  17. EXTRA_OEMAKE = ""
  18. DEPENDS_prepend = "${@autotools_dep_prepend(d)} "
  19. inherit siteinfo
  20. # Space separated list of shell scripts with variables defined to supply test
  21. # results for autoconf tests we cannot run at build time.
  22. export CONFIG_SITE = "${@siteinfo_get_files(d, False)}"
  23. acpaths = "default"
  24. EXTRA_AUTORECONF = "--exclude=autopoint"
  25. export lt_cv_sys_lib_dlsearch_path_spec = "${libdir} ${base_libdir}"
  26. # When building tools for use at build-time it's recommended for the build
  27. # system to use these variables when cross-compiling.
  28. # (http://sources.redhat.com/autobook/autobook/autobook_270.html)
  29. export CPP_FOR_BUILD = "${BUILD_CPP}"
  30. export CPPFLAGS_FOR_BUILD = "${BUILD_CPPFLAGS}"
  31. export CC_FOR_BUILD = "${BUILD_CC}"
  32. export CFLAGS_FOR_BUILD = "${BUILD_CFLAGS}"
  33. export CXX_FOR_BUILD = "${BUILD_CXX}"
  34. export CXXFLAGS_FOR_BUILD="${BUILD_CXXFLAGS}"
  35. export LD_FOR_BUILD = "${BUILD_LD}"
  36. export LDFLAGS_FOR_BUILD = "${BUILD_LDFLAGS}"
  37. def append_libtool_sysroot(d):
  38. # Only supply libtool sysroot option for non-native packages
  39. if not bb.data.inherits_class('native', d):
  40. return '--with-libtool-sysroot=${STAGING_DIR_HOST}'
  41. return ""
  42. CONFIGUREOPTS = " --build=${BUILD_SYS} \
  43. --host=${HOST_SYS} \
  44. --target=${TARGET_SYS} \
  45. --prefix=${prefix} \
  46. --exec_prefix=${exec_prefix} \
  47. --bindir=${bindir} \
  48. --sbindir=${sbindir} \
  49. --libexecdir=${libexecdir} \
  50. --datadir=${datadir} \
  51. --sysconfdir=${sysconfdir} \
  52. --sharedstatedir=${sharedstatedir} \
  53. --localstatedir=${localstatedir} \
  54. --libdir=${libdir} \
  55. --includedir=${includedir} \
  56. --oldincludedir=${oldincludedir} \
  57. --infodir=${infodir} \
  58. --mandir=${mandir} \
  59. --disable-silent-rules \
  60. ${CONFIGUREOPT_DEPTRACK} \
  61. ${@append_libtool_sysroot(d)}"
  62. CONFIGUREOPT_DEPTRACK ?= "--disable-dependency-tracking"
  63. AUTOTOOLS_SCRIPT_PATH ?= "${S}"
  64. CONFIGURE_SCRIPT ?= "${AUTOTOOLS_SCRIPT_PATH}/configure"
  65. AUTOTOOLS_AUXDIR ?= "${AUTOTOOLS_SCRIPT_PATH}"
  66. oe_runconf () {
  67. cfgscript="${CONFIGURE_SCRIPT}"
  68. if [ -x "$cfgscript" ] ; then
  69. bbnote "Running $cfgscript ${CONFIGUREOPTS} ${EXTRA_OECONF} $@"
  70. set +e
  71. ${CACHED_CONFIGUREVARS} $cfgscript ${CONFIGUREOPTS} ${EXTRA_OECONF} "$@"
  72. if [ "$?" != "0" ]; then
  73. echo "Configure failed. The contents of all config.log files follows to aid debugging"
  74. find ${B} -ignore_readdir_race -name config.log -print -exec cat {} \;
  75. die "oe_runconf failed"
  76. fi
  77. set -e
  78. else
  79. bbfatal "no configure script found at $cfgscript"
  80. fi
  81. }
  82. CONFIGURESTAMPFILE = "${WORKDIR}/configure.sstate"
  83. autotools_preconfigure() {
  84. if [ -n "${CONFIGURESTAMPFILE}" -a -e "${CONFIGURESTAMPFILE}" ]; then
  85. if [ "`cat ${CONFIGURESTAMPFILE}`" != "${BB_TASKHASH}" ]; then
  86. if [ "${S}" != "${B}" ]; then
  87. echo "Previously configured separate build directory detected, cleaning ${B}"
  88. rm -rf ${B}
  89. mkdir -p ${B}
  90. else
  91. # At least remove the .la files since automake won't automatically
  92. # regenerate them even if CFLAGS/LDFLAGS are different
  93. cd ${S}
  94. if [ "${CLEANBROKEN}" != "1" -a \( -e Makefile -o -e makefile -o -e GNUmakefile \) ]; then
  95. echo "Running \"${MAKE} clean\" in ${S}"
  96. ${MAKE} clean
  97. fi
  98. find ${S} -ignore_readdir_race -name \*.la -delete
  99. fi
  100. fi
  101. fi
  102. }
  103. autotools_postconfigure(){
  104. if [ -n "${CONFIGURESTAMPFILE}" ]; then
  105. echo ${BB_TASKHASH} > ${CONFIGURESTAMPFILE}
  106. fi
  107. }
  108. EXTRACONFFUNCS ??= ""
  109. do_configure[prefuncs] += "autotools_preconfigure autotools_copy_aclocals ${EXTRACONFFUNCS}"
  110. do_configure[postfuncs] += "autotools_postconfigure"
  111. ACLOCALDIR = "${B}/aclocal-copy"
  112. python autotools_copy_aclocals () {
  113. s = d.getVar("AUTOTOOLS_SCRIPT_PATH", True)
  114. if not os.path.exists(s + "/configure.in") and not os.path.exists(s + "/configure.ac"):
  115. if not d.getVar("AUTOTOOLS_COPYACLOCAL", False):
  116. return
  117. taskdepdata = d.getVar("BB_TASKDEPDATA", False)
  118. #bb.warn(str(taskdepdata))
  119. pn = d.getVar("PN", True)
  120. aclocaldir = d.getVar("ACLOCALDIR", True)
  121. oe.path.remove(aclocaldir)
  122. bb.utils.mkdirhier(aclocaldir)
  123. start = None
  124. configuredeps = []
  125. for dep in taskdepdata:
  126. data = taskdepdata[dep]
  127. if data[1] == "do_configure" and data[0] == pn:
  128. start = dep
  129. break
  130. if start is None:
  131. bb.fatal("Couldn't find ourself in BB_TASKDEPDATA?")
  132. # We need to find configure tasks which are either from <target> -> <target>
  133. # or <native> -> <native> but not <target> -> <native> unless they're direct
  134. # dependencies. This mirrors what would get restored from sstate.
  135. done = [dep]
  136. next = [dep]
  137. while next:
  138. new = []
  139. for dep in next:
  140. data = taskdepdata[dep]
  141. for datadep in data[3]:
  142. if datadep in done:
  143. continue
  144. if (not data[0].endswith("-native")) and taskdepdata[datadep][0].endswith("-native") and dep != start:
  145. continue
  146. done.append(datadep)
  147. new.append(datadep)
  148. if taskdepdata[datadep][1] == "do_configure":
  149. configuredeps.append(taskdepdata[datadep][0])
  150. next = new
  151. #configuredeps2 = []
  152. #for dep in taskdepdata:
  153. # data = taskdepdata[dep]
  154. # if data[1] == "do_configure" and data[0] != pn:
  155. # configuredeps2.append(data[0])
  156. #configuredeps.sort()
  157. #configuredeps2.sort()
  158. #bb.warn(str(configuredeps))
  159. #bb.warn(str(configuredeps2))
  160. cp = []
  161. siteconf = []
  162. for c in configuredeps:
  163. if c.endswith("-native"):
  164. manifest = d.expand("${SSTATE_MANIFESTS}/manifest-${BUILD_ARCH}-%s.populate_sysroot" % c)
  165. elif c.startswith("nativesdk-"):
  166. manifest = d.expand("${SSTATE_MANIFESTS}/manifest-${SDK_ARCH}_${SDK_OS}-%s.populate_sysroot" % c)
  167. elif "-cross-" in c or "-crosssdk" in c:
  168. continue
  169. else:
  170. manifest = d.expand("${SSTATE_MANIFESTS}/manifest-${MACHINE}-%s.populate_sysroot" % c)
  171. try:
  172. f = open(manifest, "r")
  173. for l in f:
  174. if "/aclocal/" in l and l.strip().endswith(".m4"):
  175. cp.append(l.strip())
  176. elif "config_site.d/" in l:
  177. cp.append(l.strip())
  178. except:
  179. bb.warn("%s not found" % manifest)
  180. for c in cp:
  181. t = os.path.join(aclocaldir, os.path.basename(c))
  182. if not os.path.exists(t):
  183. os.symlink(c, t)
  184. d.setVar("CONFIG_SITE", siteinfo_get_files(d, False))
  185. }
  186. autotools_copy_aclocals[vardepsexclude] += "MACHINE SDK_ARCH BUILD_ARCH SDK_OS BB_TASKDEPDATA"
  187. autotools_do_configure() {
  188. # WARNING: gross hack follows:
  189. # An autotools built package generally needs these scripts, however only
  190. # automake or libtoolize actually install the current versions of them.
  191. # This is a problem in builds that do not use libtool or automake, in the case
  192. # where we -need- the latest version of these scripts. e.g. running a build
  193. # for a package whose autotools are old, on an x86_64 machine, which the old
  194. # config.sub does not support. Work around this by installing them manually
  195. # regardless.
  196. ( for ac in `find ${S} -ignore_readdir_race -name configure.in -o -name configure.ac`; do
  197. rm -f `dirname $ac`/configure
  198. done )
  199. if [ -e ${AUTOTOOLS_SCRIPT_PATH}/configure.in -o -e ${AUTOTOOLS_SCRIPT_PATH}/configure.ac ]; then
  200. olddir=`pwd`
  201. cd ${AUTOTOOLS_SCRIPT_PATH}
  202. ACLOCAL="aclocal --system-acdir=${ACLOCALDIR}/"
  203. if [ x"${acpaths}" = xdefault ]; then
  204. acpaths=
  205. for i in `find ${AUTOTOOLS_SCRIPT_PATH} -ignore_readdir_race -maxdepth 2 -name \*.m4|grep -v 'aclocal.m4'| \
  206. grep -v 'acinclude.m4' | grep -v 'aclocal-copy' | sed -e 's,\(.*/\).*$,\1,'|sort -u`; do
  207. acpaths="$acpaths -I $i"
  208. done
  209. else
  210. acpaths="${acpaths}"
  211. fi
  212. AUTOV=`automake --version | sed -e '1{s/.* //;s/\.[0-9]\+$//};q'`
  213. automake --version
  214. echo "AUTOV is $AUTOV"
  215. if [ -d ${STAGING_DATADIR_NATIVE}/aclocal-$AUTOV ]; then
  216. ACLOCAL="$ACLOCAL --automake-acdir=${STAGING_DATADIR_NATIVE}/aclocal-$AUTOV"
  217. fi
  218. # autoreconf is too shy to overwrite aclocal.m4 if it doesn't look
  219. # like it was auto-generated. Work around this by blowing it away
  220. # by hand, unless the package specifically asked not to run aclocal.
  221. if ! echo ${EXTRA_AUTORECONF} | grep -q "aclocal"; then
  222. rm -f aclocal.m4
  223. fi
  224. if [ -e configure.in ]; then
  225. CONFIGURE_AC=configure.in
  226. else
  227. CONFIGURE_AC=configure.ac
  228. fi
  229. if grep "^[[:space:]]*AM_GLIB_GNU_GETTEXT" $CONFIGURE_AC >/dev/null; then
  230. if grep "sed.*POTFILES" $CONFIGURE_AC >/dev/null; then
  231. : do nothing -- we still have an old unmodified configure.ac
  232. else
  233. bbnote Executing glib-gettextize --force --copy
  234. echo "no" | glib-gettextize --force --copy
  235. fi
  236. elif grep "^[[:space:]]*AM_GNU_GETTEXT" $CONFIGURE_AC >/dev/null; then
  237. # We'd call gettextize here if it wasn't so broken...
  238. cp ${STAGING_DATADIR_NATIVE}/gettext/config.rpath ${AUTOTOOLS_AUXDIR}/
  239. if [ -d ${S}/po/ ]; then
  240. cp -f ${STAGING_DATADIR_NATIVE}/gettext/po/Makefile.in.in ${S}/po/
  241. if [ ! -e ${S}/po/remove-potcdate.sin ]; then
  242. cp ${STAGING_DATADIR_NATIVE}/gettext/po/remove-potcdate.sin ${S}/po/
  243. fi
  244. fi
  245. for i in gettext.m4 iconv.m4 lib-ld.m4 lib-link.m4 lib-prefix.m4 nls.m4 po.m4 progtest.m4; do
  246. for j in `find ${S} -ignore_readdir_race -name $i | grep -v aclocal-copy`; do
  247. rm $j
  248. done
  249. done
  250. fi
  251. mkdir -p m4
  252. if grep "^[[:space:]]*[AI][CT]_PROG_INTLTOOL" $CONFIGURE_AC >/dev/null; then
  253. bbnote Executing intltoolize --copy --force --automake
  254. intltoolize --copy --force --automake
  255. fi
  256. bbnote Executing ACLOCAL=\"$ACLOCAL\" autoreconf --verbose --install --force ${EXTRA_AUTORECONF} $acpaths
  257. ACLOCAL="$ACLOCAL" autoreconf -Wcross --verbose --install --force ${EXTRA_AUTORECONF} $acpaths || die "autoreconf execution failed."
  258. cd $olddir
  259. fi
  260. if [ -e ${CONFIGURE_SCRIPT} ]; then
  261. oe_runconf
  262. else
  263. bbnote "nothing to configure"
  264. fi
  265. }
  266. autotools_do_install() {
  267. oe_runmake 'DESTDIR=${D}' install
  268. # Info dir listing isn't interesting at this point so remove it if it exists.
  269. if [ -e "${D}${infodir}/dir" ]; then
  270. rm -f ${D}${infodir}/dir
  271. fi
  272. }
  273. inherit siteconfig
  274. EXPORT_FUNCTIONS do_configure do_install
  275. B = "${WORKDIR}/build"