tsmd: install also a little helper script to control the touchscreen daemon
[openembedded.git] / classes / package_ipk.bbclass
blob28aadc24fdfe1008cbe1dbf7e6dbb3fee33fca8e
1 inherit package
3 IMAGE_PKGTYPE ?= "ipk"
5 IPKGCONF_TARGET = "${STAGING_ETCDIR_NATIVE}/opkg.conf"
6 IPKGCONF_SDK =  "${STAGING_ETCDIR_NATIVE}/opkg-sdk.conf"
7 IPKGCONF_CANSDK =  "${STAGING_ETCDIR_NATIVE}/opkg-canadian-sdk.conf"
9 python package_ipk_fn () {
10         from bb import data
11         bb.data.setVar('PKGFN', bb.data.getVar('PKG',d), d)
14 python package_ipk_install () { 
15         #
16         # Warning - this function is not multimachine safe (see stagingdir reference)!
17         #
19         pkg = bb.data.getVar('PKG', d, 1)
20         pkgfn = bb.data.getVar('PKGFN', d, 1)
21         rootfs = bb.data.getVar('IMAGE_ROOTFS', d, 1)
22         ipkdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1)
23         stagingdir = bb.data.getVar('STAGING_DIR', d, 1)
24         tmpdir = bb.data.getVar('TMPDIR', d, 1)
26         if None in (pkg,pkgfn,rootfs):
27                 raise bb.build.FuncFailed("missing variables (one or more of PKG, PKGFN, IMAGEROOTFS)")
28         try:
29                 bb.mkdirhier(rootfs)
30                 os.chdir(rootfs)
31         except OSError:
32                 import sys
33                 (type, value, traceback) = sys.exc_info()
34                 print value
35                 raise bb.build.FuncFailed
37         # Generate ipk.conf if it or the stamp doesnt exist
38         conffile = os.path.join(stagingdir,"opkg.conf")
39         if not os.access(conffile, os.R_OK):
40                 ipkg_archs = bb.data.getVar('PACKAGE_ARCHS',d)
41                 if ipkg_archs is None:
42                         bb.error("PACKAGE_ARCHS missing")
43                         raise FuncFailed
44                 ipkg_archs = ipkg_archs.split()
45                 arch_priority = 1
47                 f = open(conffile,"w")
48                 for arch in ipkg_archs:
49                         f.write("arch %s %s\n" % ( arch, arch_priority ))
50                         arch_priority += 1
51                 f.write("src local file:%s" % ipkdir)
52                 f.close()
55         if (not os.access(os.path.join(ipkdir,"Packages"), os.R_OK) or
56                 not os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"),os.R_OK)):
57                 ret = os.system('opkg-make-index -p %s %s ' % (os.path.join(ipkdir, "Packages"), ipkdir))
58                 if (ret != 0 ):
59                         raise bb.build.FuncFailed
60                 f = open(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"),"w")
61                 f.close()
63         ret = os.system('opkg-cl  -o %s -f %s update' % (rootfs, conffile))
64         ret = os.system('opkg-cl  -o %s -f %s install %s' % (rootfs, conffile, pkgfn))
65         if (ret != 0 ):
66                 raise bb.build.FuncFailed
69 do_package_update_index_ipk[lockfiles] = "${DEPLOY_DIR_IPK}.lock"
70 do_package_update_index_ipk[nostamp] = "1"
71 do_package_update_index_ipk[recrdeptask] += "do_package_write_ipk"
72 do_package_update_index_ipk[recrdeptask] += "do_package_write_ipk"
73 do_package_update_index_ipk[depends] += "opkg-utils-native:do_populate_sysroot"
76 # Update the Packages index files in ${DEPLOY_DIR_IPK}
78 do_package_update_index_ipk () {
79         set -x
81         ipkgarchs="${PACKAGE_ARCHS}"
83         if [ ! -z "${DEPLOY_KEEP_PACKAGES}" ]; then
84                 return
85         fi
87         mkdir -p ${DEPLOY_DIR_IPK}
88         touch ${DEPLOY_DIR_IPK}/Packages
89         opkg-make-index -r ${DEPLOY_DIR_IPK}/Packages -p ${DEPLOY_DIR_IPK}/Packages -l ${DEPLOY_DIR_IPK}/Packages.filelist -m ${DEPLOY_DIR_IPK}
91         for arch in $ipkgarchs; do
92                 if [ -e ${DEPLOY_DIR_IPK}/$arch/ ] ; then 
93                         touch ${DEPLOY_DIR_IPK}/$arch/Packages
94                         opkg-make-index -r ${DEPLOY_DIR_IPK}/$arch/Packages -p ${DEPLOY_DIR_IPK}/$arch/Packages -l ${DEPLOY_DIR_IPK}/$arch/Packages.filelist -m ${DEPLOY_DIR_IPK}/$arch/
95                 fi
96                 if [ -e ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/ ] ; then 
97                         touch ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages
98                         opkg-make-index -r ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages -p ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages -l ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages.filelist -m ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/
99                 fi
100                 if [ -e ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/ ] ; then
101                         touch ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/Packages
102                         opkg-make-index -r ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/Packages -p ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/Packages -l ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/Packages.filelist -m ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/
103                 fi
104         done
108 # Generate an ipkg conf file ${IPKGCONF_TARGET} suitable for use against 
109 # the target system and an ipkg conf file ${IPKGCONF_SDK} suitable for 
110 # use against the host system in sdk builds
112 package_generate_ipkg_conf () {
113         mkdir -p ${STAGING_ETCDIR_NATIVE}/
114         echo "src oe file:${DEPLOY_DIR_IPK}" > ${IPKGCONF_TARGET}
115         echo "src oe file:${DEPLOY_DIR_IPK}" > ${IPKGCONF_SDK}
116         echo "src oe file:${DEPLOY_DIR_IPK}" > ${IPKGCONF_CANSDK}
117         ipkgarchs="${PACKAGE_ARCHS}"
118         priority=1
119         for arch in $ipkgarchs; do
120                 echo "arch $arch $priority" >> ${IPKGCONF_TARGET}
121                 echo "arch ${BUILD_ARCH}-$arch-sdk $priority" >> ${IPKGCONF_SDK}
122                 echo "arch ${SDK_SYS}-sdk-$arch $priority" >> ${IPKGCONF_CANSDK}
123                 priority=$(expr $priority + 5)
124                 if [ -e ${DEPLOY_DIR_IPK}/$arch/Packages ] ; then
125                         echo "src oe-$arch file:${DEPLOY_DIR_IPK}/$arch" >> ${IPKGCONF_TARGET}
126                 fi
127                 if [ -e ${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk/Packages ] ; then
128                         echo "src oe-${BUILD_ARCH}-$arch-sdk file:${DEPLOY_DIR_IPK}/${BUILD_ARCH}-$arch-sdk" >> ${IPKGCONF_SDK}
129                 fi
130                 if [ -e ${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch/Packages ] ; then
131                         echo "src oe-${SDK_SYS}-sdk-$arch file:${DEPLOY_DIR_IPK}/${SDK_SYS}-sdk-$arch" >> ${IPKGCONF_CANSDK}
132                 fi
133         done
134         echo "lists_dir ext /var/lib/opkg" >> ${IPKGCONF_TARGET}
135         echo "lists_dir ext /var/lib/opkg" >> ${IPKGCONF_SDK}
136         echo "lists_dir ext /var/lib/opkg" >> ${IPKGCONF_CANSDK}
139 python do_package_ipk () {
140         import re, copy
142         workdir = bb.data.getVar('WORKDIR', d, 1)
143         if not workdir:
144                 bb.error("WORKDIR not defined, unable to package")
145                 return
148         outdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1)
149         if not outdir:
150                 bb.error("DEPLOY_DIR_IPK not defined, unable to package")
151                 return
153         dvar = bb.data.getVar('D', d, 1)
154         if not dvar:
155                 bb.error("D not defined, unable to package")
156                 return
157         bb.mkdirhier(dvar)
159         tmpdir = bb.data.getVar('TMPDIR', d, 1)
161         if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
162                 os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
164         pkgdest = bb.data.getVar('PKGDEST', d, 1)
165         bb.mkdirhier(pkgdest)
167         packages = bb.data.getVar('PACKAGES', d, True)
168         for pkg in packages.split():
169                 localdata = bb.data.createCopy(d)
170                 root = "%s/%s" % (pkgdest, pkg)
171                 bb.mkdirhier(root)
173                 lf = bb.utils.lockfile(root + ".lock")
175                 bb.data.setVar('ROOT', '', localdata)
176                 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
177                 pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1)
178                 if not pkgname:
179                         pkgname = pkg
180                 bb.data.setVar('PKG', pkgname, localdata)
182                 overrides = bb.data.getVar('OVERRIDES', localdata, True)
183                 if not overrides:
184                         raise bb.build.FuncFailed('OVERRIDES not defined')
185                 bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata)
187                 bb.data.update_data(localdata)
188                 basedir = os.path.join(os.path.dirname(root))
189                 arch = bb.data.getVar('PACKAGE_ARCH', localdata, 1)
190                 pkgoutdir = "%s/%s" % (outdir, arch)
191                 bb.mkdirhier(pkgoutdir)
192                 os.chdir(root)
193                 from glob import glob
194                 g = glob('*') + glob('.[!.]*')
195                 try:
196                         del g[g.index('CONTROL')]
197                         del g[g.index('./CONTROL')]
198                 except ValueError:
199                         pass
200                 if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1":
201                         bb.note("Not creating empty archive for %s-%s" % (pkg, bb.data.expand('${PV}-${PR}${DISTRO_PR}', localdata)))
202                         bb.utils.unlockfile(lf)
203                         continue
205                 controldir = os.path.join(root, 'CONTROL')
206                 bb.mkdirhier(controldir)
207                 try:
208                         ctrlfile = file(os.path.join(controldir, 'control'), 'w')
209                 except OSError:
210                         bb.utils.unlockfile(lf)
211                         raise bb.build.FuncFailed("unable to open control file for writing.")
213                 fields = []
214                 pe = bb.data.getVar('PE', d, 1)
215                 if pe and int(pe) > 0:
216                         fields.append(["Version: %s:%s-%s\n", ['PE', 'PKGV', 'PKGR']])
217                 else:
218                         fields.append(["Version: %s-%s\n", ['PKGV', 'PKGR']])
219                 fields.append(["Description: %s\n", ['DESCRIPTION']])
220                 fields.append(["Section: %s\n", ['SECTION']])
221                 fields.append(["Priority: %s\n", ['PRIORITY']])
222                 fields.append(["Maintainer: %s\n", ['MAINTAINER']])
223                 fields.append(["License: %s\n", ['LICENSE']])
224                 fields.append(["Architecture: %s\n", ['PACKAGE_ARCH']])
225                 fields.append(["OE: %s\n", ['PN']])
226                 fields.append(["Homepage: %s\n", ['HOMEPAGE']])
227                 fields.append(["Build: %s/%s\n", ['METADATA_BRANCH', 'METADATA_REVISION']])
229                 def pullData(l, d):
230                         l2 = []
231                         for i in l:
232                                 l2.append(bb.data.getVar(i, d, 1))
233                         return l2
235                 ctrlfile.write("Package: %s\n" % pkgname)
236                 # check for required fields
237                 try:
238                         for (c, fs) in fields:
239                                 for f in fs:
240                                         if bb.data.getVar(f, localdata) is None:
241                                                 raise KeyError(f)
242                                 ctrlfile.write(c % tuple(pullData(fs, localdata)))
243                 except KeyError:
244                         import sys
245                         (type, value, traceback) = sys.exc_info()
246                         ctrlfile.close()
247                         bb.utils.unlockfile(lf)
248                         raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value)
249                 # more fields
251                 bb.build.exec_func("mapping_rename_hook", localdata)
253                 def write_dep_field(varname, outstring):
254                         var = bb.data.getVar(varname, localdata, True)
255                         if var:
256                                 ctrlfile.write('%s: %s\n' % (outstring, ", ".join(explode_deps(var))))
258                 write_dep_field('RDEPENDS', 'Depends')
259                 write_dep_field('RSUGGESTS', 'Suggests')
260                 write_dep_field('RRECOMMENDS', 'Recommends')
261                 write_dep_field('RPROVIDES', 'Provides')
262                 write_dep_field('RREPLACES', 'Replaces')
263                 write_dep_field('RCONFLICTS', 'Conflicts')
265                 src_uri = bb.data.getVar("SRC_URI", localdata, 1) or d.getVar("FILE", True)
266                 src_uri = re.sub("\s+", " ", src_uri)
267                 ctrlfile.write("Source: %s\n" % " ".join(src_uri.split()))
268                 ctrlfile.close()
270                 for script in ["preinst", "postinst", "prerm", "postrm"]:
271                         scriptvar = bb.data.getVar('pkg_%s' % script, localdata, 1)
272                         if not scriptvar:
273                                 continue
274                         try:
275                                 scriptfile = file(os.path.join(controldir, script), 'w')
276                         except OSError:
277                                 bb.utils.unlockfile(lf)
278                                 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
279                         scriptfile.write(scriptvar)
280                         scriptfile.close()
281                         os.chmod(os.path.join(controldir, script), 0755)
283                 conffiles_str = bb.data.getVar("CONFFILES", localdata, 1)
284                 if conffiles_str:
285                         try:
286                                 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
287                         except OSError:
288                                 bb.utils.unlockfile(lf)
289                                 raise bb.build.FuncFailed("unable to open conffiles for writing.")
290                         for f in conffiles_str.split():
291                                 conffiles.write('%s\n' % f)
292                         conffiles.close()
294                 os.chdir(basedir)
295                 ret = os.system("PATH=\"%s\" %s %s %s" % (bb.data.getVar("PATH", localdata, 1), 
296                                                           bb.data.getVar("OPKGBUILDCMD",d,1), pkg, pkgoutdir))
297                 if ret != 0:
298                         bb.utils.unlockfile(lf)
299                         raise bb.build.FuncFailed("opkg-build execution failed")
301                 bb.utils.prunedir(controldir)
302                 bb.utils.unlockfile(lf)
305 python () {
306     if bb.data.getVar('PACKAGES', d, True) != '':
307         deps = (bb.data.getVarFlag('do_package_write_ipk', 'depends', d) or "").split()
308         deps.append('opkg-utils-native:do_populate_sysroot')
309         deps.append('fakeroot-native:do_populate_sysroot')
310         bb.data.setVarFlag('do_package_write_ipk', 'depends', " ".join(deps), d)
313 python do_package_write_ipk () {
314         packages = bb.data.getVar('PACKAGES', d, True)
315         if not packages:
316                 bb.debug(1, "No PACKAGES defined, nothing to package")
317                 return
319         bb.build.exec_func("read_subpackage_metadata", d)
320         bb.build.exec_func("do_package_ipk", d)
322 do_package_write_ipk[dirs] = "${D}"
323 addtask package_write_ipk before do_package_write after do_package
324 addtask package_update_index_ipk before do_rootfs