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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
#!/usr/bin/env bash
set -e
# This script adds a new crosscompiler target for MLton.
#
# It takes four arguments.
#
# 1. <crossTarget>, which is what MLton would pass via the -b flag to the GCC
# cross-compiler tools. You don't need to have installed these tools in order
# to run this script, since it uses ssh and the native gcc on the target.
# Examples of $crossTarget are i386-pc-cygwin and sparc-sun-solaris.
#
# 2. <crossArch> specifies the target architecture.
#
# 3. <crossOS> specifies the target OS.
#
# 4. <machine> specifies a remote machine of the target type. This script
# will ssh to $machine to compile the runtime and to compile and run the
# program that will print the values of all the constants that the MLton
# basis library needs.
#
# Here are some example uses of this script.
#
# add-cross i386-pc-cygwin x86 cygwin cygwin
# add-cross sparc-sun-solaris sparc solaris blade
#
# (Here cygwin happens to be the name of my Cygwin machine and blade
# happens to be the name of my Sparc machine.)
#
# You also may need to set $libDir, which determines where the
# cross-compiler target will be installed.
die () {
echo >&2 "$1"
exit 1
}
usage () {
die "usage: $name <crossTarget> <crossArch> <crossOS> <machine>"
}
case "$#" in
4)
crossTarget="$1"
crossArch="$2"
crossOS="$3"
machine="$4"
;;
*)
usage
;;
esac
name=`basename "$0"`
original=`pwd`
dir=`dirname "$0"`
src=`cd "$dir/.." && pwd`
PATH="$dir":$PATH
# libDir is the mlton lib directory where you would like the
# cross-compiler information to be installed. If you have installed
# from the rpms, this will usually be /usr/lib/mlton. You must have
# write permission there.
lib="$src/build/lib"
# You shouldn't need to change anything below this line.
rm -rf "$lib/$crossTarget"
mkdir -p "$lib/$crossTarget" || die "Cannot write to $lib."
tmp='/tmp/mlton-add-cross'
( cd "$src" &&
mmake TARGET=$crossTarget TARGET_ARCH=$crossArch TARGET_OS=$crossOS \
dirs )
ssh $machine "rm -rf $tmp && mkdir $tmp"
echo "Copying files."
( cd "$src" && tar cf - --exclude '*.o' --exclude '*.a' Makefile basis-library bin include runtime ) |
ssh $machine "cd $tmp && tar xf - &&
if [ ! $crossArch == \`./bin/host-arch\` ]; then echo $machine is \`./bin/host-arch\`, not $crossArch; exit 1; fi &&
if [ ! $crossOS == \`./bin/host-os\` ]; then echo $machine is \`./bin/host-os\`, not $crossOS; exit 1; fi"
echo "Making runtime on $machine."
ssh $machine "cd $tmp && ./bin/mmake CPPFLAGS=\"$CPPFLAGS\" LDFLAGS=\"$LDFLAGS\" COMPILE_FAST=yes OMIT_BYTECODE=yes clean dirs runtime"
ssh $machine "cd $tmp/build/lib/self && tar cf - ." |
( cd "$lib/$crossTarget" && tar xf - )
ssh $machine "cd $tmp/basis-library/config/c && tar cf - $crossArch-$crossOS" |
( cd "$lib/sml/basis/config/c" && tar xf - )
( cd "$src" &&
mmake TARGET=$crossTarget TARGET_ARCH=$crossArch TARGET_OS=$crossOS \
mlbpathmap targetmap )
case "$crossOS" in
mingw)
suf='.exe'
;;
*)
suf=''
;;
esac
# Copied from mlton-script
case "$crossArch" in
amd64)
archOpts='-m64'
;;
hppa)
archOpts=''
;;
ia64)
archOpts='-mlp64'
;;
sparc)
archOpts='-m32'
;;
x86)
archOpts=''
;;
esac
case "$crossOS" in
aix)
osOpts='-maix64'
;;
cygwin)
osOpts=''
;;
darwin)
osOpts='-I/usr/local/include -I/opt/local/include -I/sw/include -L/usr/local/lib -L/opt/local/lib -L/sw/lib'
;;
freebsd)
osOpts='-I/usr/local/include -L/usr/local/lib/'
;;
hurd)
osOpts=''
;;
hpux)
osOpts=''
;;
linux)
osOpts=''
;;
mingw)
libs='-lws2_32 -lkernel32 -lpsapi -lnetapi32 -lwinmm'
;;
netbsd)
osOpts='-I/usr/pkg/include -Wl,-R/usr/pkg/lib -L/usr/pkg/lib/'
;;
openbsd)
osOpts='-I/usr/local/include -L/usr/local/lib/'
;;
solaris)
osOpts='-lnsl -lsocket -lrt'
;;
esac
exe='print-constants'
echo "Compiling and running print-constants on $machine."
"$src/build/bin/mlton" -target $crossTarget -build-constants true |
ssh $machine "cd $tmp/runtime &&
cat >$exe.c &&
gcc $archOpts $osOpts $CPPFLAGS -I. -o $exe $exe.c libmlton.a libgdtoa.a $LDFLAGS -lgmp -lm"
ssh $machine "$tmp/runtime/$exe$suf" >"$lib/$crossTarget/constants"
ssh $machine "rm -rf $tmp"
|