llvm-common: use do_install to do the stuff
[openembedded.git] / classes / staging.bbclass
blobe80644961c765600c534a93a7528a38f2b84f10d
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 -dp $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"
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         sysroot_stage_dir $src $dest
62 sysroot_stage_dirs() {
63         from="$1"
64         to="$2"
66         sysroot_stage_dir $from${includedir} $to${STAGING_INCDIR}
67         if [ "${BUILD_SYS}" = "${HOST_SYS}" ]; then
68                 sysroot_stage_dir $from${bindir} $to${STAGING_DIR_HOST}${bindir}
69                 sysroot_stage_dir $from${sbindir} $to${STAGING_DIR_HOST}${sbindir}
70                 sysroot_stage_dir $from${base_bindir} $to${STAGING_DIR_HOST}${base_bindir}
71                 sysroot_stage_dir $from${base_sbindir} $to${STAGING_DIR_HOST}${base_sbindir}
72                 sysroot_stage_dir $from${libexecdir} $to${STAGING_DIR_HOST}${libexecdir}
73                 sysroot_stage_dir $from${sysconfdir} $to${STAGING_DIR_HOST}${sysconfdir}
74                 if [ "${prefix}/lib" != "${libdir}" ]; then
75                         # python puts its files in here, make sure they are staged as well
76                         autotools_stage_dir $from/${prefix}/lib $to${STAGING_DIR_HOST}${prefix}/lib
77                 fi
78         fi
79         if [ -d $from${libdir} ]
80         then
81                 sysroot_stage_libdir $from/${libdir} $to${STAGING_LIBDIR}
82         fi
83         if [ -d $from${base_libdir} ]
84         then
85                 sysroot_stage_libdir $from${base_libdir} $to${STAGING_DIR_HOST}${base_libdir}
86         fi
87         sysroot_stage_dir $from${datadir} $to${STAGING_DATADIR}
88         sysroot_stage_dir $from${sysconfdir} $to${STAGING_ETCDIR}
91 sysroot_stage_all() {
92         sysroot_stage_dirs ${D} ${SYSROOT_DESTDIR}
95 def is_legacy_staging(d):
96     stagefunc = bb.data.getVar('do_stage', d, True)
97     legacy = True
98     if stagefunc is None:
99         legacy = False
100     elif stagefunc.strip() == "use_do_install_for_stage":
101         legacy = False
102     elif stagefunc.strip() == "autotools_stage_all":
103         legacy = False
104     elif stagefunc.strip() == "do_stage_native" and bb.data.getVar('AUTOTOOLS_NATIVE_STAGE_INSTALL', d, 1) == "1":
105         legacy = False
106     elif bb.data.getVar('NATIVE_INSTALL_WORKS', d, 1) == "1":
107         legacy = False
108     if bb.data.getVar('PSTAGE_BROKEN_DESTDIR', d, 1) == "1":
109         legacy = True
110     if bb.data.getVar('FORCE_LEGACY_STAGING', d, 1) == "1":
111         legacy = True
112     return legacy
114 do_populate_sysroot[dirs] = "${STAGING_DIR_TARGET}/${bindir} ${STAGING_DIR_TARGET}/${libdir} \
115                              ${STAGING_DIR_TARGET}/${includedir} \
116                              ${STAGING_BINDIR_NATIVE} ${STAGING_LIBDIR_NATIVE} \
117                              ${STAGING_INCDIR_NATIVE} \
118                              ${STAGING_DATADIR} \
119                              ${S} ${B}"
121 # Could be compile but populate_sysroot and do_install shouldn't run at the same time
122 addtask populate_sysroot after do_install
124 SYSROOT_PREPROCESS_FUNCS ?= ""
125 SYSROOT_DESTDIR = "${WORKDIR}/sysroot-destdir/"
126 SYSROOT_LOCK = "${STAGING_DIR}/staging.lock"
129 python do_populate_sysroot () {
130     #
131     # if do_stage exists, we're legacy. In that case run the do_stage,
132     # modify the SYSROOT_DESTDIR variable and then run the staging preprocess
133     # functions against staging directly.
134     #
135     # Otherwise setup a destdir, copy the results from do_install
136     # and run the staging preprocess against that
137     #
138     pstageactive = (bb.data.getVar("PSTAGING_ACTIVE", d, True) == "1")
139     lockfile = bb.data.getVar("SYSROOT_LOCK", d, True)
140     stagefunc = bb.data.getVar('do_stage', d, True)
141     legacy = is_legacy_staging(d)
142     if legacy:
143         bb.data.setVar("SYSROOT_DESTDIR", "", d)
144         bb.note("Legacy staging mode for %s" % bb.data.getVar("FILE", d, True))
146         try:
147             file = open("%s/legacy-staging.log" % bb.data.getVar("TMPDIR", d, 1), "a")
148             file.write("%s\n" % bb.data.getVar("FILE", d, True))
149             file.close()
150         except:
151             pass
153         if bb.data.getVarFlags('do_stage', d) is None:
154             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))
155         lock = bb.utils.lockfile(lockfile)
156         bb.build.exec_func('populate_sysroot_prehook', d)
157         bb.build.exec_func('do_stage', d)
158         for f in (bb.data.getVar('SYSROOT_PREPROCESS_FUNCS', d, True) or '').split():
159             bb.build.exec_func(f, d)
160         bb.build.exec_func('populate_sysroot_posthook', d)
161         bb.utils.unlockfile(lock)
162     else:
163         dest = bb.data.getVar('D', d, True)
164         sysrootdest = bb.data.expand('${SYSROOT_DESTDIR}${STAGING_DIR_TARGET}', d)
165         bb.mkdirhier(sysrootdest)
167         bb.build.exec_func("sysroot_stage_all", d)
168         #os.system('cp -pPR %s/* %s/' % (dest, sysrootdest))
169         for f in (bb.data.getVar('SYSROOT_PREPROCESS_FUNCS', d, True) or '').split():
170             bb.build.exec_func(f, d)
171         bb.build.exec_func("packagedstaging_fastpath", d)
173         lock = bb.utils.lockfile(lockfile)
174         os.system(bb.data.expand('cp -pPR ${SYSROOT_DESTDIR}${TMPDIR}/* ${TMPDIR}/', d))
175         bb.utils.unlockfile(lock)
178 python () {
179     if is_legacy_staging(d):
180         bb.debug(1, "Legacy staging mode for %s" % bb.data.getVar("FILE", d, True))
181         if bb.data.getVarFlags('do_stage', d) is None:
182             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))