forked from floodyberry/chacha-opt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·712 lines (596 loc) · 20.2 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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
#!/bin/sh
if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
cat << EOF
Usage: ./configure [options]
Help:
-h, --help print this message
Installation options:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
--bindir=DIR install binaries in DIR [EPREFIX/bin]
--libdir=DIR install libs in DIR [EPREFIX/lib]
--includedir=DIR install includes in DIR [PREFIX/include]
Configuration options:
--appdir=DIR read per-project files (extensions/, project.def/ver) from DIR [app]
--debug builds with no optimization and debugging symbols enbaled
--disable-as do not use external assembly
--example equivalent to --appdir=app-
--force-32bits (try to) build for 32bits regardless of underlying system
--force-64bits (try to) build for 64bits regardless of underlying system
--generic alias for --disable-as, forces a generic build
--pic pass -fPIC to the compiler, required to build shared library
--strict use strict compiler flags for C
--yasm use yasm to compile external asm
EOF
exit 1
fi
cleanup() {
rm -f test.o
rm -f test
rm -f test.log
}
fatal_error() {
cleanup
echo "ERROR: $@"
exit 1
}
try_asm() {
printf "%s\n%s\n" "$asmheader" "$1" | $AS $ASFLAGSTEST -o test.o - >test.log 2>&1
res=$?
cat test.log >> $outputlog
return $res
}
test_for_asm_instruction_set() {
echo "checking for $2.." >>$outputlog
if try_asm "$1"; then
echo "#define $2" >> $outputheader
fi
}
test_for_asm_macro_parameter_convention() {
echo "checking for $4.." >>$outputlog
prog=$(printf "%s\n%s\n%s\n%s\n" ".macro TEST1 op" "$1 $3, $3" ".endm" "TEST1 $2")
if try_asm "$prog"; then
echo "#define $4" >> $outputheader
fi
}
test_for_asm_function_annotation() {
echo "checking for $1.." >>$outputlog
prog=$(printf ".globl %s\n%s %s\n%s\n" "myfn" "$1" "myfn" "myfn:")
try_asm "$prog"
res=$?
return $res
}
try_c() {
printf "%s\n" "$1" | $CC $CFLAGSTEST -o test.o - >test.log 2>&1
res=$?
cat test.log >> $outputlog
return $res
}
try_c_visibility() {
echo "checking for $1.." >> $outputlog
OLDFLAGS="$CFLAGSTEST"
CFLAGSTEST="$CFLAGSTEST -fvisibility=hidden -Werror"
prog=$(printf "%s int vis() { return 53; }" "$1")
try_c "$prog"
res=$?
return $res
}
try_c_stdint() {
echo "checking for $1.." >> $outputlog
prog=$(printf "#include <stdint.h>\nint main() { %s x = 53; return (int)x; }" "$1")
try_c "$prog"
res=$?
return $res
}
try_c_runnable() {
rm -f test
printf "%s\n" "$1" | $CC $CFLAGSTEST -o test.o - >test.log 2>&1
res=$?
cat test.log >> $outputlog
if [ "$res" != "0" ]; then
return $res
fi
$CC -o test test.o >test.log 2>&1
res=$?
cat test.log >> $outputlog
return $res
}
try_c_type() {
echo "checking for $1.." >> $outputlog
prog=$(printf "int main() {\n%s t = 0; return (int) t;\n}" "$1")
try_c "$prog"
res=$?
return $res
}
try_c_type_unsigned() {
echo "checking for $2 with $1 bits.." >> $outputlog
prog=$(printf "typedef %s mytype; int main(int argc,char *argv[]) {mytype x; int i; x = (mytype) atoi(argv[1]); for(i=0;i<%s;i++){if(x==0) return 100; x+=x+(mytype)atoi(argv[2]);} if(x!=0) return 100; x-=1; if(x<0) return 100; return 0;}" "$2" "$1")
try_c_runnable "$prog" || return $?
./test 1 0
res=$?
return $res
}
define_c_type() {
echo "#define HAVE_$1" >> $outputheader
echo "#define DEFINE_$1 typedef $2; typedef $3;" >> $outputheader
}
define_c_type_undefined() {
echo "#define DEFINE_$1" >> $outputheader
}
does_c_define_exist() {
echo "checking for $1.." >> $outputlog
prog=$(printf "int main() {\n#if defined(%s)\nreturn 0;\n#else\n#error error\n#endif\n}" "$1")
try_c "$prog"
res=$?
return $res
}
test_for_gnu_make() {
if [ "$GNUMAKE" = "" ]; then
echo "checking for gnu make as '$1'" >> $outputlog
res=`$1 -v 2>$outputlog | grep GNU`
if [ "$res" != "" ]; then
GNUMAKE="$1"
fi
fi
}
# options
outputheader="framework/include/asmopt.h"
outputheaderstub="framework/include/asmopt_internal.h"
outpututilimpls="framework/include/util_implementations.h"
outputmake="asmopt.mak"
outputlog="config.log"
inputprojectname="project.def"
inputprojectver="project.ver"
asmheader=".text"
debug="no"
bits32="no"
bits64="no"
strict="no"
yasm="no"
pic="no"
appdir="app"
prefix="/usr/local"
exec_prefix=""
bindir=""
libdir=""
includedir=""
# handle input paramters
while [ "$1" != "" ]; do
arg="${1#*=}"
case $1 in
--appdir=* ) appdir="$arg"
;;
--example ) appdir="app-example"
;;
--prefix=* ) prefix="$arg"
;;
--exec-prefix=* ) exec_prefix="$arg"
;;
--bindir=* ) bindir="$arg"
;;
--libdir=* ) libdir="$arg"
;;
--includedir=* ) includedir="$arg"
;;
--debug ) debug="yes"
;;
--disable-as ) HAVEAS="no"
;;
--generic ) HAVEAS="no"
;;
--force-32bits ) bits32="yes"
;;
--force-64bits ) bits64="yes"
;;
--pic ) pic="yes"
;;
--strict ) strict="yes"
;;
--yasm ) yasm="yes"
;;
* ) echo "Unknown paramaters $1, skipping.."
;;
esac
shift
done
exec_prefix="${exec_prefix:-$prefix}"
bindir="${bindir:-${exec_prefix}/bin}"
libdir="${libdir:-${exec_prefix}/lib}"
includedir="${includedir:-${prefix}/include}"
GNUMAKE=""
test_for_gnu_make "make"
test_for_gnu_make "gmake"
if [ "$GNUMAKE" = "" ]; then
fatal_error "Unable to find gnu make! (tried make, gmake)"
fi
# make variables
CC="${CC:-gcc}"
AR="${AR:-ar}"
LD="${CC} -o "
RANLIB="${RANLIB:-ranlib}"
STRIP="${STRIP:-strip}"
INSTALL="${INSTALL:-install}"
CFLAGS="${CFLAGS:-}"
CFLAGSTEST="-x c -c"
SOFLAGS="${SOFLAGS:-}"
SONAME=""
SOSUFFIX=""
SOIMPORT=""
LDFLAGS="${LDFLAGS:-}"
AS="$CC"
ASFLAGS=""
ASFLAGSTEST="-x assembler -c"
HAVEAS="${HAVEAS:-yes}"
HAVESHARED="no"
DEPMM="-MMD"
DEPMF="-MF"
ARCH="generic"
OFORMAT="generic"
EXE=""
STATICLIB=".lib"
[ -e $appdir/$inputprojectname ] || fatal_error "Unable to find $appdir/$inputprojectname!"
[ -e $appdir/$inputprojectver ] || fatal_error "Unable to find $appdir/$inputprojectver!"
PROJECTNAME=`tr -d '[:cntrl:]' <$appdir/$inputprojectname 2>$outputlog | tr '[:upper:]' '[:lower:]'`
PROJECTNAMEUPPER=`tr -d '[:cntrl:]' <$appdir/$inputprojectname 2>$outputlog | tr '[:lower:]' '[:upper:]'`
PROJECTVERMAJOR=`cut -d . -f 1 $appdir/$inputprojectver` 2>$outputlog
if [ x"$PROJECTNAME" = "x" ]; then
fatal_error "Unable to determine project name! Edit $appdir/$inputprojectname to set it"
fi
if [ x"$PROJECTVERMAJOR" = "x" ]; then
fatal_error "Unable to determine project name! Edit $appdir/$inputprojectver to set it"
fi
if [ "$yasm" = "yes" ]; then
AS="yasm"
ASFLAGSTEST="-r nasm -p gas -f elf32"
fi
# set things up
mkdir -p build
rm -f $outputmake
> $outputlog
cat > $outputheaderstub << EOF
#ifndef ASMOPT_INTERNAL_H
#define ASMOPT_INTERNAL_H
EOF
cat > $outputheader << EOF
#ifndef ASMOPT_${PROJECTNAMEUPPER}_H
#define ASMOPT_${PROJECTNAMEUPPER}_H
EOF
# output format
if does_c_define_exist "__MACH__"; then
OFORMAT="macho"
elif does_c_define_exist "__ELF__"; then
OFORMAT="elf"
elif does_c_define_exist "_WIN32" || does_c_define_exist "_WIN64" || does_c_define_exist "__CYGWIN__"; then
OFORMAT="win"
EXE=".exe"
else
OFORMAT="generic"
fi
# assembler detection
foundas="no"
if [ "$HAVEAS" = "yes" ] && try_asm "xorb %al, %al"; then
ASFLAGSTEST="$ASFLAGSTEST -m32"
echo "#define ARCH_X86" >> $outputheader
ARCH="x86"
# make sure the C compiler is actually speaking x86
if does_c_define_exist "__i386__"; then
OBITS="32"
elif does_c_define_exist "__x86_64__"; then
OBITS="64"
else
fatal_error "[x86] Unable to determine output bits!"
fi
# figure out which instruction sets the assembler supports
test_for_asm_instruction_set "vpaddq %zmm0, %zmm0, %zmm0" HAVE_AVX512
test_for_asm_instruction_set "vpaddq %ymm0, %ymm0, %ymm0" HAVE_AVX2
test_for_asm_instruction_set "vpaddq %xmm0, %xmm0, %xmm0" HAVE_AVX
test_for_asm_instruction_set "vprotd \$15, %xmm0, %xmm0" HAVE_XOP
test_for_asm_instruction_set "crc32b %cl, %ebx" HAVE_SSE4_2
test_for_asm_instruction_set "pblendw \$0, %xmm0, %xmm0" HAVE_SSE4_1
test_for_asm_instruction_set "pshufb %xmm0, %xmm0" HAVE_SSSE3
test_for_asm_instruction_set "lddqu 0(%esi), %xmm0" HAVE_SSE3
test_for_asm_instruction_set "pmuludq %xmm0, %xmm0" HAVE_SSE2
test_for_asm_instruction_set "movaps 0(%esi), %xmm0" HAVE_SSE
test_for_asm_instruction_set "punpckhdq %mm0, %mm0" HAVE_MMX
# OSX as uses a different macro paramter convention
if [ "$AS" != "yasm" ]; then
test_for_asm_macro_parameter_convention "\op" "xorl" "%eax" HAVE_SLASHMACRO
test_for_asm_macro_parameter_convention "\$0" "xorl" "%eax" HAVE_DOLLARMACRO
fi
# outbit bits
if [ "$bits32" = "yes" ]; then
OBITS="32"
elif [ "$bits64" = "yes" ]; then
OBITS="64"
fi
CFLAGS="$CFLAGS -m$OBITS"
LDFLAGS="$LDFLAGS -m$OBITS"
if [ "$AS" = "yasm" ]; then
case "$OFORMAT" in
"elf" | "win" | "macho" ) ASFLAGS="-r nasm -p gas -f $OFORMAT$OBITS"
;;
* ) fatal_error "[x86/yasm] Unable to determine object format!"
;;
esac
else
ASFLAGS="$ASFLAGS -m$OBITS -c"
fi
if test_for_asm_function_annotation ".hidden"; then
echo "#define HAVE_AS_HIDDEN" >> $outputheader
elif test_for_asm_function_annotation ".private_extern"; then
echo "#define HAVE_AS_PRIVATE_EXTERN" >> $outputheader
fi
printf "#define CPU_%sBITS\n" "$OBITS" >> $outputheader
foundas="yes"
elif [ "$HAVEAS" = "yes" ] && try_asm "and r0, r0, r0"; then
echo "#define ARCH_ARM" >> $outputheader
ARCH="arm"
foundas="yes"
if does_c_define_exist "__arm__"; then
OBITS="32"
elif does_c_define_exist "__aarch64__"; then
OBITS="64"
else
fatal_error "[ARM] Unable to determine output bits!"
fi
test_for_asm_macro_parameter_convention "\op" "tst" "r0" HAVE_SLASHMACRO
test_for_asm_macro_parameter_convention "\$0" "tst" "r0" HAVE_DOLLARMACRO
if [ "$OBITS" = "32" ]; then
asmheader=$(printf ".arch armv6\n.text")
test_for_asm_instruction_set "uqadd8 r3,r3,r3" HAVE_ARMv6
asmheader=$(printf ".arch armv7-a\n.text")
test_for_asm_instruction_set "pli [r0]" HAVE_ARMv7
asmheader=$(printf ".arch armv7-a\n.fpu neon\n.text")
test_for_asm_instruction_set "veor d0,d0,d0" HAVE_NEON
asmheader=$(printf ".arch armv7-a\n.fpu vfpv3\n.text")
test_for_asm_instruction_set "fcpyd d3,d22" HAVE_VFP3
asmheader=$(printf ".arch armv7-a\n.fpu vfpv3-d16\n.text")
test_for_asm_instruction_set "fcpyd d3,d4" HAVE_VFP3D16
asmheader=$(printf ".arch armv7-a\n.fpu neon-vfpv4\n.text")
test_for_asm_instruction_set "vfma.f32 q1, q2, q3" HAVE_VFP4
asmheader=$(printf ".arch armv7-a\n.arch_extension iwmmxt\n.text")
test_for_asm_instruction_set "wzeroge wr7" HAVE_IWMMXT
asmheader=$(printf ".arch armv7-a\n.arch_extension idiv\n.text")
test_for_asm_instruction_set "udiv r0, r1, r2" HAVE_IDIVA
asmheader=$(printf ".arch armv7-a\n.arch_extension idiv\n.text\n.thumb\n.thumb_func")
test_for_asm_instruction_set "udiv r0, r1, r2" HAVE_IDIVT
elif [ "$OBITS" = "64" ]; then
asmheader=$(printf ".arch armv8-a\n.text")
test_for_asm_instruction_set "hlt" HAVE_ARMv8
asmheader=$(printf ".arch armv8-a\n.fpu neon-fp-armv8\n.text")
test_for_asm_instruction_set "vvselge.f32 s4, s1, s23" HAVE_VFP4
asmheader=$(printf ".arch armv8-a\n.fpu neon-fp-armv8\n.text")
test_for_asm_instruction_set "vcvta.u32.f32 s2, s3" HAVE_ASIMD
asmheader=$(printf ".arch armv8-a\n.arch_extension crypto\n.text")
test_for_asm_instruction_set "aese.8 q0, q0" HAVE_AES
asmheader=$(printf ".arch armv8-a\n.arch_extension crypto\n.text")
test_for_asm_instruction_set "sha1p.32 q0,q0,q0" HAVE_SHA1
asmheader=$(printf ".arch armv8-a\n.arch_extension crypto\n.text")
test_for_asm_instruction_set "sha256h.32 q0, q0, q0" HAVE_SHA256
asmheader=$(printf ".arch armv8-a\n.arch_extension crypto\n.text")
test_for_asm_instruction_set "vmull.p64 q0, d0, d0" HAVE_PMULL
asmheader=$(printf ".arch armv8-a\n.arch_extension crc\n.text")
test_for_asm_instruction_set "crc32b r0, r1, r2" HAVE_CRC32
fi
printf "#define CPU_%sBITS\n" "$OBITS" >> $outputheader
fi
if [ "$HAVEAS" = "yes" ]; then
if [ "$foundas" = "no" ]; then
echo "Unable to find a working assembler/assembler dialect, you're flying solo!"
HAVEAS="no"
fi
fi
# stdint
have_stdint="no"
have_uint128="no"
if try_c_stdint "uint8_t"; then
if [ "$OBITS" = "64" ]; then
if try_c_stdint "uint128_t"; then
echo "#define HAVE_INT128" >> $outputheader
have_uint128="yes"
fi
fi
if try_c_stdint "int64_t"; then
echo "#define HAVE_INT64" >> $outputheader
fi
echo "#define HAVE_INT32" >> $outputheader
echo "#define HAVE_INT16" >> $outputheader
echo "#define HAVE_INT8" >> $outputheader
echo "#define HAVE_STDINT" >> $outputheader
have_stdint="yes"
fi
# external uint128_t detection if stdint didn't have it
ctype="INT128"
if [ "$OBITS" = "64" ]; then
if [ "$have_uint128" = "no" ]; then
if try_c_type "__int128"; then
define_c_type "$ctype" "signed __int128 int128_t" "unsigned __int128 uint128_t"
elif try_c_type "__uint128_t"; then
define_c_type "$ctype" "__int128_t int128_t" "__uint128_t uint128_t"
elif try_c_type "unsigned int __attribute__ ((__mode__ (TI)))"; then
define_c_type "$ctype" "signed int int128_t __attribute__ ((__mode__ (TI)))" "unsigned int uint128_t __attribute__ ((__mode__ (TI)))"
else
define_c_type_undefined "$ctype"
fi
fi
else
define_c_type_undefined "$ctype"
fi
if [ "$have_stdint" = "no" ]; then
# 64 bit int
ctype="INT64"
if try_c_type_unsigned "64" "unsigned long long"; then
define_c_type "$ctype" "signed long long int64_t" "unsigned long long uint64_t"
elif try_c_type_unsigned "64" "unsigned long"; then
define_c_type "$ctype" "signed long int64_t" "unsigned long uint64_t"
elif try_c_type_unsigned "64" "int __attribute__ ((__mode__ (DI)))"; then
define_c_type "$ctype" "signed int int64_t __attribute__ ((__mode__ (DI)))" "unsigned int uint64_t __attribute__ ((__mode__ (DI)))"
else
define_c_type_undefined "$ctype"
fi
# 32 bit int
ctype="INT32"
if try_c_type_unsigned "32" "unsigned long"; then
define_c_type "$ctype" "signed long int32_t" "unsigned long uint32_t"
elif try_c_type_unsigned "32" "unsigned int"; then
define_c_type "$ctype" "signed int uint32_t" "unsigned int uint32_t"
else
define_c_type_undefined "$ctype"
fi
# 16 bit int
ctype="INT16"
if try_c_type_unsigned "16" "unsigned int"; then
define_c_type "$ctype" "signed int int16_t" "unsigned int uint16_t"
elif try_c_type_unsigned "16" "unsigned short"; then
define_c_type "$ctype" "signed short int16_t" "unsigned short uint16_t"
else
define_c_type_undefined "$ctype"
fi
# 8bits
ctype="INT8"
if try_c_type_unsigned "8" "unsigned char"; then
define_c_type "$ctype" "signed char int8_t" "unsigned char uint8_t"
else
define_c_type_undefined "$ctype"
fi
fi
# gettimeofday
if try_c "#include <sys/time.h> int main(void) { struct timeval t; gettimeofday(&t, NULL); return 0; }"; then
echo "#define HAVE_GETTIMEOFDAY" >> $outputheader
fi
# visibility
if try_c_visibility '__attribute__ ((dllexport))'; then
LIB_EXPORT="__attribute__ ((dllexport))"
LIB_IMPORT="__attribute__ ((dllimport))"
CFLAGS="$CFLAGS -fvisibility=hidden -DLIB_PUBLIC=\"__attribute__ ((dllexport))\""
elif try_c_visibility '__attribute__ ((visibility ("default")))'; then
CFLAGS="$CFLAGS -fvisibility=hidden -DLIB_PUBLIC=\"__attribute__ ((visibility (\\\"default\\\")))\""
else
LIB_EXPORT=''
LIB_IMPORT=''
CFLAGS="$CFLAGS -DLIB_PUBLIC=\"\" "
fi
if [ "$pic" = "yes" ]; then
CFLAGS="$CFLAGS -fPIC"
HAVESHARED="yes"
elif [ "$OFORMAT" = "win" ]; then
HAVESHARED="yes"
fi
if [ "$debug" = "yes" ]; then
CFLAGS="$CFLAGS -g"
else
CFLAGS="$CFLAGS -O2"
fi
if [ "$strict" = "yes" ]; then
CFLAGS="$CFLAGS -Wall -fno-strict-aliasing -W -Wextra -Werror -Wmissing-prototypes"
fi
# only GCC style for now
AR="$AR rc "
# shared library
if [ "$OFORMAT" = "win" ]; then
SONAME="lib${PROJECTNAME}.dll"
SOIMPORT="${SONAME}.a"
SOSUFFIX="dll"
SOFLAGS="-shared -Wl,--out-implib,\$(BINDIR)/\$(SOIMPORT) -Wl,--enable-auto-image-base $SOFLAGS"
elif [ "$OFORMAT" = "macho" ]; then
SONAME="lib${PROJECTNAME}.${PROJECTVERMAJOR}.dylib"
SOIMPORT=""
SOSUFFIX="dylib"
SOFLAGS="-dynamiclib -install_name \$(libdir)/\$(SONAME) $SOFLAGS"
elif [ `uname` = "SunOS" -a "`ld --version 2>&1 | grep GNU`" = "" ]; then
SONAME="lib${PROJECTNAME}.so.${PROJECTVERMAJOR}"
SOIMPORT=""
SOSUFFIX="so"
SOFLAGS="-shared -Wl,-h,\$(SONAME) $SOFLAGS"
else
SONAME="lib${PROJECTNAME}.so.${PROJECTVERMAJOR}"
SOIMPORT=""
SOSUFFIX="so"
SOFLAGS="-shared -Wl,-soname,\$(SONAME) $SOFLAGS"
fi
if [ `uname` = "SunOS" ]; then
if test -x /usr/ucb/install; then
INSTALL=/usr/ucb/install
elif test -x /usr/bin/ginstall; then
INSTALL=/usr/bin/ginstall
elif test -x /usr/gnu/bin/install ; then
INSTALL=/usr/gnu/bin/install
fi
fi
CFLAGS="$CFLAGS -DBUILDING_ASMOPT_${PROJECTNAMEUPPER}"
cat > $outputmake << EOF
PROJECTNAME=$PROJECTNAME
CC=$CC
CFLAGS=$CFLAGS
AR=$AR
LD=$LD
RANLIB=$RANLIB
STRIP=$STRIP
INSTALL=$INSTALL
HAVEAS=$HAVEAS
HAVESHARED=$HAVESHARED
AS=$AS
ASFLAGS=$ASFLAGS
ARCH=$ARCH
EXE=$EXE
STATICLIB=$STATICLIB
DEPMM=$DEPMM
DEPMF=$DEPMF
SONAME=$SONAME
SOIMPORT=$SOIMPORT
SOSUFFIX=$SOSUFFIX
SOFLAGS=$SOFLAGS
LDFLAGS=$LDFLAGS
exec_prefix=$exec_prefix
bindir=$bindir
libdir=$libdir
includedir=$includedir
appdir=$appdir
EOF
cat >> $outputheader << EOF
#if !defined(BUILDING_ASM)
#include <stddef.h>
/* use HAVE_INTxxx to determine if an integer with [8,16,32,64,128] bits is available */
#if defined(HAVE_STDINT)
#include <stdint.h>
#else
DEFINE_INT64
DEFINE_INT32
DEFINE_INT16
DEFINE_INT8
#endif
/* stdint doesn't currently detect this, but may in the future */
DEFINE_INT128
#endif /* !defined(BUILDING_ASM) */
#endif /* ASMOPT_${PROJECTNAMEUPPER}_H */
EOF
cat >> $outputheaderstub << EOF
#include "asmopt.h"
#define LOCAL_PREFIX3(a,b) a##_##b
#define LOCAL_PREFIX2(a,b) LOCAL_PREFIX3(a,b)
#define LOCAL_PREFIX(n) LOCAL_PREFIX2(PROJECT_NAME,n)
#define PROJECT_NAME ${PROJECTNAME}
/* yasm */
#if (0)
%define PROJECT_NAME ${PROJECTNAME}
#endif
#endif /* ASMOPT_INTERNAL_H */
EOF
# build util_implementations.h
util_includes=`ls $appdir/include/*.h | sed "s/$appdir\/include\/\(.*\)\.h/#include \"\1.h\"/"`
util_impls=`ls $appdir/include/*.h | sed "s/$appdir\/include\/\(.*\)\.h/make_impl(\1),/"`
cat > $outpututilimpls << EOF
$util_includes
static const implementation_t implementations[] = {
$util_impls
};
EOF
cleanup
$GNUMAKE clean
makeshared=""
if [ "$HAVESHARED" = "yes" ]; then
makeshared=",shared"
fi
echo "$outputheader generated for $PROJECTNAME, run '$GNUMAKE' or '$GNUMAKE [util,exe${makeshared}]' now"