1 : |
blume |
691 |
#!@SHELL@
|
2 : |
|
|
|
3 : |
|
|
BIN_DIR=@BINDIR@
|
4 : |
|
|
SML=$BIN_DIR/sml
|
5 : |
|
|
|
6 : |
|
|
mf=""
|
7 : |
|
|
xx=$$
|
8 : |
|
|
tmpmf=$xx-makefile
|
9 : |
|
|
mlscript=$xx-mlscript.sml
|
10 : |
|
|
thisscript=$0
|
11 : |
|
|
|
12 : |
|
|
trap 'rm -f $tmpmf $mlscript' 0 1 2 3 15
|
13 : |
|
|
|
14 : |
|
|
usage() {
|
15 : |
|
|
echo $thisscript: $*
|
16 : |
|
|
echo Usage: $thisscript '[-f makefile]' cmfile targetname
|
17 : |
|
|
exit 1
|
18 : |
|
|
}
|
19 : |
|
|
|
20 : |
|
|
#
|
21 : |
|
|
# process -f option if it is given
|
22 : |
|
|
#
|
23 : |
|
|
if [ $# != 0 ] ; then
|
24 : |
|
|
if [ "$1" = "-f" ] ; then
|
25 : |
|
|
shift
|
26 : |
|
|
if [ $# = 0 ] ; then
|
27 : |
|
|
usage
|
28 : |
|
|
else
|
29 : |
|
|
mf=$1
|
30 : |
|
|
shift
|
31 : |
|
|
if [ -f "$mf" ] ; then
|
32 : |
|
|
: ok
|
33 : |
|
|
else
|
34 : |
|
|
echo $thisscript: $mf does not exist
|
35 : |
|
|
exit 1
|
36 : |
|
|
fi
|
37 : |
|
|
fi
|
38 : |
|
|
fi
|
39 : |
|
|
fi
|
40 : |
|
|
|
41 : |
|
|
#
|
42 : |
|
|
# if there was no -f option, check for makefile and then Makefile
|
43 : |
|
|
#
|
44 : |
|
|
if [ x$mf = x ] ; then
|
45 : |
|
|
if [ -f makefile ] ; then
|
46 : |
|
|
mf=makefile
|
47 : |
|
|
elif [ -f Makefile ] ; then
|
48 : |
|
|
mf=Makefile
|
49 : |
|
|
else
|
50 : |
|
|
echo $thisscript: no makefile, no Makefile, and no -f option
|
51 : |
|
|
exit 1
|
52 : |
|
|
fi
|
53 : |
|
|
fi
|
54 : |
|
|
|
55 : |
|
|
#
|
56 : |
|
|
# get the two mandatory arguments
|
57 : |
|
|
#
|
58 : |
|
|
if [ $# = 2 ] ; then
|
59 : |
|
|
cmfile=$1
|
60 : |
|
|
target=$2
|
61 : |
|
|
else
|
62 : |
|
|
usage
|
63 : |
|
|
fi
|
64 : |
|
|
|
65 : |
|
|
#
|
66 : |
|
|
# the delimiter strings (start and end)
|
67 : |
|
|
#
|
68 : |
|
|
delims="# START: ml-makedepend (${cmfile}:${target}); DO NOT DELETE!"
|
69 : |
|
|
delime="# END : ml-makedepend (${cmfile}:${target}); DO NOT DELETE!"
|
70 : |
|
|
|
71 : |
|
|
#
|
72 : |
|
|
# remove previous result of ml-makedepend
|
73 : |
|
|
# (other cmfile/target combinations are unaffected)
|
74 : |
|
|
#
|
75 : |
|
|
awk "BEGIN { c = 1; s = \"${delims}\"; e = \"${delime}\"; }
|
76 : |
|
|
(\$0 == s) { c = 0; continue; }
|
77 : |
|
|
(\$0 == e) { c = 1; continue; }
|
78 : |
|
|
(c == 1) { print }" <$mf >$tmpmf
|
79 : |
|
|
cp $tmpmf $mf
|
80 : |
|
|
rm $tmpmf
|
81 : |
|
|
|
82 : |
|
|
#
|
83 : |
|
|
# construct the ML script
|
84 : |
|
|
#
|
85 : |
|
|
cat >$mlscript <<stop
|
86 : |
|
|
let val archos = SOME { arch = "\$(ARCH)", os = "\$(OPSYS)" }
|
87 : |
|
|
val lopt = CM.sources archos "${cmfile}"
|
88 : |
|
|
in
|
89 : |
|
|
case lopt of
|
90 : |
|
|
NONE => ignore (OS.Process.exit OS.Process.failure)
|
91 : |
|
|
| SOME l => let
|
92 : |
|
|
val s = TextIO.openOut "$tmpmf"
|
93 : |
|
|
fun pr { derived = true, file, class } = ()
|
94 : |
|
|
| pr { file, ... } = TextIO.output (s, " \\\\\\n " ^ file)
|
95 : |
|
|
in
|
96 : |
|
|
TextIO.output (s, "${delims}\\n${target}:");
|
97 : |
|
|
app pr l;
|
98 : |
|
|
TextIO.output (s, "\\n${delime}\\n");
|
99 : |
|
|
TextIO.closeOut s;
|
100 : |
|
|
ignore (OS.Process.exit OS.Process.success)
|
101 : |
|
|
end
|
102 : |
|
|
end
|
103 : |
|
|
stop
|
104 : |
|
|
|
105 : |
|
|
if $SML '$smlnj/cm.cm' $mlscript >/dev/null 2>&1 ; then
|
106 : |
|
|
cat $tmpmf >>$mf
|
107 : |
|
|
else
|
108 : |
|
|
echo $thisscript: CM dependency analysis failed
|
109 : |
|
|
exit 1
|
110 : |
|
|
fi
|
111 : |
|
|
|
112 : |
|
|
exit 0
|