[1a768ef] | 1 | #! /bin/sh |
---|
[ed70a496] | 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 | |
---|
| 16 | terminate() |
---|
| 17 | { |
---|
| 18 | echo "error: $*" >&2 |
---|
| 19 | exit 1 |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | check() |
---|
| 23 | { |
---|
| 24 | if [ $? -ne 0 ]; then |
---|
| 25 | terminate |
---|
| 26 | fi |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | processor=$(uname -p) |
---|
| 30 | |
---|
| 31 | version=4.7 |
---|
| 32 | |
---|
| 33 | base_tool_list="binutils gcc" |
---|
| 34 | |
---|
[a2d7c41] | 35 | target_list="arm avr h8300 i386 m68k mips powerpc sh sparc tic4x" |
---|
[ed70a496] | 36 | host_list="cygwin freebsd5.2 freebsd6.0 freebsd6.1 mingw32" |
---|
| 37 | |
---|
| 38 | rtems_tool_list="$base_tool_list" |
---|
[a2d7c41] | 39 | linux_tool_list="autoconf automake $base_tool_list" |
---|
| 40 | cygwin_tool_list="w32api libs autoconf automake $base_tool_list" |
---|
| 41 | freebsd_tool_list="libs autoconf automake $base_tool_list" |
---|
| 42 | mingw32_tool_list="w32api libs autoconf automake $base_tool_list" |
---|
[ed70a496] | 43 | |
---|
[1a768ef] | 44 | cygwin_cc_name="pc" |
---|
| 45 | freebsd_cc_name="pc" |
---|
| 46 | mingw32_cc_name="pc" |
---|
| 47 | |
---|
[72eb02e] | 48 | linux_cpu_list="$processor" |
---|
[ed70a496] | 49 | cygwin_cpu_list="i686" |
---|
| 50 | freebsd_cpu_list="i586" |
---|
| 51 | mingw32_cpu_list="i686" |
---|
| 52 | |
---|
[1a768ef] | 53 | rpm_topdir=$(rpm --eval "%{_topdir}") |
---|
[ed70a496] | 54 | |
---|
[a2d7c41] | 55 | prefix=/opt/rtems-$version |
---|
[ed70a496] | 56 | hosts=$host_list |
---|
| 57 | build=$processor-linux-gnu |
---|
| 58 | infos= |
---|
| 59 | targets=$target_list |
---|
| 60 | run_prefix= |
---|
| 61 | rpm_prefix=custom- |
---|
| 62 | rpm_prefix_arg= |
---|
| 63 | local_rpm_database=yes |
---|
| 64 | clean=yes |
---|
| 65 | source=$(pwd) |
---|
| 66 | |
---|
| 67 | while [ $# -gt 0 ]; |
---|
| 68 | do |
---|
| 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 |
---|
| 120 | done |
---|
| 121 | |
---|
| 122 | for t in $targets; |
---|
| 123 | do |
---|
| 124 | if [ -z "$(echo $target_list | grep $t)" ]; then |
---|
| 125 | terminate "error: invalid target: $t" |
---|
| 126 | fi |
---|
| 127 | done |
---|
| 128 | |
---|
| 129 | cd=${run_prefix}cd |
---|
| 130 | configure=${run_prefix}${source}/configure |
---|
| 131 | cp=${run_prefix}cp |
---|
| 132 | make=${run_prefix}make |
---|
| 133 | mkdir=${run_prefix}mkdir |
---|
| 134 | rm=${run_prefix}rm |
---|
| 135 | rpmbuild=${run_prefix}rpmbuild |
---|
| 136 | rpm=${run_prefix}rpm |
---|
| 137 | |
---|
| 138 | if [ $local_rpm_database = yes ]; then |
---|
| 139 | rpm_database="--dbpath $prefix/var/lib/rpm" |
---|
| 140 | else |
---|
| 141 | rpm_database= |
---|
| 142 | fi |
---|
| 143 | |
---|
| 144 | echo " Source: $source" |
---|
| 145 | echo " Prefix: $prefix" |
---|
| 146 | echo " Hosts: $hosts" |
---|
| 147 | echo "Targets: $targets" |
---|
| 148 | |
---|
| 149 | if [ ! -f $source/configure ]; then |
---|
| 150 | terminate "$source/configure not found under: $source" |
---|
| 151 | fi |
---|
| 152 | |
---|
| 153 | if [ 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)" |
---|
[72eb02e] | 160 | $mkdir -p $prefix |
---|
[ed70a496] | 161 | check "making the prefix directory: $prefix" |
---|
| 162 | fi |
---|
| 163 | fi |
---|
| 164 | |
---|
| 165 | $cd $prefix |
---|
| 166 | check "cannot change to the prefix directory: $prefix" |
---|
| 167 | |
---|
| 168 | if [ $clean = yes ]; then |
---|
| 169 | echo "Cleaning: $(pwd)" |
---|
| 170 | $rm -rf * |
---|
| 171 | fi |
---|
| 172 | |
---|
| 173 | # |
---|
| 174 | # Using a local RPM database means we do not need to be root to |
---|
| 175 | # perform the build. |
---|
| 176 | # |
---|
| 177 | if [ $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 |
---|
| 192 | fi |
---|
| 193 | |
---|
| 194 | # |
---|
| 195 | # Set the path to the new directory. |
---|
| 196 | # |
---|
| 197 | export PATH=$prefix/bin:$PATH |
---|
| 198 | |
---|
| 199 | # |
---|
| 200 | # Install the RPM. |
---|
| 201 | # |
---|
| 202 | |
---|
| 203 | rpm_installer() |
---|
| 204 | { |
---|
[1a768ef] | 205 | local rpm_common= |
---|
[ed70a496] | 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 |
---|
[1a768ef] | 228 | if [ $(echo $r | sed 's/.*common.*/yes/') = yes ]; then |
---|
| 229 | rpm_common="$rpm_common $r" |
---|
[ed70a496] | 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 | |
---|
[1a768ef] | 239 | for r in $rpm_common $rpm_libs $rpm_tools |
---|
[ed70a496] | 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 | |
---|
| 252 | rpm_arch() |
---|
| 253 | { |
---|
[a2d7c41] | 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 |
---|
[ed70a496] | 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 | # |
---|
| 269 | hosts="linux $hosts" |
---|
| 270 | |
---|
[72eb02e] | 271 | echo "Configuring target: all" |
---|
[ed70a496] | 272 | echo "configure --prefix=$prefix $rpm_prefix_arg " \ |
---|
| 273 | " --target=all $infos" |
---|
| 274 | $configure --prefix=$prefix $rpm_prefix_arg \ |
---|
| 275 | --target=all \ |
---|
| 276 | $infos |
---|
| 277 | check "configuring the crossrpms failed" |
---|
| 278 | echo "make" |
---|
| 279 | $make |
---|
| 280 | check "building the rpm spec files failed" |
---|
[a2d7c41] | 281 | echo "make -C autotools" |
---|
| 282 | $make -C autotools |
---|
| 283 | check "building the rpm spec files failed" |
---|
[ed70a496] | 284 | |
---|
[a2d7c41] | 285 | for h in $hosts; |
---|
[ed70a496] | 286 | do |
---|
[a2d7c41] | 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} |
---|
[ed70a496] | 312 | do |
---|
[a2d7c41] | 313 | pth="$p-pc-$th" |
---|
[ed70a496] | 314 | |
---|
[a2d7c41] | 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" |
---|
[ed70a496] | 319 | |
---|
[a2d7c41] | 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 |
---|
[ed70a496] | 344 | |
---|
[a2d7c41] | 345 | for t in $targets; |
---|
| 346 | do |
---|
| 347 | for s in ${rtems_tool_list} |
---|
[72eb02e] | 348 | do |
---|
[a2d7c41] | 349 | rpmbuild_cmd="-ba $prefix/rtems$version/$t/$rpm_prefix$t-rtems$version-$s.spec --target=$pth" |
---|
[ed70a496] | 350 | |
---|
[72eb02e] | 351 | if [ $canadian_cross = yes ]; then |
---|
[a2d7c41] | 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 |
---|
[72eb02e] | 371 | fi |
---|
[ed70a496] | 372 | done |
---|
| 373 | done |
---|
| 374 | done |
---|