sg3-utils: add newer buildable version
[openembedded.git] / classes / staging.bbclass
1 python populate_staging_prehook () {
2        return
3 }
4
5 python populate_staging_posthook () {
6        return
7 }
8
9 packagedstaging_fastpath () {
10        :
11 }
12
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)
19
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
28 }
29
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
39 }
40
41 sysroot_stage_libdir() {
42         src="$1"
43         dest="$2"
44
45         olddir=`pwd`
46         cd $src
47         las=$(find . -name \*.la -type f)
48         cd $olddir
49         echo "Found la files: $las"              
50         for i in $las
51         do
52                 sed -e 's/^installed=yes$/installed=no/' \
53                     -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*\),${STAGING_LIBDIR}/\1,g' \
54                     -e "/^dependency_libs=/s,\([[:space:]']\)${libdir},\1${STAGING_LIBDIR},g" \
55                     -i $src/$i
56         done
57         sysroot_stage_dir $src $dest
58 }
59
60 sysroot_stage_dirs() {
61         from="$1"
62         to="$2"
63
64         sysroot_stage_dir $from${includedir} $to${STAGING_INCDIR}
65         if [ "${BUILD_SYS}" = "${HOST_SYS}" ]; then
66                 sysroot_stage_dir $from${bindir} $to${STAGING_DIR_HOST}${bindir}
67                 sysroot_stage_dir $from${sbindir} $to${STAGING_DIR_HOST}${sbindir}
68                 sysroot_stage_dir $from${base_bindir} $to${STAGING_DIR_HOST}${base_bindir}
69                 sysroot_stage_dir $from${base_sbindir} $to${STAGING_DIR_HOST}${base_sbindir}
70                 sysroot_stage_dir $from${libexecdir} $to${STAGING_DIR_HOST}${libexecdir}
71                 if [ "${prefix}/lib" != "${libdir}" ]; then
72                         # python puts its files in here, make sure they are staged as well
73                         autotools_stage_dir $from/${prefix}/lib $to${STAGING_DIR_HOST}${prefix}/lib
74                 fi
75         fi
76         if [ -d $from${libdir} ]
77         then
78                 sysroot_stage_libdir $from/${libdir} $to${STAGING_LIBDIR}
79         fi
80         if [ -d $from${base_libdir} ]
81         then
82                 sysroot_stage_libdir $from${base_libdir} $to${STAGING_DIR_HOST}${base_libdir}
83         fi
84         sysroot_stage_dir $from${datadir} $to${STAGING_DATADIR}
85         sysroot_stage_dir $from${sysconfdir} $to${STAGING_ETCDIR}
86 }
87
88 sysroot_stage_all() {
89         sysroot_stage_dirs ${D} ${SYSROOT_DESTDIR}
90 }
91
92 def is_legacy_staging(d):
93     stagefunc = bb.data.getVar('do_stage', d, True)
94     legacy = True
95     if stagefunc is None:
96         legacy = False
97     elif stagefunc.strip() == "autotools_stage_all":
98         legacy = False
99     elif stagefunc.strip() == "do_stage_native" and bb.data.getVar('AUTOTOOLS_NATIVE_STAGE_INSTALL', d, 1) == "1":
100         legacy = False
101     elif bb.data.getVar('NATIVE_INSTALL_WORKS', d, 1) == "1":
102         legacy = False
103     if bb.data.getVar('PSTAGE_BROKEN_DESTDIR', d, 1) == "1":
104         legacy = True
105     if bb.data.getVar('FORCE_LEGACY_STAGING', d, 1) == "1":
106         legacy = True
107     return legacy
108
109 do_populate_staging[dirs] = "${STAGING_DIR_TARGET}/${bindir} ${STAGING_DIR_TARGET}/${libdir} \
110                              ${STAGING_DIR_TARGET}/${includedir} \
111                              ${STAGING_BINDIR_NATIVE} ${STAGING_LIBDIR_NATIVE} \
112                              ${STAGING_INCDIR_NATIVE} \
113                              ${STAGING_DATADIR} \
114                              ${S} ${B}"
115
116 # Could be compile but populate_staging and do_install shouldn't run at the same time
117 addtask populate_staging after do_install before do_build
118
119 SYSROOT_PREPROCESS_FUNCS ?= ""
120 SYSROOT_DESTDIR = "${WORKDIR}/sysroot-destdir/"
121 SYSROOT_LOCK = "${STAGING_DIR}/staging.lock"
122
123 python do_populate_staging () {
124     #
125     # if do_stage exists, we're legacy. In that case run the do_stage,
126     # modify the SYSROOT_DESTDIR variable and then run the staging preprocess
127     # functions against staging directly.
128     #
129     # Otherwise setup a destdir, copy the results from do_install
130     # and run the staging preprocess against that
131     #
132     pstageactive = (bb.data.getVar("PSTAGING_ACTIVE", d, True) == "1")
133     lockfile = bb.data.getVar("SYSROOT_LOCK", d, True)
134     stagefunc = bb.data.getVar('do_stage', d, True)
135     legacy = is_legacy_staging(d)
136     if legacy:
137         bb.data.setVar("SYSROOT_DESTDIR", "", d)
138         bb.note("Legacy staging mode for %s" % bb.data.getVar("FILE", d, True))
139
140         try:
141             file = open("%s/legacy-staging.log" % bb.data.getVar("TMPDIR", d, 1), "a")
142             file.write("%s\n" % bb.data.getVar("FILE", d, True))
143             file.close()
144         except:
145             pass
146
147         if bb.data.getVarFlags('do_stage', d) is None:
148             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))
149         lock = bb.utils.lockfile(lockfile)
150         bb.build.exec_func('populate_staging_prehook', d)
151         bb.build.exec_func('do_stage', d)
152         for f in (bb.data.getVar('SYSROOT_PREPROCESS_FUNCS', d, True) or '').split():
153             bb.build.exec_func(f, d)
154         bb.build.exec_func('populate_staging_posthook', d)
155         bb.utils.unlockfile(lock)
156     else:
157         dest = bb.data.getVar('D', d, True)
158         sysrootdest = bb.data.expand('${SYSROOT_DESTDIR}${STAGING_DIR_TARGET}', d)
159         bb.mkdirhier(sysrootdest)
160
161         bb.build.exec_func("sysroot_stage_all", d)
162         #os.system('cp -pPR %s/* %s/' % (dest, sysrootdest))
163         for f in (bb.data.getVar('SYSROOT_PREPROCESS_FUNCS', d, True) or '').split():
164             bb.build.exec_func(f, d)
165         bb.build.exec_func("packagedstaging_fastpath", d)
166
167         lock = bb.utils.lockfile(lockfile)
168         os.system(bb.data.expand('cp -pPR ${SYSROOT_DESTDIR}${TMPDIR}/* ${TMPDIR}/', d))
169         bb.utils.unlockfile(lock)
170 }
171
172 python () {
173     if is_legacy_staging(d):
174         bb.debug(1, "Legacy staging mode for %s" % bb.data.getVar("FILE", d, True))
175         if bb.data.getVarFlags('do_stage', d) is None:
176             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))
177 }