angstrom: prefer the git version of tslib
[openembedded.git] / classes / staging.bbclass
blob3e7adbb995dc61a063dc799ee032818085e026d6
1 python populate_sysroot_prehook () {
2         return
5 python populate_sysroot_posthook () {
6         return
9 packagedstaging_fastpath () {
10        :
13 def package_stagefile(file, d):
14     if bb.data.getVar('PSTAGING_ACTIVE', d, True) == "1":
15         destfile = file.replace(bb.data.getVar("TMPDIR", d, 1), bb.data.getVar("PSTAGE_TMPDIR_STAGE", d, 1))
16         bb.mkdirhier(os.path.dirname(destfile))
17         #print "%s to %s" % (file, destfile)
18         bb.copyfile(file, destfile)
20 package_stagefile_shell() {
21         if [ "$PSTAGING_ACTIVE" = "1" ]; then
22                 srcfile=$1
23                 destfile=`echo $srcfile | sed s#${TMPDIR}#${PSTAGE_TMPDIR_STAGE}#`
24                 destdir=`dirname $destfile`
25                 mkdir -p $destdir
26                 cp -Pp $srcfile $destfile
27         fi
30 sysroot_stage_dir() {
31         src="$1"
32         dest="$2"
33         # This will remove empty directories so we can ignore them
34         rmdir "$src" 2> /dev/null || true
35         if [ -d "$src" ]; then
36                 mkdir -p "$dest"
37                 cp -fpPR "$src"/* "$dest"
38         fi
41 SYSROOTEXTRALIBDIRSED ?= ""
42 sysroot_stage_libdir() {
43         src="$1"
44         dest="$2"
45         if [ "${LIBTOOL_HAS_SYSROOT}" = "no" ]; then
46             olddir=`pwd`
47             cd $src
48             las=$(find . -name \*.la -type f)
49             cd $olddir
50             echo "Found la files: $las" 
51             for i in $las
52             do
53                 sed -e 's/^installed=yes$/installed=no/' \
54                     -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*\),${STAGING_LIBDIR}/\1,g' \
55                     -e "/^dependency_libs=/s,\([[:space:]']\)${libdir},\1${STAGING_LIBDIR},g" \
56                     ${SYSROOTEXTRALIBDIRSED} \
57                     -i $src/$i
58             done
59         fi
60         sysroot_stage_dir $src $dest
63 sysroot_stage_dirs() {
64         from="$1"
65         to="$2"
67         sysroot_stage_dir $from${includedir} $to${STAGING_INCDIR}
68         if [ "${BUILD_SYS}" = "${HOST_SYS}" ]; then
69                 sysroot_stage_dir $from${bindir} $to${STAGING_DIR_HOST}${bindir}
70                 sysroot_stage_dir $from${sbindir} $to${STAGING_DIR_HOST}${sbindir}
71                 sysroot_stage_dir $from${base_bindir} $to${STAGING_DIR_HOST}${base_bindir}
72                 sysroot_stage_dir $from${base_sbindir} $to${STAGING_DIR_HOST}${base_sbindir}
73                 sysroot_stage_dir $from${libexecdir} $to${STAGING_DIR_HOST}${libexecdir}
74                 sysroot_stage_dir $from${sysconfdir} $to${STAGING_DIR_HOST}${sysconfdir}
75                 if [ "${prefix}/lib" != "${libdir}" ]; then
76                         # python puts its files in here, make sure they are staged as well
77                         sysroot_stage_dir $from/${prefix}/lib $to${STAGING_DIR_HOST}${prefix}/lib
78                 fi
79         fi
80         if [ -d $from${libdir} ]
81         then
82                 sysroot_stage_libdir $from/${libdir} $to${STAGING_LIBDIR}
83         fi
84         if [ -d $from${base_libdir} ]
85         then
86                 sysroot_stage_libdir $from${base_libdir} $to${STAGING_DIR_HOST}${base_libdir}
87         fi
88         sysroot_stage_dir $from${datadir} $to${STAGING_DATADIR}
89         sysroot_stage_dir $from${sysconfdir} $to${STAGING_ETCDIR}
92 sysroot_stage_all() {
93         sysroot_stage_dirs ${D} ${SYSROOT_DESTDIR}
96 def is_legacy_staging(d):
97     stagefunc = bb.data.getVar('do_stage', d, True)
98     legacy = True
99     if stagefunc is None:
100         legacy = False
101     elif stagefunc.strip() == "use_do_install_for_stage":
102         legacy = False
103     elif stagefunc.strip() == "autotools_stage_all":
104         legacy = False
105     elif stagefunc.strip() == "do_stage_native" and bb.data.getVar('AUTOTOOLS_NATIVE_STAGE_INSTALL', d, 1) == "1":
106         legacy = False
107     elif bb.data.getVar('NATIVE_INSTALL_WORKS', d, 1) == "1":
108         legacy = False
109     if bb.data.getVar('PSTAGE_BROKEN_DESTDIR', d, 1) == "1":
110         legacy = True
111     if bb.data.getVar('FORCE_LEGACY_STAGING', d, 1) == "1":
112         legacy = True
113     return legacy
115 do_populate_sysroot[dirs] = "${STAGING_DIR_TARGET}/${bindir} ${STAGING_DIR_TARGET}/${libdir} \
116                              ${STAGING_DIR_TARGET}/${includedir} \
117                              ${STAGING_BINDIR_NATIVE} ${STAGING_LIBDIR_NATIVE} \
118                              ${STAGING_INCDIR_NATIVE} \
119                              ${STAGING_DATADIR} \
120                              ${S} ${B}"
122 # Could be compile but populate_sysroot and do_install shouldn't run at the same time
123 addtask populate_sysroot after do_install
125 SYSROOT_PREPROCESS_FUNCS ?= ""
126 SYSROOT_DESTDIR = "${WORKDIR}/sysroot-destdir/"
127 SYSROOT_LOCK = "${STAGING_DIR}/staging.lock"
130 python do_populate_sysroot () {
131     #
132     # if do_stage exists, we're legacy. In that case run the do_stage,
133     # modify the SYSROOT_DESTDIR variable and then run the staging preprocess
134     # functions against staging directly.
135     #
136     # Otherwise setup a destdir, copy the results from do_install
137     # and run the staging preprocess against that
138     #
139     pstageactive = (bb.data.getVar("PSTAGING_ACTIVE", d, True) == "1")
140     lockfile = bb.data.getVar("SYSROOT_LOCK", d, True)
141     stagefunc = bb.data.getVar('do_stage', d, True)
142     legacy = is_legacy_staging(d)
143     if legacy:
144         bb.data.setVar("SYSROOT_DESTDIR", "", d)
145         bb.note("Legacy staging mode for %s" % bb.data.getVar("FILE", d, True))
147         try:
148             file = open("%s/legacy-staging.log" % bb.data.getVar("TMPDIR", d, 1), "a")
149             file.write("%s\n" % bb.data.getVar("FILE", d, True))
150             file.close()
151         except:
152             pass
154         if bb.data.getVarFlags('do_stage', d) is None:
155             bb.fatal("This recipe (%s) has a do_stage_prepend or do_stage_append and do_stage now doesn't exist. Please rename this to do_stage()" % bb.data.getVar("FILE", d, True))
156         lock = bb.utils.lockfile(lockfile)
157         bb.build.exec_func('populate_sysroot_prehook', d)
158         bb.build.exec_func('do_stage', d)
159         for f in (bb.data.getVar('SYSROOT_PREPROCESS_FUNCS', d, True) or '').split():
160             bb.build.exec_func(f, d)
161         bb.build.exec_func('populate_sysroot_posthook', d)
162         bb.utils.unlockfile(lock)
163     else:
164         dest = bb.data.getVar('D', d, True)
165         sysrootdest = bb.data.expand('${SYSROOT_DESTDIR}${STAGING_DIR_TARGET}', d)
166         bb.mkdirhier(sysrootdest)
168         bb.build.exec_func("sysroot_stage_all", d)
169         #os.system('cp -pPR %s/* %s/' % (dest, sysrootdest))
170         for f in (bb.data.getVar('SYSROOT_PREPROCESS_FUNCS', d, True) or '').split():
171             bb.build.exec_func(f, d)
172         if pstageactive:
173             bb.build.exec_func("packagedstaging_fastpath", d)
175         lock = bb.utils.lockfile(lockfile)
176         os.system(bb.data.expand('cp -pPR ${SYSROOT_DESTDIR}${TMPDIR}/* ${TMPDIR}/', d))
177         bb.utils.unlockfile(lock)
180 python () {
181     if is_legacy_staging(d):
182         bb.debug(1, "Legacy staging mode for %s" % bb.data.getVar("FILE", d, True))
183         if bb.data.getVarFlags('do_stage', d) is None:
184             bb.error("This recipe (%s) has a do_stage_prepend or do_stage_append and do_stage now doesn't exist. Please rename this to do_stage()" % bb.data.getVar("FILE", d, True))