]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/classes/base.bbclass
66563f34d379452fecbf251266fcb0b6d4427532
[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         for url in src_uri:
450
451                 (type, host, path, user, pswd, parm) = bb.decodeurl(url)
452                 if not "patch" in parm:
453                         continue
454
455                 bb.fetch.init([url], d)
456                 url = bb.encodeurl((type, host, path, user, pswd, []))
457                 local = os.path.join('/', bb.fetch.localpath(url, d))
458
459                 # did it need to be unpacked?
460                 dots = os.path.basename(local).split(".")
461                 if dots[-1] in ['gz', 'bz2', 'Z']:
462                         unpacked = os.path.join(bb.data.getVar('WORKDIR', d),'.'.join(dots[0:-1]))
463                 else:
464                         unpacked = local
465                 unpacked = bb.data.expand(unpacked, d)
466
467                 if "pnum" in parm:
468                         pnum = parm["pnum"]
469                 else:
470                         pnum = "1"
471
472                 if "pname" in parm:
473                         pname = parm["pname"]
474                 else:
475                         pname = os.path.basename(unpacked)
476
477                 bb.note("Applying patch '%s'" % pname)
478                 bb.data.setVar("do_patchcmd", bb.data.getVar("PATCHCMD", d, 1) % (pnum, pname, unpacked), d)
479                 bb.data.setVarFlag("do_patchcmd", "func", 1, d)
480                 bb.data.setVarFlag("do_patchcmd", "dirs", "${WORKDIR} ${S}", d)
481                 bb.build.exec_func("do_patchcmd", d)
482 }
483
484
485 addhandler base_eventhandler
486 python base_eventhandler() {
487         from bb import note, error, data
488         from bb.event import Handled, NotHandled, getName
489         import os
490
491         messages = {}
492         messages["Completed"] = "completed"
493         messages["Succeeded"] = "completed"
494         messages["Started"] = "started"
495         messages["Failed"] = "failed"
496
497         name = getName(e)
498         msg = ""
499         if name.startswith("Pkg"):
500                 msg += "package %s: " % data.getVar("P", e.data, 1)
501                 msg += messages.get(name[3:]) or name[3:]
502         elif name.startswith("Task"):
503                 msg += "package %s: task %s: " % (data.getVar("PF", e.data, 1), e.task)
504                 msg += messages.get(name[4:]) or name[4:]
505         elif name.startswith("Build"):
506                 msg += "build %s: " % e.name
507                 msg += messages.get(name[5:]) or name[5:]
508         elif name == "UnsatisfiedDep":
509                 msg += "package %s: dependency %s %s" % (e.pkg, e.dep, name[:-3].lower())
510         note(msg)
511
512         if name.startswith("BuildStarted"):
513                 bb.data.setVar( 'BB_VERSION', bb.__version__, e.data )
514                 path_to_bbfiles = bb.data.getVar( 'BBFILES', e.data, 1 )
515                 path_to_packages = path_to_bbfiles[:path_to_bbfiles.index( "packages" )]
516                 #monotone_revision = "<unknown>"
517                 #try:
518                 #       monotone_revision = file( "%s/MT/revision" % path_to_packages ).read().strip()
519                 #except IOError:
520                 #       pass
521                 #bb.data.setVar( 'OE_REVISION', monotone_revision, e.data )
522                 statusvars = ['BB_VERSION', 'OE_REVISION', 'TARGET_ARCH', 'TARGET_OS', 'MACHINE', 'DISTRO', 'TARGET_FPU']
523                 statuslines = ["%-13s = \"%s\"" % (i, bb.data.getVar(i, e.data, 1) or '') for i in statusvars]
524                 statusmsg = "\nOE Build Configuration:\n%s\n" % '\n'.join(statuslines)
525                 print statusmsg
526
527                 needed_vars = [ "TARGET_ARCH", "TARGET_OS" ]
528                 pesteruser = []
529                 for v in needed_vars:
530                         val = bb.data.getVar(v, e.data, 1)
531                         if not val or val == 'INVALID':
532                                 pesteruser.append(v)
533                 if pesteruser:
534                         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))
535
536         if not data in e.__dict__:
537                 return NotHandled
538
539         log = data.getVar("EVENTLOG", e.data, 1)
540         if log:
541                 logfile = file(log, "a")
542                 logfile.write("%s\n" % msg)
543                 logfile.close()
544
545         return NotHandled
546 }
547
548 addtask configure after do_unpack do_patch
549 do_configure[dirs] = "${S} ${B}"
550 do_configure[bbdepcmd] = "do_populate_staging"
551 base_do_configure() {
552         :
553 }
554
555 addtask compile after do_configure
556 do_compile[dirs] = "${S} ${B}"
557 do_compile[bbdepcmd] = "do_populate_staging"
558 base_do_compile() {
559         if [ -e Makefile -o -e makefile ]; then
560                 oe_runmake || die "make failed"
561         else
562                 oenote "nothing to compile"
563         fi
564 }
565
566
567 addtask stage after do_compile
568 base_do_stage () {
569         :
570 }
571
572 do_populate_staging[dirs] = "${STAGING_DIR}/${TARGET_SYS}/bin ${STAGING_DIR}/${TARGET_SYS}/lib \
573                              ${STAGING_DIR}/${TARGET_SYS}/include \
574                              ${STAGING_DIR}/${BUILD_SYS}/bin ${STAGING_DIR}/${BUILD_SYS}/lib \
575                              ${STAGING_DIR}/${BUILD_SYS}/include \
576                              ${STAGING_DATADIR} \
577                              ${S} ${B}"
578
579 addtask populate_staging after do_compile
580
581 #python do_populate_staging () {
582 #       if not bb.data.getVar('manifest', d):
583 #               bb.build.exec_func('do_emit_manifest', d)
584 #       if bb.data.getVar('do_stage', d):
585 #               bb.build.exec_func('do_stage', d)
586 #       else:
587 #               bb.build.exec_func('manifest_do_populate_staging', d)
588 #}
589
590 python do_populate_staging () {
591         if bb.data.getVar('manifest_do_populate_staging', d):
592                 bb.build.exec_func('manifest_do_populate_staging', d)
593         else:
594                 bb.build.exec_func('do_stage', d)
595 }
596
597 #addtask install
598 addtask install after do_compile
599 do_install[dirs] = "${S} ${B}"
600
601 base_do_install() {
602         :
603 }
604
605 #addtask populate_pkgs after do_compile
606 #python do_populate_pkgs () {
607 #       if not bb.data.getVar('manifest', d):
608 #               bb.build.exec_func('do_emit_manifest', d)
609 #       bb.build.exec_func('manifest_do_populate_pkgs', d)
610 #       bb.build.exec_func('package_do_shlibs', d)
611 #}
612
613 base_do_package() {
614         :
615 }
616
617 addtask build after do_populate_staging
618 do_build = ""
619 do_build[func] = "1"
620
621 # Functions that update metadata based on files outputted
622 # during the build process.
623
624 SHLIBS = ""
625 RDEPENDS_prepend = " ${SHLIBS}"
626
627 python read_manifest () {
628         import sys
629         mfn = bb.data.getVar("MANIFEST", d, 1)
630         if os.access(mfn, os.R_OK):
631                 # we have a manifest, so emit do_stage and do_populate_pkgs,
632                 # and stuff some additional bits of data into the metadata store
633                 mfile = file(mfn, "r")
634                 manifest = bb.manifest.parse(mfile, d)
635                 if not manifest:
636                         return
637
638                 bb.data.setVar('manifest', manifest, d)
639 }
640
641 python parse_manifest () {
642                 manifest = bb.data.getVar("manifest", d)
643                 if not manifest:
644                         return
645                 for func in ("do_populate_staging", "do_populate_pkgs"):
646                         value = bb.manifest.emit(func, manifest, d)
647                         if value:
648                                 bb.data.setVar("manifest_" + func, value, d)
649                                 bb.data.delVarFlag("manifest_" + func, "python", d)
650                                 bb.data.delVarFlag("manifest_" + func, "fakeroot", d)
651                                 bb.data.setVarFlag("manifest_" + func, "func", 1, d)
652                 packages = []
653                 for l in manifest:
654                         if "pkg" in l and l["pkg"] is not None:
655                                 packages.append(l["pkg"])
656                 bb.data.setVar("PACKAGES", " ".join(packages), d)
657 }
658
659 def explode_deps(s):
660         r = []
661         l = s.split()
662         flag = False
663         for i in l:
664                 if i[0] == '(':
665                         flag = True
666                         j = []
667                 if flag:
668                         j.append(i)
669                         if i.endswith(')'):
670                                 flag = False
671                                 r[-1] += ' ' + ' '.join(j)
672                 else:
673                         r.append(i)
674         return r
675
676 python read_shlibdeps () {
677         packages = (bb.data.getVar('PACKAGES', d, 1) or "").split()
678         for pkg in packages:
679                 rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 0) or bb.data.getVar('RDEPENDS', d, 0) or "")
680                 shlibsfile = bb.data.expand("${WORKDIR}/install/" + pkg + ".shlibdeps", d)
681                 if os.access(shlibsfile, os.R_OK):
682                         fd = file(shlibsfile)
683                         lines = fd.readlines()
684                         fd.close()
685                         for l in lines:
686                                 rdepends.append(l.rstrip())
687                 pcfile = bb.data.expand("${WORKDIR}/install/" + pkg + ".pcdeps", d)
688                 if os.access(pcfile, os.R_OK):
689                         fd = file(pcfile)
690                         lines = fd.readlines()
691                         fd.close()
692                         for l in lines:
693                                 rdepends.append(l.rstrip())
694                 bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d)
695 }
696
697 python read_subpackage_metadata () {
698         import re
699
700         def decode(str):
701                 import codecs
702                 c = codecs.getdecoder("string_escape")
703                 return c(str)[0]
704
705         data_file = bb.data.expand("${WORKDIR}/install/${PN}.package", d)
706         if os.access(data_file, os.R_OK):
707                 f = file(data_file, 'r')
708                 lines = f.readlines()
709                 f.close()
710                 r = re.compile("([^:]+):\s*(.*)")
711                 for l in lines:
712                         m = r.match(l)
713                         if m:
714                                 bb.data.setVar(m.group(1), decode(m.group(2)), d)
715 }
716
717 python __anonymous () {
718         import exceptions
719         need_host = bb.data.getVar('COMPATIBLE_HOST', d, 1)
720         if need_host:
721                 import re
722                 this_host = bb.data.getVar('HOST_SYS', d, 1)
723                 if not re.match(need_host, this_host):
724                         raise bb.parse.SkipPackage("incompatible with host %s" % this_host)
725         
726         pn = bb.data.getVar('PN', d, 1)
727
728         cvsdate = bb.data.getVar('CVSDATE_%s' % pn, d, 1)
729         if cvsdate != None:
730                 bb.data.setVar('CVSDATE', cvsdate, d)
731
732         use_nls = bb.data.getVar('USE_NLS_%s' % pn, d, 1)
733         if use_nls != None:
734                 bb.data.setVar('USE_NLS', use_nls, d)
735
736         try:
737                 bb.build.exec_func('read_manifest', d)
738                 bb.build.exec_func('parse_manifest', d)
739         except exceptions.KeyboardInterrupt:
740                 raise
741         except Exception, e:
742                 bb.error("anonymous function: %s" % e)
743                 pass
744 }
745
746 python () {
747         import bb, os
748         mach_arch = bb.data.getVar('MACHINE_ARCH', d, 1)
749         old_arch = bb.data.getVar('PACKAGE_ARCH', d, 1)
750         if (old_arch == mach_arch):
751                 # Nothing to do
752                 return
753         if (bb.data.getVar('SRC_URI_OVERRIDES_PACKAGE_ARCH', d, 1) == '0'):
754                 return
755         paths = []
756         for p in [ "${FILE_DIRNAME}/${PF}", "${FILE_DIRNAME}/${P}", "${FILE_DIRNAME}/${PN}", "${FILE_DIRNAME}/files", "${FILE_DIRNAME}" ]:
757                 paths.append(bb.data.expand(os.path.join(p, mach_arch), d))
758         for s in bb.data.getVar('SRC_URI', d, 1).split():
759                 local = bb.data.expand(bb.fetch.localpath(s, d), d)
760                 for mp in paths:
761                         if local.startswith(mp):
762 #                               bb.note("overriding PACKAGE_ARCH from %s to %s" % (old_arch, mach_arch))
763                                 bb.data.setVar('PACKAGE_ARCH', mach_arch, d)
764                                 return
765 }
766
767
768 addtask emit_manifest
769 python do_emit_manifest () {
770 #       FIXME: emit a manifest here
771 #       1) adjust PATH to hit the wrapper scripts
772         wrappers = bb.which(bb.data.getVar("BBPATH", d, 1), 'build/install', 0)
773         path = (bb.data.getVar('PATH', d, 1) or '').split(':')
774         path.insert(0, os.path.dirname(wrappers))
775         bb.data.setVar('PATH', ':'.join(path), d)
776 #       2) exec_func("do_install", d)
777         bb.build.exec_func('do_install', d)
778 #       3) read in data collected by the wrappers
779         bb.build.exec_func('read_manifest', d)
780 #       4) mangle the manifest we just generated, get paths back into
781 #          our variable form
782 #       5) write it back out
783 #       6) re-parse it to ensure the generated functions are proper
784         bb.build.exec_func('parse_manifest', d)
785 }
786
787 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
788
789 MIRRORS[func] = "0"
790 MIRRORS () {
791 ${DEBIAN_MIRROR}/main   http://snapshot.debian.net/archive/pool
792 ${DEBIAN_MIRROR}        ftp://ftp.de.debian.org/debian/pool
793 ${DEBIAN_MIRROR}        ftp://ftp.au.debian.org/debian/pool
794 ${DEBIAN_MIRROR}        ftp://ftp.cl.debian.org/debian/pool
795 ${DEBIAN_MIRROR}        ftp://ftp.hr.debian.org/debian/pool
796 ${DEBIAN_MIRROR}        ftp://ftp.fi.debian.org/debian/pool
797 ${DEBIAN_MIRROR}        ftp://ftp.hk.debian.org/debian/pool
798 ${DEBIAN_MIRROR}        ftp://ftp.hu.debian.org/debian/pool
799 ${DEBIAN_MIRROR}        ftp://ftp.ie.debian.org/debian/pool
800 ${DEBIAN_MIRROR}        ftp://ftp.it.debian.org/debian/pool
801 ${DEBIAN_MIRROR}        ftp://ftp.jp.debian.org/debian/pool
802 ${DEBIAN_MIRROR}        ftp://ftp.no.debian.org/debian/pool
803 ${DEBIAN_MIRROR}        ftp://ftp.pl.debian.org/debian/pool
804 ${DEBIAN_MIRROR}        ftp://ftp.ro.debian.org/debian/pool
805 ${DEBIAN_MIRROR}        ftp://ftp.si.debian.org/debian/pool
806 ${DEBIAN_MIRROR}        ftp://ftp.es.debian.org/debian/pool
807 ${DEBIAN_MIRROR}        ftp://ftp.se.debian.org/debian/pool
808 ${DEBIAN_MIRROR}        ftp://ftp.tr.debian.org/debian/pool
809 ${GNU_MIRROR}   ftp://mirrors.kernel.org/gnu
810 ${GNU_MIRROR}   ftp://ftp.matrix.com.br/pub/gnu
811 ${GNU_MIRROR}   ftp://ftp.cs.ubc.ca/mirror2/gnu
812 ${GNU_MIRROR}   ftp://sunsite.ust.hk/pub/gnu
813 ${GNU_MIRROR}   ftp://ftp.ayamura.org/pub/gnu
814 ftp://ftp.kernel.org/pub        http://www.kernel.org/pub
815 ftp://ftp.kernel.org/pub        ftp://ftp.us.kernel.org/pub
816 ftp://ftp.kernel.org/pub        ftp://ftp.uk.kernel.org/pub
817 ftp://ftp.kernel.org/pub        ftp://ftp.hk.kernel.org/pub
818 ftp://ftp.kernel.org/pub        ftp://ftp.au.kernel.org/pub
819 ftp://ftp.kernel.org/pub        ftp://ftp.jp.kernel.org/pub
820 ftp://.*/.*/    http://www.oesources.org/source/current/
821 http://.*/.*/   http://www.oesources.org/source/current/
822 }
823