source: rtems/contrib/mingw/build-rpms.sh @ 7eb4d4b

4.104.114.84.95
Last change on this file since 7eb4d4b was ed70a496, checked in by Chris Johns <chrisj@…>, on Jul 21, 2006 at 12:11:54 AM

Add the build-rpms.sh here until moved to crossrpms.

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