source: rtems/contrib/mingw/build-rpms.sh @ 1a768ef

4.104.114.84.95
Last change on this file since 1a768ef was 1a768ef, checked in by Chris Johns <chrisj@…>, on 08/04/06 at 09:49:35

Updated to use common rather than base. More rpmbuild work arounds.

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