Tizen 2.0 Release
[toolchains/patch-x86.git] / packaging / patch-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 patch
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 __strip /bin/true
62 %define nodebug 1
63 %define _build_name_fmt    %%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.dontuse.rpm
64
65
66 Name:          %newname
67 Version:       %newversion
68 Release:       7
69 AutoReqProv:   0
70 Provides:      %newname
71 BuildRequires: rpm grep tar patchelf sed -rpmlint-Moblin -rpmlint-mini -post-build-checks
72 BuildRequires: %oldname
73 Requires:      %oldname
74 # no auto requirements - they're generated
75 License:       %newlicense
76 Group:         %newgroup
77 ExclusiveArch: %myexclusive
78 Summary:       Don't use! %newsummary
79 BuildRoot:     %{_tmppath}/%{name}-%{version}-build
80 %if %binaries_to_prepare
81 Source10:      binaries_to_prepare
82 %endif
83 %if %libraries_to_prepare
84 Source20:      libraries_to_prepare
85 %endif
86 %if %special_script
87 Source30:      special_script
88 %endif
89 %if %files_to_ignore
90 Source40:      files_to_ignore
91 %endif
92 Source100:     baselibs.conf
93
94 %description
95 This is a meta-package providing %name.
96 It is not intended to be used on a normal system/device!
97 Original description:
98 %{expand:%(rpm -q --qf '[%{description}]' %oldname)}
99
100
101
102 %prep
103
104 %build
105
106 %install
107 %if %nodebug
108 set +x
109 %endif
110 mkdir -p %buildroot
111 rpm -ql %oldname > filestoinclude1
112
113 # ignore files - construct sed script
114 sedtmp="sedtmp.$$"
115 echo "s#^%{_docdir}.*##" >> $sedtmp
116 echo "s#^%{_mandir}.*##" >> $sedtmp
117 echo "s#^%{_infodir}.*##" >> $sedtmp
118
119 # evaluate files_to_ignore
120 %if %files_to_ignore
121 for i in `cat %{_sourcedir}/files_to_ignore`; do
122  echo "Ignoring file: $i"
123  echo "s#^${i}.*##" >> $sedtmp
124 done
125 %endif
126
127 # ignore default filesystem files
128 for i in `rpm -ql filesystem`; do
129   echo "s#^${i}\$##" >> $sedtmp
130 done
131
132 #finish up
133 echo "/^\$/d" >> $sedtmp
134
135 #execute
136 sed -f $sedtmp -i filestoinclude1
137
138 # tar copy to buildroot
139 tar -T filestoinclude1 -cpf - | ( cd %buildroot && tar -xpf - )
140 rm filestoinclude1
141
142 # Todo: refractor
143 # no directories, in filelist
144 find %buildroot >  filestoinclude2
145 cat filestoinclude2 | sed -e "s#%{buildroot}##g" | uniq | sort > filestoinclude1
146 for i in `cat filestoinclude1`; do
147 # no directories
148   if ! test -d %buildroot/$i ; then
149     # 
150     echo "$i" >> filestoinclude
151   fi
152 done
153 rm filestoinclude1
154 rm filestoinclude2
155
156 # patchelf the binaries
157 %if %binaries_to_prepare
158 echo ""
159 echo "[ .oO Preparing binaries Oo. ]"
160 echo ""
161 mkdir -p %buildroot/%{_prefix}/share/applybinary/
162 for binary in `cat %{_sourcedir}/binaries_to_prepare` ; do
163   echo "Processing binary: $binary"
164   tmp="tmp.$$"
165 %if %nodebug
166   debug=
167 %else
168   debug="--debug"
169 %endif
170   ldd $binary  | grep -v "ld-linux" | grep -v "linux-gate" |  sed -e "s#=.*##g" -e "s#^\t*##g"  > $tmp
171   deps=$(for i in `cat $tmp` ; do rpm -q --whatprovides "$i" | grep -v "no package"; done)
172   cleandeps=$(echo "$cleandeps" "$deps" | sort | uniq | sed -e "s/-[0-9].*//g")
173   patchelf $debug --set-rpath %newrpath %buildroot/$binary
174   patchelf $debug --set-interpreter %newinterpreter %buildroot/$binary
175   patchelf $debug --set-rpath %newrpath %buildroot/$binary
176   patchelf $debug --set-interpreter %newinterpreter %buildroot/$binary
177   if test -n "$debug"; then
178     patchelf --print-rpath %buildroot/$binary
179     patchelf --print-interpreter %buildroot/$binary
180   fi
181   echo "$binary" >> %buildroot/%{_prefix}/share/applybinary/%name
182   echo ""
183 done
184 %endif
185
186 # stub
187 %if %libraries_to_prepare
188 echo ""
189 echo "[ .oO Preparing libraries Oo. ]"
190 echo ""
191 %endif
192
193 # stub
194 %if %special_script
195 echo ""
196 echo "[ .oO Executing special script Oo. ]"
197 echo ""
198 %endif
199
200 # lets start the shellquote nightmare ;)
201 shellquote()
202 {
203     for arg; do
204         arg=${arg//\\/\\\\}
205 #        arg=${arg//\$/\$}   # already needs quoting ;(
206 #        arg=${arg/\"/\\\"}  # dito
207 #        arg=${arg//\`/\`}   # dito
208         arg=${arg//\\|/\|}
209         arg=${arg//\\|/|}
210         echo "$arg"
211     done
212 }
213
214
215 echo "Creating baselibs_new.conf"
216 echo ""
217 rm -rRf /tmp/baselibs_new.conf || true
218
219 shellquote "%{name}" >> /tmp/baselibs_new.conf
220 shellquote "  targettype x86 block!" >> /tmp/baselibs_new.conf
221 shellquote "  targettype 32bit block!" >> /tmp/baselibs_new.conf
222 shellquote "  targettype arm autoreqprov off" >> /tmp/baselibs_new.conf
223
224 # automagically fill in basic requirements
225 for i in $cleandeps ; do 
226   shellquote "  targettype arm requires \"${i}-x86-arm\"" >> /tmp/baselibs_new.conf
227 done
228
229 # we require the native version
230 shellquote "  targettype arm requires \"%{oldname}\" " >> /tmp/baselibs_new.conf
231 shellquote "  targettype arm prefix /emul/ia32-linux" >> /tmp/baselibs_new.conf
232 shellquote "  targettype arm extension -arm" >> /tmp/baselibs_new.conf
233 shellquote "  targettype arm +/" >> /tmp/baselibs_new.conf
234
235 # safe space and download time
236 shellquote "  targettype arm -/%{_mandir}" >> /tmp/baselibs_new.conf
237 shellquote "  targettype arm -/%{_docdir}" >> /tmp/baselibs_new.conf
238 shellquote "  targettype arm requires \"tizen-accelerator\"" >> /tmp/baselibs_new.conf
239
240 # replace native with x86 binaries as defined in file
241 %if %binaries_to_prepare
242 # Todo: error handling if .orig-arm is present
243 for binary in `cat %{_sourcedir}/binaries_to_prepare` ; do
244    shellquote "  targettype arm post \"  mv ${binary} ${binary}.orig-arm ; ln -s <prefix>${binary} ${binary} \"" >> /tmp/baselibs_new.conf
245 done
246
247 shellquote " " >> /tmp/baselibs_new.conf
248 for binary in `cat %{_sourcedir}/binaries_to_prepare` ; do
249   shellquote "  targettype arm preun \"  rm -f ${binary} ; mv ${binary}.orig-arm ${binary}\"" >> /tmp/baselibs_new.conf
250 done
251 %endif
252
253 cat /tmp/baselibs_new.conf >> %{_sourcedir}/baselibs.conf
254
255 echo "################################################################################"
256 echo ""
257 echo ""
258 echo "REQUIREMENTS:"
259 grep "requires" %{_sourcedir}/baselibs.conf | sort | uniq | sed -e "s#  targettype.*requires ##g" | while read k ; do
260  echo "CBinstall: $k"
261 done
262 echo "Runscripts: %{newname}-arm"
263 echo ""
264 echo ""
265 echo "################################################################################"
266 set -x
267
268 %clean
269 rm -rf $RPM_BUILD_ROOT
270
271 %files -f filestoinclude
272 %defattr(-,root,root)
273 %if %binaries_to_prepare
274 /%{_prefix}/share/applybinary/%name
275 %endif