OSDN Git Service

* gen-all: Print options.
[pf3gnuchains/pf3gnuchains4x.git] / cgen / gen-all
1 #! /bin/sh
2 # Generate files for all apps,
3 # maybe build all apps,
4 # and produce a report listing differences from checked in copies.
5 #
6 # NOTE: This script doesn't rm -rf the previous run since it can run
7 # different tests.  If you want to start fresh, rm -rf tmp-all yourself.
8 #
9 # File ./gen-all.rc must exist and must define several env vars.
10 # It saves us from having to always pass the same long path names as
11 # parameters.
12 # The config file lives in "." instead of say "$HOME" so that multiple
13 # different configs are easily supported.
14 # Typical contents are:
15 #
16 ## Paths to src,gcc,rel relative to ${build_dir}.
17 #SRC_DIR="../../../src"
18 #GCC_DIR="../../../gcc"
19 #REL_DIR="../../.."
20 ## Location of mpc (gmp,mpfr taken from /usr/{include,lib}).
21 #MPC_DIR="$HOME/gnu/rel32/mpc-0.8.1"
22
23 set -e
24 trap "echo ERROR: $(date)" 0
25
26 all_args="$@"
27
28 if [ ! -f ./gen-all.rc ]
29 then
30     echo "Missing gen-all.rc file." >&2
31     exit
32 fi
33
34 source ./gen-all.rc
35
36 usage() {
37     echo "Usage:"
38     echo "  gen-all help"
39     echo "  gen-all [options] [todos] [apps]"
40     echo "  gen-all all"
41     echo ""
42     echo "Options:"
43     echo "cpus=\"space-separated-list-of-cpus\""
44     echo "force    Force cgen files to be regenerated"
45     echo ""
46     echo "Things-to-do:"
47     echo "config   Configure the tree"
48     echo "build    Build the tree"
49     echo "diffs    Generate diffs from what is checked in"
50     echo ""
51     echo "Applications:"
52     echo "binutils, gcc, newlib, sim, sid, intrinsics"
53     echo ""
54     echo "Notes:"
55     echo "\"all\" can be specified which means \"config, build, and diff everything\""
56     echo "Options, todos, and apps may be specified in any order."
57     echo ""
58     echo "Example:"
59     echo "sh gen-all build binutils diffs cpus=m32r"
60 }
61
62 # Parameters to configure.
63 MPC_CONFIG="--with-mpc=${MPC_DIR}"
64
65 # Set up any env vars we need, blech.
66 export LD_LIBRARY_PATH="${MPC_DIR}/lib"
67
68 build_all_target_sys="fr30-elf"
69
70 all_cgen_cpus="arm cris fr30 frv ip2k iq2000 lm32 m32c m32r mep mt \
71 openrisc sh sh64 xc16x xstormy16"
72
73 all_sid_cpus="arm m32r mep mt sh xstormy16"
74
75 do_force=no
76
77 do_config=no
78 do_build=no
79 do_diffs=no
80
81 do_binutils=no
82 do_gcc=no
83 do_newlib=no
84 do_sim=no
85 do_sid=no
86 do_intrinsics=no
87
88 cgen_cpus="${all_cgen_cpus}"
89 sid_cpus="${all_sid_cpus}"
90
91 # Parameter processing.
92
93 for a in "$@"
94 do
95     case $a in
96     help) usage ; trap "" 0 ; exit 0 ;;
97     cpus=*) cgen_cpus=${a/cpus=} sid_cpus=${cgen_cpus} ;;
98     force) do_force=yes ;;
99     config) do_config=yes ;;
100     build) do_build=yes ;;
101     diffs) do_diffs=yes ;;
102     binutils) do_binutils=yes ;;
103     gcc) do_gcc=yes ;;
104     newlib) do_newlib=yes ;;
105     sim) do_sim=yes ;;
106     sid) do_sid=yes ;;
107     intrinsics) do_intrinsics=yes ;;
108     all)
109         do_config=yes
110         do_build=yes
111         do_diffs=yes
112         do_binutils=yes
113         do_gcc=yes
114         do_newlib=yes
115         do_sim=yes
116         do_sid=yes
117         do_intrinsics=yes
118         ;;
119     *) echo "Invalid option: $a" >&2 ; exit 1 ;;
120     esac
121 done
122
123 if [ "${do_config}" = "no" -a "${do_build}" = "no" -a "${do_diffs}" = "no" ]
124 then
125     echo "Nothing to do." >&2
126     exit 1
127 fi
128
129 for c in ${cgen_cpus}
130 do
131     if echo " ${all_cgen_cpus} " | grep -q " ${c} "
132     then
133         : ok
134     else
135         echo "Invalid cgen cpu ${c}" >&2
136         exit 1
137     fi
138 done
139 if [ "${do_sid}" == "yes" ]
140 then
141     for c in ${sid_cpus}
142     do
143         if echo " ${all_sid_cpus} " | grep -q " ${c} "
144         then
145             : ok
146         else
147             echo "Invalid sid cpu ${c}" >&2
148             exit 1
149         fi
150     done
151 fi
152
153 # Utility functions.
154
155 config_src () {
156     target_sys=$1
157     prefix=$2
158
159     extra_config_args=""
160     if [ "${target_sys}" == "${build_all_target_sys}" ]
161     then
162         extra_config_args="${extra_config_args} --enable-targets=all"
163     fi
164
165     if [ -f Makefile ]
166     then
167         true # already configured
168     elif [ "${do_config}" = "yes" ]
169     then
170         echo "Configuring: $(date)"
171         ../${SRC_DIR}/configure \
172             --prefix=${prefix} \
173             --build=${build_sys} \
174             --host=${host_sys} \
175             --target=${target_sys} \
176             --enable-shared \
177             --enable-cgen-maint \
178             --enable-languages=c \
179             ${extra_config_args}
180     fi
181 }
182
183 config_gcc () {
184     target_sys=$1
185     prefix=$2
186
187     extra_config_args=""
188
189     if [ -f Makefile ]
190     then
191         true # already configured
192     elif [ "${do_config}" = "yes" ]
193     then
194         echo "Configuring: $(date)"
195         ../${GCC_DIR}/configure \
196             --prefix=${prefix} \
197             --build=${build_sys} \
198             --host=${host_sys} \
199             --target=${target_sys} \
200             --enable-languages=c \
201             ${MPC_CONFIG} \
202             ${extra_config_args}
203     fi
204 }
205
206 build_binutils () {
207     target_sys=$1
208     prefix=$2
209     PATH=${prefix}/bin:$PATH
210
211     if [ "${do_force}" = "yes" ]
212     then
213         touch ${SRC_DIR}/cgen/opcodes.scm
214     fi
215
216     echo "Building ${target_sys} binutils, $(date)"
217     mkdir -p tmp-src-${target_sys}
218     (
219         set -e
220         cd tmp-src-${target_sys}
221
222         config_src ${target_sys} ${prefix}
223
224         if [ "${do_build}" = "yes" ]
225         then
226             echo "Building: $(date)"
227             if [ ! -f Makefile ]
228             then
229                 echo "Tree hasn't been configured."
230                 exit 1
231             fi
232             make -j3 all-binutils all-gas all-ld
233             make -j1 install-binutils install-gas install-ld
234             echo "Build done: $(date)"
235         fi
236     )
237     if [ $? != 0 ] ; then exit 1 ; fi 
238 }
239
240 build_gcc () {
241     target_sys=$1
242     prefix=$2
243     PATH=${prefix}/bin:$PATH
244
245     echo "Building ${target_sys} gcc, $(date)"
246     mkdir -p tmp-gcc-${target_sys}
247     (
248         set -e
249         cd tmp-gcc-${target_sys}
250
251         config_gcc ${target_sys} ${prefix}
252
253         if [ "${do_build}" = "yes" ]
254         then
255             echo "Building: $(date)"
256             if [ ! -f Makefile ]
257             then
258                 echo "Tree hasn't been configured."
259                 exit 1
260             fi
261             make -j3 all-gcc
262             make -j1 install-gcc
263             # FIXME: The toplevel makefile doesn't find ${target}-gcc,
264             # it sets CC_FOR_TARGET to ${target}-cc.
265             rm -f ${prefix}/bin/${target_sys}-cc
266             ln -s ${target_sys}-gcc ${prefix}/bin/${target_sys}-cc
267             echo "Build done: $(date)"
268         fi
269     )
270     if [ $? != 0 ] ; then exit 1 ; fi 
271 }
272
273 build_newlib () {
274     target_sys=$1
275     prefix=$2
276     PATH=${prefix}/bin:$PATH
277
278     echo "Building ${target_sys} newlib, $(date)"
279     mkdir -p tmp-src-${target_sys}
280     (
281         set -e
282         cd tmp-src-${target_sys}
283
284         config_src ${target_sys} ${prefix}
285
286         if [ "${do_build}" = "yes" ]
287         then
288             echo "Building: $(date)"
289             if [ ! -f Makefile ]
290             then
291                 echo "Tree hasn't been configured."
292                 exit 1
293             fi
294             make -j3 all-target-newlib all-target-libgloss
295             make -j1 install-target-newlib install-target-libgloss
296             echo "Build done: $(date)"
297         fi
298     )
299     if [ $? != 0 ] ; then exit 1 ; fi 
300 }
301
302 build_sim () {
303     target_sys=$1
304     prefix=$2
305     PATH=${prefix}/bin:$PATH
306
307     if [ "${do_force}" = "yes" ]
308     then
309         touch ${SRC_DIR}/cgen/sim.scm
310     fi
311
312     echo "Building ${cpu} sim, $(date)"
313     mkdir -p tmp-src-${target_sys}
314     (
315         set -e
316         cd tmp-src-${target_sys}
317
318         config_src ${target_sys} ${prefix}
319
320         if [ "${do_build}" = "yes" ]
321         then
322             echo "Building: $(date)"
323             if [ ! -f Makefile ]
324             then
325                 echo "Tree hasn't been configured."
326                 exit 1
327             fi
328             make -j3 all-sim all-gdb
329             make -j1 install-sim install-gdb
330             echo "Build done: $(date)"
331         fi
332     )
333     if [ $? != 0 ] ; then exit 1 ; fi 
334 }
335
336 build_sid () {
337     target_sys=$1
338     prefix=$2
339     PATH=${prefix}/bin:$PATH
340
341     if [ "${do_force}" = "yes" ]
342     then
343         touch ${SRC_DIR}/cgen/sid.scm
344     fi
345
346     echo "Building ${cpu} sid, $(date)"
347     mkdir -p tmp-src-${target_sys}
348     (
349         set -e
350         cd tmp-src-${target_sys}
351
352         config_src ${target_sys} ${prefix}
353
354         if [ "${do_build}" = "yes" ]
355         then
356             echo "Building: $(date)"
357             if [ ! -f Makefile ]
358             then
359                 echo "Tree hasn't been configured."
360                 exit 1
361             fi
362             # SID doesn't support --enable-cgen-maint, sigh.
363             if [ ! -f sid/component/cgen-cpu/Makefile ]
364             then
365                 make -j3 configure-sid
366             fi
367             (cd sid/component/cgen-cpu && make cgen-all)
368             if [ $? != 0 ] ; then exit 1 ; fi
369             make -j3 all-sid
370             make -j1 install-sid
371             echo "Build done: $(date)"
372         fi
373     )
374     if [ $? != 0 ] ; then exit 1 ; fi 
375 }
376
377 build_intrinsics () {
378     if [ "${do_build}" = "yes" ]
379     then
380         echo "Building intrinsics: $(date)"
381         (cd ${SRC_DIR}/cgen && sh ./gen-all-intrinsics ${build_dir}/${GCC_DIR})
382         if [ $? != 0 ] ; then exit 1 ; fi
383         echo "Build done: $(date)"
384     fi
385 }
386
387 build_diffs () {
388     # NOTE: cvs will return with a non-zero exit code if there are diffs.
389     if [ "${do_binutils}" = "yes" ]
390     then
391         (cd ${SRC_DIR}/opcodes && cvs diff -du >${build_dir}/opcodes.diffs)
392     fi
393     if [ "${do_sim}" = "yes" ]
394     then
395         (cd ${SRC_DIR}/sim && cvs diff -du >${build_dir}/sim.diffs)
396     fi
397     if [ "${do_sid}" = "yes" ]
398     then
399         (cd ${SRC_DIR}/sid/component/cgen-cpu && cvs diff -du >${build_dir}/sid.diffs)
400     fi
401     if [ "${do_intrinsics}" = "yes" ]
402     then
403         (cd ${GCC_DIR}/gcc/config/mep && svn diff -x -u >${build_dir}/gcc.diffs)
404     fi
405 }
406
407 # And we're off.
408
409 echo "Starting gen-all: $(date)"
410 # Print the command line to make it easier to review old builds.
411 echo "Options: ${all_args}"
412
413 mkdir -p tmp-all
414 cd tmp-all
415 build_dir=$(pwd)
416
417 # We can't call config.guess until we've cd'd into the build_dir because
418 # SRC_DIR, if relative, is relative to build_dir.
419 build_sys=$(sh ${SRC_DIR}/config.guess)
420 host_sys=${build_sys}
421
422 for cpu in ${cgen_cpus}
423 do
424     # FIXME: arm-eabi is preferred over arm-elf
425     target_sys=${cpu}-elf
426     prefix=$(cd ${REL_DIR} && pwd -P)/rel-${target_sys}
427     [ $? != 0 ] && { echo "Error setting prefix" >&2 ; exit 1 ; }
428     mkdir -p ${prefix}
429
430     if [ "${do_binutils}" = "yes" ]
431     then
432         build_binutils ${target_sys} ${prefix}
433     fi
434
435     if [ "${do_sim}" = "yes" ]
436     then
437         build_sim ${target_sys} ${prefix}
438     fi
439
440     if [ "${do_gcc}" = "yes" ]
441     then
442         # GCC doesn't support some cpus that cgen supports.
443         case ${target_sys} in
444         ip2k-*) ;;
445         mt-*) ;;
446         openrisc-* | or32-*) ;;
447         xc16x-*) ;;
448         *) build_gcc ${target_sys} ${prefix} ;;
449         esac
450     fi
451
452     if [ "${do_newlib}" = "yes" ]
453     then
454         # Newlib doesn't support some cpus that cgen supports.
455         # We also can't build newlib if we don't have gcc.
456         case ${target_sys} in
457         ip2k-*) ;;
458         mt-*) ;;
459         openrisc-* | or32-*) ;;
460         xc16x-*) ;;
461         *) build_newlib ${target_sys} ${prefix} ;;
462         esac
463     fi
464 done
465
466 for cpu in ${sid_cpus}
467 do
468     # FIXME: arm-eabi is preferred over arm-elf
469     target_sys=${cpu}-elf
470     prefix=$(cd ${REL_DIR} && pwd -P)/rel-${target_sys}
471     [ $? != 0 ] && { echo "Error setting prefix" >&2 ; exit 1 ; }
472     mkdir -p ${prefix}
473
474     if [ "${do_sid}" = "yes" ]
475     then
476         build_sid ${target_sys} ${prefix}
477     fi
478 done
479
480 if [ "${do_intrinsics}" = "yes" ]
481 then
482     build_intrinsics ${target_sys} ${prefix}
483 fi
484
485 if [ "${do_diffs}" = "yes" ]
486 then
487     build_diffs ${target_sys} ${prefix}
488 fi
489
490 echo "Ending gen-all: $(date)"
491 trap "" 0