1 | #! /bin/sh |
---|
2 | # |
---|
3 | # $Id$ |
---|
4 | # |
---|
5 | # RTEMS Build RPM script. |
---|
6 | # |
---|
7 | # This script builds the RTEMS tools into RPM packages on a Linux Fedora host, |
---|
8 | # and supports Canadian cross builds to other hosts. It is light sugar around |
---|
9 | # the fine work of Ralf Corsepius thats actually builds the RPM files. |
---|
10 | # |
---|
11 | # We build all the targets for a given host. |
---|
12 | # |
---|
13 | # Note: This file should be placed in crossrpms. |
---|
14 | # |
---|
15 | |
---|
16 | source=$(dirname $0) |
---|
17 | |
---|
18 | terminate() |
---|
19 | { |
---|
20 | echo "error: $*" >&2 |
---|
21 | exit 1 |
---|
22 | } |
---|
23 | |
---|
24 | check() |
---|
25 | { |
---|
26 | if [ $? -ne 0 ]; then |
---|
27 | terminate |
---|
28 | fi |
---|
29 | } |
---|
30 | |
---|
31 | processor=$(uname -p) |
---|
32 | |
---|
33 | . $source/version |
---|
34 | |
---|
35 | base_tool_list="binutils gcc" |
---|
36 | |
---|
37 | target_list=$(cat $source/targets) |
---|
38 | host_list="cygwin freebsd5.2 freebsd6.0 freebsd6.1 mingw32" |
---|
39 | |
---|
40 | rtems_tool_list="autoconf automake $base_tool_list gdb" |
---|
41 | linux_tool_list="autoconf automake $base_tool_list" |
---|
42 | cygwin_tool_list="w32api libs autoconf automake $base_tool_list" |
---|
43 | freebsd_tool_list="libs autoconf automake $base_tool_list" |
---|
44 | mingw32_tool_list="w32api libs autoconf automake $base_tool_list" |
---|
45 | |
---|
46 | cygwin_cc_name="pc" |
---|
47 | freebsd_cc_name="pc" |
---|
48 | mingw32_cc_name="pc" |
---|
49 | |
---|
50 | linux_cpu_list="$processor" |
---|
51 | cygwin_cpu_list="i686" |
---|
52 | freebsd_cpu_list="i586" |
---|
53 | mingw32_cpu_list="i686" |
---|
54 | |
---|
55 | rpm_topdir=$(rpm --eval "%{_topdir}") |
---|
56 | |
---|
57 | prefix=/opt/rtems-$version |
---|
58 | hosts=$host_list |
---|
59 | build=$processor-linux-gnu |
---|
60 | infos= |
---|
61 | targets=$target_list |
---|
62 | run_prefix= |
---|
63 | rpm_prefix=custom- |
---|
64 | rpm_prefix_arg= |
---|
65 | local_rpm_database=yes |
---|
66 | clean=yes |
---|
67 | |
---|
68 | while [ $# -gt 0 ]; |
---|
69 | do |
---|
70 | case $1 in |
---|
71 | -c) |
---|
72 | clean=no |
---|
73 | ;; |
---|
74 | -d) |
---|
75 | set -x |
---|
76 | ;; |
---|
77 | -h) |
---|
78 | shift |
---|
79 | hosts=$1 |
---|
80 | ;; |
---|
81 | -i) |
---|
82 | infos="--enable-infos" |
---|
83 | ;; |
---|
84 | -l) |
---|
85 | shift |
---|
86 | rpm_prefix=$1- |
---|
87 | rpm_prefix_arg="--enable-rpmprefix=$rpm_label" |
---|
88 | ;; |
---|
89 | -n) |
---|
90 | run_prefix="echo " |
---|
91 | ;; |
---|
92 | -p) |
---|
93 | shift |
---|
94 | prefix=$1 |
---|
95 | ;; |
---|
96 | -R) |
---|
97 | local_rpm_database=no |
---|
98 | ;; |
---|
99 | -s) |
---|
100 | shift |
---|
101 | source=$1 |
---|
102 | ;; |
---|
103 | -t) |
---|
104 | shift |
---|
105 | targets=$1 |
---|
106 | ;; |
---|
107 | -v) |
---|
108 | shift |
---|
109 | version=$1 |
---|
110 | ;; |
---|
111 | --help) |
---|
112 | echo "$0 -cdinr -o <output> -h <hosts>" \ |
---|
113 | "-l <rpm prefix> -p <prefix> -s <source> -t <targets> -v <version>" |
---|
114 | exit 2 |
---|
115 | ;; |
---|
116 | *) |
---|
117 | terminate "error: invalid option (try --help): $1" |
---|
118 | ;; |
---|
119 | esac |
---|
120 | shift |
---|
121 | done |
---|
122 | |
---|
123 | for t in $targets; |
---|
124 | do |
---|
125 | if [ -z "$(echo $target_list | grep $t)" ]; then |
---|
126 | terminate "error: invalid target: $t" |
---|
127 | fi |
---|
128 | done |
---|
129 | |
---|
130 | cd=${run_prefix}cd |
---|
131 | configure=${run_prefix}${source}/configure |
---|
132 | cp=${run_prefix}cp |
---|
133 | make=${run_prefix}make |
---|
134 | mkdir=${run_prefix}mkdir |
---|
135 | rm=${run_prefix}rm |
---|
136 | rpmbuild=${run_prefix}rpmbuild |
---|
137 | rpm=${run_prefix}rpm |
---|
138 | |
---|
139 | if [ $local_rpm_database = yes ]; then |
---|
140 | rpm_database="--dbpath $prefix/var/lib/rpm" |
---|
141 | else |
---|
142 | rpm_database= |
---|
143 | fi |
---|
144 | |
---|
145 | echo " Source: $source" |
---|
146 | echo " Prefix: $prefix" |
---|
147 | echo " Hosts: $hosts" |
---|
148 | echo "Targets: $targets" |
---|
149 | |
---|
150 | if [ ! -f $source/configure ]; then |
---|
151 | terminate "$source/configure not found under: $source" |
---|
152 | fi |
---|
153 | |
---|
154 | if [ x$prefix != x ]; then |
---|
155 | if [ -e $prefix ]; then |
---|
156 | if [ ! -d $prefix ]; then |
---|
157 | terminate "$prefix is not a directory" |
---|
158 | fi |
---|
159 | else |
---|
160 | echo "Creating $(pwd)" |
---|
161 | $mkdir -p $prefix |
---|
162 | check "making the prefix directory: $prefix" |
---|
163 | fi |
---|
164 | fi |
---|
165 | |
---|
166 | $cd $prefix |
---|
167 | check "cannot change to the prefix directory: $prefix" |
---|
168 | |
---|
169 | if [ $clean = yes ]; then |
---|
170 | echo "Cleaning: $(pwd)" |
---|
171 | $rm -rf * |
---|
172 | fi |
---|
173 | |
---|
174 | # |
---|
175 | # Using a local RPM database means we do not need to be root to |
---|
176 | # perform the build. |
---|
177 | # |
---|
178 | if [ $local_rpm_database = yes ]; then |
---|
179 | echo "Creating private RPM database: $(pwd)/var/lib/rpm" |
---|
180 | if [ ! -d /var/lib/rpm ]; then |
---|
181 | terminate "no RPM database found on this host" |
---|
182 | exit 1 |
---|
183 | fi |
---|
184 | if [ ! -d var/lib ]; then |
---|
185 | $mkdir -p var/lib |
---|
186 | check "making the local RPM database directory: var/lib" |
---|
187 | fi |
---|
188 | if [ $clean = yes -o ! -e var/lib/rpmPackages ]; then |
---|
189 | echo "Copying RPM database to a local RPM database" |
---|
190 | $cp -r /var/lib/rpm var/lib/rpm |
---|
191 | check "copying the RPM database to the local database" |
---|
192 | fi |
---|
193 | fi |
---|
194 | |
---|
195 | # |
---|
196 | # Set the path to the new directory. |
---|
197 | # |
---|
198 | export PATH=$prefix/bin:$PATH |
---|
199 | |
---|
200 | # |
---|
201 | # Install the RPM. |
---|
202 | # |
---|
203 | |
---|
204 | rpm_installer() |
---|
205 | { |
---|
206 | local rpm_common= |
---|
207 | local rpm_libs= |
---|
208 | local rpm_tools= |
---|
209 | local r |
---|
210 | |
---|
211 | local rpm_database=$1 |
---|
212 | shift |
---|
213 | local rpm_arch=$1 |
---|
214 | shift |
---|
215 | local rpm_path=$1 |
---|
216 | shift |
---|
217 | |
---|
218 | # |
---|
219 | # Get the names of the rpm files that have been built. This means we |
---|
220 | # do not have maintain version info. |
---|
221 | # |
---|
222 | rpm_names=$(rpmbuild $rpm_database $* --nobuild 2> /dev/null | \ |
---|
223 | grep -v "debuginfo" | grep "Process" | sed 's/Process.*\: //') |
---|
224 | # |
---|
225 | # If we have a base place that one first then libs then the tools. |
---|
226 | # |
---|
227 | for r in $rpm_names |
---|
228 | do |
---|
229 | if [ $(echo $r | sed 's/.*common.*/yes/') = yes ]; then |
---|
230 | rpm_common="$rpm_common $r" |
---|
231 | elif [ $(echo $r | sed 's/.*lib.*/yes/') = yes ]; then |
---|
232 | rpm_libs="$rpm_libs $r" |
---|
233 | elif [ $(echo $r | sed 's/.*sys\-root.*/yes/') = yes ]; then |
---|
234 | rpm_libs="$rpm_libs $r" |
---|
235 | else |
---|
236 | rpm_tools="$rpm_tools $r" |
---|
237 | fi |
---|
238 | done |
---|
239 | |
---|
240 | for r in $rpm_common $rpm_libs $rpm_tools |
---|
241 | do |
---|
242 | echo "rpm $rpm_database --force" \ |
---|
243 | "-i $rpm_path/$rpm_arch/$r.$rpm_arch.rpm" |
---|
244 | $rpm $rpm_database --force -i $rpm_path/$rpm_arch/$r.$rpm_arch.rpm |
---|
245 | check "installing the $r.$rpm_arch.rpm rpm failed" |
---|
246 | done |
---|
247 | } |
---|
248 | |
---|
249 | # |
---|
250 | # Select the type of arch we have. |
---|
251 | # |
---|
252 | |
---|
253 | rpm_arch() |
---|
254 | { |
---|
255 | if [ $(echo $1 | sed 's/.*api.*/yes/') = yes ]; then |
---|
256 | echo "noarch" |
---|
257 | elif [ $(echo $1 | sed 's/.*lib.*/yes/') = yes ]; then |
---|
258 | echo "noarch" |
---|
259 | elif [ $(echo $1 | sed 's/.*auto.*/yes/') = yes ]; then |
---|
260 | echo "noarch" |
---|
261 | else |
---|
262 | echo $2 |
---|
263 | fi |
---|
264 | } |
---|
265 | |
---|
266 | # |
---|
267 | # We always build tools for the build host. We need them to |
---|
268 | # build the libraries for the target processor. |
---|
269 | # |
---|
270 | hosts="linux $hosts" |
---|
271 | |
---|
272 | echo "Configuring target: all" |
---|
273 | echo "configure --prefix=$prefix $rpm_prefix_arg " \ |
---|
274 | " --target=all $infos" |
---|
275 | $configure --prefix=$prefix $rpm_prefix_arg \ |
---|
276 | --target=all \ |
---|
277 | $infos |
---|
278 | check "configuring the crossrpms failed" |
---|
279 | echo "make" |
---|
280 | $make |
---|
281 | check "building the rpm spec files failed" |
---|
282 | echo "make -C autotools" |
---|
283 | $make -C autotools |
---|
284 | check "building the rpm spec files failed" |
---|
285 | |
---|
286 | for h in $hosts; |
---|
287 | do |
---|
288 | # |
---|
289 | # Need to translate the build host to an RTEMS host. Create a |
---|
290 | # target host (th) and specs directory (sd) variable to handle |
---|
291 | # the use of RTEMS. |
---|
292 | # |
---|
293 | if [ $h = "linux" ]; then |
---|
294 | th="linux-gnu" |
---|
295 | sd=rtems$version |
---|
296 | canadian_cross=no |
---|
297 | else |
---|
298 | th=$h |
---|
299 | sd=$h |
---|
300 | canadian_cross=yes |
---|
301 | fi |
---|
302 | |
---|
303 | # |
---|
304 | # Associate the host to its tool list to get the packages to build. |
---|
305 | # |
---|
306 | tl=${h}_tool_list |
---|
307 | pl=${h}_cpu_list |
---|
308 | |
---|
309 | echo "Native Host Tools: ${!tl} for ${!pl}" |
---|
310 | echo "Canadian Cross: $canadian_cross ($t $h)" |
---|
311 | |
---|
312 | for p in ${!pl} |
---|
313 | do |
---|
314 | pth="$p-pc-$th" |
---|
315 | |
---|
316 | if [ $canadian_cross = yes ]; then |
---|
317 | echo "make -C $sd/$p" |
---|
318 | $make -C $sd/$p |
---|
319 | check "building the rpm spec files failed: $sd/$p" |
---|
320 | |
---|
321 | for s in ${!tl} |
---|
322 | do |
---|
323 | case $s in |
---|
324 | autoconf|automake) |
---|
325 | # Hack around the prefix in the spec files for autotools. |
---|
326 | ba="-ba $prefix/autotools/$rpm_prefix$s.spec" |
---|
327 | ;; |
---|
328 | *) |
---|
329 | ba="-ba $prefix/$sd/$p/$rpm_prefix$pth-$s.spec" |
---|
330 | esac |
---|
331 | |
---|
332 | rpmbuild_cmd="$ba --target=$build" |
---|
333 | |
---|
334 | echo "rpmbuild --define '_defaultdocdir $prefix/share/doc' $rpm_database $rpmbuild_cmd" |
---|
335 | $rpmbuild --define "_defaultdocdir $prefix/share/doc" $rpm_database $rpmbuild_cmd |
---|
336 | check "building the $sd/$p/$rpm_prefix$pth-$s rpm failed" |
---|
337 | |
---|
338 | rpm_installer "$rpm_database" \ |
---|
339 | $(rpm_arch $rpm_prefix$pth-$s $processor) \ |
---|
340 | $rpm_topdir/linux/RPMS \ |
---|
341 | $rpmbuild_cmd |
---|
342 | done |
---|
343 | fi |
---|
344 | done |
---|
345 | |
---|
346 | for t in $targets; |
---|
347 | do |
---|
348 | for s in ${rtems_tool_list} |
---|
349 | do |
---|
350 | case $s in |
---|
351 | autoconf|automake) |
---|
352 | # Hack around the prefix in the spec files for autotools. |
---|
353 | ba="-ba $prefix/autotools/$rpm_prefix$s.spec" |
---|
354 | ;; |
---|
355 | *) |
---|
356 | ba="-ba $prefix/rtems$version/$t/$rpm_prefix$t-rtems$version-$s.spec" |
---|
357 | esac |
---|
358 | |
---|
359 | rpmbuild_cmd="$ba --target=$pth" |
---|
360 | |
---|
361 | if [ $canadian_cross = yes ]; then |
---|
362 | ccl=${h}_cc_name |
---|
363 | echo "rpmbuild --define '_build $processor-redhat-linux' " \ |
---|
364 | "--define '_host $pth' " \ |
---|
365 | "--define '_defaultdocdir $prefix/share/doc' " \ |
---|
366 | "$rpm_database $rpmbuild_cmd " |
---|
367 | $rpmbuild --define "_build $processor-redhat-linux" \ |
---|
368 | --define "_host $pth" \ |
---|
369 | --define "_defaultdocdir $prefix/share/doc" \ |
---|
370 | --define "__cc $p-${!ccl}-$h-gcc" \ |
---|
371 | $rpm_database $rpmbuild_cmd |
---|
372 | check "building host cross target: $rpm_prefix$t-rtems$version-$s" |
---|
373 | else |
---|
374 | echo "rpmbuild --define '_defaultdocdir $prefix/share/doc' "\ |
---|
375 | "$rpm_database $rpmbuild_cmd" |
---|
376 | $rpmbuild --define "_defaultdocdir $prefix/share/doc" \ |
---|
377 | $rpm_database $rpmbuild_cmd |
---|
378 | check "building host cross target: $rpm_prefix$t-rtems$version-$s" |
---|
379 | fi |
---|
380 | |
---|
381 | if [ $canadian_cross != yes ]; then |
---|
382 | rpm_installer "$rpm_database" \ |
---|
383 | $(rpm_arch $rpm_prefix$t-rtems$version-$s $p) \ |
---|
384 | $rpm_topdir/$h/RPMS \ |
---|
385 | $rpmbuild_cmd |
---|
386 | fi |
---|
387 | done |
---|
388 | done |
---|
389 | done |
---|