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