-
Notifications
You must be signed in to change notification settings - Fork 30
/
configure.sh
executable file
·120 lines (104 loc) · 2.48 KB
/
configure.sh
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
#!/bin/sh
prog_NAME="$(basename $0)"
err()
{
echo "${prog_NAME}: ERROR: $@" 1>&2
}
die()
{
echo "${prog_NAME}: ERROR: $@" 1>&2
exit 1
}
usage()
{
cat <<EOM 1>&2
usage: ${prog_NAME} [ OPTIONS ]
Configures the ocaml-solo5 build system.
Options:
--prefix=DIR:
Installation prefix (default: /usr/local).
--target=TARGET
Solo5 compiler toolchain to use.
--ocaml-configure-option=OPTION
Add an option to the OCaml compiler configuration.
EOM
exit 1
}
OCAML_CONFIGURE_OPTIONS=
MAKECONF_PREFIX=/usr/local
CC=cc
while [ $# -gt 0 ]; do
OPT="$1"
case "${OPT}" in
--target=*)
CONFIG_TARGET="${OPT##*=}"
;;
--prefix=*)
MAKECONF_PREFIX="${OPT##*=}"
;;
--ocaml-configure-option=*)
OCAML_CONFIGURE_OPTIONS="${OCAML_CONFIGURE_OPTIONS} ${OPT##*=}"
;;
--help)
usage
;;
*)
err "Unknown option: '${OPT}'"
usage
;;
esac
shift
done
[ -z "${CONFIG_TARGET}" ] && die "The --target option needs to be specified."
MAKECONF_CFLAGS=""
MAKECONF_CC="$CONFIG_TARGET-cc"
MAKECONF_LD="$CONFIG_TARGET-ld"
MAKECONF_AS="$MAKECONF_CC -c"
BUILD_TRIPLET="$($MAKECONF_CC -dumpmachine)"
OCAML_BUILD_ARCH=
# Canonicalize BUILD_ARCH and set OCAML_BUILD_ARCH. The former is for autoconf,
# the latter for the rest of the OCaml build system.
case "${BUILD_TRIPLET}" in
amd64-*|x86_64-*)
BUILD_ARCH="x86_64"
OCAML_BUILD_ARCH="amd64"
;;
aarch64-*)
BUILD_ARCH="aarch64"
OCAML_BUILD_ARCH="arm64"
;;
*)
die "Unsupported build architecture: ${BUILD_TRIPLET}"
;;
esac
TRIPLET="$($CC -dumpmachine)"
ARCH=
case "${TRIPLET}" in
amd64-*|x86_64-*)
ARCH="x86_64"
;;
aarch64-*)
ARCH="aarch64"
;;
*)
die "Unsupported host architecture: ${TRIPLET}"
;;
esac
EXTRA_LIBS=
if [ "${BUILD_ARCH}" = "aarch64" ]; then
EXTRA_LIBS="$EXTRA_LIBS -lgcc" || exit 1
fi
cat <<EOM >Makeconf
MAKECONF_PREFIX=${MAKECONF_PREFIX}
MAKECONF_CFLAGS=${MAKECONF_CFLAGS}
MAKECONF_TOOLCHAIN=${CONFIG_TARGET}
MAKECONF_CC=${MAKECONF_CC}
MAKECONF_LD=${MAKECONF_LD}
MAKECONF_AS=${MAKECONF_AS}
MAKECONF_ARCH=${ARCH}
MAKECONF_BUILD_ARCH=${BUILD_ARCH}
MAKECONF_OCAML_BUILD_ARCH=${OCAML_BUILD_ARCH}
MAKECONF_OCAML_CONFIGURE_OPTIONS=${OCAML_CONFIGURE_OPTIONS}
MAKECONF_NOLIBC_SYSDEP_OBJS=sysdeps_solo5.o
MAKECONF_EXTRA_LIBS=${EXTRA_LIBS}
EOM