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