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 | host_list="mingw32" |
---|
40 | |
---|
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 | # We may build a different set of packages for different |
---|
47 | # hosts depending on what builds. |
---|
48 | rtems_tool_list="autoconf automake $base_tool_list" |
---|
49 | linux_rtems_tool_list=$rtems_tool_list |
---|
50 | mingw32_rtems_tool_list="$rtems_tool_list gdb" |
---|
51 | |
---|
52 | cygwin_cc_name="pc" |
---|
53 | freebsd_cc_name="pc" |
---|
54 | mingw32_cc_name="pc" |
---|
55 | |
---|
56 | linux_cpu_list="$processor" |
---|
57 | cygwin_cpu_list="i686" |
---|
58 | freebsd_cpu_list="i586" |
---|
59 | mingw32_cpu_list="i686" |
---|
60 | |
---|
61 | expat_list="mingw32" |
---|
62 | . $source/expat-version |
---|
63 | |
---|
64 | prefix=/opt/rtems-$version |
---|
65 | hosts=$host_list |
---|
66 | build=$processor-linux-gnu |
---|
67 | infos= |
---|
68 | targets=$target_list |
---|
69 | run_prefix= |
---|
70 | rpm_prefix=custom- |
---|
71 | rpm_prefix_arg= |
---|
72 | local_rpm_database=yes |
---|
73 | clean=yes |
---|
74 | |
---|
75 | while [ $# -gt 0 ]; |
---|
76 | do |
---|
77 | case $1 in |
---|
78 | -c) |
---|
79 | clean=no |
---|
80 | ;; |
---|
81 | -d) |
---|
82 | set -x |
---|
83 | ;; |
---|
84 | -h) |
---|
85 | shift |
---|
86 | hosts=$1 |
---|
87 | ;; |
---|
88 | -i) |
---|
89 | infos="--enable-infos" |
---|
90 | ;; |
---|
91 | -l) |
---|
92 | shift |
---|
93 | rpm_prefix=$1- |
---|
94 | rpm_prefix_arg="--enable-rpmprefix=$rpm_label" |
---|
95 | ;; |
---|
96 | -n) |
---|
97 | run_prefix="echo " |
---|
98 | ;; |
---|
99 | -p) |
---|
100 | shift |
---|
101 | prefix=$1 |
---|
102 | ;; |
---|
103 | -R) |
---|
104 | local_rpm_database=no |
---|
105 | ;; |
---|
106 | -s) |
---|
107 | shift |
---|
108 | source=$1 |
---|
109 | ;; |
---|
110 | -t) |
---|
111 | shift |
---|
112 | targets=$1 |
---|
113 | ;; |
---|
114 | -v) |
---|
115 | shift |
---|
116 | version=$1 |
---|
117 | ;; |
---|
118 | --help) |
---|
119 | echo "$0 -cdinr -o <output> -h <hosts>" \ |
---|
120 | "-l <rpm prefix> -p <prefix> -s <source> -t <targets> -v <version>" |
---|
121 | exit 2 |
---|
122 | ;; |
---|
123 | *) |
---|
124 | terminate "error: invalid option (try --help): $1" |
---|
125 | ;; |
---|
126 | esac |
---|
127 | shift |
---|
128 | done |
---|
129 | |
---|
130 | rpm_topdir=$(rpm --eval "%{_topdir}") |
---|
131 | |
---|
132 | for t in $targets; |
---|
133 | do |
---|
134 | if [ -z "$(echo $target_list | grep $t)" ]; then |
---|
135 | terminate "error: invalid target: $t" |
---|
136 | fi |
---|
137 | done |
---|
138 | |
---|
139 | cd=${run_prefix}cd |
---|
140 | configure=${run_prefix}${source}/configure |
---|
141 | cp=${run_prefix}cp |
---|
142 | make=${run_prefix}make |
---|
143 | mkdir=${run_prefix}mkdir |
---|
144 | rm=${run_prefix}rm |
---|
145 | rpmbuild=${run_prefix}rpmbuild |
---|
146 | rpm=${run_prefix}rpm |
---|
147 | tar=${run_prefix}tar |
---|
148 | |
---|
149 | if [ $local_rpm_database = yes ]; then |
---|
150 | rpm_database="--dbpath $prefix/var/lib/rpm" |
---|
151 | else |
---|
152 | rpm_database= |
---|
153 | fi |
---|
154 | |
---|
155 | # |
---|
156 | # We always build tools for the build host. We need them to |
---|
157 | # build the libraries for the target processor. |
---|
158 | # |
---|
159 | hosts="linux $hosts" |
---|
160 | |
---|
161 | echo " Source: $source" |
---|
162 | echo " Prefix: $prefix" |
---|
163 | echo " Hosts: $hosts" |
---|
164 | echo "Targets: $targets" |
---|
165 | |
---|
166 | if [ ! -f $source/configure ]; then |
---|
167 | terminate "$source/configure not found under: $source" |
---|
168 | fi |
---|
169 | |
---|
170 | if [ x$prefix != x ]; then |
---|
171 | if [ -e $prefix ]; then |
---|
172 | if [ ! -d $prefix ]; then |
---|
173 | terminate "$prefix is not a directory" |
---|
174 | fi |
---|
175 | else |
---|
176 | echo "Creating $(pwd)" |
---|
177 | $mkdir -p $prefix |
---|
178 | check "making the prefix directory: $prefix" |
---|
179 | fi |
---|
180 | fi |
---|
181 | |
---|
182 | $cd $prefix |
---|
183 | check "cannot change to the prefix directory: $prefix" |
---|
184 | |
---|
185 | # |
---|
186 | # Clean the files from the current prefix. Remove the various RPM |
---|
187 | # and SRPM files. |
---|
188 | # |
---|
189 | if [ $clean = yes ]; then |
---|
190 | echo "Cleaning: $(pwd)" |
---|
191 | $rm -rf * |
---|
192 | $rm -rf $rpm_topdir/BUILD/* |
---|
193 | for h in $hosts; |
---|
194 | do |
---|
195 | for d in RPMS SRPMS |
---|
196 | do |
---|
197 | rm -rf $rpm_topdir/$h/$d |
---|
198 | check "removing rpm/srpm directory: $rpm_topdir/$h/$d" |
---|
199 | mkdir -p $rpm_topdir/$h/$d |
---|
200 | check "creating directory: $rpm_topdir/$h/$d" |
---|
201 | done |
---|
202 | done |
---|
203 | fi |
---|
204 | |
---|
205 | # |
---|
206 | # Using a local RPM database means we do not need to be root to |
---|
207 | # perform the build. |
---|
208 | # |
---|
209 | if [ $local_rpm_database = yes ]; then |
---|
210 | echo "Creating private RPM database: $(pwd)/var/lib/rpm" |
---|
211 | if [ ! -d /var/lib/rpm ]; then |
---|
212 | terminate "no RPM database found on this host" |
---|
213 | exit 1 |
---|
214 | fi |
---|
215 | if [ ! -d var/lib ]; then |
---|
216 | $mkdir -p var/lib |
---|
217 | check "making the local RPM database directory: var/lib" |
---|
218 | fi |
---|
219 | if [ $clean = yes ]; then |
---|
220 | $rm -rf var/lib/rpm/* |
---|
221 | check "Deleting the current database." |
---|
222 | fi |
---|
223 | if [ $clean = yes -o ! -e var/lib/rpmPackages ]; then |
---|
224 | echo "Copying RPM database to a local RPM database" |
---|
225 | $cp -r /var/lib/rpm var/lib/rpm |
---|
226 | check "copying the RPM database to the local database" |
---|
227 | fi |
---|
228 | fi |
---|
229 | |
---|
230 | # |
---|
231 | # Set the path to the new directory. |
---|
232 | # |
---|
233 | export PATH=$prefix/bin:$PATH |
---|
234 | |
---|
235 | # |
---|
236 | # Install the RPM. |
---|
237 | # |
---|
238 | |
---|
239 | rpm_installer() |
---|
240 | { |
---|
241 | local rpm_common= |
---|
242 | local rpm_libs= |
---|
243 | local rpm_tools= |
---|
244 | local r |
---|
245 | |
---|
246 | local rpm_database=$1 |
---|
247 | shift |
---|
248 | local rpm_arch=$1 |
---|
249 | shift |
---|
250 | local rpm_path=$1 |
---|
251 | shift |
---|
252 | |
---|
253 | # |
---|
254 | # Get the names of the rpm files that have been built. This means we |
---|
255 | # do not have maintain version info. |
---|
256 | # |
---|
257 | rpm_names=$(rpmbuild $rpm_database $* --nobuild 2> /dev/null | \ |
---|
258 | grep -v "debuginfo" | grep "Process" | sed 's/Process.*\: //') |
---|
259 | # |
---|
260 | # If we have a base place that one first then libs then the tools. |
---|
261 | # |
---|
262 | for r in $rpm_names |
---|
263 | do |
---|
264 | if [ $(echo $r | sed 's/.*common.*/yes/') = yes ]; then |
---|
265 | rpm_common="$rpm_common $r" |
---|
266 | elif [ $(echo $r | sed 's/.*lib.*/yes/') = yes ]; then |
---|
267 | rpm_libs="$rpm_libs $r" |
---|
268 | elif [ $(echo $r | sed 's/.*sys\-root.*/yes/') = yes ]; then |
---|
269 | rpm_libs="$rpm_libs $r" |
---|
270 | else |
---|
271 | rpm_tools="$rpm_tools $r" |
---|
272 | fi |
---|
273 | done |
---|
274 | |
---|
275 | for r in $rpm_common $rpm_libs $rpm_tools |
---|
276 | do |
---|
277 | echo "rpm $rpm_database --force" \ |
---|
278 | "-i $rpm_path/$rpm_arch/$r.$rpm_arch.rpm" |
---|
279 | $rpm $rpm_database --force -i $rpm_path/$rpm_arch/$r.$rpm_arch.rpm |
---|
280 | check "installing the $r.$rpm_arch.rpm rpm failed" |
---|
281 | done |
---|
282 | } |
---|
283 | |
---|
284 | # |
---|
285 | # Select the type of arch we have. |
---|
286 | # |
---|
287 | |
---|
288 | rpm_arch() |
---|
289 | { |
---|
290 | if [ $(echo $1 | sed 's/.*api.*/yes/') = yes ]; then |
---|
291 | echo "noarch" |
---|
292 | elif [ $(echo $1 | sed 's/.*lib.*/yes/') = yes ]; then |
---|
293 | echo "noarch" |
---|
294 | elif [ $(echo $1 | sed 's/.*auto.*/yes/') = yes ]; then |
---|
295 | echo "noarch" |
---|
296 | else |
---|
297 | echo $2 |
---|
298 | fi |
---|
299 | } |
---|
300 | |
---|
301 | echo "Configuring target: all" |
---|
302 | echo "configure --prefix=$prefix $rpm_prefix_arg " \ |
---|
303 | " --target=all $infos" |
---|
304 | $configure --prefix=$prefix $rpm_prefix_arg \ |
---|
305 | --target=all \ |
---|
306 | $infos |
---|
307 | check "configuring the crossrpms failed" |
---|
308 | echo "make" |
---|
309 | $make |
---|
310 | check "building the rpm spec files failed" |
---|
311 | echo "make -C autotools" |
---|
312 | $make -C autotools |
---|
313 | check "building the rpm spec files failed" |
---|
314 | |
---|
315 | # |
---|
316 | # Build for each type of host in your host list. The build host |
---|
317 | # will always be present. |
---|
318 | # |
---|
319 | for h in $hosts; |
---|
320 | do |
---|
321 | # |
---|
322 | # Need to translate the build host to an RTEMS host. Create a |
---|
323 | # target host (th) and specs directory (sd) variable to handle |
---|
324 | # the use of RTEMS. |
---|
325 | # |
---|
326 | if [ $h = "linux" ]; then |
---|
327 | th="linux-gnu" |
---|
328 | sd=rtems$version |
---|
329 | canadian_cross=no |
---|
330 | else |
---|
331 | th=$h |
---|
332 | sd=$h |
---|
333 | canadian_cross=yes |
---|
334 | fi |
---|
335 | |
---|
336 | # |
---|
337 | # Associate the host to its tool list to get the packages to build. |
---|
338 | # |
---|
339 | tl=${h}_tool_list |
---|
340 | pl=${h}_cpu_list |
---|
341 | |
---|
342 | echo "Native Host Tools: ${!tl} for ${!pl}" |
---|
343 | echo "Canadian Cross: $canadian_cross ($t $h)" |
---|
344 | |
---|
345 | for p in ${!pl} |
---|
346 | do |
---|
347 | pth="$p-pc-$th" |
---|
348 | |
---|
349 | if [ $canadian_cross = yes ]; then |
---|
350 | echo "make -C $sd/$p" |
---|
351 | $make -C $sd/$p |
---|
352 | check "building the rpm spec files failed: $sd/$p" |
---|
353 | |
---|
354 | for s in ${!tl} |
---|
355 | do |
---|
356 | case $s in |
---|
357 | autoconf|automake) |
---|
358 | # Hack around the prefix in the spec files for autotools. |
---|
359 | ba="-ba $prefix/autotools/$rpm_prefix$s.spec" |
---|
360 | ;; |
---|
361 | *) |
---|
362 | ba="-ba $prefix/$sd/$p/$rpm_prefix$pth-$s.spec" |
---|
363 | esac |
---|
364 | |
---|
365 | rpmbuild_cmd="$ba --target=$build" |
---|
366 | |
---|
367 | echo "rpmbuild --define '_defaultdocdir $prefix/share/doc' $rpm_database $rpmbuild_cmd" |
---|
368 | $rpmbuild --define "_defaultdocdir $prefix/share/doc" $rpm_database $rpmbuild_cmd |
---|
369 | check "building the $sd/$p/$rpm_prefix$pth-$s rpm failed" |
---|
370 | |
---|
371 | rpm_installer "$rpm_database" \ |
---|
372 | $(rpm_arch $rpm_prefix$pth-$s $processor) \ |
---|
373 | $rpm_topdir/linux/RPMS \ |
---|
374 | $rpmbuild_cmd |
---|
375 | done |
---|
376 | fi |
---|
377 | |
---|
378 | # |
---|
379 | # See if the host is listed in the expat list. If it is build the |
---|
380 | # expat library. |
---|
381 | # |
---|
382 | for eh in $expat_list |
---|
383 | do |
---|
384 | if [ $th == $eh ]; then |
---|
385 | _curpath=$PATH |
---|
386 | PATH=$prefix/bin:$PATH |
---|
387 | expat_build=${rpm_prefix}${th}-expat-${expat_version} |
---|
388 | $rm -rf ${rpm_topdir}/BUILD/$expat_build |
---|
389 | check "cleaning expat directory: ${rpm_topdir}/BUILD/$expat_build" |
---|
390 | $mkdir ${rpm_topdir}/BUILD/$expat_build |
---|
391 | check "make directory: ${rpm_topdir}/BUILD/$expat_build" |
---|
392 | _curdir=$(pwd) |
---|
393 | $cd ${rpm_topdir}/BUILD/$expat_build |
---|
394 | check "change to directory: ${rpm_topdir}/BUILD/$expat_build" |
---|
395 | $tar x${expat_tar_comp}f $rpm_topdir/SOURCES/expat-${expat_version}.tar.${expat_tar_ext} |
---|
396 | check "extract tar file: $rpm_topdir/SOURCES/expat-${expat_version}.tar.${expat_tar_ext}" |
---|
397 | $mkdir build |
---|
398 | check "make directory: build" |
---|
399 | $cd build |
---|
400 | check "change directory: build" |
---|
401 | ${run_prefix}../expat-${expat_version}/configure --build=$build --host=$p-pc-$th --prefix=$prefix |
---|
402 | check "configure failed: ../expat-${expat_version}/configure --build=$build --host=$p-pc-$th --prefix=$prefix" |
---|
403 | $make all install |
---|
404 | check "expat make all install" |
---|
405 | $cd $_curdir |
---|
406 | check "change directory: $_curdir" |
---|
407 | PATH=$_curpath |
---|
408 | fi |
---|
409 | done |
---|
410 | done |
---|
411 | |
---|
412 | for t in $targets; |
---|
413 | do |
---|
414 | rtl=${h}_rtems_tool_list |
---|
415 | echo "RTEMS Tool List: ${!rtl}" |
---|
416 | for s in ${!rtl} |
---|
417 | do |
---|
418 | case $s in |
---|
419 | autoconf|automake) |
---|
420 | # Hack around the prefix in the spec files for autotools. |
---|
421 | ba="-ba $prefix/autotools/$rpm_prefix$s.spec" |
---|
422 | ;; |
---|
423 | *) |
---|
424 | ba="-ba $prefix/rtems$version/$t/$rpm_prefix$t-rtems$version-$s.spec" |
---|
425 | esac |
---|
426 | |
---|
427 | rpmbuild_cmd="$ba --target=$pth" |
---|
428 | |
---|
429 | if [ $canadian_cross = yes ]; then |
---|
430 | ccl=${h}_cc_name |
---|
431 | echo "rpmbuild --define '_build $processor-redhat-linux' " \ |
---|
432 | "--define '_host $pth' " \ |
---|
433 | "--define '_defaultdocdir $prefix/share/doc' " \ |
---|
434 | "$rpm_database $rpmbuild_cmd " |
---|
435 | $rpmbuild --define "_build $processor-redhat-linux" \ |
---|
436 | --define "_host $pth" \ |
---|
437 | --define "_defaultdocdir $prefix/share/doc" \ |
---|
438 | --define "__cc $p-${!ccl}-$h-gcc" \ |
---|
439 | $rpm_database $rpmbuild_cmd |
---|
440 | check "building host cross target: $rpm_prefix$t-rtems$version-$s" |
---|
441 | else |
---|
442 | echo "rpmbuild --define '_defaultdocdir $prefix/share/doc' "\ |
---|
443 | "$rpm_database $rpmbuild_cmd" |
---|
444 | $rpmbuild --define "_defaultdocdir $prefix/share/doc" \ |
---|
445 | $rpm_database $rpmbuild_cmd |
---|
446 | check "building host cross target: $rpm_prefix$t-rtems$version-$s" |
---|
447 | fi |
---|
448 | |
---|
449 | if [ $canadian_cross != yes ]; then |
---|
450 | rpm_installer "$rpm_database" \ |
---|
451 | $(rpm_arch $rpm_prefix$t-rtems$version-$s $p) \ |
---|
452 | $rpm_topdir/$h/RPMS \ |
---|
453 | $rpmbuild_cmd |
---|
454 | fi |
---|
455 | done |
---|
456 | done |
---|
457 | done |
---|