Tizen 2.1 base
[toolchains/zlib-x86.git] / packaging / zlib-x86.spec
1 # meta spec file for cross-chroot setup 
2 #
3 # Copyright (c) 2010  Jan-Simon Möller (jsmoeller@linuxfoundation.org)
4 # License: GPLv2
5
6 ## README
7 ##
8 ## In this file:
9 ## 1) define name of original package (see oldname)
10 ## 
11 ## File binaries_to_prepare:
12 ## 2) fill in the binaries which need to be available to the foreign chroot
13 ##    e.g. /bin/bash   -  this will make a i586 bash available
14 ##
15
16 #\/\/\/\/\/\/\/\/\/\/
17 ### only changes here
18 #
19 # The original package name
20 %define oldname zlib
21 #
22 # The architectures this meta package is built on
23 %define myexclusive i586
24 #
25 ### no changes needed below this line
26 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27
28
29
30 ### no changes needed
31 #
32 # The new package name - convention is %oldname-x86
33 %define newname %{oldname}-x86
34 #
35 # The version of the original package is read from its rpm db info
36 %{expand:%%define newversion %(rpm -q --qf '[%{version}]' %oldname)}
37 #
38 # The license of the original package is read from its rpm db info
39 %{expand:%%define newlicense %(rpm -q --qf '[%{license}]' %oldname)}
40 #
41 # The group information of the original package
42 %{expand:%%define newgroup %(rpm -q --qf '[%{group}]' %oldname)}
43 #
44 # The summary of the original package
45 %{expand:%%define newsummary %(rpm -q --qf '[%{summary} - special version ]' %oldname)}
46 #
47 # New rpath to add to files on request
48 %define newrpath "/emul/ia32-linux/lib:/emul/ia32-linux/usr/lib"
49 %define newinterpreter /emul/ia32-linux/lib/ld-linux.so.2
50 #
51 # Some automatic checks for availability
52 # binaries_to_prepare
53 %define binaries_to_prepare %{expand:%(test -e %{_sourcedir}/binaries_to_prepare && echo 1 || echo 0)}
54 %define libraries_to_prepare %{expand:%(test -e %{_sourcedir}/libraries_to_prepare && echo 1 || echo 0)}
55 %define special_script %{expand:%(test -e %{_sourcedir}/special_script && echo 1 || echo 0)}
56 %define files_to_ignore %{expand:%(test -e %{_sourcedir}/files_to_ignore && echo 1 || echo 0)}
57 #
58 ### no changes needed below this line
59 %define __strip /bin/true
60 %define nodebug 1
61 %define _build_name_fmt    %%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.dontuse.rpm
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 for binary in `cat %{_sourcedir}/binaries_to_prepare` ; do
241    shellquote "  targettype arm post \"  mv ${binary} ${binary}.orig-arm ; ln -s <prefix>${binary} ${binary} \"" >> /tmp/baselibs_new.conf
242 done
243
244 shellquote " " >> /tmp/baselibs_new.conf
245 for binary in `cat %{_sourcedir}/binaries_to_prepare` ; do
246   shellquote "  targettype arm preun \"  rm -f ${binary} ; mv ${binary}.orig-arm ${binary}\"" >> /tmp/baselibs_new.conf
247 done
248 %endif
249
250 cat /tmp/baselibs_new.conf >> %{_sourcedir}/baselibs.conf
251
252 # Print requirements
253 echo ""
254 echo ""
255 echo ""
256 echo "REQUIREMENTS:"
257 grep "requires" %{_sourcedir}/baselibs.conf
258 echo ""
259 echo ""
260 echo ""
261 sleep 2
262 set -x
263
264 %clean
265 rm -rf $RPM_BUILD_ROOT
266
267 %files -f filestoinclude
268 %defattr(-,root,root)
269 %if %binaries_to_prepare
270 /%{_prefix}/share/applybinary/%name
271 %endif