-
Notifications
You must be signed in to change notification settings - Fork 3
/
configure
executable file
·192 lines (156 loc) · 4.4 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
#!/bin/sh
# simple risu configure script
#
# Copyright (c) 2013 Linaro Limited
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Claudio Fontana (Linaro) - initial implementation
# Locate the directory where this configure script is
SRCDIR="$(cd "$(dirname "$0")"; pwd)"
# Temporary directory used for files created by this script.
# Like autoconf (and like QEMU) we put this directory in the
# build directory, which means we can just give it a fixed name and
# blow it away when configure is run, and we don't need to jump
# through complicated hoops to delete it when configure exits
# abnormally (it may be useful for debug purposes on an
# abnormal exit).
tmp_dir="config-temp"
rm -rf "$tmp_dir"
mkdir -p "$tmp_dir"
if [ $? -ne 0 ]; then
echo "ERROR: could not create temporary directory"
exit 1
fi
compile() {
$CC $CFLAGS -c -o ${1}.o ${1}.c 2>/dev/null
}
link() {
$LD $LDFLAGS -l${2} -o ${1} ${1}.o 2>/dev/null
}
check_define() {
c=${tmp_dir}/check_define_${1}
cat > ${c}.c <<EOF
#if !defined($1)
#error $1 not defined
#endif
int main(void) { return 0; }
EOF
compile $c
}
guess_arch() {
if check_define __m68k__ ; then
ARCH="m68k"
elif check_define __arm__ ; then
ARCH="arm"
elif check_define __aarch64__ ; then
ARCH="aarch64"
elif check_define __powerpc64__ ; then
ARCH="ppc64"
else
echo "This cpu is not supported by risu. Try -h. " >&2
exit 1
fi
}
check_type() {
c=${tmp_dir}/check_type_${1}
cat > ${c}.c <<EOF
#include <inttypes.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/socket.h>
int main(void) { $1 thisone; return 0; }
EOF
compile $c
}
check_lib() {
c=${tmp_dir}/check_lib${1}
cat > ${c}.c <<EOF
#include <stdint.h>
#include <$2.h>
int main(void) { $3; return 0; }
EOF
compile $c && link $c $1
}
generate_config() {
cfg=config.h
echo "generating config.h..."
echo "/* config.h - generated by the 'configure' script */" > $cfg
echo "#ifndef CONFIG_H" >> $cfg
echo "#define CONFIG_H 1" >> $cfg
if check_lib z zlib "zlibVersion()"; then
echo "#define HAVE_ZLIB 1" >> $cfg
LDFLAGS=-lz
fi
echo "#endif /* CONFIG_H */" >> $cfg
echo "...done"
}
generate_makefilein() {
m=Makefile.in
echo "generating Makefile.in..."
echo "# Makefile.in - generated by the 'configure' script" > $m
echo "ARCH:=${ARCH}" >> $m
echo "CC:=${CC}" >> $m
echo "LDFLAGS:=${LDFLAGS}" >> $m
echo "AS:=${AS}" >> $m
echo "OBJCOPY:=${OBJCOPY}" >> $m
echo "OBJDUMP:=${OBJDUMP}" >> $m
echo "STATIC:=${STATIC}" >> $m
echo "SRCDIR:=${SRCDIR}" >> $m
echo "BUILD_INC:=${BUILD_INC}" >> $m
echo "...done"
}
usage() {
cat <<EOF
Usage: [VAR=VALUE]... ./configure [-h|--help] [-s|--static]
-s/--static - force a static build of risu
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Some influential environment variables:
CROSS_PREFIX cross-compiler prefix, defaults to gcc and other tools
prefixed with the given string.
ARCH force target architecture instead of trying to detect it.
Valid values=[arm|aarch64|ppc64|ppc64le|m68k]
CC C compiler command
CFLAGS C compiler flags
CPPFLAGS C preprocessor flags, e.g. -I<include dir>
AS assembler command
OBJCOPY object copy utility command
OBJDUMP object dump utility command
EOF
}
# STARTUP: entry point
STATIC=""
for opt do
case "$opt" in
--help | -h)
usage;
exit 0;;
--static | -s)
STATIC="-static"
;;
esac
done
CC="${CC-${CROSS_PREFIX}gcc}"
AS="${AS-${CROSS_PREFIX}as}"
LD="${LD-${CROSS_PREFIX}ld}"
OBJCOPY="${OBJCOPY-${CROSS_PREFIX}objcopy}"
OBJDUMP="${OBJDUMP-${CROSS_PREFIX}objdump}"
if test "x${ARCH}" = "x"; then
guess_arch
fi
# Are we in a separate build tree? If so, link the Makefile
# so that 'make' works.
if test ! -e Makefile; then
echo "linking Makefile..."
BUILD_INC="-I $(pwd)"
ln -s "${SRCDIR}/Makefile" .
fi
generate_config
generate_makefilein
rm -r "$tmp_dir"
echo "type 'make' to start the build"
exit 0