Merge branch 'org.openembedded.dev' of git@git.openembedded.org:openembedded into...
[openembedded.git] / classes / autotools.bbclass
blob8236a27c7630b79c534f570bce368dcc5ada31d3
1 inherit base
3 # use autotools_stage_all for native packages
4 AUTOTOOLS_NATIVE_STAGE_INSTALL = "1"
6 def autotools_dep_prepend(d):
7         import bb;
9         if bb.data.getVar('INHIBIT_AUTOTOOLS_DEPS', d, 1):
10                 return ''
12         pn = bb.data.getVar('PN', d, 1)
13         deps = ''
15         if pn in ['autoconf-native', 'automake-native']:
16                 return deps
17         deps += 'autoconf-native automake-native '
19         if not pn in ['libtool', 'libtool-native', 'libtool-cross']:
20                 deps += 'libtool-native '
21                 if not bb.data.inherits_class('native', d) \
22                         and not bb.data.inherits_class('cross', d) \
23                         and not bb.data.inherits_class('sdk', d) \
24                         and not bb.data.getVar('INHIBIT_DEFAULT_DEPS', d, 1):
25                     deps += 'libtool-cross '
27         return deps + 'gnu-config-native '
29 EXTRA_OEMAKE = ""
30 DEPENDS_prepend = "${@autotools_dep_prepend(d)}"
31 acpaths = "default"
32 EXTRA_AUTORECONF = "--exclude=autopoint"
34 def autotools_set_crosscompiling(d):
35         import bb
36         if not bb.data.inherits_class('native', d):
37                 return " cross_compiling=yes"
38         return ""
40 # EXTRA_OECONF_append = "${@autotools_set_crosscompiling(d)}"
42 oe_runconf () {
43         if [ -x ${S}/configure ] ; then
44                 cfgcmd="${S}/configure \
45                     --build=${BUILD_SYS} \
46                     --host=${HOST_SYS} \
47                     --target=${TARGET_SYS} \
48                     --prefix=${prefix} \
49                     --exec_prefix=${exec_prefix} \
50                     --bindir=${bindir} \
51                     --sbindir=${sbindir} \
52                     --libexecdir=${libexecdir} \
53                     --datadir=${datadir} \
54                     --sysconfdir=${sysconfdir} \
55                     --sharedstatedir=${sharedstatedir} \
56                     --localstatedir=${localstatedir} \
57                     --libdir=${libdir} \
58                     --includedir=${includedir} \
59                     --oldincludedir=${oldincludedir} \
60                     --infodir=${infodir} \
61                     --mandir=${mandir} \
62                         ${EXTRA_OECONF} \
63                     $@"
64                 oenote "Running $cfgcmd..."
65                 $cfgcmd || oefatal "oe_runconf failed" 
66         else
67                 oefatal "no configure script found"
68         fi
71 autotools_do_configure() {
72         case ${PN} in
73         autoconf*)
74         ;;
75         automake*)
76         ;;
77         *)
78                 # WARNING: gross hack follows:
79                 # An autotools built package generally needs these scripts, however only
80                 # automake or libtoolize actually install the current versions of them.
81                 # This is a problem in builds that do not use libtool or automake, in the case
82                 # where we -need- the latest version of these scripts.  e.g. running a build
83                 # for a package whose autotools are old, on an x86_64 machine, which the old
84                 # config.sub does not support.  Work around this by installing them manually
85                 # regardless.
86                 ( for ac in `find ${S} -name configure.in -o -name configure.ac`; do
87                         rm -f `dirname $ac`/configure
88                         done )
89                 if [ -e ${S}/configure.in -o -e ${S}/configure.ac ]; then
90                         olddir=`pwd`
91                         cd ${S}
92                         if [ x"${acpaths}" = xdefault ]; then
93                                 acpaths=
94                                 for i in `find ${S} -maxdepth 2 -name \*.m4|grep -v 'aclocal.m4'| \
95                                         grep -v 'acinclude.m4' | sed -e 's,\(.*/\).*$,\1,'|sort -u`; do
96                                         acpaths="$acpaths -I $i"
97                                 done
98                         else
99                                 acpaths="${acpaths}"
100                         fi
101                         AUTOV=`automake --version |head -n 1 |sed "s/.* //;s/\.[0-9]\+$//"`
102                         automake --version
103                         echo "AUTOV is $AUTOV"
104                         install -d ${STAGING_DATADIR}/aclocal
105                         install -d ${STAGING_DATADIR}/aclocal-$AUTOV
106                         acpaths="$acpaths -I${STAGING_DATADIR}/aclocal-$AUTOV -I ${STAGING_DATADIR}/aclocal"
107                         # autoreconf is too shy to overwrite aclocal.m4 if it doesn't look
108                         # like it was auto-generated.  Work around this by blowing it away
109                         # by hand, unless the package specifically asked not to run aclocal.
110                         if ! echo ${EXTRA_AUTORECONF} | grep -q "aclocal"; then
111                                 rm -f aclocal.m4
112                         fi
113                         if [ -e configure.in ]; then
114                           CONFIGURE_AC=configure.in
115                         else
116                           CONFIGURE_AC=configure.ac
117                         fi
118                         if grep "^AM_GLIB_GNU_GETTEXT" $CONFIGURE_AC >/dev/null; then
119                           if grep "sed.*POTFILES" $CONFIGURE_AC >/dev/null; then
120                             : do nothing -- we still have an old unmodified configure.ac
121                           else
122                             oenote Executing glib-gettextize --force --copy
123                             echo "no" | glib-gettextize --force --copy
124                           fi
125                         fi
126                         if grep "^[AI][CT]_PROG_INTLTOOL" $CONFIGURE_AC >/dev/null; then
127                           oenote Executing intltoolize --copy --force --automake
128                           intltoolize --copy --force --automake
129                         fi
130                         oenote Executing autoreconf --verbose --install --force ${EXTRA_AUTORECONF} $acpaths
131                         mkdir -p m4
132                         autoreconf -Wcross --verbose --install --force ${EXTRA_AUTORECONF} $acpaths || oefatal "autoreconf execution failed."
133                         cd $olddir
134                 fi
135         ;;
136         esac
137         if [ -e ${S}/configure ]; then
138                 oe_runconf $@
139         else
140                 oenote "nothing to configure"
141         fi
144 autotools_do_install() {
145         oe_runmake 'DESTDIR=${D}' install
148 do_install_append() {
149         for i in `find ${D} -name "*.la"` ; do \
150                 sed -i -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*\),${libdir}/\1,g' $i
151                 sed -i -e s:${CROSS_DIR}/${HOST_SYS}::g $i
152                 sed -i -e s:${CROSS_DIR}::g $i
153                 sed -i -e s:${STAGING_LIBDIR}:${libdir}:g $i
154                 sed -i -e s:${STAGING_DIR_HOST}::g $i
155                 sed -i -e s:${STAGING_DIR}::g $i
156                 sed -i -e s:${S}::g $i
157                 sed -i -e s:${T}::g $i
158                 sed -i -e s:${D}::g $i
159         done
162 STAGE_TEMP="${WORKDIR}/temp-staging"
164 autotools_stage_includes() {
165         if [ "${INHIBIT_AUTO_STAGE_INCLUDES}" != "1" ]
166         then
167                 rm -rf ${STAGE_TEMP}
168                 mkdir -p ${STAGE_TEMP}
169                 make DESTDIR="${STAGE_TEMP}" install
170                 cp -pPR ${STAGE_TEMP}/${includedir}/* ${STAGING_INCDIR}
171                 rm -rf ${STAGE_TEMP}
172         fi
175 autotools_stage_dir() {
176         from="$1"
177         to="$2"
178         # This will remove empty directories so we can ignore them
179         rmdir "$from" 2> /dev/null || true
180         if [ -d "$from" ]; then
181                 mkdir -p "$to"
182                 cp -fpPR "$from"/* "$to"
183         fi
186 autotools_stage_all() {
187         if [ "${INHIBIT_AUTO_STAGE}" = "1" ]
188         then
189                 return
190         fi
191         rm -rf ${STAGE_TEMP}
192         mkdir -p ${STAGE_TEMP}
193         oe_runmake DESTDIR="${STAGE_TEMP}" install
194         autotools_stage_dir ${STAGE_TEMP}/${includedir} ${STAGING_INCDIR}
195         if [ "${BUILD_SYS}" = "${HOST_SYS}" ]; then
196                 autotools_stage_dir ${STAGE_TEMP}/${bindir} ${STAGING_DIR_HOST}${layout_bindir}
197                 autotools_stage_dir ${STAGE_TEMP}/${sbindir} ${STAGING_DIR_HOST}${layout_sbindir}
198                 autotools_stage_dir ${STAGE_TEMP}/${base_bindir} ${STAGING_DIR_HOST}${layout_base_bindir}
199                 autotools_stage_dir ${STAGE_TEMP}/${base_sbindir} ${STAGING_DIR_HOST}${layout_base_sbindir}
200                 autotools_stage_dir ${STAGE_TEMP}/${libexecdir} ${STAGING_DIR_HOST}${layout_libexecdir}
201                 if [ "${prefix}/lib" != "${libdir}" ]; then
202                         # python puts its files in here, make sure they are staged as well
203                         autotools_stage_dir ${STAGE_TEMP}/${prefix}/lib ${STAGING_DIR_HOST}${layout_prefix}/lib
204                 fi
205         fi
206         if [ -d ${STAGE_TEMP}/${libdir} ]
207         then
208                 olddir=`pwd`
209                 cd ${STAGE_TEMP}/${libdir}
210                 las=$(find . -name \*.la -type f)
211                 cd $olddir
212                 echo "Found la files: $las"              
213                 for i in $las
214                 do
215                         sed -e 's/^installed=yes$/installed=no/' \
216                             -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*.la\),${STAGING_LIBDIR}/\1,g' \
217                             -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*\),${STAGING_LIBDIR},g' \
218                             -e "/^dependency_libs=/s,\([[:space:]']\)${libdir},\1${STAGING_LIBDIR},g" \
219                             -i ${STAGE_TEMP}/${libdir}/$i
220                 done
221                 autotools_stage_dir ${STAGE_TEMP}/${libdir} ${STAGING_LIBDIR}
222         fi
223         # Ok, this is nasty. pkgconfig.bbclass is usually used to install .pc files,
224         # however some packages rely on the presence of .pc files to enable/disable
225         # their configurataions in which case we better should not install everything
226         # unconditionally, but rather depend on the actual results of make install.
227         # The good news though: a) there are not many packages doing this and
228         # b) packaged staging will fix that anyways. :M:
229         if [ "${AUTOTOOLS_STAGE_PKGCONFIG}" = "1" ]
230         then
231                 if [ -e ${STAGE_TEMP}/${libdir}/pkgconfig/ ] ; then
232                         echo "cp -f ${STAGE_TEMP}/${libdir}/pkgconfig/*.pc ${STAGING_LIBDIR}/pkgconfig/"
233                         cp -f ${STAGE_TEMP}/${libdir}/pkgconfig/*.pc ${STAGING_LIBDIR}/pkgconfig/
234                 fi
235                 if [ -e ${STAGE_TEMP}/${datadir}/pkgconfig/ ] ; then
236                         echo "cp -f ${STAGE_TEMP}/${datadir}/pkgconfig/*.pc ${STAGING_DATADIR}/pkgconfig/"
237                         cp -f ${STAGE_TEMP}/${datadir}/pkgconfig/*.pc ${STAGING_DATADIR}/pkgconfig/
238                 fi
239         fi
240         rm -rf ${STAGE_TEMP}/${mandir} || true
241         rm -rf ${STAGE_TEMP}/${infodir} || true
242         autotools_stage_dir ${STAGE_TEMP}/${datadir} ${STAGING_DATADIR}
243         rm -rf ${STAGE_TEMP}
246 EXPORT_FUNCTIONS do_configure do_install