blob: e8825439ca15261dd06bb17722e95942514b4b4f (
plain)
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
|
#!/bin/sh
#
# configure script for ghdl (c) 2014 Tristan Gingold
#
backend=mcode
CC=${CC:-gcc}
CFLAGS=${CFLAGS:--g}
GNATMAKE=${GNATMAKE:-gnatmake}
LDFLAGS=
prefix=/usr/local
libdirsuffix=lib/ghdl
libdirreverse=../..
gcc_src_dir=
gcc_version=unknown
llvm_prefix=
build=
show_help=no
progname=$0
subst_vars="CC GNATMAKE CFLAGS LDFLAGS build srcdir prefix backend libdirsuffix libdirreverse gcc_src_dir llvm_prefix"
# Find srcdir
srcdir=`dirname $progname`
if test x$srcdir = x; then
srcdir=.
fi
# Check echo -n / echo \c
if test x`echo -n` = x"-n" ; then
echon=
echoc="\c"
else
echon="-n"
echoc=
fi
# Read required gcc version from README file
gcc_version=`grep '^gcc version' $srcdir/README |
sed -e 's/gcc version \([0-9.]*\) \[.*\]\.$/\1/'`
# Read required llvm version from README file
llvm_version=`grep '^llvm version' $srcdir/README |
sed -e 's/llvm version \([0-9.]*\) \[.*\]\.$/\1/'`
# Check $1 is a prefix of $2
check_version()
{
exp_ver=`echo $1 | sed 's/\./v/g'`
tool_ver=`echo $2 | sed 's/\./v/g'`
if echo $tool_ver | grep -q "^$exp_ver"; then
return 0
else
return 1
fi
}
# Decode options
for opt do
optarg=`expr x"$opt" : 'x[^=]*=\(.*\)'`
case "$opt" in
CC=*|CFLAGS=*|GNATMAKE=*)
optvar=`expr x"$opt" : 'x\([^=]*\)=.*'`
eval $optvar=\"$optarg\"
;;
--prefix=*) prefix="$optarg";;
--srcdir=*) srcdir="$optarg";;
--with-gcc=*) gcc_src_dir="$optarg"; backend=gcc;;
--with-llvm=*) llvm_prefix="$optarg"; backend=llvm;;
-h|-help|--help) show_help=yes;;
*) echo "$0: unknown option $opt; try $0 --help"
exit 1
;;
esac
done
# Help
if test $show_help != no; then
cat <<EOF
Usage: configure [options]
Options [defaults in brackets]:
--prefix=PREFIX install in PREFIX [$prefix]
--srcdir=SRCDIR source code path [$srcdir]
--with-gcc=DIR use gcc backend from DIR (needs gcc $gcc_version)
--with-llvm=DIR use llvm installed in DIR (needs llvm $llvm_version)
EOF
exit 0
fi
# Sanity checks
# Check that gnatmake exists
if ! $GNATMAKE --version >/dev/null 2>&1; then
echo "Sorry, you need GNAT to build GHDL. See the README"
echo "(gnatmake executable is: $GNATMAKE)"
exit 1
fi
# Check that compiler exists
if ! $CC -v 2> /dev/null; then
echo "Sorry, you need a C compiler to build GHDL. See the README"
exit 1
fi
# Compute build machine
if test x$build = x; then
build=`$CC $CFLAGS -dumpmachine`
fi
echo "Build machine is: $build"
# For mcode, check that gcc emits i386
if test $backend = mcode; then
if ! $CC $CFLAGS -dumpmachine | grep -q "[3-6]86"; then
echo "WARNING: GHDL for mcode is supported only on x86 (32 bits)"
echo "continuing, but build failure expected (See the README)"
fi
fi
# For gcc backend, check version
if test $backend = gcc; then
if ! test -f $gcc_src_dir/gcc/BASE-VER; then
echo "cannot find gcc/BASE-VER in $gcc_src_dir"
exit 1
fi
base_ver=`cat $gcc_src_dir/gcc/BASE-VER`
if ! check_version $gcc_version $base_ver; then
echo "Mismatch gcc version from $gcc_src_dir"
echo "Need gcc version $gcc_version"
exit 1
fi
fi
# For llvm backend, check llvm-config
if test $backend = llvm; then
llvm_cmd="$llvm_prefix/bin/llvm-config --version"
llvm_ver=`$llvm_cmd 2>/dev/null`
if [ $? != 0 ]; then
echo "cannot run $llvm_cmd"
exit 1
fi
if ! check_version $llvm_version $llvm_ver; then
echo "Mismatch llvm version $llvm_ver from $llvm_prefix"
echo "Need llvm version $llvm_version"
exit 1
fi
# For llvm, the c++ compiler isused for linking so that the standard c++
# library is included. However, the linker needs the no_compact_unwind
# flag because code generated by gcc is not compatible with compact unwind.
case "$build" in
*darwin*) LDFLAGS="$LDFLAGS -Wl,-no_compact_unwind" ;;
esac
fi
# Generate config.status
rm -f config.status
{
echo "#! /bin/sh"
echo "# Generated by configure."
echo "# Run this file to recreate the current configuration."
echo
echo "# Generated by:"
echo $echon "# $progname"$echoc
for opt do
echo $echon \ \"$opt\"$echoc
done
echo
echo
echo subst_vars=\"$subst_vars\"
for v in $subst_vars; do
eval vval=\$$v
echo $v=\"$vval\"
done
sed_opts=`echo $subst_vars | sed -e "s/\\([a-zA-Z_]*\\)/ -e \"s%@\1@%\$\1%g\"/g"`
echo 'echo "Creating ghdl.gpr"'
echo sed $sed_opts '< $srcdir/ghdl.gpr.in > ghdl.gpr'
echo 'echo "Creating Makefile"'
echo sed $sed_opts '< $srcdir/Makefile.in > Makefile'
} > config.status || \
{
echo "$progname: cannot create config.status"
exit 1
}
chmod +x ./config.status
# Run config.status to generate files
if ! sh ./config.status; then
echo "$progname: cannot execute config.status"
exit 1
fi
# Generate ortho_code-x86-flags
if test $backend = mcode; then
case "$build" in
*darwin*) ortho_flags="Flags_Macosx" ;;
*mingw32*) ortho_flags="Flags_Windows" ;;
*linux*) ortho_flags="Flags_Linux" ;;
*) echo "Unsupported $build build for mcode"; exit 1;;
esac
echo "Generate ortho_code-x86-flags.ads"
{
echo "with Ortho_Code.X86.$ortho_flags;"
echo "package Ortho_Code.X86.Flags renames Ortho_Code.X86.$ortho_flags;"
} > ortho_code-x86-flags.ads
fi
# Generate default_pathes.ads
echo "Generate default_pathes.ads"
curdir=`pwd`
sed -e "s%@COMPILER_GCC@%ghdl1-gcc%" \
-e "s%@COMPILER_DEBUG@%ghdl1-debug%" \
-e "s%@COMPILER_MCODE@%ghdl1-mcode%" \
-e "s%@COMPILER_LLVM@%bin/ghdl1-llvm%" \
-e "s%@POST_PROCESSOR@%oread-$backend%" \
-e "s%@INSTALL_PREFIX@%$prefix%" \
-e "s%@LIB_PREFIX@%$libdirsuffix%" \
< $srcdir/src/ghdldrv/default_pathes.ads.in > default_pathes.ads
exit 0
|