File: Configure

package info (click to toggle)
sympow 2.023.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 496 kB
  • sloc: ansic: 3,871; sh: 687; makefile: 17
file content (382 lines) | stat: -rwxr-xr-x 13,181 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
#! /bin/bash

if [ "$1" != "" ];
then
echo "**ERROR**: Configure does not take any options for SYMPOW"; exit;
fi

ADDBINPATH=${ADDBINPATH:-"no"}

DEB_PKG_VERSION=${DEB_VERSION:-"0.000.0-0"}

PREFIX=${PREFIX:-"/usr"}
VARPREFIX=${VARPREFIX:-"/var"}

FILE="Makefile.new"
CONFIG="config.h"
RM=`which \rm`
if [ -z "$RM" ];
then
echo "**ERROR**: Could not find rm"; exit;
fi
$RM -f $FILE
$RM -f $CONFIG
VERSION=2.023.7
echo "#define PREFIX \"$PREFIX\"" >> $CONFIG
echo "#define VARPREFIX \"$VARPREFIX\"" >> $CONFIG
echo "#define VERSION \"$VERSION\"" >> $CONFIG
echo "#define FLAVOUR \"RELEASE (Debian $DEB_PKG_VERSION)\"" >> $CONFIG
echo "VERSION = $VERSION" >> $FILE
echo "DEB_PKG_VERSION = ${DEB_PKG_VERSION}" >> $FILE

GREP=`which \grep`
if [ -z "$GREP" ];
then
echo "*WARNING*: Could not find grep --- will not be able to build new_data"
fi

##GP=`which \gp`
GP="/usr/bin/gp"
if [ -z "$GP" ];
then
echo "*WARNING*: Could not find gp --- will not be able to build new_data"
fi

SED=`which \sed` && echo "SED = $SED" >> $FILE
if [ -z "$SED" ];
then
echo "*WARNING*: Could not find sed --- will not be able to build new_data"
fi

if [ "x$ADDBINPATH" = "xyes" ]; then
echo "#define RM \"$RM\"" >> $CONFIG
[ -n "$GREP" ] && echo "#define GREP \"$GREP\"" >> $CONFIG
[ -n "$GP" ] && echo "#define GP \"$GP\"" >> $CONFIG
[ -n "$SED" ] && echo "#define SED \"$SED\"" >> $CONFIG
else
echo "#define RM \"rm\"" >> $CONFIG
[ -n "$GREP" ] && echo "#define GREP \"grep\"" >> $CONFIG
[ -n "$GP" ] && echo "#define GP \"gp\"" >> $CONFIG
[ -n "$SED" ] && echo "#define SED \"sed\"" >> $CONFIG
fi

[ -n "$GREP" ] && [ -n "$GP" ] && [ -n "$SED" ]\
 && echo "#define NEW_DATA" >> $CONFIG

SH=/bin/sh
echo "#define SH \"$SH\"" >> $CONFIG
echo "SH = $SH" >> $FILE

CC=${CC:-gcc} && echo "CC = $CC" >> $FILE
##if [ -z "$CC" ];
##then
##echo "**ERROR**: Could not find cc"; exit;
##fi
export CC

##UNAME=`which \uname`
##if [ -z "$UNAME" ];
##then
##echo "**ERROR**: Could not find uname"; exit;
##fi

HELP2MAN=`which \help2man` && echo "HELP2MAN = $HELP2MAN" >> $FILE
if [ -z "$HELP2MAN" ];
then
echo "**ERROR**: Could not find help2man"; exit;
fi

## Sage material (spkg-install)
#######################################################################
# Fix FPU precision
#######################################################################
# SYMPOW really needs doubles to have *exactly* 53 bits precision,
# they need to be true IEEE-754 double precision numbers.
# In particular, we need to avoid 80 bits extended precision on i386
# and we need to avoid fused multiply-add instructions (e.g. on ia64).
# We might need to add various flags to CFLAGS to ensure this.
# See Trac tickets #9703, #9734, #9166, #11226, #11920.

ORIGINALCFLAGS=${CFLAGS}
CFLAGS=''

# Usage: try_add_CFLAG $FLAG
# Try adding $FLAG to $CFLAGS, compile and run the fpubits program.
# If it compiles and running it doesn't crash it (with an Illegal
# Instruction for example), then we add $FLAG to $CFLAGS.
# Return 0 if we added $FLAG and the FPU correctly used 53 bits,
# return 1 if we added $FLAG but the FPU doesn't use 53 bits,
# return 2 if we did not add $FLAG.
try_add_CFLAG()
{
    # We use -O3 here to really force generation of fused
    # multiply-add instructions and to keep floats as much as
    # possible in registers.
    # We compile in the fpu.c which only does
    # something if the macro x86 is defined.
    local flag=$1                      # first argument:  C FLAG to test
    local bypassfputest=${2:-nobypass} # second argument: whether or not bypass the numerical test (default: not)
    local status=0
    if $CC $ORIGINALCFLAGS -Werror $CFLAGS -O3 $flag config/fpubits1.c config/fpubits2.c fpu.c -o config/fpubits 2>/dev/null; then
        # Compiled successfully, now run it
        config/fpubits >/dev/null 2>/dev/null
        status=$?
        if [ $status -le 1 ]; then
            # The program ran successfully.  For now, we don't need
            # the exit status to be zero (indicating exactly 53 bits),
            # we simply need the program not to crash (which would
            # give an exit status > 128).
            CFLAGS="$CFLAGS $flag"
            if [ "x$bypassfputest" = "xnobypass" ]; then
                return $status
            else
                return 0
            fi
        fi
    fi
    return 2
}

# Let move to 21st century and add GNU features (asprintf)
try_add_CFLAG '-std=gnu17' bypass
if [ $? -ne 0 ]; then
    try_add_CFLAG '-std=gnu11' bypass
    if [ $? -ne 0 ]; then
      echo >&2 "Error: moving to 21st century and adding GNU feature are denied"
      exit 1
    fi
fi

# These flags never hurt, so add them if possible
for FLAG in '-fno-fast-math' '-mfpmath=sse'; do
    try_add_CFLAG $FLAG bypass
done

# Add at most one flag of the following to avoid gcc warnings:
# gcc versions which support -ffp-contract deprecate -mno-fused-madd
for FLAG in '-ffp-contract=on' '-mno-fused-madd'; do
    try_add_CFLAG $FLAG bypass && break
done

# Select the most appropriate FPU control scheme
for FLAG in '-DISOC99_FENV' '-DFPUCONTROLH' '-Dx86'; do
    try_add_CFLAG $FLAG && break
done

# Some flags to try as last resort.  These hurt performance, so only add
# them if needed.
for FLAG in '' '-ffloat-store' '-O0'; do
    # Stop the loop if the FPU precision already is 53 bits
    try_add_CFLAG $FLAG && break
done

# Check the actual FPU precision with our new flags.
CC_ARGS="$ORIGINALCFLAGS -O3 $CFLAGS config/fpubits1.c config/fpubits2.c fpu.c -o config/fpubits"
$CC $CC_ARGS
if [ $? -ne 0 ]; then
echo >&2 "Error: the command below failed:"
    echo >&2 "$CC $CC_ARGS"
    exit 1
fi
export CFLAGS

echo "CFLAGS for SYMPOW: $CFLAGS"

config/fpubits
status=$?
if [ $status -eq 1 ]; then
cat >&2 <<EOF
Error: the Quad Double library used by SYMPOW assumes IEEE-754 double
precision numbers with exactly 53 bits in the mantissa (64 bits in
total).  Unfortunately, this is not the case on your system and we
currently have no workaround for your system.  Running SYMPOW will
almost certainly fail on some inputs.

Please report this problem to sage-devel
(http://groups.google.com/group/sage-devel), mentioning in particular
your operating system, processor type and compiler version
(run $CC --version).
EOF
elif [ $status -ne 0 ]; then
cat >&2 <<EOF
Error: something very bad happened while checking the precision of your
FPU.  Please report this problem (mentioning any error messages above)
to sage-devel (http://groups.google.com/group/sage-devel).
Mention in particular your operating system and compiler version
(run $CC --version).
EOF
exit 1
fi

## non-sage material
#######################################################################
# Determine architecture endianess-tuple
#######################################################################
CC_ARGS="config/endiantuple.c -o config/endiantuple"
$CC $CC_ARGS
if [ $? -ne 0 ]; then
    echo >&2 "Error: the command below failed:"
    echo >&2 "$CC $CC_ARGS"
    exit 1
fi
ENDIANTUPLE=$(config/endiantuple) && echo "#define ENDIANTUPLE \"$ENDIANTUPLE\"" >> $CONFIG
if [ -z "$ENDIANTUPLE" ]; then
    echo >&2 "Error: could not determine the endian tuple"
		exit 1
fi

echo "ENDIANTUPLE for SYMPOW: $ENDIANTUPLE"

echo "CONFEXE = config/endiantuple config/fpubits" >> $FILE

##

##MACH=`"$UNAME" -m`
##for x in ix86 i386 i486 i586 i686 i386pc x86_64 ia64
##do
##if [ "$MACH" = "$x" ];
##then
##if [ "$x" = "x86_64" ] || [ "$x" = "ia64" ]
##then
##echo "You appear to have a $x based system --- linking fpu.s to fpu64.s"
##$RM -f fpu.s
##LN=ln
##$LN -s fpu64.s fpu.s
##DEFS="-Dx86 -m64"
##else
##echo "You appear to have a $x based system --- linking fpu.s to fpu32.s"
##$RM -f fpu.s
##LN=ln
##$LN -s fpu32.s fpu.s
##DEFS="-Dx86 -m32"
##fi
##fi
##done
##if [ -z "$DEFS" ];
##then
##echo "You do not appear to have an x86 based system --- not using fpu.s"
##$RM -f fpu.s
##$TOUCH fpu.s
##fi
##
##echo "DEFS = $DEFS" >> $FILE

OPT="-O3 ${CFLAGS}" && echo "OPT = $OPT" >> $FILE

echo "H2MFLAGS = \\" >> $FILE
echo "	--manual=\"SYMPOW package\" \\" >> $FILE
echo "	--source=\"SYMPOW (Debian \$(DEB_PKG_VERSION))\" \\" >> $FILE
echo "	--help-option=-help \\" >> $FILE
echo "	--version-option=-dump-versiontuple \\" >> $FILE
echo "	--no-info" >> $FILE

echo "CFLAGS += -Wno-unused-result" >> $FILE

echo "SRCS0 = fpu.c" >> $FILE
echo "SRCS1 = analrank.c analytic.c compute.c compute2.c help.c" >> $FILE
echo "SRCS2 = conductors.c disk.c ec_ap.c ec_ap_bsgs.c ec_ap_large.c" >> $FILE
echo "SRCS3 = eulerfactors.c factor.c generate.c init_curve.c main.c" >> $FILE
echo "SRCS4 = moddeg.c periods.c prepare.c QD.c rootno.c util.c" >> $FILE
echo "SRCS = \$(SRCS0) \$(SRCS1) \$(SRCS2) \$(SRCS3) \$(SRCS4)" >> $FILE
echo "OBJS = \$(SRCS:.c=.o)" >> $FILE
##echo "OBJSf = \$(OBJS) fpu.o" >> $FILE
echo "OTHER = new_data COPYING README Configure fpu32.s fpu64.s"  >> $FILE
echo "OTHERgp = standard1.gp standard2.gp standard3.gp" >> $FILE
echo "OTHERb = armd.gp ianalrank.gp ihmd.gp imd.gp armd.sh" >> $FILE
echo "OTHERS = \$(OTHER) \$(OTHERgp) \$(OTHERb)" >> $FILE
echo "HEADERS = sympow.h" >> $FILE
echo "SRC = \$(SRCS) \$(HEADERS) \$(OTHERS)" >> $FILE
echo "TILDES = *~ datafiles/*~" >> $FILE
df="datafiles"
echo "DATAFILES = $df/*M.txt $df/*S.txt $df/param_data" >> $FILE

echo "RM = $RM" >> $FILE
CP=`which \cp` && echo "CP = $CP" >> $FILE
if [ -z "$CP" ];
then
echo "**ERROR**: Could not find cp"; exit;
fi
MKDIR=`which \mkdir` && echo "MKDIR = $MKDIR" >> $FILE
if [ -z "$MKDIR" ];
then
echo "**ERROR**: Could not find mkdir"; exit;
fi
TOUCH=`which \touch` && echo "TOUCH = $TOUCH" >> $FILE
if [ -z "$TOUCH" ];
then
echo "**ERROR**: Could not find touch"; exit;
fi
####TAR=`which \tar` && echo "TAR = $TAR" >> $FILE
####if [ -z "$TAR" ];
####then
####echo "*WARNING*: Could not find tar --- source/archive omitted from Makefile";
####else
####echo "TARS = sympow.tar sympow.src.tar" >> $FILE
####echo "WDIR = SYMPOW-\$(VERSION)" >> $FILE && echo "" >> $FILE
####fi

echo "default: build-arch" >> $FILE
echo "all: build-arch build-indep" >> $FILE
echo "build-arch: sympow sympow.1" >> $FILE
echo "build-indep: datafiles/param_data" >> $FILE
echo "sympow: \$(OBJS)" >> $FILE
echo "	\$(CC) \$(CPPFLAGS) \$(CFLAGS) \$(OPT) -o \$@ \$(DEFS) \$(OBJS) \$(LDFLAGS) \$(LIBS)" >> $FILE
##echo "fpu.o : fpu.s Makefile" >> $FILE
##echo "	\$(CC) \$(OPT) -c fpu.s" >> $FILE
echo "%.o : %.c \$(HEADERS) Makefile" >> $FILE
echo "	\$(CC) \$(CPPFLAGS) \$(CFLAGS) \$(OPT) \$(DEFS) -c -o \$@ \$<" >> $FILE
echo "datafiles/param_data: \$(OTHERb)" >> $FILE
echo "	\$(MKDIR) -p datafiles" >> $FILE
echo "	\$(TOUCH) datafiles/param_data" >> $FILE
echo "	\$(SH) armd.sh" >> $FILE
echo "	\$(SH) debian/adhoc/job/sympow-new_data.job" >> $FILE
echo "	\$(SED) -i -e '/logfile =/d'  datafiles/*.txt" >> $FILE
echo "	\$(SED) -i -e '/logfile is/d' datafiles/*.txt" >> $FILE
echo "sympow.1: sympow" >> $FILE
echo "	\$(HELP2MAN) \$(H2MFLAGS) -s 1 -n \"SYMPOW program\" -I sympow.h2m -o \$@ ./\$<" >> $FILE
echo "clean:" >> $FILE
##echo "	\$(RM) -f \$(OBJSf) sympow \$(TILDES) \$(TARS)" >> $FILE
echo "	\$(RM) -f \$(OBJS) sympow sympow.1 \$(TILDES)" >> $FILE
echo "	\$(RM) -rf datafiles" >> $FILE
echo "distclean: clean" >> $FILE
echo "	\$(RM) -f \$(CONFEXE)" >> $FILE
echo "	\$(RM) -f config.h Makefile" >> $FILE
echo "install-arch: build-arch" >> $FILE
echo "	install -d \$(DESTDIR)$PREFIX/bin" >> $FILE
echo "	install -d \$(DESTDIR)$PREFIX/share/man/man1" >> $FILE
echo "	install -m 0755 sympow \$(DESTDIR)$PREFIX/bin" >> $FILE
echo "	install -m 0644 sympow.1 \$(DESTDIR)$PREFIX/share/man/man1" >> $FILE
echo "install-indep: build-indep" >> $FILE
echo "	install -d \$(DESTDIR)$PREFIX/libexec/sympow" >> $FILE
echo "	install -d \$(DESTDIR)$PREFIX/share/sympow" >> $FILE
echo "	install -d \$(DESTDIR)$PREFIX/share/sympow/datafiles" >> $FILE
##echo "	install -d \$(DESTDIR)$VARPREFIX/cache/sympow/datafiles" >> $FILE
echo "	install -m 0755 new_data \$(DESTDIR)$PREFIX/libexec/sympow" >> $FILE
echo "	install -m 0644 standard1.gp standard2.gp standard3.gp \$(DESTDIR)$PREFIX/share/sympow" >> $FILE
echo "	install -m 0644 datafiles/*.txt datafiles/param_data \$(DESTDIR)$PREFIX/share/sympow/datafiles" >> $FILE
echo "install: install-arch #install-indep" >> $FILE
####if [ -n "$TAR" ];
####then
####echo "source:" >> $FILE
####echo "	\$(MKDIR) \$(WDIR)" >> $FILE
####echo "	\$(CP) -f \$(SRC) \$(WDIR)" >> $FILE
####echo "	\$(TAR) cf sympow.src.tar \$(WDIR)/*" >> $FILE
####echo "	\$(RM) -rf \$(WDIR)" >> $FILE
####echo "archive:" >> $FILE
####echo "	\$(MKDIR) \$(WDIR)" >> $FILE
####echo "	\$(CP) -f \$(SRC) \$(WDIR)" >> $FILE
####echo "	\$(MKDIR) \$(WDIR)/datafiles" >> $FILE
####echo "	\$(CP) -f \$(DATAFILES) \$(WDIR)/datafiles" >> $FILE
####echo "	\$(TAR) cf sympow.tar \$(WDIR)/*" >> $FILE
####echo "	\$(RM) -rf \$(WDIR)" >> $FILE
####fi

$RM -f Makefile
$CP -f Makefile.new Makefile
$RM -f Makefile.new

echo "Makefile has been re-made. Use make if you wish to build SYMPOW"
####echo ""
####echo "**ATTENTION** If you wish build SYMPOW, please ensure beforehand"
####echo "that the various licenses of your C compiler, linker, assembler, etc."
####echo "allow you to create a derived work based on SYMPOW and your C libraries"