source: rtems/contrib/mingw/build-rpms.sh @ 72eb02e

4.104.114.84.95
Last change on this file since 72eb02e was 72eb02e, checked in by Chris Johns <chrisj@…>, on 08/07/06 at 07:02:41

Updated to handle a different build processor to a i686.

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