forked from wbhart/bsdnt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·476 lines (427 loc) · 11 KB
/
configure
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
#!/bin/bash
# Copyright (c):
# * William Hart 2010, 2013. All rights reserved.
# * Antony Vennard 2010. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
# BSDNT UNIX Build System.
AS=
ASFILES=
AR=
CC=gcc
AFLAGS=
CFLAGS=
PIC_FLAG=
PREFIX=
SHARED=1
STATIC=1
ASSERT=0
REDZONES=1
BUILD=
ABI=
LIBRARIES=
# Header
echo "BSDNT Unix Build Script."
echo "BSDNT is a BSD-Licensed Bignum Library."
echo "BSDNT is Copyright (C) its contributors. See LICENSE."
echo "====================================================="
usage()
{
echo "Usage: ./configure <options> <args>"
echo " where <options> can be"
echo " -h display help"
echo " and <args> can be:"
echo " --build=arch-os Specify arch/OS combination"
echo " --prefix=<path> Use path as installation location (default: /usr/local)"
echo " --enable-shared Build a shared library (default)"
echo " --disable-shared Don't build a shared library"
echo " --enable-static Build a static library (default)"
echo " --disable-static Don't build a static library"
echo " --enable-assert Enable use of asserts (use for debug builds only)"
echo " --disable-assert Disable use of asserts (default)"
echo " --enable-redzones Enable redzones in test code (default)"
echo " --disable-redzones Disable redzones in test code"
echo " AS=<name> Use the given assembler (default gcc)"
echo " CC=<name> Use the given C compiler (default: gcc)"
echo " CXX=<name> Use the given C++ compiler (default: g++)"
echo " AR=<name> Use the given AR lib builder (default: ar)"
echo " CFLAGS=<flags> Specify the given compiler flags"
echo " ABI=[32|64] Use given ABI (default: empty)"
}
input_handler()
{
while [ "$1" != "" ]; do
PARAM=`echo $1 | sed 's/=.*//'`
VALUE=`echo $1 | sed 's/[^=]*//; s/=//'`
case "$PARAM" in
-h|--help)
usage
exit 0
;;
--build)
BUILD="$VALUE"
;;
--prefix)
PREFIX=$VALUE
;;
--enable-shared)
SHARED=1
;;
--disable-shared)
SHARED=0
;;
--enable-static)
STATIC=1
;;
--disable-static)
STATIC=0
;;
--enable-assert)
ASSERT=1
;;
--disable-assert)
ASSERT=0
;;
--enable-redzones)
ASSERT=1
;;
--disable-redzones)
ASSERT=0
;;
AR)
AR="$VALUE"
;;
AS)
AS="$VALUE"
;;
CC)
CC="$VALUE"
;;
CXX)
CXX="$VALUE"
;;
CFLAGS)
CFLAGS="$VALUE"
;;
ABI)
ABI="$VALUE"
;;
*)
usage
exit 1
;;
esac
shift
done
}
create_config_h()
{
echo "#define WANT_ASSERT ${ASSERT}" > config.h
echo "#define WANT_REDZONES ${REDZONES}" >> config.h
echo "#define IS_LITTLE_ENDIAN 0x10" >> config.h
echo "#define IS_BIG_ENDIAN 0x20" >> config.h
$CC arch/endian.c -o endian
ENDIAN=`./endian`
case $ENDIAN in
little)
echo "#define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN" >> config.h;;
big)
echo "#define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN" >> config.h;;
*)
echo "#error Machine must be either big or little endian!" >> config.h;;
esac
}
os_handler()
{
# Set Operating system
if [ -z "$BUILD" ]; then
OS=`uname -s`
else
OS=`echo "$BUILD" | cut -d- -f2`
fi
case "$OS" in
CYGWIN*)
if [ "$ABI" = "32" ]; then
OS="CYGWIN32"
elif [ "$ABI" = "64" ]; then
OS="CYGWIN64"
else
OS="CYGWIN"
fi
;;
MINGW*)
if [ "$ABI" = "64" ]; then
OS="MINGW64"
else
OS="MINGW"
fi
;;
*)
PIC_FLAG="-fPIC"
;;
esac
# Libraries
if [ -z "$LIBRARIES" ]; then
if [ "$SHARED" = "1" ]; then
case "$OS" in
Darwin)
LIBRARIES="libbsdnt.dylib";;
CYGWIN* | MINGW*)
LIBRARIES="libbsdnt.dll";;
*)
LIBRARIES="libbsdnt.so";;
esac
fi
if [ "$STATIC" = "1" ]; then
LIBRARIES="${LIBRARIES} libbsdnt.a"
fi
fi
}
arch_handler()
{
# Set Architecture
if [ -z "$BUILD" ]; then
ARCH=`uname -m`
else
ARCH=`echo "$BUILD" | cut -d- -f1`
fi
# Canonicalise machine name
case $ARCH in
x86_64 | amd64)
MACHINE="x86_64"
if [ "$OS" = "CYGWIN" ]; then
OS="CYGWIN64"
fi
;;
x86 | i*86 | pc)
MACHINE="x86"
if [ "$OS" = "CYGWIN" ]; then
OS="CYGWIN32"
fi
;;
*)
MACHINE="unknown"
;;
ia64)
MACHINE="ia64";;
sparc | sun4*)
MACHINE="sparc";;
sparc64)
MACHINE="sparc64";;
ppc64 | powerpc64)
MACHINE="ppc64";;
ppc | powerpc | [P|p]ower*)
MACHINE="ppc";;
*)
MACHINE="unknown";;
esac
# ABI flag
if [ "$ABI" = "32" ]; then
ABI_FLAG="-m32"
case "$MACHINE" in
x86_64)
MACHINE="x86";;
sparc64)
MACHINE="sparc";;
ppc64)
MACHINE="ppc";;
*)
;;
esac
elif [ "$ABI" = "64" ]; then
ABI_FLAG="-m64"
if [ "$MACHINE" = "sparc" ]; then
MACHINE="sparc64"
fi
if [ "$MACHINE" = "x86" ]; then
MACHINE="x86_64"
fi
fi
# Sparc fix
if [ "$MACHINE" = "sparc" ] || [ "$MACHINE" = "sparc64" ]; then
if [ "$CC" = "gcc" ]; then
CC="gcc -mno-relax"
fi
fi
# Create ARCH headers.
echo "" > helper_arch.h
if [ $MACHINE = "x86" -o $MACHINE = "x86_64" ]
then
$CC arch/cpuid.c -o cpuid
ARCH=`./cpuid`
case $ARCH in
k10)
EXTS="_k10 _k8";;
k102)
EXTS="_k102 _k10 _k8";;
k103)
EXTS="_k103 _k102 _k10 _k8";;
bobcat)
EXTS="_bobcat _k10 _k8";;
bulldozer)
EXTS="_bulldozer _k10 _k8";;
k8)
EXTS="_k8";;
atom)
EXTS="_atom";;
nehalem)
EXTS="_nehalem _core2";;
westmere)
EXTS="_iwestmere _core2";;
sandybridge)
EXTS="_sndybridge _core2";;
core2)
EXTS="_core2";;
p4)
EXTS="_p4";;
* | x86)
EXTS="";;
esac
if [ $MACHINE = "x86_64" ]
then
ASFLAGS="-felf64"
elif [ $MACHINE = "x86" ]
then
ASFLAGS="-felf32"
fi
for file in nn*.c
do
name=${file%\.*}
#echo " Writing ${name}_arch.h"
echo "#ifndef ${name}_H" > ${name}_arch.h
echo "#define ${name}_H" >> ${name}_arch.h
for ext in $EXTS
do
hname=arch/inline/$name"_"$MACHINE$ext.h
if [ -f $hname ]
then
echo "#include \"${hname}\"" >> ${name}_arch.h
fi
hname=arch/inline/$name"_"$MACHINE.h
if [ -f $hname ]
then
echo "#include \"${hname}\"" >> ${name}_arch.h
fi
done
echo "#endif" >> ${name}_arch.h
done
else
for file in nn*.c
do
name=${file%\.*}
echo "#ifndef ${name}_H" > ${name}_arch.h
echo "#define ${name}_H" >> ${name}_arch.h
echo "#endif" >> ${name}_arch.h
done
fi
}
defaults()
{
if [ -z "$CC" ]; then
CC=gcc
fi
if [ -z "$CXX" ]; then
CXX=g++
fi
if [ -z "$AR" ]; then
AR=ar
fi
if [ -z "$AS" ]; then
AS=gcc
fi
if [ -z "$CFLAGS" ]; then
CFLAGS="-pedantic -O2 -g -Wall ${ABI_FLAG} ${PIC_FLAG}"
fi
if [ -z "$PREFIX" ]; then
PREFIX="/usr/local"
fi
}
fill_makefile_wireframe()
{
echo "Examining source"
CFILESARR=`ls -1 *.c rand/*.c`
HFILESARR=`ls -1 *.h`
ARCHHFILESARR=`ls -1 arch/inline/*.h`
TFILESARR=`ls -1 test/t-*.c`
PFILESARR=`ls -1 profile/p-*.c`
for C in `echo ${CFILESARR[*]}`;
do
CFILES="$CFILES $C"
done
for H in `echo ${HFILESARR[*]}`;
do
HFILES="$HFILES $H"
done
for AH in `echo ${ARCHHFILESARR[*]}`;
do
ARCHHFILES="$ARCHHFILES $AH"
done
for T in `echo ${TFILESARR[*]}`;
do
TFILES="$TFILES $T"
done
for P in `echo ${PFILESARR[*]}`;
do
PFILES="$PFILES $P"
done
echo "Creating Makefile "
cp -f Makefile.unix Makefile
}
sed_makefile()
{
sed "s|__ASSEMBLER__|${AS}|g" Makefile > Makefile.tmp
sed "s|__ARCHIVE__|${AR}|g" Makefile.tmp > Makefile
sed "s|__COMPILER__|${CC}|g" Makefile > Makefile.tmp
sed "s|__AFLAGS__|${ASFLAGS}|g" Makefile.tmp > Makefile
sed "s|__CFLAGS__|${CFLAGS}|g" Makefile > Makefile.tmp
sed "s|__ASFILES__|${ASFILES}|g" Makefile.tmp > Makefile
sed "s|__SOURCES__|${CFILES}|g" Makefile > Makefile.tmp
sed "s|__HEADERS__|${HFILES}|g" Makefile.tmp > Makefile
sed "s|__TSOURCES__|${TFILES}|g" Makefile > Makefile.tmp
sed "s|__TESTS__|${TESTS}|g" Makefile.tmp > Makefile
sed "s|__PSOURCES__|${PFILES}|g" Makefile > Makefile.tmp
sed "s|__BINARIES__|${BINARIES}|g" Makefile.tmp > Makefile
sed "s|__LIBRARIES__|${LIBRARIES}|g" Makefile > Makefile.tmp
sed "s|__PREFIX__|${PREFIX}|g" Makefile.tmp > Makefile
sed "s|__ARCHHEADERS__|${ARCHHFILES}|g" Makefile > Makefile.tmp
mv Makefile.tmp Makefile
}
make_directory_structure()
{
mkdir -p build/arch
mkdir -p build/rand
mkdir -p build/test
mkdir -p build/profile
mkdir -p dist/lib
}
create_types_arch_h()
{
echo "" >> types_arch.h
}
input_handler $@
create_config_h
os_handler
arch_handler
defaults
create_types_arch_h
fill_makefile_wireframe
sed_makefile
make_directory_structure
echo "Done. "
echo " "
echo "Type make to build this library. We strongly recommend you run "
echo "make check and ensure all tests pass."
exit 0