-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·147 lines (127 loc) · 2.87 KB
/
configure
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
#!/usr/bin/env bash
rootdir=$(cd "$(dirname "$0")"; pwd)
libdir=$(cd "${rootdir}/src/lib"; pwd)
exampledir=$(cd "${rootdir}/examples"; pwd)
checkdir=$(cd "${rootdir}/src/casemate-check-c"; pwd)
cc='clang'
ld='ld'
objdump='objdump'
objcopy='objcopy'
casemate_o="${libdir}/casemate.o"
casemate_h="${libdir}/casemate.h"
lib_includes="${libdir}/include"
arch=`uname -m`
cross_prefix=
clangd=1
force=0
warned=0
usage() {
echo "Usage $0 [OPTIONS]";
echo
echo "Options:";
echo " -h --help print this help";
echo " --cross-prefix=PREFIX compilation tool prefix";
echo " --cc=CC compiler";
echo " --ld=LD linker";
echo " --arch=ARCH machine architecture (aarch64 or x86)";
echo " --[no-]clangd force enable/disable clangd targets";
echo " --force overrule checks";
}
warning() {
if [ ${force} -eq 0 ]; then
echo "configure: $1. use --force to force generation of config anyway"
exit 1
else
echo "configure: $1"
warned=$((warned + 1))
fi
}
# collect all the -arg and --args
while [[ "$1" = -* ]]; do
opt="$1"; shift
arg=
if [[ "$opt" = *=* ]]; then
arg="${opt#*=}";
opt="${opt%%=*}";
fi
case "$opt" in
--cross-prefix)
cross_prefix="$arg"
;;
--arch)
arch="$arg"
;;
--cc)
cc="$arg"
;;
--ld)
ld="$arg"
;;
--clangd)
clangd=1
;;
--no-clangd)
clangd=
;;
--force)
force=1
;;
-h|--help)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
tool_prefix=${cross_prefix}
cc=${tool_prefix}${cc}
ld=${tool_prefix}${ld}
objcopy=${tool_prefix}${objcopy}
objdump=${tool_prefix}${objdump}
# check for existence of tools
check_tool () {
if ! which $2 >/dev/null; then
warning "--$1: cannot find '$2'"
fi
}
check_tool "cc" ${cc}
check_tool "ld" ${ld}
check_tool "objcopy" ${objcopy}
check_tool "objdump" ${objdump}
# normalise arch name
[ "$arch" = "arm64" ] && arch="aarch64"
[ "$arch" = "i386" ] && arch="x86"
[ "$arch" = "i686" ] && arch="x86"
[ "$arch" = "x86_64" ] && arch="x86"
arch_name=
if [ "$arch" = "aarch64" ]; then
arch_name="AARCH64";
elif [ "$arch" = "x86" ]; then
arch_name="X86";
else
echo "unknown architecture '${arch}'"
exit 1
fi
if [ ${warned} -eq 1 ]; then
echo "configure: warning suppressed, writing config anyway"
elif [ ${warned} -gt 1 ]; then
echo "configure: multiple warnings suppressed, writing config anyway"
fi
cat <<EOF > config.mk
# Auto-generated, see ./configure script.
root = ${rootdir}
CC = ${cc}
LD = ${ld}
OBJDUMP = ${objdump}
OBJCOPY = ${objcopy}
ARCH = ${arch_name}
CFLAGS = -Wall -MD -g -gdwarf-4 -D__${arch_name}__
LDFLAGS =
CLANGD = ${clangd}
casemate_o = ${casemate_o}
casemate_h = ${casemate_h}
lib_includes = ${lib_includes}
EOF