3 # usage: get-cm work_dir
5 # Find all .cm Group and Library descriptions that are referenced
6 # from the top level alias files in $SML_BASE/lib/
9 tmpfile="${TMP:-/tmp}/chomp$$"
11 # attempt to change directory to work dir
13 work_dir=`pwd` # get the canonical name for the current directory
15 trap "rm -f $tmpfile" 0 1 2 3 15
17 # hack to remove SML comments '(* ... *)'
21 # caveat: the following assumes gcc is present ...
22 gcc -x c -E -P -ansi -DOPSYS_UNIX $1 | awk '{
24 if (match(line, "\\(\\*")) {
25 while (match($0, "\\(\\*")) {
27 print substr($0, 0, RSTART-1);
30 while (!match($0, "\\*\\)")) {
33 $0 = substr($0, RSTART+RLENGTH);
40 # return canonical name for a path with embedded ..'s
44 echo $(cd `dirname $1` && pwd)/`basename $1`
47 # initial list of CM description files
48 global_cm_list="$(cat ./lib/*.cm | awk '{ print $2 }')"
50 set -- $global_cm_list
54 # process the global list
55 while [ $# -ge 1 ]; do
60 echo $cm_file >> $tmpfile
62 cm_dir=`dirname $cm_file`
63 cm_new=$(strip_comments $cm_file | grep '\.cm' | \
66 # append new CM files to current global list
68 new_cm_file=$(canonical $cm_dir/$i)
69 if [ -r $new_cm_file ]; then
70 if ! grep "^$new_cm_file" $tmpfile > /dev/null; then
71 global_cm_list="$new_cm_file $global_cm_list"
72 echo $new_cm_file >> $tmpfile
77 set -- $global_cm_list
81 sort -u < $tmpfile | sed -e "s,^$work_dir/,,"