Last active
September 23, 2023 20:44
-
-
Save DarinM223/ae46bcb59284fdde36e1e28163705eae to your computer and use it in GitHub Desktop.
Loads all the dependencies of a smi file and then runs the command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cat > build.smi <<EOL | |
_require "basis.smi" | |
_require "smlnj-lib.smi" | |
EOL | |
cat > build.sml <<EOL | |
signature PACK_REAL = sig | |
type real | |
val bytesPerElem : int | |
val isBigEndian : bool | |
val toBytes : real -> Word8Vector.vector | |
val fromBytes : Word8Vector.vector -> real | |
val subVec : Word8Vector.vector * int -> real | |
val subArr : Word8Array.array * int -> real | |
val update : Word8Array.array * int * real -> unit | |
end | |
signature PACK_WORD = sig | |
val bytesPerElem : int | |
val isBigEndian : bool | |
val subVec : Word8Vector.vector * int -> LargeWord.word | |
val subVecX : Word8Vector.vector * int -> LargeWord.word | |
val subArr : Word8Array.array * int -> LargeWord.word | |
val subArrX : Word8Array.array * int -> LargeWord.word | |
val update : Word8Array.array * int * LargeWord.word | |
-> unit | |
end | |
EOL | |
mlton -stop f project.mlb \ | |
| grep -v ".mlb" \ | |
| grep -v "/lib/mlton/sml/" \ | |
| grep -v "/lib/mlton/targets/" \ | |
| while read line ; do \ | |
if [[ $line == *.mlton.sml ]] ; then \ | |
if [ -f "${line/%.mlton.sml/.polyml.sml}" ]; then \ | |
echo "_use \"${line/%.mlton.sml/.polyml.sml}\"" ; \ | |
elif [ -f "${line/%.mlton.sml/.default.sml}" ]; then \ | |
echo "_use \"${line/%.mlton.sml/.default.sml}\"" ; \ | |
elif [ -f "${line/%.mlton.sml/.common.sml}" ]; then \ | |
echo "_use \"${line/%.mlton.sml/.common.sml}\"" ; \ | |
elif [ -f "${line/%.mlton.sml/.sml}" ]; then \ | |
echo "_use \"${line/%.mlton.sml/.sml}\"" ; \ | |
fi \ | |
elif [[ $line == *.mlton.fun ]] ; then \ | |
if [ -f "${line/%.mlton.fun/.polyml.fun}" ]; then \ | |
echo "_use \"${line/%.mlton.fun/.polyml.fun}\"" ; \ | |
elif [ -f "${line/%.mlton.fun/.default.fun}" ]; then \ | |
echo "_use \"${line/%.mlton.fun/.default.fun}\"" ; \ | |
elif [ -f "${line/%.mlton.fun/.common.fun}" ]; then \ | |
echo "_use \"${line/%.mlton.fun/.common.fun}\"" ; \ | |
elif [ -f "${line/%.mlton.fun/.fun}" ]; then \ | |
echo "_use \"${line/%.mlton.fun/.fun}\"" ; \ | |
fi \ | |
elif [[ $line == *.mlton.sig ]] ; then \ | |
if [ -f "${line/%.mlton.sig/.polyml.sig}" ]; then \ | |
echo "_use \"${line/%.mlton.sig/.polyml.sig}\"" ; \ | |
elif [ -f "${line/%.mlton.sig/.default.sig}" ]; then \ | |
echo "_use \"${line/%.mlton.sig/.default.sig}\"" ; \ | |
elif [ -f "${line/%.mlton.sig/.common.sig}" ]; then \ | |
echo "_use \"${line/%.mlton.sig/.common.sig}\"" ; \ | |
elif [ -f "${line/%.mlton.sig/.sig}" ]; then \ | |
echo "_use \"${line/%.mlton.sig/.sig}\"" ; \ | |
fi \ | |
else\ | |
echo "_use \"$line\"" ; \ | |
fi \ | |
done \ | |
>> build.sml | |
mlton -stop f project.mlb \ | |
| grep -v ".mlb" \ | |
| grep -v "/lib/mlton/sml/" \ | |
| grep -v "/lib/mlton/targets/" \ | |
| while read line ; do \ | |
if [[ $line == *.mlton.sml ]] ; then \ | |
if [ -f "${line/%.mlton.sml/.polyml.sml}" ]; then \ | |
echo "_use local \"${line/%.mlton.sml/.polyml.sml}\"" ; \ | |
elif [ -f "${line/%.mlton.sml/.default.sml}" ]; then \ | |
echo "_use local \"${line/%.mlton.sml/.default.sml}\"" ; \ | |
elif [ -f "${line/%.mlton.sml/.common.sml}" ]; then \ | |
echo "_use local \"${line/%.mlton.sml/.common.sml}\"" ; \ | |
elif [ -f "${line/%.mlton.sml/.sml}" ]; then \ | |
echo "_use local \"${line/%.mlton.sml/.sml}\"" ; \ | |
fi \ | |
elif [[ $line == *.mlton.fun ]] ; then \ | |
if [ -f "${line/%.mlton.fun/.polyml.fun}" ]; then \ | |
echo "_use local \"${line/%.mlton.fun/.polyml.fun}\"" ; \ | |
elif [ -f "${line/%.mlton.fun/.default.fun}" ]; then \ | |
echo "_use local\"${line/%.mlton.fun/.default.fun}\"" ; \ | |
elif [ -f "${line/%.mlton.fun/.common.fun}" ]; then \ | |
echo "_use local \"${line/%.mlton.fun/.common.fun}\"" ; \ | |
elif [ -f "${line/%.mlton.fun/.fun}" ]; then \ | |
echo "_use local \"${line/%.mlton.fun/.fun}\"" ; \ | |
fi \ | |
elif [[ $line == *.mlton.sig ]] ; then \ | |
if [ -f "${line/%.mlton.sig/.polyml.sig}" ]; then \ | |
echo "_use local \"${line/%.mlton.sig/.polyml.sig}\"" ; \ | |
elif [ -f "${line/%.mlton.sig/.default.sig}" ]; then \ | |
echo "_use local \"${line/%.mlton.sig/.default.sig}\"" ; \ | |
elif [ -f "${line/%.mlton.sig/.common.sig}" ]; then \ | |
echo "_use local \"${line/%.mlton.sig/.common.sig}\"" ; \ | |
elif [ -f "${line/%.mlton.sig/.sig}" ]; then \ | |
echo "_use local \"${line/%.mlton.sig/.sig}\"" ; \ | |
fi \ | |
else\ | |
echo "_use local \"$line\"" ; \ | |
fi \ | |
done \ | |
>> build.smi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deps=$(printf "\n"; smlsharp -MMl "$1" | tr " " "\n" | grep ".smi") | |
deps=$(echo "$deps" | sed ':a; N; $!ba; s/\n/\ -r\ /g') | |
shift 1 | |
echo "$deps" | |
if [ "$*" = "" ] ; | |
then | |
smlsharp $deps | |
else | |
echo "$@" \ | |
| smlsharp $deps \ | |
| sed "/val/s/=$//g" \ | |
| sed "/val/s/=.*:/:/g" \ | |
| sed "s/fn\ :/:/g" \ | |
| sed "s/<builtin>//g" \ | |
| grep -v "^ *fn *$" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment