Initial commit
[toolchains/rpm-libs-x86.git] / packaging / rpm-libs-x86.spec
1 %define __strip /bin/true
2 %define _build_name_fmt    %%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.dontuse.rpm
3 # meta spec file for cross-chroot setup 
4 #
5 # Copyright (c) 2010  Jan-Simon Möller (jsmoeller@linuxfoundation.org)
6 # License: GPLv2
7
8 ## README
9 ##
10 ## In this file:
11 ## 1) define name of original package (see oldname)
12 ## 
13 ## File binaries_to_prepare:
14 ## 2) fill in the binaries which need to be available to the foreign chroot
15 ##    e.g. /bin/bash   -  this will make a i586 bash available
16 ##
17
18 #\/\/\/\/\/\/\/\/\/\/
19 ### only changes here
20 #
21 # The original package name
22 %define oldname rpm-libs
23 #
24 # The architectures this meta package is built on
25 %define myexclusive i586
26 #
27 ### no changes needed below this line
28 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29
30
31
32 ### no changes needed
33 #
34 # The new package name - convention is %oldname-x86
35 %define newname %{oldname}-x86
36 #
37 # The version of the original package is read from its rpm db info
38 %{expand:%%define newversion %(rpm -q --qf '[%{version}]' %oldname)}
39 #
40 # The license of the original package is read from its rpm db info
41 %{expand:%%define newlicense %(rpm -q --qf '[%{license}]' %oldname)}
42 #
43 # The group information of the original package
44 %{expand:%%define newgroup %(rpm -q --qf '[%{group}]' %oldname)}
45 #
46 # The summary of the original package
47 %{expand:%%define newsummary %(rpm -q --qf '[%{summary} - special version ]' %oldname)}
48 #
49 # New rpath to add to files on request
50 %define newrpath "/emul/ia32-linux/lib:/emul/ia32-linux/usr/lib"
51 %define newinterpreter /emul/ia32-linux/lib/ld-linux.so.2
52 #
53 # Some automatic checks for availability
54 # binaries_to_prepare
55 %define binaries_to_prepare %{expand:%(test -e %{_sourcedir}/binaries_to_prepare && echo 1 || echo 0)}
56 %define libraries_to_prepare %{expand:%(test -e %{_sourcedir}/libraries_to_prepare && echo 1 || echo 0)}
57 %define special_script %{expand:%(test -e %{_sourcedir}/special_script && echo 1 || echo 0)}
58 %define files_to_ignore %{expand:%(test -e %{_sourcedir}/files_to_ignore && echo 1 || echo 0)}
59 #
60 ### no changes needed below this line
61 %define nodebug 1
62
63
64 Name:          %newname
65 Version:       %newversion
66 Release:       7
67 AutoReqProv:   0
68 Provides:      %newname
69 BuildRequires: rpm grep tar patchelf sed -rpmlint-Moblin -rpmlint-mini -post-build-checks
70 BuildRequires: %oldname
71 Requires:      %oldname
72 # no auto requirements - they're generated
73 License:       %newlicense
74 Group:         %newgroup
75 ExclusiveArch: %myexclusive
76 Summary:       Don't use! %newsummary
77 BuildRoot:     %{_tmppath}/%{name}-%{version}-build
78 %if %binaries_to_prepare
79 Source10:      binaries_to_prepare
80 %endif
81 %if %libraries_to_prepare
82 Source20:      libraries_to_prepare
83 %endif
84 %if %special_script
85 Source30:      special_script
86 %endif
87 %if %files_to_ignore
88 Source40:      files_to_ignore
89 %endif
90 Source100:     baselibs.conf
91
92 %description
93 This is a meta-package providing %name.
94 It is not intended to be used on a normal system/device!
95 Original description:
96 %{expand:%(rpm -q --qf '[%{description}]' %oldname)}
97
98
99
100 %prep
101
102 %build
103
104 %install
105 %if %nodebug
106 set +x
107 %endif
108 mkdir -p %buildroot
109 rpm -ql %oldname > filestoinclude1
110
111 # ignore files - construct sed script
112 sedtmp="sedtmp.$$"
113 echo "s#^%{_docdir}.*##" >> $sedtmp
114 echo "s#^%{_mandir}.*##" >> $sedtmp
115 echo "s#^%{_infodir}.*##" >> $sedtmp
116
117 # evaluate files_to_ignore
118 %if %files_to_ignore
119 for i in `cat %{_sourcedir}/files_to_ignore`; do
120  echo "Ignoring file: $i"
121  echo "s#^${i}.*##" >> $sedtmp
122 done
123 %endif
124
125 # ignore default filesystem files
126 for i in `rpm -ql filesystem`; do
127   echo "s#^${i}\$##" >> $sedtmp
128 done
129
130 #finish up
131 echo "/^\$/d" >> $sedtmp
132
133 #execute
134 sed -f $sedtmp -i filestoinclude1
135
136 # tar copy to buildroot
137 tar -T filestoinclude1 -cpf - | ( cd %buildroot && tar -xpf - )
138 rm filestoinclude1
139
140 # Todo: refractor
141 # no directories, in filelist
142 find %buildroot >  filestoinclude2
143 cat filestoinclude2 | sed -e "s#%{buildroot}##g" | uniq | sort > filestoinclude1
144 for i in `cat filestoinclude1`; do
145 # no directories
146   if ! test -d %buildroot/$i ; then
147     # 
148     echo "$i" >> filestoinclude
149   fi
150 done
151 rm filestoinclude1
152 rm filestoinclude2
153
154 # patchelf the binaries
155 %if %binaries_to_prepare
156 echo ""
157 echo "[ .oO Preparing binaries Oo. ]"
158 echo ""
159 mkdir %buildroot/%{_prefix}/share/applybinary/
160 for binary in `cat %{_sourcedir}/binaries_to_prepare` ; do
161   echo "Processing binary: $binary"
162   tmp="tmp.$$"
163 %if %nodebug
164   debug=
165 %else
166   debug="--debug"
167 %endif
168   ldd $binary  | grep -v "ld-linux" | grep -v "linux-gate" |  sed -e "s#=.*##g" -e "s#^\t*##g"  > $tmp
169   deps=$(for i in `cat $tmp` ; do rpm -q --whatprovides "$i" | grep -v "no package"; done)
170   cleandeps=$(echo "$cleandeps" "$deps" | sort | uniq | sed -e "s/-[0-9].*//g")
171   patchelf $debug --set-rpath %newrpath %buildroot/$binary
172   patchelf $debug --set-interpreter %newinterpreter %buildroot/$binary
173   patchelf $debug --set-rpath %newrpath %buildroot/$binary
174   patchelf $debug --set-interpreter %newinterpreter %buildroot/$binary
175   if test -n "$debug"; then
176     patchelf --print-rpath %buildroot/$binary
177     patchelf --print-interpreter %buildroot/$binary
178   fi
179   echo "$binary" >> %buildroot/%{_prefix}/share/applybinary/%name
180   echo ""
181 done
182 %endif
183
184 # stub
185 %if %libraries_to_prepare
186 echo ""
187 echo "[ .oO Preparing libraries Oo. ]"
188 echo ""
189 %endif
190
191 # stub
192 %if %special_script
193 echo ""
194 echo "[ .oO Executing special script Oo. ]"
195 echo ""
196 %endif
197
198 # lets start the shellquote nightmare ;)
199 shellquote()
200 {
201     for arg; do
202         arg=${arg//\\/\\\\}
203 #        arg=${arg//\$/\$}   # already needs quoting ;(
204 #        arg=${arg/\"/\\\"}  # dito
205 #        arg=${arg//\`/\`}   # dito
206         arg=${arg//\\|/\|}
207         arg=${arg//\\|/|}
208         echo "$arg"
209     done
210 }
211
212
213 echo "Creating baselibs_new.conf"
214 echo ""
215 rm -rRf /tmp/baselibs_new.conf || true
216
217 shellquote "%{name}" >> /tmp/baselibs_new.conf
218 shellquote "  targettype x86 block!" >> /tmp/baselibs_new.conf
219 shellquote "  targettype 32bit block!" >> /tmp/baselibs_new.conf
220 shellquote "  targettype arm autoreqprov off" >> /tmp/baselibs_new.conf
221
222 # automagically fill in basic requirements
223 for i in $cleandeps ; do 
224   shellquote "  targettype arm requires \"${i}-x86-arm\"" >> /tmp/baselibs_new.conf
225 done
226
227 # we require the native version
228 shellquote "  targettype arm requires \"%{oldname}\" " >> /tmp/baselibs_new.conf
229 shellquote "  targettype arm prefix /emul/ia32-linux" >> /tmp/baselibs_new.conf
230 shellquote "  targettype arm extension -arm" >> /tmp/baselibs_new.conf
231 shellquote "  targettype arm +/" >> /tmp/baselibs_new.conf
232
233 # safe space and download time
234 shellquote "  targettype arm -/%{_mandir}" >> /tmp/baselibs_new.conf
235 shellquote "  targettype arm -/%{_docdir}" >> /tmp/baselibs_new.conf
236 shellquote "  targettype arm requires \"tizen-accelerator\"" >> /tmp/baselibs_new.conf
237
238 # replace native with x86 binaries as defined in file
239 %if %binaries_to_prepare
240 # Todo: error handling if .orig-arm is present
241 for binary in `cat %{_sourcedir}/binaries_to_prepare` ; do
242    shellquote "  targettype arm post \"  if test -e ${binary}.orig-arm; then \" " >> /tmp/baselibs_new.conf
243    shellquote "  targettype arm post \"    echo \"${binary}.orig-arm already present - skipping.\" \" " >> /tmp/baselibs_new.conf
244    shellquote "  targettype arm post \"  else \" " >> /tmp/baselibs_new.conf
245    shellquote "  targettype arm post \"    mv ${binary} ${binary}.orig-arm ; ln -s <prefix>${binary} ${binary} \"" >> /tmp/baselibs_new.conf
246    shellquote "  targettype arm post \"  fi \" " >> /tmp/baselibs_new.conf
247 done
248
249 shellquote " " >> /tmp/baselibs_new.conf
250 for binary in `cat %{_sourcedir}/binaries_to_prepare` ; do
251
252   shellquote "  targettype arm preun \"  if test -e ${binary}.orig-arm ; then \"" >> /tmp/baselibs_new.conf
253   shellquote "  targettype arm preun \"    rm -f ${binary} ; mv ${binary}.orig-arm ${binary}\"" >> /tmp/baselibs_new.conf
254   shellquote "  targettype arm preun \"  fi \"" >> /tmp/baselibs_new.conf
255
256 done
257 %endif
258
259 cat /tmp/baselibs_new.conf >> %{_sourcedir}/baselibs.conf
260
261 echo "################################################################################"
262 echo ""
263 echo ""
264 echo "REQUIREMENTS:"
265 grep "requires" %{_sourcedir}/baselibs.conf | sort | uniq | sed -e "s#  targettype.*requires ##g" | while read k ; do
266  echo "CBinstall: $k"
267 done
268 echo "Runscripts: %{newname}-arm"
269 echo ""
270 echo ""
271 echo "################################################################################"
272 set -x
273
274 %clean
275 rm -rf $RPM_BUILD_ROOT
276
277 %files -f filestoinclude
278 %defattr(-,root,root)
279 %if %binaries_to_prepare
280 /%{_prefix}/share/applybinary/%name
281 %endif