]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/classes/base.bbclass
gnupg: add 1.4.3-2 from Debian.
[familiar-h63xx-build.git] / org.handhelds.familiar / classes / base.bbclass
1 PATCHES_DIR="${S}"
2
3 def base_dep_prepend(d):
4         import bb;
5         #
6         # Ideally this will check a flag so we will operate properly in
7         # the case where host == build == target, for now we don't work in
8         # that case though.
9         #
10         deps = ""
11
12         # INHIBIT_DEFAULT_DEPS doesn't apply to the patch command.  Whether or  not
13         # we need that built is the responsibility of the patch function / class, not
14         # the application.
15         patchdeps = bb.data.getVar("PATCH_DEPENDS", d, 1)
16         if patchdeps and not patchdeps in bb.data.getVar("PROVIDES", d, 1):
17                 deps = patchdeps
18
19         if not bb.data.getVar('INHIBIT_DEFAULT_DEPS', d):
20                 if (bb.data.getVar('HOST_SYS', d, 1) !=
21                     bb.data.getVar('BUILD_SYS', d, 1)):
22                         deps += " virtual/${TARGET_PREFIX}gcc virtual/libc "
23         return deps
24
25 def base_read_file(filename):
26         import bb
27         try:
28                 f = file( filename, "r" )
29         except IOError, reason:
30                 raise bb.build.FuncFailed("can't read from file '%s' (%s)", (filename,reason))
31         else:
32                 return f.read().strip()
33         return None
34
35 def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
36         import bb
37         if bb.data.getVar(variable,d,1) == checkvalue:
38                 return truevalue
39         else:
40                 return falsevalue
41
42 DEPENDS_prepend="${@base_dep_prepend(d)} "
43
44 def base_set_filespath(path, d):
45         import os, bb
46         filespath = []
47         for p in path:
48                 overrides = bb.data.getVar("OVERRIDES", d, 1) or ""
49                 overrides = overrides + ":"
50                 for o in overrides.split(":"):
51                         filespath.append(os.path.join(p, o))
52         bb.data.setVar("FILESPATH", ":".join(filespath), d)
53
54 FILESPATH = "${@base_set_filespath([ "${FILE_DIRNAME}/${PF}", "${FILE_DIRNAME}/${P}", "${FILE_DIRNAME}/${PN}", "${FILE_DIRNAME}/files", "${FILE_DIRNAME}" ], d)}"
55
56 def oe_filter(f, str, d):
57         from re import match
58         return " ".join(filter(lambda x: match(f, x, 0), str.split()))
59
60 def oe_filter_out(f, str, d):
61         from re import match
62         return " ".join(filter(lambda x: not match(f, x, 0), str.split()))
63
64 die() {
65         oefatal "$*"
66 }
67
68 oenote() {
69         echo "NOTE:" "$*"
70 }
71
72 oewarn() {
73         echo "WARNING:" "$*"
74 }
75
76 oefatal() {
77         echo "FATAL:" "$*"
78         exit 1
79 }
80
81 oedebug() {
82         test $# -ge 2 || {
83                 echo "Usage: oedebug level \"message\""
84                 exit 1
85         }
86
87         test ${OEDEBUG:-0} -ge $1 && {
88                 shift
89                 echo "DEBUG:" $*
90         }
91 }
92
93 oe_runmake() {
94         if [ x"$MAKE" = x ]; then MAKE=make; fi
95         oenote ${MAKE} ${EXTRA_OEMAKE} "$@"
96         ${MAKE} ${EXTRA_OEMAKE} "$@" || die "oe_runmake failed"
97 }
98
99 oe_soinstall() {
100         # Purpose: Install shared library file and
101         #          create the necessary links
102         # Example:
103         #
104         # oe_
105         #
106         #oenote installing shared library $1 to $2
107         #
108         libname=`basename $1`
109         install -m 755 $1 $2/$libname
110         sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
111         solink=`echo $libname | sed -e 's/\.so\..*/.so/'`
112         ln -sf $libname $2/$sonamelink
113         ln -sf $libname $2/$solink
114 }
115
116 oe_libinstall() {
117         # Purpose: Install a library, in all its forms
118         # Example
119         #
120         # oe_libinstall libltdl ${STAGING_LIBDIR}/
121         # oe_libinstall -C src/libblah libblah ${D}/${libdir}/
122         dir=""
123         libtool=""
124         silent=""
125         require_static=""
126         require_shared=""
127         staging_install=""
128         while [ "$#" -gt 0 ]; do
129                 case "$1" in
130                 -C)
131                         shift
132                         dir="$1"
133                         ;;
134                 -s)
135                         silent=1
136                         ;;
137                 -a)
138                         require_static=1
139                         ;;
140                 -so)
141                         require_shared=1
142                         ;;
143                 -*)
144                         oefatal "oe_libinstall: unknown option: $1"
145                         ;;
146                 *)
147                         break;
148                         ;;
149                 esac
150                 shift
151         done
152
153         libname="$1"
154         shift
155         destpath="$1"
156         if [ -z "$destpath" ]; then
157                 oefatal "oe_libinstall: no destination path specified"
158         fi
159         if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null
160         then
161                 staging_install=1
162         fi
163
164         __runcmd () {
165                 if [ -z "$silent" ]; then
166                         echo >&2 "oe_libinstall: $*"
167                 fi
168                 $*
169         }
170
171         if [ -z "$dir" ]; then
172                 dir=`pwd`
173         fi
174         if [ -d "$dir/.libs" ]; then
175                 dir=$dir/.libs
176         fi
177         dotlai=$libname.lai
178         dir=$dir`(cd $dir; find -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"`
179         olddir=`pwd`
180         __runcmd cd $dir
181
182         lafile=$libname.la
183         if [ -f "$lafile" ]; then
184                 # libtool archive
185                 eval `cat $lafile|grep "^library_names="`
186                 libtool=1
187         else
188                 library_names="$libname.so* $libname.dll.a"
189         fi
190
191         __runcmd install -d $destpath/
192         dota=$libname.a
193         if [ -f "$dota" -o -n "$require_static" ]; then
194                 __runcmd install -m 0644 $dota $destpath/
195         fi
196         if [ -f "$dotlai" -a -n "$libtool" ]; then
197                 if test -n "$staging_install"
198                 then
199                         # stop libtool using the final directory name for libraries
200                         # in staging:
201                         __runcmd rm -f $destpath/$libname.la
202                         __runcmd sed -e 's/^installed=yes$/installed=no/' -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*\),${STAGING_LIBDIR}/\1,g' $dotlai >$destpath/$libname.la
203                 else
204                         __runcmd install -m 0644 $dotlai $destpath/$libname.la
205                 fi
206         fi
207
208         for name in $library_names; do
209                 files=`eval echo $name`
210                 for f in $files; do
211                         if [ ! -e "$f" ]; then
212                                 if [ -n "$libtool" ]; then
213                                         oefatal "oe_libinstall: $dir/$f not found."
214                                 fi
215                         elif [ -L "$f" ]; then
216                                 __runcmd cp -P "$f" $destpath/
217                         elif [ ! -L "$f" ]; then
218                                 libfile="$f"
219                                 __runcmd install -m 0755 $libfile $destpath/
220                         fi
221                 done
222         done
223
224         if [ -z "$libfile" ]; then
225                 if  [ -n "$require_shared" ]; then
226                         oefatal "oe_libinstall: unable to locate shared library"
227                 fi
228         elif [ -z "$libtool" ]; then
229                 # special case hack for non-libtool .so.#.#.# links
230                 baselibfile=`basename "$libfile"`
231                 if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then
232                         sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
233                         solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'`
234                         if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then
235                                 __runcmd ln -sf $baselibfile $destpath/$sonamelink
236                         fi
237                         __runcmd ln -sf $baselibfile $destpath/$solink
238                 fi
239         fi
240
241         __runcmd cd "$olddir"
242 }
243
244 oe_machinstall() {
245         # Purpose: Install machine dependent files, if available
246         #          If not available, check if there is a default
247         #          If no default, just touch the destination
248         # Example:
249         #                $1  $2   $3         $4
250         # oe_machinstall -m 0644 fstab ${D}/etc/fstab
251         #
252         # TODO: Check argument number?
253         #
254         filename=`basename $3`
255         dirname=`dirname $3`
256
257         for o in `echo ${OVERRIDES} | tr ':' ' '`; do
258                 if [ -e $dirname/$o/$filename ]; then
259                         oenote $dirname/$o/$filename present, installing to $4
260                         install $1 $2 $dirname/$o/$filename $4
261                         return
262                 fi
263         done
264 #       oenote overrides specific file NOT present, trying default=$3...
265         if [ -e $3 ]; then
266                 oenote $3 present, installing to $4
267                 install $1 $2 $3 $4
268         else
269                 oenote $3 NOT present, touching empty $4
270                 touch $4
271         fi
272 }
273
274 addtask showdata
275 do_showdata[nostamp] = "1"
276 python do_showdata() {
277         import sys
278         # emit variables and shell functions
279         bb.data.emit_env(sys.__stdout__, d, True)
280         # emit the metadata which isnt valid shell
281         for e in d.keys():
282             if bb.data.getVarFlag(e, 'python', d):
283                 sys.__stdout__.write("\npython %s () {\n%s}\n" % (e, bb.data.getVar(e, d, 1)))
284 }
285
286 addtask listtasks
287 do_listtasks[nostamp] = "1"
288 python do_listtasks() {
289         import sys
290         # emit variables and shell functions
291         #bb.data.emit_env(sys.__stdout__, d)
292         # emit the metadata which isnt valid shell
293         for e in d.keys():
294                 if bb.data.getVarFlag(e, 'task', d):
295                         sys.__stdout__.write("%s\n" % e)
296 }
297
298 addtask clean
299 do_clean[dirs] = "${TOPDIR}"
300 do_clean[nostamp] = "1"
301 do_clean[bbdepcmd] = ""
302 python base_do_clean() {
303         """clear the build and temp directories"""
304         dir = bb.data.expand("${WORKDIR}", d)
305         if dir == '//': raise bb.build.FuncFailed("wrong DATADIR")
306         bb.note("removing " + dir)
307         os.system('rm -rf ' + dir)
308
309         dir = "%s.*" % bb.data.expand(bb.data.getVar('STAMP', d), d)
310         bb.note("removing " + dir)
311         os.system('rm -f '+ dir)
312 }
313
314 addtask mrproper
315 do_mrproper[dirs] = "${TOPDIR}"
316 do_mrproper[nostamp] = "1"
317 do_mrproper[bbdepcmd] = ""
318 python base_do_mrproper() {
319         """clear downloaded sources, build and temp directories"""
320         dir = bb.data.expand("${DL_DIR}", d)
321         if dir == '/': bb.build.FuncFailed("wrong DATADIR")
322         bb.debug(2, "removing " + dir)
323         os.system('rm -rf ' + dir)
324         bb.build.exec_task('do_clean', d)
325 }
326
327 addtask fetch
328 do_fetch[dirs] = "${DL_DIR}"
329 do_fetch[nostamp] = "1"
330 python base_do_fetch() {
331         import sys
332
333         localdata = bb.data.createCopy(d)
334         bb.data.update_data(localdata)
335
336         src_uri = bb.data.getVar('SRC_URI', localdata, 1)
337         if not src_uri:
338                 return 1
339
340         try:
341                 bb.fetch.init(src_uri.split(),d)
342         except bb.fetch.NoMethodError:
343                 (type, value, traceback) = sys.exc_info()
344                 raise bb.build.FuncFailed("No method: %s" % value)
345
346         try:
347                 bb.fetch.go(localdata)
348         except bb.fetch.MissingParameterError:
349                 (type, value, traceback) = sys.exc_info()
350                 raise bb.build.FuncFailed("Missing parameters: %s" % value)
351         except bb.fetch.FetchError:
352                 (type, value, traceback) = sys.exc_info()
353                 raise bb.build.FuncFailed("Fetch failed: %s" % value)
354 }
355
356 def oe_unpack_file(file, data, url = None):
357         import bb, os
358         if not url:
359                 url = "file://%s" % file
360         dots = file.split(".")
361         if dots[-1] in ['gz', 'bz2', 'Z']:
362                 efile = os.path.join(bb.data.getVar('WORKDIR', data, 1),os.path.basename('.'.join(dots[0:-1])))
363         else:
364                 efile = file
365         cmd = None
366         if file.endswith('.tar'):
367                 cmd = 'tar x --no-same-owner -f %s' % file
368         elif file.endswith('.tgz') or file.endswith('.tar.gz'):
369                 cmd = 'tar xz --no-same-owner -f %s' % file
370         elif file.endswith('.tbz') or file.endswith('.tar.bz2'):
371                 cmd = 'bzip2 -dc %s | tar x --no-same-owner -f -' % file
372         elif file.endswith('.gz') or file.endswith('.Z') or file.endswith('.z'):
373                 cmd = 'gzip -dc %s > %s' % (file, efile)
374         elif file.endswith('.bz2'):
375                 cmd = 'bzip2 -dc %s > %s' % (file, efile)
376         elif file.endswith('.zip'):
377                 cmd = 'unzip -q %s' % file
378         elif os.path.isdir(file):
379                 filesdir = os.path.realpath(bb.data.getVar("FILESDIR", data, 1))
380                 destdir = "."
381                 if file[0:len(filesdir)] == filesdir:
382                         destdir = file[len(filesdir):file.rfind('/')]
383                         destdir = destdir.strip('/')
384                         if len(destdir) < 1:
385                                 destdir = "."
386                         elif not os.access("%s/%s" % (os.getcwd(), destdir), os.F_OK):
387                                 os.makedirs("%s/%s" % (os.getcwd(), destdir))
388                 cmd = 'cp -pPR %s %s/%s/' % (file, os.getcwd(), destdir)
389         else:
390                 (type, host, path, user, pswd, parm) = bb.decodeurl(url)
391                 if not 'patch' in parm:
392                         # The "destdir" handling was specifically done for FILESPATH
393                         # items.  So, only do so for file:// entries.
394                         if type == "file":
395                                 destdir = bb.decodeurl(url)[1] or "."
396                         else:
397                                 destdir = "."
398                         bb.mkdirhier("%s/%s" % (os.getcwd(), destdir))
399                         cmd = 'cp %s %s/%s/' % (file, os.getcwd(), destdir)
400         if not cmd:
401                 return True
402         cmd = "PATH=\"%s\" %s" % (bb.data.getVar('PATH', data, 1), cmd)
403         bb.note("Unpacking %s to %s/" % (file, os.getcwd()))
404         ret = os.system(cmd)
405         return ret == 0
406
407 addtask unpack after do_fetch
408 do_unpack[dirs] = "${WORKDIR}"
409 python base_do_unpack() {
410         import re, os
411
412         localdata = bb.data.createCopy(d)
413         bb.data.update_data(localdata)
414
415         src_uri = bb.data.getVar('SRC_URI', localdata)
416         if not src_uri:
417                 return
418         src_uri = bb.data.expand(src_uri, localdata)
419         for url in src_uri.split():
420                 try:
421                         local = bb.data.expand(bb.fetch.localpath(url, localdata), localdata)
422                 except bb.MalformedUrl, e:
423                         raise FuncFailed('Unable to generate local path for malformed uri: %s' % e)
424                 # dont need any parameters for extraction, strip them off
425                 local = re.sub(';.*$', '', local)
426                 local = os.path.realpath(local)
427                 ret = oe_unpack_file(local, localdata, url)
428                 if not ret:
429                         raise bb.build.FuncFailed()
430 }
431
432 addtask patch after do_unpack
433 do_patch[dirs] = "${WORKDIR}"
434 python base_do_patch() {
435         import re
436         import bb.fetch
437
438         src_uri = (bb.data.getVar('SRC_URI', d, 1) or '').split()
439         if not src_uri:
440                 return
441
442         patchcleancmd = bb.data.getVar('PATCHCLEANCMD', d, 1)
443         if patchcleancmd:
444                 bb.data.setVar("do_patchcleancmd", patchcleancmd, d)
445                 bb.data.setVarFlag("do_patchcleancmd", "func", 1, d)
446                 bb.build.exec_func("do_patchcleancmd", d)
447
448         workdir = bb.data.getVar('WORKDIR', d, 1)
449         i = 0
450         for url in src_uri:
451
452                 (type, host, path, user, pswd, parm) = bb.decodeurl(url)
453                 if not "patch" in parm:
454                         continue
455
456                 bb.fetch.init([url], d)
457                 url = bb.encodeurl((type, host, path, user, pswd, []))
458                 local = os.path.join('/', bb.fetch.localpath(url, d))
459
460                 # did it need to be unpacked?
461                 dots = os.path.basename(local).split(".")
462                 if dots[-1] in ['gz', 'bz2', 'Z']:
463                         unpacked = os.path.join(bb.data.getVar('WORKDIR', d),'.'.join(dots[0:-1]))
464                 else:
465                         unpacked = local
466                 unpacked = bb.data.expand(unpacked, d)
467
468                 if "pnum" in parm:
469                         pnum = parm["pnum"]
470                 else:
471                         pnum = "1"
472
473                 if "pname" in parm:
474                         pname = parm["pname"]
475                 else:
476                         pname = os.path.basename(unpacked)
477
478                 bb.note("Applying patch '%s'" % pname)
479                 bb.data.setVar("do_patchcmd", bb.data.getVar("PATCHCMD", d, 1) % (pnum, pname, unpacked), d)
480                 bb.data.setVarFlag("do_patchcmd", "func", 1, d)
481                 bb.data.setVarFlag("do_patchcmd", "dirs", "${WORKDIR} ${S}", d)
482                 bb.build.exec_func("do_patchcmd", d)
483
484                 if bb.data.getVar("patch_applied", d):
485                         bb.data.setVar("PATCH_APPLIED_NUM", i, d)
486                         bb.build.exec_func("patch_applied", d)
487                 i += 1
488 }
489
490
491 addhandler base_eventhandler
492 python base_eventhandler() {
493         from bb import note, error, data
494         from bb.event import Handled, NotHandled, getName
495         import os
496
497         messages = {}
498         messages["Completed"] = "completed"
499         messages["Succeeded"] = "completed"
500         messages["Started"] = "started"
501         messages["Failed"] = "failed"
502
503         name = getName(e)
504         msg = ""
505         if name.startswith("Pkg"):
506                 msg += "package %s: " % data.getVar("P", e.data, 1)
507                 msg += messages.get(name[3:]) or name[3:]
508         elif name.startswith("Task"):
509                 msg += "package %s: task %s: " % (data.getVar("PF", e.data, 1), e.task)
510                 msg += messages.get(name[4:]) or name[4:]
511         elif name.startswith("Build"):
512                 msg += "build %s: " % e.name
513                 msg += messages.get(name[5:]) or name[5:]
514         elif name == "UnsatisfiedDep":
515                 msg += "package %s: dependency %s %s" % (e.pkg, e.dep, name[:-3].lower())
516         note(msg)
517
518         if name.startswith("BuildStarted"):
519                 bb.data.setVar( 'BB_VERSION', bb.__version__, e.data )
520                 path_to_bbfiles = bb.data.getVar( 'BBFILES', e.data, 1 )
521                 path_to_packages = path_to_bbfiles[:path_to_bbfiles.index( "packages" )]
522                 #monotone_revision = "<unknown>"
523                 #try:
524                 #       monotone_revision = file( "%s/MT/revision" % path_to_packages ).read().strip()
525                 #except IOError:
526                 #       pass
527                 #bb.data.setVar( 'OE_REVISION', monotone_revision, e.data )
528                 statusvars = ['BB_VERSION', 'OE_REVISION', 'TARGET_ARCH', 'TARGET_OS', 'MACHINE', 'DISTRO', 'TARGET_FPU']
529                 statuslines = ["%-13s = \"%s\"" % (i, bb.data.getVar(i, e.data, 1) or '') for i in statusvars]
530                 statusmsg = "\nOE Build Configuration:\n%s\n" % '\n'.join(statuslines)
531                 print statusmsg
532
533                 needed_vars = [ "TARGET_ARCH", "TARGET_OS" ]
534                 pesteruser = []
535                 for v in needed_vars:
536                         val = bb.data.getVar(v, e.data, 1)
537                         if not val or val == 'INVALID':
538                                 pesteruser.append(v)
539                 if pesteruser:
540                         bb.fatal('The following variable(s) were not set: %s\nPlease set them directly, or choose a MACHINE or DISTRO that sets them.' % ', '.join(pesteruser))
541
542         if not data in e.__dict__:
543                 return NotHandled
544
545         log = data.getVar("EVENTLOG", e.data, 1)
546         if log:
547                 logfile = file(log, "a")
548                 logfile.write("%s\n" % msg)
549                 logfile.close()
550
551         return NotHandled
552 }
553
554 addtask configure after do_unpack do_patch
555 do_configure[dirs] = "${S} ${B}"
556 do_configure[bbdepcmd] = "do_populate_staging"
557 base_do_configure() {
558         :
559 }
560
561 addtask compile after do_configure
562 do_compile[dirs] = "${S} ${B}"
563 do_compile[bbdepcmd] = "do_populate_staging"
564 base_do_compile() {
565         if [ -e Makefile -o -e makefile ]; then
566                 oe_runmake || die "make failed"
567         else
568                 oenote "nothing to compile"
569         fi
570 }
571
572
573 addtask stage after do_compile
574 base_do_stage () {
575         :
576 }
577
578 do_populate_staging[dirs] = "${STAGING_DIR}/${TARGET_SYS}/bin ${STAGING_DIR}/${TARGET_SYS}/lib \
579                              ${STAGING_DIR}/${TARGET_SYS}/include \
580                              ${STAGING_DIR}/${BUILD_SYS}/bin ${STAGING_DIR}/${BUILD_SYS}/lib \
581                              ${STAGING_DIR}/${BUILD_SYS}/include \
582                              ${STAGING_DATADIR} \
583                              ${S} ${B}"
584
585 addtask populate_staging after do_compile
586
587 #python do_populate_staging () {
588 #       if not bb.data.getVar('manifest', d):
589 #               bb.build.exec_func('do_emit_manifest', d)
590 #       if bb.data.getVar('do_stage', d):
591 #               bb.build.exec_func('do_stage', d)
592 #       else:
593 #               bb.build.exec_func('manifest_do_populate_staging', d)
594 #}
595
596 python do_populate_staging () {
597         if bb.data.getVar('manifest_do_populate_staging', d):
598                 bb.build.exec_func('manifest_do_populate_staging', d)
599         else:
600                 bb.build.exec_func('do_stage', d)
601 }
602
603 #addtask install
604 addtask install after do_compile
605 do_install[dirs] = "${S} ${B}"
606
607 base_do_install() {
608         :
609 }
610
611 #addtask populate_pkgs after do_compile
612 #python do_populate_pkgs () {
613 #       if not bb.data.getVar('manifest', d):
614 #               bb.build.exec_func('do_emit_manifest', d)
615 #       bb.build.exec_func('manifest_do_populate_pkgs', d)
616 #       bb.build.exec_func('package_do_shlibs', d)
617 #}
618
619 base_do_package() {
620         :
621 }
622
623 addtask build after do_populate_staging
624 do_build = ""
625 do_build[func] = "1"
626
627 # Functions that update metadata based on files outputted
628 # during the build process.
629
630 SHLIBS = ""
631 RDEPENDS_prepend = " ${SHLIBS}"
632
633 python read_manifest () {
634         import sys
635         mfn = bb.data.getVar("MANIFEST", d, 1)
636         if os.access(mfn, os.R_OK):
637                 # we have a manifest, so emit do_stage and do_populate_pkgs,
638                 # and stuff some additional bits of data into the metadata store
639                 mfile = file(mfn, "r")
640                 manifest = bb.manifest.parse(mfile, d)
641                 if not manifest:
642                         return
643
644                 bb.data.setVar('manifest', manifest, d)
645 }
646
647 python parse_manifest () {
648                 manifest = bb.data.getVar("manifest", d)
649                 if not manifest:
650                         return
651                 for func in ("do_populate_staging", "do_populate_pkgs"):
652                         value = bb.manifest.emit(func, manifest, d)
653                         if value:
654                                 bb.data.setVar("manifest_" + func, value, d)
655                                 bb.data.delVarFlag("manifest_" + func, "python", d)
656                                 bb.data.delVarFlag("manifest_" + func, "fakeroot", d)
657                                 bb.data.setVarFlag("manifest_" + func, "func", 1, d)
658                 packages = []
659                 for l in manifest:
660                         if "pkg" in l and l["pkg"] is not None:
661                                 packages.append(l["pkg"])
662                 bb.data.setVar("PACKAGES", " ".join(packages), d)
663 }
664
665 def explode_deps(s):
666         r = []
667         l = s.split()
668         flag = False
669         for i in l:
670                 if i[0] == '(':
671                         flag = True
672                         j = []
673                 if flag:
674                         j.append(i)
675                         if i.endswith(')'):
676                                 flag = False
677                                 r[-1] += ' ' + ' '.join(j)
678                 else:
679                         r.append(i)
680         return r
681
682 python read_shlibdeps () {
683         packages = (bb.data.getVar('PACKAGES', d, 1) or "").split()
684         for pkg in packages:
685                 rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 0) or bb.data.getVar('RDEPENDS', d, 0) or "")
686                 shlibsfile = bb.data.expand("${WORKDIR}/install/" + pkg + ".shlibdeps", d)
687                 if os.access(shlibsfile, os.R_OK):
688                         fd = file(shlibsfile)
689                         lines = fd.readlines()
690                         fd.close()
691                         for l in lines:
692                                 rdepends.append(l.rstrip())
693                 pcfile = bb.data.expand("${WORKDIR}/install/" + pkg + ".pcdeps", d)
694                 if os.access(pcfile, os.R_OK):
695                         fd = file(pcfile)
696                         lines = fd.readlines()
697                         fd.close()
698                         for l in lines:
699                                 rdepends.append(l.rstrip())
700                 bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d)
701 }
702
703 python read_subpackage_metadata () {
704         import re
705
706         def decode(str):
707                 import codecs
708                 c = codecs.getdecoder("string_escape")
709                 return c(str)[0]
710
711         data_file = bb.data.expand("${WORKDIR}/install/${PN}.package", d)
712         if os.access(data_file, os.R_OK):
713                 f = file(data_file, 'r')
714                 lines = f.readlines()
715                 f.close()
716                 r = re.compile("([^:]+):\s*(.*)")
717                 for l in lines:
718                         m = r.match(l)
719                         if m:
720                                 bb.data.setVar(m.group(1), decode(m.group(2)), d)
721 }
722
723 python __anonymous () {
724         import exceptions
725         need_host = bb.data.getVar('COMPATIBLE_HOST', d, 1)
726         if need_host:
727                 import re
728                 this_host = bb.data.getVar('HOST_SYS', d, 1)
729                 if not re.match(need_host, this_host):
730                         raise bb.parse.SkipPackage("incompatible with host %s" % this_host)
731         
732         pn = bb.data.getVar('PN', d, 1)
733
734         cvsdate = bb.data.getVar('CVSDATE_%s' % pn, d, 1)
735         if cvsdate != None:
736                 bb.data.setVar('CVSDATE', cvsdate, d)
737
738         use_nls = bb.data.getVar('USE_NLS_%s' % pn, d, 1)
739         if use_nls != None:
740                 bb.data.setVar('USE_NLS', use_nls, d)
741
742         try:
743                 bb.build.exec_func('read_manifest', d)
744                 bb.build.exec_func('parse_manifest', d)
745         except exceptions.KeyboardInterrupt:
746                 raise
747         except Exception, e:
748                 bb.error("anonymous function: %s" % e)
749                 pass
750 }
751
752 python () {
753         import bb, os
754         mach_arch = bb.data.getVar('MACHINE_ARCH', d, 1)
755         old_arch = bb.data.getVar('PACKAGE_ARCH', d, 1)
756         if (old_arch == mach_arch):
757                 # Nothing to do
758                 return
759         if (bb.data.getVar('SRC_URI_OVERRIDES_PACKAGE_ARCH', d, 1) == '0'):
760                 return
761         paths = []
762         for p in [ "${FILE_DIRNAME}/${PF}", "${FILE_DIRNAME}/${P}", "${FILE_DIRNAME}/${PN}", "${FILE_DIRNAME}/files", "${FILE_DIRNAME}" ]:
763                 paths.append(bb.data.expand(os.path.join(p, mach_arch), d))
764         for s in bb.data.getVar('SRC_URI', d, 1).split():
765                 local = bb.data.expand(bb.fetch.localpath(s, d), d)
766                 for mp in paths:
767                         if local.startswith(mp):
768 #                               bb.note("overriding PACKAGE_ARCH from %s to %s" % (old_arch, mach_arch))
769                                 bb.data.setVar('PACKAGE_ARCH', mach_arch, d)
770                                 return
771 }
772
773
774 addtask emit_manifest
775 python do_emit_manifest () {
776 #       FIXME: emit a manifest here
777 #       1) adjust PATH to hit the wrapper scripts
778         wrappers = bb.which(bb.data.getVar("BBPATH", d, 1), 'build/install', 0)
779         path = (bb.data.getVar('PATH', d, 1) or '').split(':')
780         path.insert(0, os.path.dirname(wrappers))
781         bb.data.setVar('PATH', ':'.join(path), d)
782 #       2) exec_func("do_install", d)
783         bb.build.exec_func('do_install', d)
784 #       3) read in data collected by the wrappers
785         bb.build.exec_func('read_manifest', d)
786 #       4) mangle the manifest we just generated, get paths back into
787 #          our variable form
788 #       5) write it back out
789 #       6) re-parse it to ensure the generated functions are proper
790         bb.build.exec_func('parse_manifest', d)
791 }
792
793 EXPORT_FUNCTIONS do_clean do_mrproper do_fetch do_unpack do_configure do_compile do_install do_package do_patch do_populate_pkgs do_stage
794
795 MIRRORS[func] = "0"
796 MIRRORS () {
797 ${DEBIAN_MIRROR}/main   http://snapshot.debian.net/archive/pool
798 ${DEBIAN_MIRROR}        ftp://ftp.de.debian.org/debian/pool
799 ${DEBIAN_MIRROR}        ftp://ftp.au.debian.org/debian/pool
800 ${DEBIAN_MIRROR}        ftp://ftp.cl.debian.org/debian/pool
801 ${DEBIAN_MIRROR}        ftp://ftp.hr.debian.org/debian/pool
802 ${DEBIAN_MIRROR}        ftp://ftp.fi.debian.org/debian/pool
803 ${DEBIAN_MIRROR}        ftp://ftp.hk.debian.org/debian/pool
804 ${DEBIAN_MIRROR}        ftp://ftp.hu.debian.org/debian/pool
805 ${DEBIAN_MIRROR}        ftp://ftp.ie.debian.org/debian/pool
806 ${DEBIAN_MIRROR}        ftp://ftp.it.debian.org/debian/pool
807 ${DEBIAN_MIRROR}        ftp://ftp.jp.debian.org/debian/pool
808 ${DEBIAN_MIRROR}        ftp://ftp.no.debian.org/debian/pool
809 ${DEBIAN_MIRROR}        ftp://ftp.pl.debian.org/debian/pool
810 ${DEBIAN_MIRROR}        ftp://ftp.ro.debian.org/debian/pool
811 ${DEBIAN_MIRROR}        ftp://ftp.si.debian.org/debian/pool
812 ${DEBIAN_MIRROR}        ftp://ftp.es.debian.org/debian/pool
813 ${DEBIAN_MIRROR}        ftp://ftp.se.debian.org/debian/pool
814 ${DEBIAN_MIRROR}        ftp://ftp.tr.debian.org/debian/pool
815 ${GNU_MIRROR}   ftp://mirrors.kernel.org/gnu
816 ${GNU_MIRROR}   ftp://ftp.matrix.com.br/pub/gnu
817 ${GNU_MIRROR}   ftp://ftp.cs.ubc.ca/mirror2/gnu
818 ${GNU_MIRROR}   ftp://sunsite.ust.hk/pub/gnu
819 ${GNU_MIRROR}   ftp://ftp.ayamura.org/pub/gnu
820 ftp://ftp.kernel.org/pub        http://www.kernel.org/pub
821 ftp://ftp.kernel.org/pub        ftp://ftp.us.kernel.org/pub
822 ftp://ftp.kernel.org/pub        ftp://ftp.uk.kernel.org/pub
823 ftp://ftp.kernel.org/pub        ftp://ftp.hk.kernel.org/pub
824 ftp://ftp.kernel.org/pub        ftp://ftp.au.kernel.org/pub
825 ftp://ftp.kernel.org/pub        ftp://ftp.jp.kernel.org/pub
826 ftp://.*/.*/    http://www.oesources.org/source/current/
827 http://.*/.*/   http://www.oesources.org/source/current/
828 }
829