autotools.bbclass 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. def get_autotools_dep(d):
  7. if d.getVar('INHIBIT_AUTOTOOLS_DEPS'):
  8. return ''
  9. pn = d.getVar('PN')
  10. deps = ''
  11. if pn in ['autoconf-native', 'automake-native']:
  12. return deps
  13. deps += 'autoconf-native automake-native '
  14. if not pn in ['libtool', 'libtool-native'] and not pn.endswith("libtool-cross"):
  15. deps += 'libtool-native '
  16. if not bb.data.inherits_class('native', d) \
  17. and not bb.data.inherits_class('nativesdk', d) \
  18. and not bb.data.inherits_class('cross', d) \
  19. and not d.getVar('INHIBIT_DEFAULT_DEPS'):
  20. deps += 'libtool-cross '
  21. return deps
  22. DEPENDS:prepend = "${@get_autotools_dep(d)} "
  23. inherit siteinfo
  24. # Space separated list of shell scripts with variables defined to supply test
  25. # results for autoconf tests we cannot run at build time.
  26. # The value of this variable is filled in in a prefunc because it depends on
  27. # the contents of the sysroot.
  28. export CONFIG_SITE
  29. acpaths ?= "default"
  30. EXTRA_AUTORECONF = "--exclude=autopoint --exclude=gtkdocize"
  31. export lt_cv_sys_lib_dlsearch_path_spec = "${libdir} ${base_libdir}"
  32. # When building tools for use at build-time it's recommended for the build
  33. # system to use these variables when cross-compiling.
  34. # (http://sources.redhat.com/autobook/autobook/autobook_270.html)
  35. export CPP_FOR_BUILD = "${BUILD_CPP}"
  36. export CPPFLAGS_FOR_BUILD = "${BUILD_CPPFLAGS}"
  37. export CC_FOR_BUILD = "${BUILD_CC}"
  38. export CFLAGS_FOR_BUILD = "${BUILD_CFLAGS}"
  39. export CXX_FOR_BUILD = "${BUILD_CXX}"
  40. export CXXFLAGS_FOR_BUILD="${BUILD_CXXFLAGS}"
  41. export LD_FOR_BUILD = "${BUILD_LD}"
  42. export LDFLAGS_FOR_BUILD = "${BUILD_LDFLAGS}"
  43. def append_libtool_sysroot(d):
  44. # Only supply libtool sysroot option for non-native packages
  45. if not bb.data.inherits_class('native', d):
  46. return '--with-libtool-sysroot=${STAGING_DIR_HOST}'
  47. return ""
  48. CONFIGUREOPTS = " --build=${BUILD_SYS} \
  49. --host=${HOST_SYS} \
  50. --target=${TARGET_SYS} \
  51. --prefix=${prefix} \
  52. --exec_prefix=${exec_prefix} \
  53. --bindir=${bindir} \
  54. --sbindir=${sbindir} \
  55. --libexecdir=${libexecdir} \
  56. --datadir=${datadir} \
  57. --sysconfdir=${sysconfdir} \
  58. --sharedstatedir=${sharedstatedir} \
  59. --localstatedir=${localstatedir} \
  60. --libdir=${libdir} \
  61. --includedir=${includedir} \
  62. --oldincludedir=${oldincludedir} \
  63. --infodir=${infodir} \
  64. --mandir=${mandir} \
  65. --disable-silent-rules \
  66. ${CONFIGUREOPT_DEPTRACK} \
  67. ${@append_libtool_sysroot(d)}"
  68. CONFIGUREOPT_DEPTRACK ?= "--disable-dependency-tracking"
  69. CACHED_CONFIGUREVARS ?= ""
  70. AUTOTOOLS_SCRIPT_PATH ?= "${S}"
  71. CONFIGURE_SCRIPT ?= "${AUTOTOOLS_SCRIPT_PATH}/configure"
  72. AUTOTOOLS_AUXDIR ?= "${AUTOTOOLS_SCRIPT_PATH}"
  73. oe_runconf () {
  74. # Use relative path to avoid buildpaths in files
  75. cfgscript_name="`basename ${CONFIGURE_SCRIPT}`"
  76. cfgscript=`python3 -c "import os; print(os.path.relpath(os.path.dirname('${CONFIGURE_SCRIPT}'), '.'))"`/$cfgscript_name
  77. if [ -x "$cfgscript" ] ; then
  78. bbnote "Running $cfgscript ${CONFIGUREOPTS} ${EXTRA_OECONF} $@"
  79. if ! CONFIG_SHELL=${CONFIG_SHELL-/bin/bash} ${CACHED_CONFIGUREVARS} $cfgscript ${CONFIGUREOPTS} ${EXTRA_OECONF} "$@"; then
  80. bbnote "The following config.log files may provide further information."
  81. bbnote `find ${B} -ignore_readdir_race -type f -name config.log`
  82. bbfatal_log "configure failed"
  83. fi
  84. else
  85. bbfatal "no configure script found at $cfgscript"
  86. fi
  87. }
  88. CONFIGURESTAMPFILE = "${WORKDIR}/configure.sstate"
  89. autotools_preconfigure() {
  90. if [ -n "${CONFIGURESTAMPFILE}" -a -e "${CONFIGURESTAMPFILE}" ]; then
  91. if [ "`cat ${CONFIGURESTAMPFILE}`" != "${BB_TASKHASH}" ]; then
  92. if [ "${S}" != "${B}" ]; then
  93. echo "Previously configured separate build directory detected, cleaning ${B}"
  94. rm -rf ${B}
  95. mkdir -p ${B}
  96. else
  97. # At least remove the .la files since automake won't automatically
  98. # regenerate them even if CFLAGS/LDFLAGS are different
  99. cd ${S}
  100. if [ "${CLEANBROKEN}" != "1" -a \( -e Makefile -o -e makefile -o -e GNUmakefile \) ]; then
  101. oe_runmake clean
  102. fi
  103. find ${S} -ignore_readdir_race -name \*.la -delete
  104. fi
  105. fi
  106. fi
  107. }
  108. autotools_postconfigure(){
  109. if [ -n "${CONFIGURESTAMPFILE}" ]; then
  110. mkdir -p `dirname ${CONFIGURESTAMPFILE}`
  111. echo ${BB_TASKHASH} > ${CONFIGURESTAMPFILE}
  112. fi
  113. }
  114. EXTRACONFFUNCS ??= ""
  115. EXTRA_OECONF:append = " ${PACKAGECONFIG_CONFARGS}"
  116. do_configure[prefuncs] += "autotools_preconfigure autotools_aclocals ${EXTRACONFFUNCS}"
  117. do_compile[prefuncs] += "autotools_aclocals"
  118. do_install[prefuncs] += "autotools_aclocals"
  119. do_configure[postfuncs] += "autotools_postconfigure"
  120. ACLOCALDIR = "${STAGING_DATADIR}/aclocal"
  121. ACLOCALEXTRAPATH = ""
  122. ACLOCALEXTRAPATH:class-target = " -I ${STAGING_DATADIR_NATIVE}/aclocal/"
  123. ACLOCALEXTRAPATH:class-nativesdk = " -I ${STAGING_DATADIR_NATIVE}/aclocal/"
  124. python autotools_aclocals () {
  125. sitefiles, searched = siteinfo_get_files(d, sysrootcache=True)
  126. d.setVar("CONFIG_SITE", " ".join(sitefiles))
  127. }
  128. do_configure[file-checksums] += "${@' '.join(siteinfo_get_files(d, sysrootcache=False)[1])}"
  129. CONFIGURE_FILES = "${S}/configure.in ${S}/configure.ac ${S}/config.h.in *.m4 Makefile.am"
  130. autotools_do_configure() {
  131. # WARNING: gross hack follows:
  132. # An autotools built package generally needs these scripts, however only
  133. # automake or libtoolize actually install the current versions of them.
  134. # This is a problem in builds that do not use libtool or automake, in the case
  135. # where we -need- the latest version of these scripts. e.g. running a build
  136. # for a package whose autotools are old, on an x86_64 machine, which the old
  137. # config.sub does not support. Work around this by installing them manually
  138. # regardless.
  139. PRUNE_M4=""
  140. for ac in `find ${S} -ignore_readdir_race -name configure.in -o -name configure.ac`; do
  141. rm -f `dirname $ac`/configure
  142. done
  143. if [ -e ${AUTOTOOLS_SCRIPT_PATH}/configure.in -o -e ${AUTOTOOLS_SCRIPT_PATH}/configure.ac ]; then
  144. olddir=`pwd`
  145. cd ${AUTOTOOLS_SCRIPT_PATH}
  146. mkdir -p ${ACLOCALDIR}
  147. ACLOCAL="aclocal --system-acdir=${ACLOCALDIR}/"
  148. if [ x"${acpaths}" = xdefault ]; then
  149. acpaths=
  150. for i in `find ${AUTOTOOLS_SCRIPT_PATH} -ignore_readdir_race -maxdepth 2 -name \*.m4|grep -v 'aclocal.m4'| \
  151. grep -v 'acinclude.m4' | sed -e 's,\(.*/\).*$,\1,'|sort -u`; do
  152. acpaths="$acpaths -I $i"
  153. done
  154. else
  155. acpaths="${acpaths}"
  156. fi
  157. acpaths="$acpaths ${ACLOCALEXTRAPATH}"
  158. AUTOV=`automake --version | sed -e '1{s/.* //;s/\.[0-9]\+$//};q'`
  159. automake --version
  160. echo "AUTOV is $AUTOV"
  161. if [ -d ${STAGING_DATADIR_NATIVE}/aclocal-$AUTOV ]; then
  162. ACLOCAL="$ACLOCAL --automake-acdir=${STAGING_DATADIR_NATIVE}/aclocal-$AUTOV"
  163. fi
  164. # autoreconf is too shy to overwrite aclocal.m4 if it doesn't look
  165. # like it was auto-generated. Work around this by blowing it away
  166. # by hand, unless the package specifically asked not to run aclocal.
  167. if ! echo ${EXTRA_AUTORECONF} | grep -q "aclocal"; then
  168. rm -f aclocal.m4
  169. fi
  170. if [ -e configure.in ]; then
  171. CONFIGURE_AC=configure.in
  172. else
  173. CONFIGURE_AC=configure.ac
  174. fi
  175. if grep -q "^[[:space:]]*AM_GLIB_GNU_GETTEXT" $CONFIGURE_AC; then
  176. if grep -q "sed.*POTFILES" $CONFIGURE_AC; then
  177. : do nothing -- we still have an old unmodified configure.ac
  178. else
  179. bbnote Executing glib-gettextize --force --copy
  180. echo "no" | glib-gettextize --force --copy
  181. fi
  182. elif [ "${BPN}" != "gettext" ] && grep -q "^[[:space:]]*AM_GNU_GETTEXT" $CONFIGURE_AC; then
  183. # We'd call gettextize here if it wasn't so broken...
  184. cp ${STAGING_DATADIR_NATIVE}/gettext/config.rpath ${AUTOTOOLS_AUXDIR}/
  185. if [ -d ${S}/po/ ]; then
  186. cp -f ${STAGING_DATADIR_NATIVE}/gettext/po/Makefile.in.in ${S}/po/
  187. if [ ! -e ${S}/po/remove-potcdate.sin ]; then
  188. cp ${STAGING_DATADIR_NATIVE}/gettext/po/remove-potcdate.sin ${S}/po/
  189. fi
  190. fi
  191. PRUNE_M4="$PRUNE_M4 gettext.m4 iconv.m4 lib-ld.m4 lib-link.m4 lib-prefix.m4 nls.m4 po.m4 progtest.m4"
  192. fi
  193. mkdir -p m4
  194. for i in $PRUNE_M4; do
  195. find ${S} -ignore_readdir_race -name $i -delete
  196. done
  197. bbnote Executing ACLOCAL=\"$ACLOCAL\" autoreconf -Wcross --verbose --install --force ${EXTRA_AUTORECONF} $acpaths
  198. ACLOCAL="$ACLOCAL" autoreconf -Wcross -Wno-obsolete --verbose --install --force ${EXTRA_AUTORECONF} $acpaths || die "autoreconf execution failed."
  199. cd $olddir
  200. fi
  201. if [ -e ${CONFIGURE_SCRIPT} ]; then
  202. oe_runconf
  203. else
  204. bbnote "nothing to configure"
  205. fi
  206. }
  207. autotools_do_compile() {
  208. oe_runmake
  209. }
  210. autotools_do_install() {
  211. oe_runmake 'DESTDIR=${D}' install
  212. # Info dir listing isn't interesting at this point so remove it if it exists.
  213. if [ -e "${D}${infodir}/dir" ]; then
  214. rm -f ${D}${infodir}/dir
  215. fi
  216. }
  217. inherit siteconfig
  218. EXPORT_FUNCTIONS do_configure do_compile do_install
  219. B = "${WORKDIR}/build"