3 # Configure script for GHDL (C) 2014-2018 Tristan Gingold
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <gnu.org/licenses>.
19 # Current version. This is the only place where the version is written.
20 # Any code that needs version should read it directly or indirectly from this
22 # Note the absence of spaces and the quotes.
23 # Suffix "-dev" is used during development.
24 ghdl_version
="3.0.0-dev"
30 CXXFLAGS
=${CXXFLAGS:--g}
31 GNATMAKE
=${GNATMAKE:-gnatmake}
32 ADA_FLAGS
=${ADA_FLAGS:-}
37 libghdldirsuffix
=lib
/ghdl
47 enable_gplcompat
=unknown
62 subst_vars
="CC CXX GNATMAKE ADA_FLAGS MAKE CFLAGS CXXFLAGS LDFLAGS build
63 srcdir abs_srcdir prefix backend libdirsuffix libghdldirsuffix
64 incdirsuffix gcc_src_dir llvm_config llvm_be backtrace_lib
65 build_mode EXEEXT SOEXT PIC_FLAGS default_pic enable_werror enable_checks
66 enable_gplcompat enable_libghdl libghdl_version ghdl_version
67 with_sundials sundials_incflags sundials_ldflags
68 COMPILER_GCC COMPILER_DEBUG COMPILER_MCODE COMPILER_LLVM POST_PROCESSOR
69 INSTALL_PREFIX LIBDIR_SUFFIX LIBGHDLDIR_SUFFIX INCDIR_SUFFIX
73 srcdir
=`dirname $progname`
74 if test x
$srcdir = x
; then
78 # Check echo -n / echo \c
79 if test x
`echo -n` = x
"-n" ; then
87 # Check $1 is a prefix of $2
90 exp_ver
=`echo $1 | sed 's/\./v/g'`
91 tool_ver
=`echo $2 | sed 's/\./v/g'`
92 if echo $tool_ver |
grep -q "^$exp_ver"; then
101 optarg
=`expr x"$opt" : 'x[^=]*=\(.*\)'`
103 CC
=*|CFLAGS
=*|GNATMAKE
=*|LDFLAGS
=*|CXX
=*)
104 optvar
=`expr x"$opt" : 'x\([^=]*\)=.*'`
105 eval $optvar=\"$optarg\"
107 --prefix=*) prefix
="$optarg";;
108 --srcdir=*) srcdir
="$optarg";;
109 --libdir=*) libdirsuffix
="$optarg";;
110 --libghdldir=*) libghdldirsuffix
="$optarg";;
111 --incdir=*) incdirsuffix
="$optarg";;
112 --with-gcc=*) gcc_src_dir
="$optarg"; backend
=gcc
;;
114 echo "--with-llvm is deprecated, use --with-llvm-config"
115 llvm_config
="$optarg/bin/llvm-config"; backend
=llvm
;;
116 --with-llvm-config) llvm_config
="llvm-config"; backend
=llvm
;;
117 --with-llvm-config=*) llvm_config
="$optarg"; backend
=llvm
;;
118 --with-backtrace-lib=*) backtrace_lib
="$optarg";;
119 --with-readline) with_readline
="Gnu";;
120 --with-sundials=*) with_sundials
=true
;
121 sundials_incflags
="-I$optarg/include";
122 sundials_ldflags
="-L$optarg/lib -lsundials_ida";;
123 --with-sundials) with_sundials
=true
;;
124 --enable-werror) enable_werror
=true
;;
125 --disable-werror) enable_werror
=false
;;
126 --enable-checks) enable_checks
=true
;;
127 --disable-checks) enable_checks
=false
;;
128 --enable-gplcompat) enable_gplcompat
=true
;;
129 --disable-gplcompat) enable_gplcompat
=false
;;
130 --enable-libghdl) enable_libghdl
=true
;;
131 --disable-libghdl) enable_libghdl
=false
;;
132 --enable-synth) enable_synth
=true
;;
133 --disable-synth) enable_synth
=false
;;
134 --default-pic) default_pic
=true
;;
135 --enable-coverage) build_mode
="coverage";;
136 -h|
-help|
--help) show_help
=yes;;
138 echo "$0: unknown option $opt; try $0 --help"
145 if test $show_help != no
; then
147 Usage: configure [options]
149 Options [defaults in brackets]:
150 --prefix=PREFIX install in PREFIX [$prefix]
151 --srcdir=SRCDIR source code path [$srcdir]
152 --libdir=LIBDIR lib dir path relative to PREFIX [$libdirsuffix]
153 --libghdldir=LIBGHDLDIR ghdl lib dir path relative to PREFIX [$libdirsuffix]
154 --incdir=INCDIR C include dir path relative to PREFIX [$incdirsuffix]
155 --with-gcc=DIR use gcc backend from DIR
156 --with-llvm-config[=LLVM-CONFIG] use llvm backend [llvm-config]
157 --with-backtrace-lib=LIB.a link with libbacktrace LIB.a to display a
158 backtrace on errors (only for llvm).
159 --disable-werror warnings don't stop build
160 --disable-checks disable internal checks
161 --disable-libghdl do not build libghdl shared library
162 --enable-gplcompat use GPL-compatible sources for ieee library
163 --enable-libghdl also build the libghdl shared library
164 --disable-synth do not build with synthesis feature
166 Binaries are installed in PREFIX/bin
167 Shared libraries are installed in PREFIX/LIBDIRSUFFIX
168 C header files are installed in PREFIX/INCDIR
169 GHDL libraries are installed in PREFIX/LIBGHDLDIR
174 # Set abs_srcdir (absolute srcdir)
176 /*) abs_srcdir
=$srcdir;;
178 # Use a Windows path on windows.
180 Windows_NT
) curdir
=`pwd -W 2>/dev/null || pwd` ;;
183 abs_srcdir
=$curdir/$srcdir
189 pat
="2019802090ed76fc5c54cec58f22a2c1"
190 if ! grep $pat $srcdir/configure
> /dev
/null
2>&1; then
191 echo "Incorrect srcdir; try with --srcdir=xx"
192 echo "srcdir=$srcdir"
196 if ! `cmp /dev/null /dev/null > /dev/null 2>&1`; then
197 echo "Sorry, you need 'cmp' to configure GHDL.";
201 if ! cmp $srcdir/configure
$abs_srcdir/configure
> /dev
/null
2>&1; then
202 echo "Cannot compute absolute source dir (or incorrect srcdir)"
203 echo "srcdir=$srcdir"
204 echo "abs_srcdir=$abs_srcdir"
207 # Check that gnatmake exists
208 if ! $GNATMAKE --version >/dev
/null
2>&1; then
209 echo "Sorry, you need GNAT to build GHDL. See the README"
210 echo "(gnatmake executable is: $GNATMAKE)"
214 # Check that compiler exists
215 if ! $CC --version 2> /dev
/null
; then
216 echo "Sorry, you need a C compiler to build GHDL. See the README"
220 # Check the version of libghdl is correct.
221 if [ "$enable_libghdl" = true
]; then
222 libghdl_version
="$srcdir/pyGHDL/__init__.py"
223 # Extract content between double quotes in __init__.py, to avoid false positives due to LF/CRLF mismatch.
224 if [ "$ghdl_version" != "`sed -n 's/^__version__.*"\
(.
*\
)".*/\1/gp' $libghdl_version`" ]; then
225 echo "Sorry, the version of $libghdl_version is not correct"
226 echo "update the version to: $ghdl_version"
227 echo "or use --disable-libghdl"
232 # Default for enable_gplcompat
233 if [ "$enable_gplcompat" = "unknown" ]; then
234 if test -d $srcdir/libraries
/vital95
&& test -d $srcdir/libraries
/vital2000
; then
235 enable_gplcompat
=false
236 echo "Use full IEEE library"
238 enable_gplcompat
=true
239 echo "Use GPL-compatible source files for IEEE library (but partial)"
241 elif [ "$enable_gplcompat" = false
]; then
242 if ! test -d $srcdir/libraries
/vital95 ||
! test -d $srcdir/libraries
/vital2000
; then
243 echo "Sorry, full IEEE library source files not present"
244 echo "consider --enable-gplcompat"
249 # Compute build machine
250 if test x
$build = x
; then
251 build
=`$CC $CFLAGS -dumpmachine`
253 echo "Build machine is: $build"
255 # For mcode, check that gcc emits i386
256 if test $backend = mcode
; then
258 i
[3-6]86*) mcode64
="" ;;
259 x86_64
*) mcode64
="64" ;;
260 amd64
*) mcode64
="64" ;;
263 echo "WARNING: GHDL for mcode is supported only on x86"
264 echo "continuing, but build failure expected (See the README)"
267 if test "x$backtrace_lib" != x
; then
268 echo "WARNING: --with-backtrace-lib= ignored with mcode"
273 # For gcc backend, check existing version
274 if test $backend = gcc
; then
275 if ! test -f $gcc_src_dir/gcc
/BASE-VER
; then
276 echo "cannot find gcc/BASE-VER in $gcc_src_dir"
279 if test "x$backtrace_lib" = x
; then
280 # Automatically use libbacktrace from gcc.
281 backtrace_lib
="$prefix/$libghdldirsuffix/libbacktrace.a"
285 # For llvm backend, check llvm-config
286 if test $backend = llvm
; then
287 # No quotes for llvm_config, so that options (like --link-static) can be
288 # added. As a consequence, spaces in --with-llvm-config= are not allowed
290 llvm_version
=`$llvm_config --version 2>/dev/null`
292 echo "cannot run $llvm_config"
295 if check_version
3.5 $llvm_version ||
296 check_version
3.6 $llvm_version ||
297 check_version
3.7 $llvm_version ||
298 check_version
3.8 $llvm_version ||
299 check_version
3.9 $llvm_version ||
300 check_version
4.0 $llvm_version ||
301 check_version
5.0 $llvm_version ||
303 echo "Debugging not enabled with llvm $llvm_version"
304 elif check_version
6.0 $llvm_version ||
305 check_version
7.0 $llvm_version ||
306 check_version
8.0 $llvm_version ||
307 check_version
9.0 $llvm_version ||
308 check_version
10.0 $llvm_version ||
309 check_version
11.0 $llvm_version ||
310 check_version
11.1 $llvm_version ||
311 check_version
12.0 $llvm_version ||
312 check_version
13.0 $llvm_version ||
313 check_version
14.0 $llvm_version ||
314 check_version
15.0 $llvm_version ||
316 echo "Debugging is enabled with llvm $llvm_version"
318 echo "Unhandled version llvm $llvm_version"
321 # For llvm, the c++ compiler is used for linking so that the standard c++
322 # library is included. However, the linker needs the no_compact_unwind
323 # flag because code generated by gcc is not compatible with compact unwind.
325 *darwin
*) LDFLAGS
="$LDFLAGS -Wl,-no_compact_unwind" ;;
329 # Define default file extensions for Windows or Linux-like systems and
332 *mingw
* |
*cygwin
* |
*windows-gnu
*) SOEXT
=".dll"; EXEEXT
=".exe"; PIC_FLAGS
="";;
333 *darwin
*) SOEXT
=".dylib"; EXEEXT
=""; PIC_FLAGS
="";;
334 *) SOEXT
=".so"; EXEEXT
=""; PIC_FLAGS
="-fPIC";;
337 # Define libghdl_version
338 libghdl_version
=`echo $ghdl_version | sed -e 's/[-.]/_/g'`
340 # Check if gcc was configured with --enable-default-pie. In that case -fPIC
342 if gcc
-v 2>&1 |
grep -q enable-default-pie
; then
346 # Create subdirectories
347 if [ ! -d pic
]; then
348 echo "create pic/ subdirectory"
350 echo "failed to create pic/"
355 # Define variables derrived from configuration
357 # Note most of these are used to generate default_paths.ads, you should
358 # also update scripts/windows/mcode/default_paths.ads if you change them.
359 COMPILER_GCC
=ghdl1-gcc
$EXEEXT
360 COMPILER_DEBUG
=ghdl1-debug
$EXEEXT
361 COMPILER_MCODE
=ghdl1-mcode
$EXEEXT
362 COMPILER_LLVM
=ghdl1-llvm
$EXEEXT
363 POST_PROCESSOR
=oread-
$backend
364 INSTALL_PREFIX
=$prefix
365 LIBDIR_SUFFIX
=$libdirsuffix
366 LIBGHDLDIR_SUFFIX
=$libghdldirsuffix
367 INCDIR_SUFFIX
=$incdirsuffix
369 # Generate config.status
373 echo "# Generated by configure."
374 echo "# Run this file to recreate the current configuration."
376 echo 'if [ x"$1" = x"--reconfigure" ]; then'
377 # Do not use exec as bash 3.2 pass the absolute path in argv[0]
378 echo $echon " $progname"$echoc
380 echo $echon \
\"$opt\"$echoc
386 echo subst_vars
=\"$subst_vars\"
387 for v
in $subst_vars; do
391 subst_files
="Makefile default_paths.ads ghdl.gpr scripts/gcc/Make-lang.in"
392 echo "for f in $subst_files; do"
393 echo ' echo "Creating $f"'
394 echo ' mkdir -p "$(dirname "$f")"'
396 for v
in $subst_vars; do
397 echo " -e \"s%@$v@%\$$v%g\" \\"
399 echo ' < $srcdir/${f}.in > $f'
401 } > config.status || \
403 echo "$progname: cannot create config.status"
407 chmod +x .
/config.status
409 # Run config.status to generate files
410 if ! sh .
/config.status
; then
411 echo "$progname: cannot execute config.status"
416 if ! $MAKE create-dirs
; then
417 echo "$progname: cannot execute $MAKE create-dirs"
421 # Generate ortho_code-x86-flags
422 if test $backend = mcode
; then
424 *darwin
*) ortho_flags
="Flags_Macosx${mcode64}" ;;
425 *mingw32
*) ortho_flags
="Flags_Windows${mcode64}" ;;
426 *linux
*) ortho_flags
="Flags_Linux${mcode64}" ;;
427 *openbsd
*) ortho_flags
="Flags_Macosx${mcode64}" ;;
428 *) echo "Unsupported $build build for mcode"; exit 1;;
430 echo "Generate ortho_code-x86-flags.ads"
432 echo "with Ortho_Code.X86.$ortho_flags;"
433 echo "package Ortho_Code.X86.Flags renames Ortho_Code.X86.$ortho_flags;"
434 } > ortho_code-x86-flags.ads
435 echo "Generate elf_arch.ads"
437 echo "with Elf_Arch${mcode64:-32};"
438 echo "package Elf_Arch renames Elf_Arch${mcode64:-32};"
442 # Generate ghdlsynth_maybe.ads
443 echo "Generate ghdlsynth_maybe.ads"
444 if [ "$enable_synth" = "true" ]; then
449 echo "with $pkg_synth;" > ghdlsynth_maybe.ads
450 echo "package Ghdlsynth_Maybe renames $pkg_synth;" >> ghdlsynth_maybe.ads
452 # Generate grt-readline.ads
453 echo "Generate grt-readline.ads"
454 echo "with Grt.Readline_${with_readline};" > grt-readline.ads
455 echo "package Grt.Readline renames Grt.Readline_${with_readline};" >> grt-readline.ads