summaryrefslogtreecommitdiffstats
path: root/contrib/mingw/build-rpms.sh
blob: 451358d86411ba898226569c47fb34865bbdf377 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#! /bin/sh
#
# $Id$
#
# RTEMS Build RPM script.
#
# This script builds the RTEMS tools into RPM packages on a Linux Fedora host,
# and supports Canadian cross builds to other hosts. It is light sugar around
# the fine work of Ralf Corsepius thats actuallt builds the RPM files.
# 
# We build all the targets for a given host.
#
# Note: This file should be placed in crossrpms.
#

source=$(dirname $0)

terminate()
{
  echo "error: $*" >&2
  exit 1
}

check()
{
 if [ $? -ne 0 ]; then
  terminate
 fi
}

processor=$(uname -p)

version=4.7

base_tool_list="binutils gcc"

target_list=$(cat $source/targets)
host_list="cygwin freebsd5.2 freebsd6.0 freebsd6.1 mingw32"

rtems_tool_list="autoconf automake $base_tool_list"
linux_tool_list="autoconf automake $base_tool_list"
cygwin_tool_list="w32api libs autoconf automake $base_tool_list"
freebsd_tool_list="libs autoconf automake $base_tool_list"
mingw32_tool_list="w32api libs autoconf automake $base_tool_list"

cygwin_cc_name="pc"
freebsd_cc_name="pc"
mingw32_cc_name="pc"

linux_cpu_list="$processor"
cygwin_cpu_list="i686"
freebsd_cpu_list="i586"
mingw32_cpu_list="i686"

rpm_topdir=$(rpm --eval "%{_topdir}")

prefix=/opt/rtems-$version
hosts=$host_list
build=$processor-linux-gnu
infos=
targets=$target_list
run_prefix=
rpm_prefix=custom-
rpm_prefix_arg=
local_rpm_database=yes
clean=yes

while [ $# -gt 0 ];
do
 case $1 in
  -c)
   clean=no
   ;;
  -d)
   set -x
   ;;
  -h)
   shift
   hosts=$1
   ;;
  -i)
   infos="--enable-infos"
   ;;
  -l)
   shift
   rpm_prefix=$1-
   rpm_prefix_arg="--enable-rpmprefix=$rpm_label"
   ;;
  -n)
   run_prefix="echo "
   ;;
  -p)
   shift
   prefix=$1
   ;;
  -R)
   local_rpm_database=no
   ;;
  -s)
   shift
   source=$1
   ;;
  -t)
   shift
   targets=$1
   ;;
  -v)
   shift
   version=$1
   ;;
  --help)
   echo "$0 -cdinr -o <output> -h <hosts>" \
        "-l <rpm prefix> -p <prefix> -s <source> -t <targets> -v <version>"
   exit 2
   ;;
  *)
   terminate "error: invalid option (try --help): $1"
   ;;
 esac
 shift
done

for t in $targets;
do
 if [ -z "$(echo $target_list | grep $t)" ]; then
  terminate "error: invalid target: $t"
 fi
done

cd=${run_prefix}cd
configure=${run_prefix}${source}/configure
cp=${run_prefix}cp
make=${run_prefix}make
mkdir=${run_prefix}mkdir
rm=${run_prefix}rm
rpmbuild=${run_prefix}rpmbuild
rpm=${run_prefix}rpm

if [ $local_rpm_database = yes ]; then
  rpm_database="--dbpath $prefix/var/lib/rpm"
else
  rpm_database=
fi

echo " Source: $source"
echo " Prefix: $prefix"
echo "  Hosts: $hosts"
echo "Targets: $targets"

if [ ! -f $source/configure ]; then
 terminate "$source/configure not found under: $source"
fi

if [ x$prefix != x ]; then
 if [ -e $prefix ]; then
  if [ ! -d $prefix ]; then
   terminate "$prefix is not a directory"
  fi
 else
  echo "Creating $(pwd)"
  $mkdir -p $prefix
  check "making the prefix directory: $prefix"
 fi
fi

$cd $prefix
check "cannot change to the prefix directory: $prefix"

if [ $clean = yes ]; then
 echo "Cleaning: $(pwd)"
 $rm -rf *
fi

#
# Using a local RPM database means we do not need to be root to
# perform the build.
#
if [ $local_rpm_database = yes ]; then
 echo "Creating private RPM database: $(pwd)/var/lib/rpm"
 if [ ! -d /var/lib/rpm ]; then
  terminate "no RPM database found on this host"
  exit 1
 fi
 if [ ! -d var/lib ]; then
  $mkdir -p var/lib
  check "making the local RPM database directory: var/lib"
 fi
 if [ $clean = yes -o ! -e var/lib/rpmPackages ]; then
  echo "Coping RPM database to a local RPM database"
  $cp -r /var/lib/rpm var/lib/rpm
  check "coping the RPM database to the local database"
 fi
fi

#
# Set the path to the new directory.
#
export PATH=$prefix/bin:$PATH

#
# Install the RPM.
#

rpm_installer()
{
 local rpm_common=
 local rpm_libs=
 local rpm_tools=
 local r

 local rpm_database=$1
 shift
 local rpm_arch=$1
 shift
 local rpm_path=$1
 shift

 #
 # Get the names of the rpm files that have been built. This means we
 # do not have maintain version info.
 #
 rpm_names=$(rpmbuild $rpm_database $* --nobuild 2> /dev/null | \
             grep -v "debuginfo" | grep "Process" | sed 's/Process.*\: //')
 #
 # If we have a base place that one first then libs then the tools.
 #
 for r in $rpm_names
 do
  if [ $(echo $r | sed 's/.*common.*/yes/') = yes ]; then
   rpm_common="$rpm_common $r"
  elif [ $(echo $r | sed 's/.*lib.*/yes/') = yes ]; then
   rpm_libs="$rpm_libs $r"
  elif [ $(echo $r | sed 's/.*sys\-root.*/yes/') = yes ]; then
   rpm_libs="$rpm_libs $r"
  else
   rpm_tools="$rpm_tools $r"
  fi
 done

 for r in $rpm_common $rpm_libs $rpm_tools
 do
  echo "rpm $rpm_database --force" \
           "-i $rpm_path/$rpm_arch/$r.$rpm_arch.rpm"
  $rpm $rpm_database --force -i $rpm_path/$rpm_arch/$r.$rpm_arch.rpm
  check "installing the $r.$rpm_arch.rpm rpm failed"
 done
}

#
# Select the type of arch we have.
#

rpm_arch()
{
 if [ $(echo $1 | sed 's/.*api.*/yes/') = yes ]; then
  echo "noarch"
 elif [ $(echo $1 | sed 's/.*lib.*/yes/') = yes ]; then
  echo "noarch"
 elif [ $(echo $1 | sed 's/.*auto.*/yes/') = yes ]; then
  echo "noarch"
 else
  echo $2
 fi
}

#
# We always build tools for the build host. We need them to
# build the libraries for the target processor.
#
hosts="linux $hosts"

echo "Configuring target: all"
echo "configure --prefix=$prefix $rpm_prefix_arg " \
     " --target=all $infos"
$configure --prefix=$prefix $rpm_prefix_arg \
           --target=all \
           $infos
check "configuring the crossrpms failed"
echo "make"
$make
check "building the rpm spec files failed"
echo "make -C autotools"
$make -C autotools
check "building the rpm spec files failed"

for h in $hosts;
do
 #
 # Need to translate the build host to an RTEMS host. Create a
 # target host (th) and specs directory (sd) variable to handle
 # the use of RTEMS.
 #
 if [ $h = "linux" ]; then
  th="linux-gnu"
  sd=rtems$version
  canadian_cross=no
 else
  th=$h
  sd=$h
  canadian_cross=yes
 fi

 #
 # Associate the host to its tool list to get the packages to build.
 #
 tl=${h}_tool_list
 pl=${h}_cpu_list

 echo "Native Host Tools: ${!tl} for ${!pl}"
 echo "Canadian Cross: $canadian_cross ($t $h)"

 for p in ${!pl}
 do
  pth="$p-pc-$th"

  if [ $canadian_cross = yes ]; then
   echo "make -C $sd/$p"
   $make -C $sd/$p
   check "building the rpm spec files failed: $sd/$p"

   for s in ${!tl}
   do
    case $s in
     autoconf|automake)
      # Hack around the prefix in the spec files for autotools.
      ba="-ba $prefix/autotools/$rpm_prefix$s-rtems.spec"
      ;;
     *)
      ba="-ba $prefix/$sd/$p/$rpm_prefix$pth-$s.spec"
    esac

    rpmbuild_cmd="$ba --target=$build"

    echo "rpmbuild --define '_defaultdocdir $prefix/share/doc' $rpm_database $rpmbuild_cmd"
    $rpmbuild --define "_defaultdocdir $prefix/share/doc" $rpm_database $rpmbuild_cmd
    check "building the $sd/$p/$rpm_prefix$pth-$s rpm failed"

    rpm_installer "$rpm_database" \
                  $(rpm_arch $rpm_prefix$pth-$s $processor) \
                  $rpm_topdir/linux/RPMS \
                  $rpmbuild_cmd
   done
  fi
 done

 for t in $targets;
 do
  for s in ${rtems_tool_list}
  do
   case $s in
    autoconf|automake)
     # Hack around the prefix in the spec files for autotools.
     ba="-ba $prefix/autotools/$rpm_prefix$s-rtems.spec"
     ;;
    *)
     ba="-ba $prefix/rtems$version/$t/$rpm_prefix$t-rtems$version-$s.spec"
   esac

   rpmbuild_cmd="$ba --target=$pth"

   if [ $canadian_cross = yes ]; then
    ccl=${h}_cc_name
    echo "rpmbuild --define '_build $processor-redhat-linux' " \
         "--define '_host $pth' " \
         "--define '_defaultdocdir $prefix/share/doc' " \
         "$rpm_database $rpmbuild_cmd "
    $rpmbuild --define "_build $processor-redhat-linux" \
              --define "_host $pth" \
              --define "_defaultdocdir $prefix/share/doc" \
              --define "__cc $p-${!ccl}-$h-gcc" \
              $rpm_database $rpmbuild_cmd
    check "building host cross target: $rpm_prefix$t-rtems$version-$s"
   else
    echo "rpmbuild --define '_defaultdocdir $prefix/share/doc' "\
         "$rpm_database $rpmbuild_cmd"
    $rpmbuild --define "_defaultdocdir $prefix/share/doc" \
              $rpm_database $rpmbuild_cmd
    check "building host cross target: $rpm_prefix$t-rtems$version-$s"
   fi 

   if [ $canadian_cross != yes ]; then
    rpm_installer "$rpm_database" \
                  $(rpm_arch $rpm_prefix$t-rtems$version-$s $p) \
                  $rpm_topdir/$h/RPMS \
                  $rpmbuild_cmd
   fi
  done
 done
done