-
Notifications
You must be signed in to change notification settings - Fork 3
/
with-mlb-dependencies
executable file
·77 lines (67 loc) · 2.14 KB
/
with-mlb-dependencies
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
#
# with-mlb-dependencies - run a (presumed) compiler command, while also
# dumping out a dependency file. Intended for Meson build integration.
#
# Chris Cannam, 2020. MIT licence
set -e
if [ -z "$1" ]; then
myname=$(basename "$0")
echo 1>&2
echo "Usage: $myname <buildcommand> <buildargs>" 1>&2
echo 1>&2
echo "First runs the supplied build command with the supplied build arguments;" 1>&2
echo "then scans the build arguments, locating the first argument that names an .mlb" 1>&2
echo "or .sml file, and writes out the dependency list for that file to a" 1>&2
echo "similarly-named .deps file in the same location." 1>&2
echo 1>&2
echo "Example: $myname mlton program.mlb" 1>&2
echo 1>&2
echo "The above example runs mlton with the argument program.mlb; if that was" 1>&2
echo "successful, it then writes out a dependency file called program.deps," 1>&2
echo "containing a list of the input files which the target program depends on," 1>&2
echo "in Makefile dependency syntax." 1>&2
echo 1>&2
echo "This program also looks for the -o, -output, and -mlb-path-var options in the" 1>&2
echo "build arguments and interprets them appropriately." 1>&2
exit 2
fi
set -u
mydir=$(dirname "$0")
. "$mydir/smlbuild-include.sh"
arg=""
output=""
env_args=
expecting_pathvar=false
expecting_output=false
for x in "$@" ; do
if [ "$expecting_pathvar" = "true" ]; then
env_args="$env_args $(echo $x |sed 's/ /=/')"
expecting_pathvar=false
elif [ "$expecting_output" = "true" ]; then
output="$x"
expecting_output=false
else
case "$x" in
*.mlb) arg="$x";;
*.sml) arg="$x";;
-mlb-path-var) expecting_pathvar=true;;
-o) expecting_output=true;;
-output) expecting_output=true;;
*) ;;
esac
if [ -n "$arg" ]; then
break
fi
fi
done
"$@" || exit 1
if [ -z "$output" ]; then
output=$(get_outfile "$arg")
fi
deps="$output".deps
shift
env $env_args \
"$mydir/mlb-dependencies" "$arg" | \
sed 's|^[^:]*: |'"$output: "'|' \
> "$deps"