-
Notifications
You must be signed in to change notification settings - Fork 18
/
configure
executable file
·240 lines (211 loc) · 7.33 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/bash
set -e
function usage() {
echo "usage: configure [ <option> ... ]"
echo "Configure Circle with newlib standard C library and mbed TLS library."
echo
echo "Options:"
echo " -d, --debug build with debug information, without optimizer"
echo " -h, --help show usage message"
echo " -n, --no-cpp do not support C++ standard library"
echo " -o, --option <name>[=<value>] additional preprocessor define (optionally with value)"
echo " can be repeated"
echo " --opt-tls build with mbed TLS support"
echo " -p <string>, --prefix <string> prefix of the toolchain commands (default: arm-none-eabi-)"
echo " --qemu build for running under QEMU in semihosting mode"
echo " -r <number>, --raspberrypi <number>"
echo " Circle Raspberry Pi model number (1, 2, 3, 4, 5, default: 1)"
echo " --softfp use float ABI setting \"softfp\" instead of \"hard\""
echo " -s <path>, --stddefpath <path>"
echo " path where stddef.h header is located (only necessary"
echo " if script cannot determine it automatically)"
}
# From the bash FAQ: How to use pathnames relative to the script
cd "${BASH_SOURCE%/*}" || exit 1
TOPDIR="$PWD"
TEMP=$(getopt -o dhno:p:r:s: --long debug,help,no-circle-build,no-cpp,option:,opt-tls,qemu,prefix:,raspberrypi:,script-debug,softfp,stddefpath: \
-n 'build.bash' -- "$@")
if [ $? != 0 ] ; then echo usage; exit 1 ; fi
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
DEBUG=0
RASPBERRYPI=1
CIRCLE_BUILD=1
CIRCLE_QEMU=0
CIRCLE_CFLAGS=""
NEWLIB_BUILD=1
TOOLPREFIX=arm-none-eabi-
STDDEF_INCPATH=""
STDLIB_SUPPORT=3
OPTIONS=""
FLOAT_ABI=hard
OPTTLS=0
SIXTY_FOUR_BIT=0
NEWLIB_ARCH="arm-none-circle"
NEWLIB_INSTALL_DIR="$TOPDIR/install"
NEWLIB_BUILD_DIR="$TOPDIR/build/circle-newlib"
CIRCLEHOME="$TOPDIR/libs/circle"
while true ; do
case "$1" in
-d|--debug) DEBUG=1 ; shift;;
-h|--help) usage ; exit 0;;
-n|--no-cpp) STDLIB_SUPPORT=2 ; shift;;
-o|--option) OPTIONS="$OPTIONS -D$2" ; shift 2;;
--opt-tls) OPTTLS=1 ; shift;;
--qemu) CIRCLE_QEMU=1 ; shift;;
-p|--prefix) TOOLPREFIX="$2" ; shift 2;;
-r|--raspberrypi) RASPBERRYPI="$2" ; shift 2;;
--script-debug) set -x ; shift;;
--softfp) FLOAT_ABI=softfp ; shift;;
-s|--stddefpath) STDDEF_INCPATH="$2" ; shift 2;;
--) shift ; break ;;
*) echo "Internal error!" ; exit 1;;
esac
done
echo "RASPBERRYPI=$RASPBERRYPI"
echo "TOOLPREFIX=$TOOLPREFIX"
echo "CIRCLE_BUILD=$CIRCLE_BUILD"
echo "CIRCLE_QEMU=$CIRCLE_QEMU"
echo "FLOAT_ABI=$FLOAT_ABI"
echo "NEWLIB_BUILD=$NEWLIB_BUILD"
echo "RASPBERRYPI=$RASPBERRYPI"
echo "STDLIB_SUPPORT=$STDLIB_SUPPORT"
echo "OPTIONS=$OPTIONS"
echo "NEWLIB_INSTALL_DIR=$NEWLIB_INSTALL_DIR"
echo "NEWLIB_BUILD_DIR=$NEWLIB_BUILD_DIR"
echo "DEBUG=$DEBUG"
echo "Remaining arguments:"
for arg do echo '--> '"\`$arg'" ; done
: ${CC:="$TOOLPREFIX"gcc}
if [ ! -x "`which $CC 2> /dev/null`" ]
then
echo "Error: Invalid toolchain prefix, exiting" >&2
echo "TOOLPREFIX is \"$TOOLPREFIX\"" >&2
exit 1
fi
# Try to determine 64-bit build from Target: output of gcc
if [ "$($CC -v 2>&1 | grep '^Target:.*64')" != "" ]
then
echo "64-bit compiler detected"
SIXTY_FOUR_BIT=1
NEWLIB_ARCH="aarch64-none-circle"
fi
if [ "$STDDEF_INCPATH" = "" ]
then
# TODO this is probably very GCC-specific
STDDEF_INCPATH=$(echo | "$CC" -v -x c -E - 2>&1 | grep "^ /.*include$" | head -1 | sed -e "s/ //")
fi
if [ ! -f "$STDDEF_INCPATH/stddef.h" ]
then
echo "Error: Unable to determine include path for stddef.h, exiting" >&2
echo "STDDEF_INCPATH is \"$STDDEF_INCPATH\"" >&2
exit 1
fi
echo "STDDEF_INCPATH=$STDDEF_INCPATH"
case "$RASPBERRYPI" in
1|2|3|4|5) ;;
*) echo "Unknown Raspberry Pi target" >&2; exit 1;;
esac
# Sanity checks that sub-modules are checked out
if [ ! -f "libs/circle/Rules.mk" ]
then
echo "Circle sub-module not found" >&2
exit 1
fi
if [ ! -f "libs/circle-newlib/README.md" ]
then
echo "newlib sub-module not found" >&2
exit 1
fi
if [ $OPTTLS -eq 1 ]
then
if [ ! -f "libs/mbedtls/README.md" ]
then
echo "mbedtls sub-module not found" >&2
exit 1
fi
fi
# Special compiler flags for running under QEMU
if [ $CIRCLE_QEMU -eq 1 ]
then
CIRCLE_CFLAGS="$CIRCLE_CFLAGS -DLEAVE_QEMU_ON_HALT -DNO_SDHOST"
if [ $SIXTY_FOUR_BIT -eq 0 ]
then
CIRCLE_CFLAGS="$CIRCLE_CFLAGS -DNO_PHYSICAL_COUNTER -DUSE_QEMU_USB_FIX"
fi
fi
# Create Circle's Config.mk file
(
echo "RASPPI = $RASPBERRYPI"
echo "PREFIX = $TOOLPREFIX"
echo "FLOAT_ABI = $FLOAT_ABI"
echo "STDLIB_SUPPORT = $STDLIB_SUPPORT"
echo "STDDEF_INCPATH = \"$STDDEF_INCPATH\""
echo "CFLAGS = -Wno-parentheses $CIRCLE_CFLAGS"
if [ "$OPTIONS" != "" ]
then
echo "DEFINE += $OPTIONS"
fi
if [ $DEBUG -eq 1 ]
then
echo "OPTIMIZE = -O0 -g"
fi
if [ $SIXTY_FOUR_BIT -eq 1 ]
then
echo "AARCH = 64"
echo "PREFIX64 = $TOOLPREFIX"
fi
) > libs/circle/Config.mk
# Retrieve the resulting compiler flags from Circle's top-level Makefile rules
ARCHCPU=$(make -n -p -f libs/circle/Rules.mk CIRCLEHOME=libs/circle | grep '^ARCHCPU =' | \
sed -e "s/\$(FLOAT_ABI)/$FLOAT_ABI/" -e 's/ARCHCPU = //')
ARCH=$(make -n -p -f libs/circle/Rules.mk CIRCLEHOME=libs/circle | grep '^ARCH ='| \
sed -e "s/\$(ARCHCPU)/$ARCHCPU/" -e 's/ARCH = //')
export \
CPPFLAGS_FOR_TARGET="-I\"$CIRCLEHOME/include\" -I\"$CIRCLEHOME/addon\" -I\"$TOPDIR/include\"" \
CC_FOR_TARGET=${TOOLPREFIX}gcc \
CXX_FOR_TARGET=${TOOLPREFIX}g++ \
GCC_FOR_TARGET=${TOOLPREFIX}gcc \
AR_FOR_TARGET=${TOOLPREFIX}gcc-ar \
AS_FOR_TARGET=${TOOLPREFIX}gcc-as \
LD_FOR_TARGET=${TOOLPREFIX}gcc-ld \
RANLIB_FOR_TARGET=${TOOLPREFIX}gcc-ranlib \
OBJCOPY_FOR_TARGET=${TOOLPREFIX}gcc-objcopy \
OBJDUMP_FOR_TARGET=${TOOLPREFIX}gcc-objdump
if [ $DEBUG -eq 1 ]
then
CFLAGS_FOR_TARGET="$ARCH -DRASPPI=$RASPBERRYPI $OPTIONS -O0 -g -Wno-parentheses"
else
CFLAGS_FOR_TARGET="$ARCH -DRASPPI=$RASPBERRYPI $OPTIONS -Wno-parentheses"
fi
export CFLAGS_FOR_TARGET
(
cd $NEWLIB_BUILD_DIR
"$TOPDIR/libs/circle-newlib/configure" --target "${NEWLIB_ARCH}" --disable-multilib \
--prefix "$NEWLIB_INSTALL_DIR" --enable-newlib-long-time_t
)
# create circle-stdlib's configuration file
(
echo "CC = ${CC}"
echo "ARCH = ${ARCH}"
echo "TOOLPREFIX = ${TOOLPREFIX}"
echo "NEWLIB_BUILD_DIR = ${NEWLIB_BUILD_DIR}"
echo "NEWLIB_INSTALL_DIR = ${NEWLIB_INSTALL_DIR}"
echo "CFLAGS_FOR_TARGET = ${CFLAGS_FOR_TARGET}"
echo "CPPFLAGS_FOR_TARGET = ${CPPFLAGS_FOR_TARGET}"
echo "CC_FOR_TARGET = ${CC_FOR_TARGET}"
echo "CXX_FOR_TARGET = ${CXX_FOR_TARGET}"
echo "GCC_FOR_TARGET = ${GCC_FOR_TARGET}"
echo "AR_FOR_TARGET = ${AR_FOR_TARGET}"
echo "AS_FOR_TARGET = ${AS_FOR_TARGET}"
echo "LD_FOR_TARGET = ${LD_FOR_TARGET}"
echo "RANLIB_FOR_TARGET = ${RANLIB_FOR_TARGET}"
echo "OBJCOPY_FOR_TARGET = ${OBJCOPY_FOR_TARGET}"
echo "OBJDUMP_FOR_TARGET = ${OBJDUMP_FOR_TARGET}"
echo "NEWLIB_ARCH = ${NEWLIB_ARCH}"
if [ $OPTTLS -eq 1 ]
then
echo "MBEDTLS = mbedtls"
echo "MBEDTLS_SAMPLES = build-mbedtls-samples"
fi
) >Config.mk