aboutsummaryrefslogtreecommitdiffstats
path: root/configure
blob: eb9c2e7bbac6de8c1f8a78a1e0d03b639faa0028 (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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
#!/bin/sh

#######################################################################
#                                                                     #
#              The Compcert verified compiler                         #
#                                                                     #
#          Xavier Leroy, INRIA Paris-Rocquencourt                     #
#                                                                     #
#  Copyright Institut National de Recherche en Informatique et en     #
#  Automatique.  All rights reserved.  This file is distributed       #
#  under the terms of the INRIA Non-Commercial License Agreement.     #
#                                                                     #
#######################################################################

prefix=/usr/local
bindir='$(PREFIX)/bin'
libdir='$(PREFIX)/lib/compcert'
toolprefix=''
target=''
has_runtime_lib=true
has_standard_headers=true
build_checklink=true
advanced_debug=false

usage='Usage: ./configure [options] target

Supported targets:
  ppc-linux        (PowerPC, Linux)
  ppc-eabi         (PowerPC, EABI with GNU/Unix tools)
  ppc-eabi-diab    (PowerPC, EABI with Diab tools)
  arm-linux        (ARM, EABI)
  arm-eabi         (ARM, EABI)
  arm-eabihf       (ARM, EABI using hardware FP registers)
  arm-hardfloat    (ARM, EABI using hardware FP registers)
  ia32-linux       (x86 32 bits, Linux)
  ia32-bsd         (x86 32 bits, BSD)
  ia32-macosx      (x86 32 bits, MacOS X)
  ia32-cygwin      (x86 32 bits, Cygwin environment under Windows)
  manual           (edit configuration file by hand)

For ARM targets, the "arm-" prefix can be refined into:
  armv6-           ARMv6   + VFPv2
  armv7a-          ARMv7-A + VFPv3-d16   (default)
  armv7r-          ARMv7-R + VFPv3-d16
  armv7m-          ARMv7-M + VFPv3-d16

Options:
  -prefix <dir>    Install in <dir>/bin and <dir>/lib/compcert
  -bindir <dir>    Install binaries in <dir>
  -libdir <dir>    Install libraries in <dir>
  -toolprefix <pref>  Prefix names of tools ("gcc", etc) with <pref>
  -no-runtime-lib  Do not compile nor install the runtime support library
  -no-standard-headers Do not install nor use the standard .h headers
'

# Parse command-line arguments

while : ; do
  case "$1" in
    "") break;;
    -prefix|--prefix)
        prefix="$2"; shift;;
    -bindir|--bindir)
        bindir="$2"; shift;;
    -libdir|--libdir)
        libdir="$2"; shift;;
    -toolprefix|--toolprefix)
        toolprefix="$2"; shift;;
    -no-runtime-lib)
        has_runtime_lib=false;;
    -no-standard-headers)
        has_standard_headers=false;;
    -no-checklink)
        build_checklink=false;;
    *)
        if test -n "$target"; then echo "$usage" 1>&2; exit 2; fi
        target="$1";;
  esac
  shift
done

# Per-target configuration

cchecklink=false
casmruntime=""
asm_supports_cfi=""
struct_passing=""
struct_return=""

case "$target" in
  powerpc-linux|ppc-linux|powerpc-eabi|ppc-eabi)
    arch="powerpc"
    model="standard"
    abi="eabi"
    struct_passing="ref-caller"
    case "$target" in
      *-linux) struct_return="ref";;
      *-eabi)  struct_return="int1-8";;
    esac
    system="linux"
    cc="${toolprefix}gcc"
    cprepro="${toolprefix}gcc -std=c99 -U__GNUC__ -E"
    casm="${toolprefix}gcc -c"
    casmruntime="${toolprefix}gcc -c -Wa,-mregnames"
    clinker="${toolprefix}gcc"
    libmath="-lm"
    cchecklink=${build_checklink}
    advanced_debug=true;;
  powerpc-eabi-diab|ppc-eabi-diab)
    arch="powerpc"
    model="standard"
    abi="eabi"
    struct_passing="ref-caller"
    struct_return="int1-8"
    system="diab"
    cc="${toolprefix}dcc"
    cprepro="${toolprefix}dcc -E -D__GNUC__"
    casm="${toolprefix}das"
    asm_supports_cfi=false
    clinker="${toolprefix}dcc"
    libmath="-lm"
    cchecklink=${build_checklink}
    advanced_debug=true;;
  arm*-*)
    arch="arm"
    case "$target" in
      armv6-*) model="armv6";;
      arm-*|armv7a-*) model="armv7a";;
      armv7r-*) model="armv7r";;
      armv7m-*) model="armv7m";;
      *)
        echo "Unknown target '$target'." 1>&2
        echo "$usage" 1>&2
        exit 2;;
    esac
    case "$target" in
      *-eabi|*-linux) abi="eabi";;
      *-eabihf|*-hf|*-hardfloat) abi="hardfloat";;
      *)
        echo "Unknown target '$target'." 1>&2
        echo "$usage" 1>&2
        exit 2;;
    esac
    struct_passing="ints"
    struct_return="int1-4"
    system="linux"
    cc="${toolprefix}gcc"
    cprepro="${toolprefix}gcc -std=c99 -U__GNUC__ '-D__REDIRECT(name,proto,alias)=name proto' '-D__REDIRECT_NTH(name,proto,alias)=name proto' -E"
    casm="${toolprefix}gcc -c"
    clinker="${toolprefix}gcc"
    libmath="-lm";;
  ia32-linux)
    arch="ia32"
    model="sse2"
    abi="standard"
    struct_passing="ints"
    struct_return="ref"
    system="linux"
    cc="${toolprefix}gcc -m32"
    cprepro="${toolprefix}gcc -std=c99 -m32 -U__GNUC__ -E"
    casm="${toolprefix}gcc -m32 -c"
    clinker="${toolprefix}gcc -m32"
    libmath="-lm";;
  ia32-bsd)
    arch="ia32"
    model="sse2"
    abi="standard"
    struct_passing="ints"
    struct_return="int1248"    # to check!
    system="bsd"
    cc="${toolprefix}gcc -m32"
    cprepro="${toolprefix}gcc -std=c99 -m32 -U__GNUC__ -E"
    casm="${toolprefix}gcc -m32 -c"
    clinker="${toolprefix}gcc -m32"
    libmath="-lm";;
  ia32-macosx)
    arch="ia32"
    model="sse2"
    abi="macosx"
    struct_passing="ints"
    struct_return="int1248"
    system="macosx"
    cc="${toolprefix}gcc -arch i386"
    cprepro="${toolprefix}gcc -std=c99 -arch i386 -U__GNUC__ -U__clang__ -U__BLOCKS__ '-D__attribute__(x)=' '-D__asm(x)=' -E"
    casm="${toolprefix}gcc -arch i386 -c"
    case `uname -r` in
      [1-9].*|10.*|11.*)    # up to MacOS 10.7 included
        clinker="${toolprefix}gcc -arch i386";;
      *)                    # MacOS 10.8 and up
        clinker="${toolprefix}gcc -arch i386 -Wl,-no_pie";;
    esac
    libmath="";;
  ia32-cygwin)
    arch="ia32"
    model="sse2"
    abi="standard"
    struct_passing="ints"
    struct_return="ref"
    system="cygwin"
    cc="${toolprefix}gcc -m32"
    cprepro="${toolprefix}gcc -std=c99 -m32 -U__GNUC__ -E"
    casm="${toolprefix}gcc -m32 -c"
    clinker="${toolprefix}gcc -m32"
    libmath="-lm";;
  manual)
    ;;
  "")
    echo "No target specified." 1>&2
    echo "$usage" 1>&2
    exit 2;;
  *)
    echo "Unknown target '$target'." 1>&2
    echo "$usage" 1>&2
    exit 2;;
esac

if test -z "$casmruntime"; then casmruntime="$casm"; fi

# Test assembler support for CFI directives

if test "$target" != "manual" && test -z "$asm_supports_cfi"; then
  echo "Testing assembler support for CFI directives... " | tr -d '\n'
  f=/tmp/compcert-configure-$$.s
  rm -f $f
  cat >> $f <<EOF
testfun:
	.file 1 "testfun.c"
	.loc 1 1
	.cfi_startproc
	.cfi_adjust_cfa_offset 16
	.cfi_endproc
EOF
  if $casm -o /dev/null $f 2>/dev/null
  then echo "yes"; asm_supports_cfi=true
  else echo "no";  asm_supports_cfi=false
  fi
  rm -f $f
fi

# Testing availability of required tools

missingtools=false

echo "Testing Coq... " | tr -d '\n'
coq_ver=`coqc -v 2>/dev/null | sed -n -e 's/The Coq Proof Assistant, version \([^ ]*\).*$/\1/p'`
case "$coq_ver" in
  8.4pl*)
        echo "version $coq_ver -- good!";;
  ?.*)
        echo "version $coq_ver -- UNSUPPORTED"
        echo "Error: CompCert requires Coq version 8.4, pl1 and up."
        missingtools=true;;
  *)
        echo "NOT FOUND"
        echo "Error: make sure Coq version 8.4 pl5 is installed."
        missingtools=true;;
esac

echo "Testing OCaml... " | tr -d '\n'
ocaml_ver=`ocamlopt -version 2>/dev/null`
case "$ocaml_ver" in
  4.*)
        echo "version $ocaml_ver -- good!";;
  ?.*)
        echo "version $ocaml_ver -- UNSUPPORTED"
        echo "Error: CompCert requires OCaml version 4.00 or later."
        missingtools=true;;
  *)
        echo "NOT FOUND"
        echo "Error: make sure OCaml version 4.00 or later is installed."
        missingtools=true;;
esac

echo "Testing OCaml .opt compilers... " | tr -d '\n'
ocaml_opt_ver=`ocamlopt.opt -version 2>/dev/null`
if test "$ocaml_opt_ver" = "$ocaml_ver"; then
  echo "yes"
  ocaml_opt_comp=true
else
  echo "no, will do without"
  ocaml_opt_comp=false
fi

MENHIR_REQUIRED=20151023
echo "Testing Menhir... " | tr -d '\n'
menhir_ver=`menhir --version 2>/dev/null | sed -n -e 's/^.*version \([0-9]*\).*$/\1/p'`
case "$menhir_ver" in
  20[0-9][0-9][0-9][0-9][0-9][0-9])
        if test "$menhir_ver" -ge $MENHIR_REQUIRED; then
          echo "version $menhir_ver -- good!"
        else
          echo "version $menhir_ver -- UNSUPPORTED"
          echo "Error: CompCert requires Menhir version $MENHIR_REQUIRED or later."
          missingtools=true
        fi;;
  *)
        echo "NOT FOUND"
        echo "Error: make sure Menhir version $MENHIR_REQUIRED or later is installed."
        missingtools=true;;
esac

echo "Testing GNU make... " | tr -d '\n'
make=''
for mk in make gmake gnumake; do
  make_ver=`$mk -v 2>/dev/null | head -1 | sed -n -e 's/^GNU Make //p'`
  case "$make_ver" in
    3.8*|3.9*|[4-9].*)
        echo "version $make_ver (command '$mk') -- good!"
        make="$mk"
        break;;
  esac
done
if test -z "$make"; then 
  echo "NOT FOUND"
  echo "Error: make sure GNU Make version 3.80 or later is installed."
  missingtools=true
fi

if $missingtools; then
  echo "One or several required tools are missing or too old.  Aborting."
  exit 2
fi

# Additional packages needed for cchecklink

if $cchecklink; then
  echo "Testing availability of ocaml-bitstring... " | tr -d '\n'
  if ocamlfind query bitstring > /dev/null
  then
    echo "yes"
  else 
    echo "no"
    echo "ocamlfind or ocaml-bitstring missing, cchecklink will not be built"
    cchecklink=false
  fi
fi

# Generate Makefile.config

sharedir="$(dirname "$bindir")"/share

rm -f Makefile.config
cat > Makefile.config <<EOF
PREFIX=$prefix
BINDIR=$bindir
LIBDIR=$libdir
SHAREDIR=$sharedir
OCAML_OPT_COMP=$ocaml_opt_comp
EOF

if test "$target" != "manual"; then
cat >> Makefile.config <<EOF
ARCH=$arch
MODEL=$model
ABI=$abi
STRUCT_PASSING=$struct_passing
STRUCT_RETURN=$struct_return
SYSTEM=$system
CC=$cc
CPREPRO=$cprepro
CASM=$casm
CASMRUNTIME=$casmruntime
CLINKER=$clinker
LIBMATH=$libmath
HAS_RUNTIME_LIB=$has_runtime_lib
HAS_STANDARD_HEADERS=$has_standard_headers
CCHECKLINK=$cchecklink
ASM_SUPPORTS_CFI=$asm_supports_cfi
ADVANCED_DEBUG=$advanced_debug
EOF
else
cat >> Makefile.config <<'EOF'

# Target architecture
# ARCH=powerpc
# ARCH=arm
# ARCH=ia32
ARCH=

# Hardware variant
# MODEL=standard  # for PowerPC
# MODEL=armv6     # for ARM
# MODEL=armv7a    # for ARM
# MODEL=armv7r    # for ARM
# MODEL=armv7m    # for ARM
# MODEL=sse2      # for IA32
MODEL=

# Target ABI
# ABI=eabi     # for PowerPC / Linux and other SVR4 or EABI platforms
# ABI=eabi     # for ARM
# ABI=hardfloat # for ARM
# ABI=standard # for IA32
ABI=

# Default calling conventions for passing structs and unions by value
# See options -fstruct-passing=<style> and -fstruct-return=<style>
# in the CompCert user's manual
STRUCT_PASSING=ref_callee
# STRUCT_PASSING=ref_caller
# STRUCT_PASSING=ints
STRUCT_RETURN=ref
# STRUCT_RETURN=int1248
# STRUCT_RETURN=int1-4
# STRUCT_RETURN=int1-8

# Target operating system and development environment
# Possible choices for PowerPC:
# SYSTEM=linux
# SYSTEM=diab
# Possible choices for ARM:
# SYSTEM=linux
# Possible choices for IA32:
# SYSTEM=linux
# SYSTEM=bsd
# SYSTEM=macosx
# SYSTEM=cygwin
SYSTEM=

# C compiler for compiling runtime library files and some tests
CC=gcc

# Preprocessor for .c files
CPREPRO=gcc -U__GNUC__ -E

# Assembler for assembling .s files
CASM=gcc -c

# Assembler for assembling runtime library files
CASMRUNTIME=gcc -c

# Linker
CLINKER=gcc

# Math library.  Set to empty under MacOS X
LIBMATH=-lm

# Turn on/off the installation and use of the runtime support library
HAS_RUNTIME_LIB=true

# Turn on/off the installation and use of the standard header files
HAS_STANDARD_HEADERS=true

# Whether the assembler $(CASM) supports .cfi debug directives
ASM_SUPPORTS_CFI=false
#ASM_SUPPORTS_CFI=true

EOF

fi

# Summarize configuration

if test "$target" = "manual"; then
cat <<EOF

Please finish the configuration by editing file ./Makefile.config.

EOF

else

bindirexp=`echo "$bindir" | sed -e "s|\\\$(PREFIX)|$prefix|"`
libdirexp=`echo "$libdir" | sed -e "s|\\\$(PREFIX)|$prefix|"`

cat <<EOF

CompCert configuration:
    Target architecture........... $arch
    Hardware model................ $model
    Application binary interface.. $abi
    Composite passing conventions. arguments: $struct_passing, return values: $struct_return
    OS and development env........ $system
    C compiler.................... $cc
    C preprocessor................ $cprepro
    Assembler..................... $casm
    Assembler supports CFI........ $asm_supports_cfi
    Assembler for runtime lib..... $casmruntime
    Linker........................ $clinker
    Math library.................. $libmath
    Binaries installed in......... $bindirexp
    Runtime library provided...... $has_runtime_lib
    Library files installed in.... $libdirexp
    Standard headers provided..... $has_standard_headers
    Standard headers installed in. $libdirexp/include
    cchecklink tool supported..... $cchecklink
    Build command to use.......... $make

If anything above looks wrong, please edit file ./Makefile.config to correct.

EOF

fi