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 | |
---|
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 | |
---|
35 | target_list="i386 m68k powerpc sparc arm mips" |
---|
36 | host_list="cygwin freebsd5.2 freebsd6.0 freebsd6.1 mingw32" |
---|
37 | |
---|
38 | rtems_tool_list="$base_tool_list" |
---|
39 | linux_tool_list="$base_tool_list" |
---|
40 | cygwin_tool_list="w32api libs $base_tool_list" |
---|
41 | freebsd_tool_list="libs $base_tool_list" |
---|
42 | mingw32_tool_list="w32api libs $base_tool_list" |
---|
43 | |
---|
44 | cygwin_cc_name="pc" |
---|
45 | freebsd_cc_name="pc" |
---|
46 | mingw32_cc_name="pc" |
---|
47 | |
---|
48 | linux_cpu_list="$processor" |
---|
49 | cygwin_cpu_list="i686" |
---|
50 | freebsd_cpu_list="i586" |
---|
51 | mingw32_cpu_list="i686" |
---|
52 | |
---|
53 | rpm_topdir=$(rpm --eval "%{_topdir}") |
---|
54 | |
---|
55 | prefix=/opt/rtems |
---|
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)" |
---|
160 | $mkdir -p $prefix |
---|
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 | { |
---|
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 | |
---|
252 | rpm_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 | else |
---|
259 | echo $2 |
---|
260 | fi |
---|
261 | } |
---|
262 | |
---|
263 | # |
---|
264 | # We always build tools for the build host. We need them to |
---|
265 | # build the libraries for the target processor. |
---|
266 | # |
---|
267 | hosts="linux $hosts" |
---|
268 | |
---|
269 | echo "Configuring target: all" |
---|
270 | echo "configure --prefix=$prefix $rpm_prefix_arg " \ |
---|
271 | " --target=all $infos" |
---|
272 | $configure --prefix=$prefix $rpm_prefix_arg \ |
---|
273 | --target=all \ |
---|
274 | $infos |
---|
275 | check "configuring the crossrpms failed" |
---|
276 | echo "make" |
---|
277 | $make |
---|
278 | check "building the rpm spec files failed" |
---|
279 | |
---|
280 | for t in $targets; |
---|
281 | do |
---|
282 | for h in $hosts; |
---|
283 | do |
---|
284 | # |
---|
285 | # Need to translate the build host to an RTEMS host. Create a |
---|
286 | # target host (th) and specs directory (sd) variable to handle |
---|
287 | # the use of RTEMS. |
---|
288 | # |
---|
289 | if [ $h = "linux" ]; then |
---|
290 | th="linux-gnu" |
---|
291 | sd=rtems$version |
---|
292 | canadian_cross=no |
---|
293 | else |
---|
294 | th=$h |
---|
295 | sd=$h |
---|
296 | canadian_cross=yes |
---|
297 | fi |
---|
298 | |
---|
299 | # |
---|
300 | # Associate the host to its tool list to get the packages to build. |
---|
301 | # |
---|
302 | tl=${h}_tool_list |
---|
303 | pl=${h}_cpu_list |
---|
304 | |
---|
305 | echo "Native Host Tools: ${!tl} for ${!pl}" |
---|
306 | echo "Canadian Cross: $canadian_cross ($t $h)" |
---|
307 | |
---|
308 | for p in ${!pl} |
---|
309 | do |
---|
310 | pth="$p-pc-$th" |
---|
311 | |
---|
312 | if [ $canadian_cross = yes ]; then |
---|
313 | echo "make -C $sd/$p" |
---|
314 | $make -C $sd/$p |
---|
315 | check "building the rpm spec files failed: $sd/$p" |
---|
316 | |
---|
317 | for s in ${!tl} |
---|
318 | do |
---|
319 | rpmbuild_cmd="-ba $prefix/$sd/$p/$rpm_prefix$pth-$s.spec --target=$build" |
---|
320 | |
---|
321 | echo "rpmbuild $rpm_database $rpmbuild_cmd" |
---|
322 | $rpmbuild $rpm_database $rpmbuild_cmd |
---|
323 | check "building the $sd/$p/$rpm_prefix$pth-$s rpm failed" |
---|
324 | |
---|
325 | rpm_installer "$rpm_database" \ |
---|
326 | $(rpm_arch $rpm_prefix$pth-$s $processor) \ |
---|
327 | $rpm_topdir/linux/RPMS \ |
---|
328 | $rpmbuild_cmd |
---|
329 | done |
---|
330 | fi |
---|
331 | |
---|
332 | for s in ${rtems_tool_list} |
---|
333 | do |
---|
334 | rpmbuild_cmd="-ba $prefix/rtems$version/$t/$rpm_prefix$t-rtems$version-$s.spec --target=$pth" |
---|
335 | |
---|
336 | if [ $canadian_cross = yes ]; then |
---|
337 | ccl=${h}_cc_name |
---|
338 | echo "rpmbuild --define '_build $processor-redhat-linux' --define '_host $pth' $rpm_database $rpmbuild_cmd" |
---|
339 | $rpmbuild --define "_build $processor-redhat-linux" \ |
---|
340 | --define "_host $pth" \ |
---|
341 | --define "__cc $p-${!ccl}-$h-gcc" \ |
---|
342 | $rpm_database $rpmbuild_cmd |
---|
343 | check "building host cross target: $rpm_prefix$t-rtems$version-$s" |
---|
344 | else |
---|
345 | echo "rpmbuild $rpm_database $rpmbuild_cmd" |
---|
346 | $rpmbuild $rpm_database $rpmbuild_cmd |
---|
347 | check "building host cross target: $rpm_prefix$t-rtems$version-$s" |
---|
348 | fi |
---|
349 | |
---|
350 | if [ $canadian_cross != yes ]; then |
---|
351 | rpm_installer "$rpm_database" \ |
---|
352 | $(rpm_arch $rpm_prefix$t-rtems$version-$s $p) \ |
---|
353 | $rpm_topdir/$h/RPMS \ |
---|
354 | $rpmbuild_cmd |
---|
355 | fi |
---|
356 | done |
---|
357 | done |
---|
358 | done |
---|
359 | done |
---|