File: Configure

package info (click to toggle)
iroffer 1.4.b03-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, lenny, squeeze, wheezy
  • size: 744 kB
  • ctags: 920
  • sloc: ansic: 15,074; sh: 864; makefile: 53
file content (1101 lines) | stat: -rwxr-xr-x 29,573 bytes parent folder | download | duplicates (4)
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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
#!/bin/sh

#
# @(#) Configure 1.115@(#)
# pmg@wellington.i202.centerclick.org|Configure|20051213024432|40052
#

VERSION=1.4.b03
RELEASE=1

if [ -d BitKeeper -a -f "`type bk 2>/dev/null | awk '{print $NF}'`" ]; then
 CSET=`bk prs -h -d':UTC:\n' -r+ ChangeSet`
 echo $CSET > .cset_number
elif [ -f .cset_number ]; then
 CSET=`cat .cset_number`
else
 CSET="Unknown"
fi

if [ $RELEASE -eq 1 ]; then
 VERSIONLONG="$VERSION [$CSET]"
else
 VERSIONLONG="$VERSION [PRERELEASE $CSET]"
fi

echo
echo "Configure for iroffer $VERSIONLONG"

usage()
{
echo "Usage: Configure [ options ]"
echo "   -h           This help"
echo "   -e           Print errors while running Configure"
echo "   -d           Compile with debug symbols"
echo "   -p           Compile with profiling flags"
echo "   -w           Compile with extra warning flags"
exit 1
}

OPT_ERRORS=false
OPT_DEBUG=false
OPT_WARN=false
OPT_PROF=false

while getopts 'hedpw' OPTNAME; do
  case "$OPTNAME" in
    h) usage;;

    e) OPT_ERRORS=true;;
    d) OPT_DEBUG=true;;
    w) OPT_WARN=true;;
    p) OPT_PROF=true;;

    *) usage;;
  esac
done

echo -n "Determining OS... "
uname
ostype=`uname`
platform=`uname -m`
short_ostype=`uname | cut -d "_" -f 1`
libs=""

rm -f config.error.* config.temp*

case "$ostype" in
 Linux | FreeBSD | OpenBSD | NetBSD | IRIX | IRIX64 | \
 OSF1 | Rhapsody | Darwin | AIX )
  # nothing fancy
  ;;
 GNU/kFreeBSD | GNU )
  ostype=Linux
  ;;
 SunOS )
  libs="$libs -lsocket -lnsl"
  ;;
 BSD/OS )
  ostype=BSD_OS
  ;;
 HP-UX )
  ostype=HPUX
  ;;
 CYGWIN* )
  ostype=$short_ostype
  exe=.exe
  
  # only 1.5.6 or later is supported
  echo -n "Checking for cygwin >= 1.5.6... "
  ver=`uname -r | cut -d '(' -f 1`
  ver_A=`echo $ver | cut -d '.' -f 1`
  ver_B=`echo $ver | cut -d '.' -f 2`
  ver_C=`echo $ver | cut -d '.' -f 3`
  
  # 2.x.x - 9.x.x, 1.6.x - 1.9.x, and 1.5.6 - 1.5.9 are ok
  if [ \( "$ver_A" -ge "2" \)                                         \
    -o \( "$ver_A" -eq "1" -a "$ver_B" -ge "6" \)                     \
    -o \( "$ver_A" -eq "1" -a "$ver_B" -eq "5" -a "$ver_C" -ge "6" \) \
     ]; then
   echo "OK, $ver"
  else
   echo "***ERROR***: $ver < 1.5.6"
   exit # fatal error
   waserror=yes
  fi
  ;;
 *)
  echo "***ERROR***: This OS is not supported"
  exit
  ;;
esac

echo "/* Automatically Generated, Do Not Edit */" > src/iroffer_config.h
echo "" >> src/iroffer_config.h

echo "#define VERSIONLONG \"$VERSIONLONG\"" >> src/iroffer_config.h
echo "#define _OS_$ostype" >> src/iroffer_config.h

if $OPT_ERRORS; then
 echo "Printing Errors During Execution..."
 shift
else
 exec 2>/dev/null
fi

if $OPT_DEBUG; then
echo "Configuring for debugging."
DEBUG="-g"
shift
else
DEBUG="-O2"
fi

if $OPT_WARN; then
echo "Configuring for extra warnings."
WARNS="-Wshadow
-Wpointer-arith
-Wcast-qual
-Wcast-align
-Wstrict-prototypes
-Wmissing-prototypes
-Wmissing-declarations
-Winline
-Wwrite-strings
-Werror"
shift
fi

if $OPT_PROF; then
echo "Configuring for profiling."
PROF="-pg"
shift
fi

echo -n "Checking for make... "
if [ -f "`type make | awk '{print $NF}'`" ]; then
 maketype="make"
 if [ -x "`type $maketype | awk '{print $NF}'`" ]; then
  echo "found $maketype"
 else
  echo "found $maketype. ***ERROR***: You are not allowed to execute $maketype"
  waserror=yes
 fi
elif [ -f "`type gmake | awk '{print $NF}'`" ]; then
 maketype="gmake"
 if [ -x "`type $maketype | awk '{print $NF}'`" ]; then
  echo "found $maketype"
 else
  echo "found $maketype. ***ERROR***: You are not allowed to execute $maketype"
  waserror=yes
 fi
else
 echo "not found. ***ERROR***: Couldn't find make or gmake"
 maketype="make"
 waserror=yes
fi

echo -n "Checking for gcc/cc... "
if [ -f "`type gcc | awk '{print $NF}'`" ]; then
 cctype="gcc"
 if [ -x "`type $cctype | awk '{print $NF}'`" ]; then
  echo "found $cctype"
 else
  echo "found $cctype. ***ERROR***: You are not allowed to execute $cctype"
  waserror=yes
 fi
elif [ -f "`type cc | awk '{print $NF}'`" ]; then
 cctype="cc"
 if [ -x "`type $cctype | awk '{print $NF}'`" ]; then
  echo "found $cctype"
 else
  echo "found $cctype. ***ERROR***: You are not allowed to execute $cctype"
  waserror=yes
 fi
else
 echo "not found. ***ERROR***: Couldn't find gcc or cc"
 maketype="gcc"
 waserror=yes
fi

echo -n "Seeing if $cctype works... "
echo "
int main (int argc, char **argv) {exit(0);}
" > config.temp.c
if $cctype -o config.temp config.temp.c ; then
 echo "yes"
else
 echo " ***ERROR***: $cctype didn't seem to work."
 waserror=yes
fi

echo -n "Seeing if $cctype accepts '-Wall'... "
echo "
#include <stdlib.h>
int main (int argc, char **argv) {exit(0);}
" > config.temp.c
if $cctype -Wall -o config.temp config.temp.c ; then
 echo "yes"
 WARNS="-Wall $WARNS"
else
 echo " no"
fi

echo -n "Seeing if $cctype accepts '-Werror'... "
echo "
int main (int argc, char **argv) {exit(0);}
" > config.temp.c
if $cctype -Werror -o config.temp config.temp.c ; then
 echo "yes"
 WERROR="-Werror"
else
 echo " no"
fi


echo -n "Seeing how to define a 16 bit integer... "
echo "
#define GEX 
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char **argv) {
 printf(\"%d\", (int)sizeof( C_IR_INT16 ));
 exit(0);
 }
" > config.temp.c
if $cctype -DC_IR_INT16="short" config.temp.c $libs -o config.temp $WARNS $WERROR && [ "`./config.temp`" = "2" ]; then
 echo "short"
 echo "typedef short ir_int16;" >> src/iroffer_config.h
 echo "typedef unsigned short ir_uint16;" >> src/iroffer_config.h
elif $cctype -DC_IR_INT16="int" config.temp.c $libs -o config.temp $WARNS $WERROR && [ "`./config.temp`" = "2" ]; then
 echo "int"
 echo "typedef int ir_int16;" >> src/iroffer_config.h
 echo "typedef unsigned int ir_uint16;" >> src/iroffer_config.h
else
 echo "Unknown. ***ERROR***: neither short or int worked."
 waserror=yes
fi


echo -n "Seeing how to define a 32 bit integer... "
echo "
#define GEX 
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char **argv) {
 printf(\"%d\", (int)sizeof( C_IR_INT32 ));
 exit(0);
 }
" > config.temp.c
if $cctype -DC_IR_INT32="int" config.temp.c $libs -o config.temp $WARNS $WERROR && [ "`./config.temp`" = "4" ]; then
 echo "int"
 echo "typedef int ir_int32;" >> src/iroffer_config.h
 echo "typedef unsigned int ir_uint32;" >> src/iroffer_config.h
elif $cctype -DC_IR_INT32="long" config.temp.c $libs -o config.temp $WARNS $WERROR && [ "`./config.temp`" = "4" ]; then
 echo "long"
 echo "typedef long ir_int32;" >> src/iroffer_config.h
 echo "typedef unsigned long ir_uint32;" >> src/iroffer_config.h
elif $cctype -DC_IR_INT32="long long" config.temp.c $libs -o config.temp $WARNS $WERROR && [ "`./config.temp`" = "4" ]; then
 echo "long long"
 echo "typedef long long ir_int32;" >> src/iroffer_config.h
 echo "typedef unsigned long long ir_uint32;" >> src/iroffer_config.h
elif $cctype -DC_IR_INT32="short" config.temp.c $libs -o config.temp $WARNS $WERROR && [ "`./config.temp`" = "4" ]; then
 echo "short"
 echo "typedef short ir_int32;" >> src/iroffer_config.h
 echo "typedef unsigned short ir_uint32;" >> src/iroffer_config.h
else
 echo "Unknown. ***ERROR***: neither short, int, long or long long worked."
 waserror=yes
fi

echo -n "Seeing how to define a 64 bit integer... "
echo "
#define GEX 
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char **argv) {
 printf(\"%d\", (int)sizeof( C_IR_INT64 ));
 exit(0);
 }
" > config.temp.c
if $cctype -DC_IR_INT64="long long" config.temp.c $libs -o config.temp $WARNS $WERROR && [ "`./config.temp`" = "8" ]; then
 echo "long long"
 echo "typedef long long ir_int64;" >> src/iroffer_config.h
 echo "typedef unsigned long long ir_uint64;" >> src/iroffer_config.h
elif $cctype -DC_IR_INT64="long" config.temp.c $libs -o config.temp $WARNS $WERROR && [ "`./config.temp`" = "8" ]; then
 echo "long"
 echo "typedef long ir_int64;" >> src/iroffer_config.h
 echo "typedef unsigned long ir_uint64;" >> src/iroffer_config.h
elif $cctype -DC_IR_INT64="int" config.temp.c $libs -o config.temp $WARNS $WERROR && [ "`./config.temp`" = "8" ]; then
 echo "int"
 echo "typedef int ir_int64;" >> src/iroffer_config.h
 echo "typedef unsigned int ir_uint64;" >> src/iroffer_config.h
elif $cctype -DC_IR_INT64="short" config.temp.c $libs -o config.temp $WARNS $WERROR && [ "`./config.temp`" = "8" ]; then
 echo "short"
 echo "typedef short ir_int64;" >> src/iroffer_config.h
 echo "typedef unsigned short ir_uint64;" >> src/iroffer_config.h
else
 echo "Unknown. ***ERROR***: neither short, int, long or long long worked."
 waserror=yes
fi


echo -n "Seeing if compiling with standard #include's works... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {exit(0);}
" > config.temp.c
if $cctype -DSIGNEDSOCK=signed config.temp.c $libs -o config.temp; then
 echo "looks good"
else
 echo " ***ERROR***: couldn't build with standard #include's"
 waserror=yes
fi


echo -n "Seeing how large FD_SETSIZE is... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
FD_SETSIZE
" > config.temp.c
if $cctype -E -o config.temp.p config.temp.c $WARNS $WERROR ; then
 setsize=`tail -2 config.temp.p |grep -v "config.temp"`
 echo -n " $setsize"
 
 if [ "$ostype" = CYGWIN -a $setsize -le 255 ]; then
   echo ", Boosting up to 255"
   echo "#define FD_SETSIZE 255" >> src/iroffer_config.h
 else
   echo
 fi
else
 echo " ***ERROR***: couldn't determine it"
 waserror=yes
fi

echo -n "Determining endianness... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {
 printf(\"%s\", (100 == ntohl(100)) ? \"big\" : \"little\");
 exit(0);
 }
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR && [ "`./config.temp`" = "big" ]; then
 echo "big"
 echo "#define IR_ENDIAN_BIG" >> src/iroffer_config.h
elif [ "`./config.temp`" = "little" ]; then
 echo "little"
 echo "#define IR_ENDIAN_LITTLE" >> src/iroffer_config.h
else
 echo "Unknown. ***ERROR***"
 waserror=yes
fi


echo -n "Seeing if large file support works... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {
 int fd;
 int array[ ((int)sizeof(off_t)) - 7 ];
 fd=open(\"foo\", O_RDWR | O_CREAT | ADDED_OPEN_FLAGS);
 array[0] = array[0];
 exit(0);
 }
" > config.temp.c
if $cctype -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE config.temp.c $libs -o config.temp $WARNS $WERROR ; then
 echo "yes"
 echo "#define _FILE_OFFSET_BITS 64" >> src/iroffer_config.h
 echo "#define _LARGEFILE_SOURCE" >> src/iroffer_config.h
else
 echo "No.  Max filesize will be 2GB."
fi

echo -n "Determing the signedness of 'addrlen'... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {
 int a; struct sockaddr_in b; SIGNEDSOCK int c;
 getsockname(a,(struct sockaddr *)&b,&c);
 exit(0);
 }
" > config.temp.c
if $cctype -DSIGNEDSOCK=signed config.temp.c $libs -o config.temp $WARNS $WERROR ; then
 echo "signed"
 echo "#define SIGNEDSOCK signed" >> src/iroffer_config.h
elif $cctype -DSIGNEDSOCK=unsigned config.temp.c $libs -o config.temp $WARNS $WERROR ; then
 echo "unsigned"
 echo "#define SIGNEDSOCK unsigned" >> src/iroffer_config.h
else
 echo "Unknown. ***ERROR***: neither signed or unsigned worked."
 echo "#define SIGNEDSOCK signed" >> src/iroffer_config.h
 waserror=yes
fi


echo -n "Seeing how to display long long using printf... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv)
  {
    long long a = 1000000000;
    a = a*10;
    printf(\"%\" LLPRINTFMT \"i\",a);
    exit(0);
  }
" > config.temp.c
if $cctype -DLLPRINTFMT=\"ll\" config.temp.c $libs -o config.temp $WARNS $WERROR && [ "`./config.temp`" = "10000000000" ]; then
 echo "ll"
 echo "#define LLPRINTFMT \"ll\"" >> src/iroffer_config.h
elif $cctype -DLLPRINTFMT=\"L\" config.temp.c $libs -o config.temp $WARNS $WERROR && [ "`./config.temp`" = "10000000000" ]; then
 echo "L"
 echo "#define LLPRINTFMT \"L\"" >> src/iroffer_config.h
elif $cctype -DLLPRINTFMT=\"l\" config.temp.c $libs -o config.temp $WARNS $WERROR && [ "`./config.temp`" = "10000000000" ]; then
 echo "l"
 echo "#define LLPRINTFMT \"l\"" >> src/iroffer_config.h
else
 echo "Unknown. ***ERROR***: neither ll, l, or L worked."
 echo "#define LLPRINTFMT \"L\"" >> src/iroffer_config.h
 waserror=yes
fi


echo -n "Checking for snprintf()... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {char *s; snprintf(s,10,\"blah\"); exit(0);}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR ; then
 echo "found"
else
 echo "#define NO_SNPRINTF" >> src/iroffer_config.h
 echo "missing, will emulate"
fi

echo -n "Checking for strcasecmp()... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {strcasecmp(\"blah\",\"blah\"); exit(0);}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR ; then
 echo "found"
else
 echo "#define NO_STRCASECMP" >> src/iroffer_config.h
 echo "missing, will emulate"
fi

echo -n "Checking for strsignal()... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {strsignal(1); exit(0);}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR ; then
 echo "found"
else
 echo "#define NO_STRSIGNAL" >> src/iroffer_config.h
 echo "missing, will emulate"
fi

echo -n "Checking for regcomp()... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {regex_t *t; regcomp(t,\"blah\",REG_ICASE|REG_NOSUB); exit(0);}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR ; then
 echo "found"
else
 echo "Missing. ***ERROR***: couldn't find regcomp()"
 waserror=yes
fi

echo -n "Seeing if 'sys/mman.h' exists... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {exit(0);}
" > config.temp.c
if $cctype -c -DHAS_SYS_MMAN_H -o config.temp.o config.temp.c $WARNS $WERROR ; then
 echo "#define HAS_SYS_MMAN_H" >> src/iroffer_config.h
 echo "found"
else
 echo "not found"
fi

echo -n "Seeing if 'sys/sendfile.h' exists... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {exit(0);}
" > config.temp.c
if $cctype -c -DHAS_SYS_SENDFILE_H -o config.temp.o config.temp.c $WARNS $WERROR ; then
 echo "#define HAS_SYS_SENDFILE_H" >> src/iroffer_config.h
 echo "found"
else
 echo "not found"
fi

echo -n "Seeing if 'sys/vfs.h' exists... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {exit(0);}
" > config.temp.c
if $cctype -c -DHAS_SYS_VFS_H -o config.temp.o config.temp.c $WARNS $WERROR ; then
 echo "#define HAS_SYS_VFS_H" >> src/iroffer_config.h
 echo "found"
else
 echo "not found"
fi

echo -n "Seeing if 'sys/statfs.h' exists... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {exit(0);}
" > config.temp.c
if $cctype -c -DHAS_SYS_STATFS_H -o config.temp.o config.temp.c $WARNS $WERROR ; then
 echo "#define HAS_SYS_STATFS_H" >> src/iroffer_config.h
 echo "found"
else
 echo "not found"
fi

echo -n "Seeing if 'sys/param.h' exists... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {exit(0);}
" > config.temp.c
if $cctype -c -DHAS_SYS_PARAM_H -o config.temp.o config.temp.c $WARNS $WERROR ; then
 echo "#define HAS_SYS_PARAM_H" >> src/iroffer_config.h
 echo "found"
else
 echo "not found"
fi

echo -n "Seeing if 'sys/mount.h' exists... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {exit(0);}
" > config.temp.c
if $cctype -c -DHAS_SYS_MOUNT_H -o config.temp.o config.temp.c $WARNS $WERROR ; then
 echo "#define HAS_SYS_MOUNT_H" >> src/iroffer_config.h
 echo "found"
else
 echo "not found"
fi

echo -n "Seeing if 'sys/statvfs.h' exists... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {exit(0);}
" > config.temp.c
if $cctype -c -DHAS_SYS_STATVFS_H -o config.temp.o config.temp.c $WARNS $WERROR ; then
 echo "#define HAS_SYS_STATVFS_H" >> src/iroffer_config.h
 echo "found"
else
 echo "not found"
fi

echo -n "Checking for statvfs()... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {struct statvfs stf; statvfs(\"\",&stf); exit(0);}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR ; then
 echo "found"
else
 echo "#define NO_STATVFS" >> src/iroffer_config.h
 echo "missing"
fi

echo -n "Checking for statfs()... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {struct statfs stf; statfs(\"\",&stf); exit(0);}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR ; then
 echo "found"
else
 echo "#define NO_STATFS" >> src/iroffer_config.h
 echo "missing"
fi

echo -n "Seeing if 'crypt.h' is needed... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {crypt(\"aaaaaaaa\",\"aa\"); exit(0);}
" > config.temp.c
if $cctype -c -o config.temp.o config.temp.c $WARNS $WERROR ; then
 echo "not needed"
elif $cctype -c -DHAS_CRYPT_H -o config.temp.o config.temp.c $WARNS $WERROR ; then
 echo "#define HAS_CRYPT_H" >> src/iroffer_config.h
 echo "needed"
else
 echo "Missing. ***ERROR***: couldn't find crypt() with or without crypt.h"
 echo "#define HAS_CRYPT_H" >> src/iroffer_config.h
 waserror=yes
fi

echo -n "Seeing if '-lcrypt' is needed... "
if $cctype -o config.temp config.temp.o $WARNS $WERROR ; then
 echo "not needed"
elif $cctype -o config.temp config.temp.o $libs -lcrypt $WARNS $WERROR ; then
 libs="$libs -lcrypt"
 echo "needed"
else
 echo "Neither!"
 echo -n "Seeing if '-lcrypto' works instead... "
 if $cctype -o config.temp config.temp.o $libs -lcrypto $WARNS $WERROR ; then
  libs="$libs -lcrypto"
  echo "yes"
 else
  echo "Missing. ***ERROR***: couldn't link with or without -lcrypt or -lcrypto"
  libs="$libs -lcrypt"
  waserror=yes
 fi
fi

echo -n "Seeing if crypt() works as expected... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv)
  {
    char *pwout;
    pwout = crypt(\"testtest\",\"LH\");
    if (pwout && !strcmp(\"LHD/pLKwfn0.k\", pwout))
      {
        exit(0);
      }
    exit(1);
  }
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR && ./config.temp; then
 echo "yes"
else
 echo "no, will disable encrypted passwords"
 echo "#define NO_CRYPT" >> src/iroffer_config.h
fi


echo -n "Checking for chroot()... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {chroot(\".\"); exit(0);}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR; then
echo "found"
else
echo "#define NO_CHROOT" >> src/iroffer_config.h
echo "missing, will desactivate chroot()-ing"
fi

echo -n "Seeing if NSS libraries exist (for chroot)... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {exit(0);}
" > config.temp.c
if $cctype config.temp.c $libs -lnss_files -lnss_dns -o config.temp $WARNS $WERROR; then
NSSLIBS="-lnss_files -lnss_dns"
echo "found"
else
NSSLIBS=""
echo "missing"
fi

echo -n "Checking for setuid()... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {setuid(0); exit(0);}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR; then
echo "found"
else
echo "#define NO_SETUID" >> src/iroffer_config.h
echo "missing, will desactivate setuid()-ing"
fi

echo -n "Checking for getgrouplist()... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {getgrouplist (NULL, 0, NULL, NULL); exit(0);}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR; then
echo "found"
else
echo "#define NO_GETGROUPLIST" >> src/iroffer_config.h
echo "missing, group list will be incorrect when setuid()-ing"
fi

if [ "x$ostype" = "xLinux" ]; then
echo -n "Checking for Linux-style sendfile()... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv)
{
  int     out_fd = 0;
  int     in_fd = 0;
  off_t   offset = 0;
  size_t  count = 0;
  ssize_t ret_val;
  ret_val = sendfile(out_fd, in_fd, &offset, count);
  exit(0);
}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR; then
echo "#define HAVE_LINUX_SENDFILE" >> src/iroffer_config.h
echo "found"
else
echo "missing, won't use sendfile()"
fi
fi

if [ "x$ostype" = "xFreeBSD" ]; then
echo -n "Checking for FreeBSD-style sendfile()... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv)
{
  int     in_fd = 0;
  int     out_fd = 0;
  off_t   offset = 0;
  off_t   offset2 = 0;
  size_t  count = 0;
  struct sf_hdtr hdr = {};
  int ret_val;
  ret_val = sendfile(in_fd, out_fd, offset, count,
                     &hdr, &offset2, 0);
  exit(0);
}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR; then
echo "#define HAVE_FREEBSD_SENDFILE" >> src/iroffer_config.h
echo "found"
else
echo "missing, won't use sendfile()"
fi
fi

echo -n "Checking for mmap()/munmap()... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv)
{
  mmap(NULL,0,PROT_READ,MAP_SHARED,0,0);
  munmap(NULL,0);
  exit(0);
}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR; then
echo "#define HAVE_MMAP" >> src/iroffer_config.h
echo "found"
else
echo "missing, won't use mmap()"
fi


echo -n "Checking for name of fd limit... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv)
{
  struct rlimit rlim;
  getrlimit(RLIMIT_NOFILE, &rlim);
  exit(0);
}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR; then
echo "RLIMIT_NOFILE"
else
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv)
{
  struct rlimit rlim;
  getrlimit(RLIMIT_OFILE, &rlim);
  exit(0);
}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR; then
echo "RLIMIT_OFILE"
echo "#define USE_OFILE" >> src/iroffer_config.h
else
waserror=yes
echo "neither work, thats not good"
fi
fi

echo -n "Checking for siginfo_t/sa_sigaction... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {siginfo_t si; struct sigaction sa; sa.sa_sigaction = NULL; si.si_code = 0; exit(0);}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR; then
echo "found"
else
echo "#define NO_SIGINFO" >> src/iroffer_config.h
echo "missing, will use lame signal handlers"
fi

echo -n "Checking for si_code values... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {
  siginfo_t si;
  si.si_code = BUS_ADRALN;
  si.si_code = BUS_ADRERR;
  si.si_code = BUS_OBJERR;
  si.si_code = ILL_ILLOPC;
  si.si_code = ILL_ILLOPN;
  si.si_code = ILL_ILLADR;
  si.si_code = ILL_ILLTRP;
  si.si_code = ILL_PRVOPC;
  si.si_code = ILL_PRVREG;
  si.si_code = ILL_COPROC;
  si.si_code = ILL_BADSTK;
  si.si_code = FPE_INTDIV;
  si.si_code = FPE_INTOVF;
  si.si_code = FPE_FLTDIV;
  si.si_code = FPE_FLTOVF;
  si.si_code = FPE_FLTUND;
  si.si_code = FPE_FLTRES;
  si.si_code = FPE_FLTINV;
  si.si_code = FPE_FLTSUB;
  si.si_code = SEGV_MAPERR;
  si.si_code = SEGV_ACCERR;
  exit(0);
}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR; then
echo "found"
else
echo "#define NO_SIGCODES" >> src/iroffer_config.h
echo "missing, won't report si_codes"
fi

echo -n "Checking for wait status values... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {
  int status = 0;
  if (WIFEXITED(status) ||
      WIFSIGNALED(status) ||
      WEXITSTATUS(status) ||
      WTERMSIG(status))
    {
      status++;
    }
  exit(0);
}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR; then
echo "found"
else
echo "#define NO_WSTATUS_CODES" >> src/iroffer_config.h
echo "missing, won't report wait status codes"
fi


echo -n "Seeing if TOS can be set for IP sockets... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {
  int fd = 0;
  int tempc = 0x8; /* IPTOS_THROUGHPUT */
  setsockopt(fd, SOL_IP, IP_TOS, &tempc, sizeof(int));
  exit(0);
}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR; then
echo "yes"
else
echo "#define CANT_SET_TOS" >> src/iroffer_config.h
echo "no"
fi

echo -n "Checking for gethostbyname error values... "
echo "
#define GEX 
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
int main (int argc, char **argv) {
  extern int h_errno;
  int i;
  switch (h_errno)
    {
     case HOST_NOT_FOUND:
     case NO_ADDRESS:
#if NO_ADDRESS != NO_DATA
     case NO_DATA:
#endif
     case NO_RECOVERY:
     case TRY_AGAIN:
       i = 1;
     default:
       i = 0;
    }
  exit(i);
}
" > config.temp.c
if $cctype config.temp.c $libs -o config.temp $WARNS $WERROR; then
echo "found"
else
echo "#define NO_HOSTCODES" >> src/iroffer_config.h
echo "missing, won't report error codes"
fi

rm -f config.temp*

echo "Creating src/iroffer_config.h... Done"

echo -n "Creating Makefile... "

cp /dev/null Makefile
(
echo "# Automatically Generated, Do Not Edit #"
echo
echo VERSION=$VERSION
echo CC=$cctype
echo CONFIG_EXE=$exe
echo CONFIG_LDLIBS=$libs
echo CONFIG_LDFLAGS=$PROF $DEBUG
echo CONFIG_CFLAGS=$PROF $WARNS $DEBUG
echo CONFIG_CPPFLAGS=
echo CONFIG_CHROOT=$NSSLIBS
if [ -z "$NSSLIBS" ]; then
 echo CONFIG_TARGETS=
else
 echo CONFIG_TARGETS=iroffer_chroot$exe
fi
echo
cat Makefile.config 
) > Makefile

echo Done
echo

if [ -n "$waserror" ]; then
echo "!!!!!WARNING!!!!!  one or more errors occured, guesses for those values that failed were included."
echo "You should re-run Configure with the 'errors' arguemnt to see the details."
echo
fi

echo "Type \"$maketype\" to compile"
echo "No errors or warnings should appear when compiling, if they do, something is wrong"
echo

# end