File: configure

package info (click to toggle)
ocaml-zarith 1.14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 620 kB
  • sloc: ansic: 2,998; ml: 2,767; sh: 288; makefile: 81
file content (389 lines) | stat: -rwxr-xr-x 8,968 bytes parent folder | download
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
#! /bin/sh

# configuration script

# This file is part of the Zarith library 
# http://forge.ocamlcore.org/projects/zarith .
# It is distributed under LGPL 2 licensing, with static linking exception.
# See the LICENSE file included in the distribution.
#   
# Copyright (c) 2010-2011 Antoine Miné, Abstraction project.
# Abstraction is part of the LIENS (Laboratoire d'Informatique de l'ENS),
# a joint laboratory by:
# CNRS (Centre national de la recherche scientifique, France),
# ENS (École normale supérieure, Paris, France),
# INRIA Rocquencourt (Institut national de recherche en informatique, France).


# options
installdir='auto'
ocamllibdir='auto'
gmp='auto'
perf='no'

ocaml='ocaml'
ocamlc='ocamlc'
ocamlopt='ocamlopt'
ocamlmklib='ocamlmklib'
ocamldep='ocamldep'
ocamldoc='ocamldoc'
ccinc="$CPPFLAGS"
ldflags="$LDFLAGS"
cclib=''
ccdef=''
mlflags="$OCAMLFLAGS"
mloptflags="$OCAMLOPTFLAGS"
mlinc="$OCAMLINC"
objsuffix="o"
ocamlfind="auto"

# sanitize
LC_ALL=C
export LC_ALL
unset IFS


# help
help()
{
    cat <<EOF
usage: configure [options]

where options include:
  -installdir dir      installation directory
  -ocamllibdir dir     ocaml library directory
  -gmp                 use GMP library (default if found)
  -mpir                use MPIR library instead of GMP
  -perf                enable performance statistics
  -prefixnonocaml      add for non ocaml tool, e.g. -prefixnonocaml x86_64-w64-mingw32-

Environment variables that affect configuration:
  CFLAGS               extra flags to pass to the C compiler
  CPPFLAGS             extra includes, e.g. -I/path/to/gmp/include
  LDFLAGS              extra link flags, e.g. -L/path/to/gmp/lib
  OCAMLFLAGS           extra flags to pass to the ocamlc Caml compiler
  OCAMLOPTFLAGS        extra flags to pass to the ocamlopt Caml compiler
  OCAMLINC             extra includes to pass to the Caml compilers
EOF
    exit
}

# parse arguments
while : ; do
    case "$1" in
        "") 
            break;;
        -installdir|--installdir)
            installdir="$2"
            shift;;
        -ocamllibdir|--ocamllibdir)
            ocamllibdir="$2"
            shift;;
        -no-ocamlfind|--no-ocamlfind)
            ocamlfind="no"
            shift;;
        -help|--help)
            help;;
        -gmp|--gmp)
            gmp='gmp';;
        -mpir|--mpir)
            gmp='mpir';;
        -perf|--perf)
            perf='yes';;
        -prefixnonocaml|--prefixnonocaml)
            prefixnonocaml="$2"
            shift;;
        *)
            echo "unknown option $1, try -help"
            exit 2;;
    esac
    shift
done

if test "$perf" = "yes"; then ccdef="-DZ_PERF_COUNTER $ccdef"; fi

echo_n()
{
    echo "$1" | tr -d '\012'
}

# checking binaries in $PATH

searchbin()
{
    if test "x$1" = "x"; then return 0; fi
    echo_n "binary $1: "
    case "$1" in
      /*|./*|../*)
        if test -f "$1" && test -x "$1"
        then echo "found"; return 1
        else echo "not found"; return 0
        fi;;
    esac
    IFS=':'
    for i in $PATH
    do
        if test -z "$i"; then i='.'; fi
        if test -f $i/$1 && test -x $i/$1; then echo "found in $i"; unset IFS; return 1; fi
    done
    echo "not found"
    unset IFS
    return 0
}

searchbinreq()
{
    searchbin $1
    if test $? -eq 0; then echo "required program $1 not found"; exit 2; fi
}


# checking includes and libraries

checkinc()
{
    echo_n "include $1: "
    rm -f tmp.c tmp.o
    echo "#include <$1>" > tmp.c
    echo "int main() { return 1; }" >> tmp.c
    r=1
    $ocamlc -ccopt "$ccopt $ccinc" -c tmp.c -o tmp.o >/dev/null 2>/dev/null || r=0
    if test ! -f tmp.o; then r=0; fi
    rm -f tmp.c tmp.o
    if test $r -eq 0; then echo "not found"; else echo "found"; fi
    return $r
}

checklib()
{
    echo_n "library $1: "
    rm -f tmp.ml tmp.out
    echo "" > tmp.ml
    r=1
    $ocamlc -custom -ccopt "$ldflags $cclib" tmp.ml -cclib -l$1 -o tmp.out >/dev/null 2>/dev/null || r=0
    if test ! -x tmp.out; then r=0; fi
    rm -f tmp.out tmp.ml tmp.cmi tmp.cmo
    if test $r -eq 0; then echo "not found"; else echo "found"; fi
    return $r
}

checkcc()
{
    echo_n "checking compilation with $ocamlc $ccopt: "
    rm -f tmp.c tmp.out
    echo "int main() { return 1; }" >> tmp.c
    echo "" > tmpml.ml
    r=1
    $ocamlc -ccopt "$ccopt" tmp.c tmpml.ml -o tmp.out >/dev/null 2>/dev/null || r=0
    if test ! -x tmp.out; then r=0; fi
    rm -f tmp.c tmp.o tmp.out tmpml.ml tmpml.cm*
    if test $r -eq 0; then echo "not working"; else echo "working"; fi
    return $r
}

checkcmxalib()
{
    echo_n "library $1: "
    $ocamlopt $mloptflags $1 -o tmp.out >/dev/null 2>/dev/null || r=0
    if test ! -x tmp.out; then r=0; fi
    rm -f tmp.out
    if test $r -eq 0; then echo "not found"; else echo "found"; fi
    return $r    
}


# check required programs

searchbinreq $ocaml
searchbinreq $ocamlc
searchbinreq $ocamldep
searchbinreq $ocamlmklib
if searchbin $ocamldoc; then
  ocamldoc=''
fi

if test -n "$CC"; then
  searchbinreq "$CC"
  ccopt="$CFLAGS"
else
  ccopt="-O3 -Wall -Wextra $CFLAGS"
fi

# optional native-code generation

hasocamlopt='no'

searchbin $ocamlopt
if test $? -eq 1; then hasocamlopt='yes'; fi


# check C compiler

checkcc
if test $? -eq 0; then
    # try again with (almost) no options
    ccopt='-O'
    checkcc
    if test $? -eq 0; then echo "cannot compile and link program"; exit 2; fi
fi


# directories

if test "$ocamllibdir" = "auto"
then ocamllibdir=`ocamlc -where | sed 's/\r$//'`
fi

if test ! -f "$ocamllibdir/caml/mlvalues.h"
then echo "cannot find OCaml libraries in $ocamllibdir"; exit 2; fi
ccinc="-I$ocamllibdir $ccinc"
checkinc "caml/mlvalues.h"
if test $? -eq 0; then echo "cannot include caml/mlvalues.h"; exit 2; fi


# optional dynamic linking

hasdynlink='no'

if test $hasocamlopt = yes
then
    checkcmxalib dynlink.cmxa
    if test $? -eq 1; then hasdynlink='yes'; fi
fi


# installation method

searchbin ocamlfind
if test $? -eq 1 && test $ocamlfind != "no"; then 
    instmeth='findlib'
    if test "$installdir" = "auto"
    then installdir=`ocamlfind printconf destdir`; fi
else
    searchbin install
    if test $? -eq 1; then instmeth='install'
    else echo "no installation method found"; exit 2; fi
    if test "$installdir" = "auto"; then installdir="$ocamllibdir"; fi
fi


# detect OCaml's word-size

echo "print_int (Sys.word_size);;" > tmp.ml
wordsize=`ocaml tmp.ml`
echo "OCaml's word size is $wordsize"
rm -f tmp.ml


# check GMP, MPIR

if test "$gmp" = 'gmp' || test "$gmp" = 'auto'; then
    if pkg-config gmp 2>/dev/null; then
        echo 'package gmp: found'
        gmp='OK'
        cclib="$cclib $(pkg-config --libs gmp)"
        ccinc="$ccinc $(pkg-config --cflags gmp)"
        ccdef="-DHAS_GMP $ccdef"
    else
        checkinc gmp.h
        if test $? -eq 1; then
            checklib gmp
            if test $? -eq 1; then 
                gmp='OK'
                cclib="$cclib -lgmp"
                ccdef="-DHAS_GMP $ccdef"
            fi
        fi
    fi
fi
if test "$gmp" = 'mpir' || test "$gmp" = 'auto'; then
    checkinc mpir.h
    if test $? -eq 1; then
        checklib mpir
        if test $? -eq 1; then 
            gmp='OK'
            cclib="$cclib -lmpir"
            ccdef="-DHAS_MPIR $ccdef"
        fi
    fi
fi
if test "$gmp" != 'OK'; then echo "cannot find GMP nor MPIR"; exit 2; fi


# OCaml version

ocamlver=`ocamlc -version`

# OCaml version 4.04 or later is required

case "$ocamlver" in
    [123].* | 4.0[0123].*)
        echo "OCaml version $ocamlver is no longer supported."
        echo "OCaml version 4.04.0 or later is required."
        exit 2
        ;;
esac

# -bin-annot available since 4.00.0
echo "OCaml supports -bin-annot to produce documentation"
hasbinannot='yes'

# Changes to C API (the custom_operation struct) since 4.08.0
case "$ocamlver" in
    [123].* | 4.0[01234567].* )
        echo "Using OCaml legacy C API custom operations"
        ccdef="-DZ_OCAML_LEGACY_CUSTOM_OPERATIONS $ccdef"
    ;;
    *)
    ;;
esac

# dump Makefile

cat > Makefile <<EOF
# generated by ./configure

OCAMLC=$ocamlc
OCAMLOPT=$ocamlopt
OCAMLDEP=$ocamldep
OCAMLMKLIB=$ocamlmklib
OCAMLDOC=$ocamldoc
OCAMLFLAGS=$mlflags
OCAMLOPTFLAGS=$mloptflags
OCAMLINC=$mlinc
CFLAGS=$ccinc $ccdef $ccopt
LIBS=$cclib
LDFLAGS=$ldflags
INSTALLDIR=$installdir
INSTALL=install
OCAMLFIND=ocamlfind
INSTMETH=$instmeth
OBJSUFFIX=$objsuffix
HASOCAMLOPT=$hasocamlopt
HASDYNLINK=$hasdynlink
HASBINANNOT=$hasbinannot

include project.mak
EOF


# dump summary

cat <<EOF

detected configuration:

  native-code:          $hasocamlopt
  dynamic linking:      $hasdynlink
  defines:              $ccdef
  includes:             $ccinc
  libraries:            $cclib
  linker options:       $ldflags
  C options:            $ccopt
  installation path:    $installdir
  installation method   $instmeth

configuration successful!
now type "make" to build
then type "make install" or "sudo make install" to install
EOF