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

4.104.114.84.95
Last change on this file since a2d7c41 was a2d7c41, checked in by Chris Johns <chrisj@…>, on Aug 21, 2006 at 10:29:53 PM

Move the build to host tools out of the target root,

  • Property mode set to 100755
File size: 7.9 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="arm avr h8300 i386 m68k mips powerpc sh sparc tic4x"
36host_list="cygwin freebsd5.2 freebsd6.0 freebsd6.1 mingw32"
37
38rtems_tool_list="$base_tool_list"
39linux_tool_list="autoconf automake $base_tool_list"
40cygwin_tool_list="w32api libs autoconf automake $base_tool_list"
41freebsd_tool_list="libs autoconf automake $base_tool_list"
42mingw32_tool_list="w32api libs autoconf automake $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-$version
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 elif [ $(echo $1 | sed 's/.*auto.*/yes/') = yes ]; then
259  echo "noarch"
260 else
261  echo $2
262 fi
263}
264
265#
266# We always build tools for the build host. We need them to
267# build the libraries for the target processor.
268#
269hosts="linux $hosts"
270
271echo "Configuring target: all"
272echo "configure --prefix=$prefix $rpm_prefix_arg " \
273     " --target=all $infos"
274$configure --prefix=$prefix $rpm_prefix_arg \
275           --target=all \
276           $infos
277check "configuring the crossrpms failed"
278echo "make"
279$make
280check "building the rpm spec files failed"
281echo "make -C autotools"
282$make -C autotools
283check "building the rpm spec files failed"
284
285for h in $hosts;
286do
287 #
288 # Need to translate the build host to an RTEMS host. Create a
289 # target host (th) and specs directory (sd) variable to handle
290 # the use of RTEMS.
291 #
292 if [ $h = "linux" ]; then
293  th="linux-gnu"
294  sd=rtems$version
295  canadian_cross=no
296 else
297  th=$h
298  sd=$h
299  canadian_cross=yes
300 fi
301
302 #
303 # Associate the host to its tool list to get the packages to build.
304 #
305 tl=${h}_tool_list
306 pl=${h}_cpu_list
307
308 echo "Native Host Tools: ${!tl} for ${!pl}"
309 echo "Canadian Cross: $canadian_cross ($t $h)"
310
311 for p in ${!pl}
312 do
313  pth="$p-pc-$th"
314
315  if [ $canadian_cross = yes ]; then
316   echo "make -C $sd/$p"
317   $make -C $sd/$p
318   check "building the rpm spec files failed: $sd/$p"
319
320   for s in ${!tl}
321   do
322    case $s in
323     autoconf|automake)
324      # Hack around the prefix in the spec files for autotools.
325      ba="-ba $prefix/autotools/$rpm_prefix$s-rtems.spec"
326      ;;
327     *)
328      ba="-ba $prefix/$sd/$p/$rpm_prefix$pth-$s.spec"
329    esac
330
331    rpmbuild_cmd="$ba --target=$build"
332
333    echo "rpmbuild --define '_defaultdocdir $prefix/share/doc' $rpm_database $rpmbuild_cmd"
334    $rpmbuild --define "_defaultdocdir $prefix/share/doc" $rpm_database $rpmbuild_cmd
335    check "building the $sd/$p/$rpm_prefix$pth-$s rpm failed"
336
337    rpm_installer "$rpm_database" \
338                  $(rpm_arch $rpm_prefix$pth-$s $processor) \
339                  $rpm_topdir/linux/RPMS \
340                  $rpmbuild_cmd
341   done
342  fi
343 done
344
345 for t in $targets;
346 do
347  for s in ${rtems_tool_list}
348  do
349   rpmbuild_cmd="-ba $prefix/rtems$version/$t/$rpm_prefix$t-rtems$version-$s.spec --target=$pth"
350
351   if [ $canadian_cross = yes ]; then
352    ccl=${h}_cc_name
353    echo "rpmbuild --define '_build $processor-redhat-linux' " \
354         "--define '_host $pth' $rpm_database $rpmbuild_cmd "
355    $rpmbuild --define "_build $processor-redhat-linux" \
356              --define "_host $pth" \
357              --define "__cc $p-${!ccl}-$h-gcc" \
358              $rpm_database $rpmbuild_cmd
359    check "building host cross target: $rpm_prefix$t-rtems$version-$s"
360   else
361    echo "rpmbuild $rpm_database $rpmbuild_cmd"
362    $rpmbuild $rpm_database $rpmbuild_cmd
363    check "building host cross target: $rpm_prefix$t-rtems$version-$s"
364   fi 
365
366   if [ $canadian_cross != yes ]; then
367    rpm_installer "$rpm_database" \
368                  $(rpm_arch $rpm_prefix$t-rtems$version-$s $p) \
369                  $rpm_topdir/$h/RPMS \
370                  $rpmbuild_cmd
371   fi
372  done
373 done
374done
Note: See TracBrowser for help on using the repository browser.