-
Notifications
You must be signed in to change notification settings - Fork 36
/
Build.sh
3470 lines (3309 loc) · 85.8 KB
/
Build.sh
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
#!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.858 2024/08/17 23:33:47 tg Exp $'
set +evx
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019,
# 2020, 2021, 2022, 2023, 2024
# mirabilos <[email protected]>
#
# Provided that these terms and disclaimer and all copyright notices
# are retained or reproduced in an accompanying document, permission
# is granted to deal in this work without restriction, including un-
# limited rights to use, publicly perform, distribute, sell, modify,
# merge, give away, or sublicence.
#
# This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
# the utmost extent permitted by applicable law, neither express nor
# implied; without malicious intent or gross negligence. In no event
# may a licensor, author or contributor be held liable for indirect,
# direct, other damage, loss, or other issues arising in any way out
# of dealing in the work, even if advised of the possibility of such
# damage or existence of a defect, except proven that it results out
# of said person's immediate fault when using the work as intended.
#-
# People analysing the output must whitelist conftest.c for any kind
# of compiler warning checks (mirtoconf is by design not quiet).
#
# Used environment documentation is at the end of this file.
LC_ALL=C; LANGUAGE=C
export LC_ALL; unset LANGUAGE
use_ach=x; unset use_ach
case $ZSH_VERSION:$VERSION in
:zsh*) ZSH_VERSION=2 ;;
esac
if test -n "${ZSH_VERSION+x}" && (emulate sh) >/dev/null 2>&1; then
emulate sh
NULLCMD=:
fi
if test -d /usr/xpg4/bin/. >/dev/null 2>&1; then
# Solaris: some of the tools have weird behaviour, use portable ones
PATH=/usr/xpg4/bin:$PATH
export PATH
fi
test_tool() {
x=`echo $2 | $3`
y=$?
test x"$y" = x"0" && test x"$x" = x"$4" && return
echo >&2 "E: your $1 does not work correctly!"
echo >&2 "N: 'echo $2 | $3' exited $y and returned '$x'; expected '$4'"
echo >&2 'N: install a better one and prepend its location to $PATH'
exit 1
}
test_tool grep foobarbaz 'grep bar' foobarbaz
test_tool sed abc 'sed y/ac/AC/' AbC
test_tool tr abc 'tr ac AC' AbC
sp=' '
ht=' '
nl='
'
safeIFS="$sp$ht$nl"
IFS=$safeIFS
allu=QWERTYUIOPASDFGHJKLZXCVBNM
alll=qwertyuiopasdfghjklzxcvbnm
alln=0123456789
alls=______________________________________________________________
test_n() {
test x"$1" = x"" || return 0
return 1
}
test_z() {
test x"$1" = x""
}
case `echo a | tr '\201' X` in
X)
# EBCDIC build system
lfcr='\n\r'
;;
*)
lfcr='\012\015'
;;
esac
genopt_die() {
if test_z "$1"; then
echo >&2 "E: invalid input in '$srcfile': '$line'"
else
echo >&2 "E: $*"
echo >&2 "N: in '$srcfile': '$line'"
fi
rm -f "$bn.gen"
exit 1
}
genopt_soptc() {
optc=`echo "$line" | sed 's/^[<>]\(.\).*$/\1/'`
test x"$optc" = x'|' && return
optclo=`echo "$optc" | tr $allu $alll`
if test x"$optc" = x"$optclo"; then
islo=1
else
islo=0
fi
sym=`echo "$line" | sed 's/^[<>]/|/'`
o_str=$o_str$nl"<$optclo$islo$sym"
}
genopt_scond() {
case x$cond in
x)
cond=
;;
x*' '*)
cond=`echo "$cond" | sed 's/^ //'`
cond="#if $cond"
;;
x'!'*)
cond=`echo "$cond" | sed 's/^!//'`
cond="#ifndef $cond"
;;
x*)
cond="#ifdef $cond"
;;
esac
}
do_genopt() {
srcfile=$1
test -f "$srcfile" || genopt_die Source file \$srcfile not set.
bn=`basename "$srcfile" | sed 's/.opt$//'`
o_hdr='/* +++ GENERATED FILE +++ DO NOT EDIT +++ */'
o_gen=
o_str=
o_sym=
ddefs=
state=0
exec <"$srcfile"
IFS=
while IFS= read line; do
IFS=$safeIFS
case $state:$line in
2:'|'*)
# end of input
o_sym=`echo "$line" | sed 's/^.//'`
o_gen=$o_gen$nl"#undef F0"
o_gen=$o_gen$nl"#undef FN"
o_gen=$o_gen$ddefs
state=3
;;
1:@@)
# start of data block
o_gen=$o_gen$nl"#endif"
o_gen=$o_gen$nl"#ifndef F0"
o_gen=$o_gen$nl"#define F0 FN"
o_gen=$o_gen$nl"#endif"
state=2
;;
*:@@*)
genopt_die ;;
0:/\*-|0:"$sp"\**|0:)
o_hdr=$o_hdr$nl$line
;;
0:@*|1:@*)
# start of a definition block
sym=`echo "$line" | sed 's/^@//'`
if test $state = 0; then
o_gen=$o_gen$nl"#if defined($sym)"
else
o_gen=$o_gen$nl"#elif defined($sym)"
fi
ddefs="$ddefs$nl#undef $sym"
state=1
;;
0:*|3:*)
genopt_die ;;
1:*)
# definition line
o_gen=$o_gen$nl$line
;;
2:'<'*'|'*)
genopt_soptc
;;
2:'>'*'|'*)
genopt_soptc
cond=`echo "$line" | sed 's/^[^|]*|//'`
genopt_scond
case $optc in
'|') optc=0 ;;
*) optc=\'$optc\' ;;
esac
IFS= read line || genopt_die Unexpected EOF
IFS=$safeIFS
test_z "$cond" || o_gen=$o_gen$nl"$cond"
o_gen=$o_gen$nl"$line, $optc)"
test_z "$cond" || o_gen=$o_gen$nl"#endif"
;;
esac
done
case $state:$o_sym in
3:) genopt_die Expected optc sym at EOF ;;
3:*) ;;
*) genopt_die Missing EOF marker ;;
esac
echo "$o_str" | sort | while IFS='|' read x opts cond; do
IFS=$safeIFS
test_n "$x" || continue
genopt_scond
test_z "$cond" || echo "$cond"
echo "\"$opts\""
test_z "$cond" || echo "#endif"
done | {
echo "$o_hdr"
echo "#ifndef $o_sym$o_gen"
echo "#endif"
echo "#ifdef $o_sym"
cat
echo "#undef $o_sym"
echo "#endif"
} >"$bn.gen"
IFS=$safeIFS
return 0
}
if test x"$BUILDSH_RUN_GENOPT" = x"1"; then
set x -G "$srcfile"
shift
fi
if test x"$1" = x"-G"; then
do_genopt "$2"
exit $?
fi
echo "For the build logs, demonstrate that /dev/null and /dev/tty exist:"
ls -l /dev/null /dev/tty
cat <<EOF
Flags on entry (plus HAVE_* which are not shown here):
- CC <$CC>
- CFLAGS <$CFLAGS>
- CPPFLAGS <$CPPFLAGS>
- LDFLAGS <$LDFLAGS>
- LIBS <$LIBS>
- LDSTATIC <$LDSTATIC>
- TARGET_OS <$TARGET_OS> TARGET_OSREV <$TARGET_OSREV>
EOF
v() {
$e "$*"
eval "$@"
}
vv() {
_c=$1
shift
$e "\$ $*" 2>&1
eval "$@" >vv.out 2>&1
sed "s^${_c} " <vv.out
}
vq() {
eval "$@"
}
rmf() {
for _f in "$@"; do
case $_f in
lksh.1|mksh.1|mksh.faq|mksh.ico) ;;
*) rm -f "$_f" ;;
esac
done
}
tcfn=no
bi=
ui=
ao=
fx=
me=`basename "$0"`
orig_CFLAGS=$CFLAGS
phase=x
oldish_ed='stdout-ed no-stderr-ed'
if test -t 1; then
bi='[1m'
ui='[4m'
ao='[0m'
fi
upper() {
echo :"$@" | sed 's/^://' | tr $alll $allu
}
# clean up after ac_testrun()
ac_testdone() {
eval HAVE_$fu=$fv
fr=no
test 0 = $fv || fr=yes
$e "$bi==> $fd...$ao $ui$fr$ao$fx"
fx=
}
# ac_cache label: sets f, fu, fv?=0
ac_cache() {
f=$1
fu=`upper $f`
eval fv=\$HAVE_$fu
case $fv in
0|1)
fx=' (cached)'
return 0
;;
esac
fv=0
return 1
}
# ac_testinit label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
# returns 1 if value was cached/implied, 0 otherwise: call ac_testdone
ac_testinit() {
if ac_cache $1; then
test x"$2" = x"!" && shift
test x"$2" = x"" || shift
fd=${3-$f}
ac_testdone
return 1
fi
fc=0
if test x"$2" = x""; then
ft=1
else
if test x"$2" = x"!"; then
fc=1
shift
fi
eval ft=\$HAVE_`upper $2`
if test_z "$ft"; then
echo >&2
echo >&2 "E: test $f depends on $2 which is not defined yet"
exit 255
fi
shift
fi
fd=${3-$f}
if test $fc = "$ft"; then
fv=$2
fx=' (implied)'
ac_testdone
return 1
fi
$e ... $fd
return 0
}
cat_h_blurb() {
echo '#ifdef MKSH_USE_AUTOCONF_H
/* things that “should” have been on the command line */
#include "autoconf.h"
#undef MKSH_USE_AUTOCONF_H
#endif
'
cat
}
# pipe .c | ac_test[n] [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
ac_testnndnd() {
if test x"$1" = x"!"; then
fr=1
shift
else
fr=0
fi
cat_h_blurb >conftest.c
ac_testinit "$@" || return 1
vv ']' "$CC $CFLAGS $Cg $CPPFLAGS $LDFLAGS $NOWARN conftest.c $LIBS $ccpr"
test $tcfn = no && test -f a.out && tcfn=a.out
test $tcfn = no && test -f a.exe && tcfn=a.exe
test $tcfn = no && test -f conftest.exe && tcfn=conftest.exe
test $tcfn = no && test -f conftest && tcfn=conftest
if test -f $tcfn; then
test 1 = $fr || fv=1
else
test 0 = $fr || fv=1
fi
vscan=
if test $phase = u; then
case $ct in
gcc*) vscan='unrecogni[sz]ed' ;;
hpcc) vscan='unsupported' ;;
pcc) vscan='unsupported' ;;
sunpro) vscan='-e ignored -e turned.off' ;;
esac
fi
test_n "$vscan" && grep $vscan vv.out >/dev/null 2>&1 && fv=$fr
return 0
}
ac_testn() {
if ac_testnndnd "$@"; then
rmf conftest.c conftest.o ${tcfn}* vv.out
ac_testdone
else
rm -f conftest.c
fi
}
ac_testnnd() {
if ac_testnndnd "$@"; then
ac_testdone
fi
}
# ac_ifcpp cppexpr [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
ac_ifcpp() {
expr=$1; shift
ac_testn "$@" <<-EOF
#include <unistd.h>
extern int thiswillneverbedefinedIhope(void);
int main(void) { return (isatty(0) +
#$expr
0
#else
/* force a failure: expr is false */
thiswillneverbedefinedIhope()
#endif
); }
EOF
test x"$1" = x"!" && shift
f=$1
fu=`upper $f`
eval fv=\$HAVE_$fu
test x"$fv" = x"1"
}
addtoach() {
if echo "$1" >>autoconf.h; then
echo ">>> $1"
else
echo >&2 "E: could not write autoconf.h"
exit 255
fi
}
# simple only (is IFS-split by shell)
cpp_define() {
case $use_ach in
0)
add_cppflags "-D$1=$2"
;;
1)
addtoach "#define $1 $2"
;;
*)
echo >&2 "E: cpp_define() called too early!"
exit 255
;;
esac
}
add_cppflags() {
CPPFLAGS="$CPPFLAGS $*"
}
ac_cppflags() {
test x"$1" = x"" || fu=$1
fv=$2
test x"$2" = x"" && eval fv=\$HAVE_$fu
cpp_define HAVE_$fu $fv
}
ac_test() {
ac_testn "$@"
ac_cppflags
}
# ac_flags [-] add varname cflags [text] [ldflags]
ac_flags() {
if test x"$1" = x"-"; then
shift
hf=1
else
hf=0
fi
fa=$1
vn=$2
f=$3
ft=$4
fl=$5
test x"$ft" = x"" && ft="if $f can be used"
save_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS $f"
save_LDFLAGS=$LDFLAGS
test_z "$fl" || LDFLAGS="$LDFLAGS $fl"
if test 1 = $hf; then
ac_testn can_$vn '' "$ft"
else
ac_testn can_$vn '' "$ft" <<-'EOF'
/* evil apo'stroph in comment test */
#include <unistd.h>
int main(void) { int t[2]; return (isatty(pipe(t))); }
EOF
#'
fi
eval fv=\$HAVE_CAN_`upper $vn`
test_z "$fl" || test 11 = $fa$fv || LDFLAGS=$save_LDFLAGS
test 11 = $fa$fv || CFLAGS=$save_CFLAGS
}
# ac_header [!] header [prereq ...]
ac_header() {
if test x"$1" = x"!"; then
na=1
shift
else
na=0
fi
hf=$1; shift
hv=`echo "$hf" | tr -d "$lfcr" | tr -c $alll$allu$alln $alls`
echo "/* NeXTstep bug workaround */" >x
for i
do
case $i in
_time)
echo '#if HAVE_BOTH_TIME_H && HAVE_SELECT_TIME_H' >>x
echo '#include <sys/time.h>' >>x
echo '#include <time.h>' >>x
echo '#elif HAVE_SYS_TIME_H && HAVE_SELECT_TIME_H' >>x
echo '#include <sys/time.h>' >>x
echo '#elif HAVE_TIME_H' >>x
echo '#include <time.h>' >>x
echo '#endif' >>x
echo '#if HAVE_SYS_SELECT_H' >>x
echo '#include <sys/select.h>' >>x
echo '#endif' >>x
;;
*)
echo "#include <$i>" >>x
;;
esac
done
echo "#include <$hf>" >>x
echo '#include <unistd.h>' >>x
echo 'int main(void) { return (isatty(0)); }' >>x
ac_testn "$hv" "" "<$hf>" <x
rmf x
test 1 = $na || ac_cppflags
}
addsrcs() {
if test x"$1" = x"!"; then
fr=0
shift
else
fr=1
fi
eval i=\$$1
test $fr = "$i" && case "$sp$SRCS$sp" in
*"$sp$2$sp"*) ;;
*) SRCS="$SRCS$sp$2" ;;
esac
}
# --- main ---
curdir=`pwd` srcdir=`dirname "$0" 2>/dev/null`
curdisp=.
case x$curdir in
x)
curdir=.
;;
*"$sp"*|*"$ht"*|*"$nl"*)
echo >&2 Current directory should not contain space or tab or newline.
echo >&2 Errors may occur.
;;
*"'"*)
echo >&2 Current directory should not contain single quotes.
echo >&2 Errors may occur.
;;
*)
curdisp=$curdir
;;
esac
case x$srcdir in
x)
srcdir=.
;;
*"$sp"*|*"$ht"*|*"$nl"*)
echo >&2 Source directory should not contain space or tab or newline.
echo >&2 Errors may occur.
;;
*"'"*)
echo >&2 Source directory must not contain single quotes.
exit 1
;;
esac
srcdisp=`cd "$srcdir" && pwd` || srcdisp=
test_n "$srcdisp" || srcdisp=$srcdir
if test x"$srcdisp" = x"$curdir"; then
srcdisp=
else
srcdisp=$srcdir/
fi
dstversion=`sed -n '/define MKSH_VERSION/s/^.*"\([^"]*\)".*$/\1/p' "$srcdir/sh.h"`
whatlong='The MirBSD Korn Shell (mksh)'
whatshort=mksh
e=echo
r=0
eq=0
pm=0
cm=normal
Cg=
optflags=-std-compile-opts
check_categories=
last=
tfn=
legacy=0
textmode=0
ebcdic=false
for i
do
case $last:$i in
c:dragonegg|c:llvm|c:trace)
cm=$i
last=
;;
c:*)
echo "$me: Unknown option -c '$i'!" >&2
exit 1
;;
o:*)
optflags=$i
last=
;;
:-A)
rm -f autoconf.h
addtoach '/* work around NeXTstep bug */'
use_ach=1
add_cppflags -DMKSH_USE_AUTOCONF_H
;;
:-c)
last=c
;;
:-E)
ebcdic=true
;;
:-G)
echo "$me: Do not call me with '-G'!" >&2
exit 1
;;
:-g)
# checker, debug, valgrind build
add_cppflags -DDEBUG
Cg=' '
;;
:-j)
pm=1
;;
:-L)
legacy=1
;;
:+L)
legacy=0
;;
:-M)
cm=makefile
;;
:-O)
optflags=-std-compile-opts
;;
:-o)
last=o
;;
:-Q)
eq=1
;;
:-r)
r=1
;;
:-T)
textmode=1
;;
:+T)
textmode=0
;;
:-v)
echo "Build.sh $srcversion"
echo "for $whatlong $dstversion"
exit 0
;;
:*)
echo "$me: Unknown option '$i'!" >&2
exit 1
;;
*)
echo "$me: Unknown option -'$last' '$i'!" >&2
exit 1
;;
esac
done
if test_n "$last"; then
echo "$me: Option -'$last' not followed by argument!" >&2
exit 1
fi
test_n "$tfn" || if test $legacy = 0; then
tfn=mksh
else
tfn=lksh
fi
if test -d $tfn || test -d $tfn.exe; then
echo "$me: Error: ./$tfn is a directory!" >&2
exit 1
fi
test x"$use_ach" = x"1" || use_ach=0
cpp_define MKSH_BUILDSH 1
rmf a.exe* a.out* conftest.* *core core.* ${tfn}* *.bc *.dbg *.ll *.o *.cat? \
*.gen Rebuild.sh Makefrag.inc lft no signames.inc test.sh x vv.out *.htm
SRCS="lalloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c jobs.c"
SRCS="$SRCS lex.c main.c misc.c shf.c syn.c tree.c var.c"
if test $legacy = 0; then
check_categories="$check_categories shell:legacy-no int:32"
else
check_categories="$check_categories shell:legacy-yes"
cpp_define MKSH_LEGACY_MODE 1
fi
if $ebcdic; then
cpp_define MKSH_EBCDIC 1
fi
if test $textmode = 0; then
check_categories="$check_categories shell:textmode-no shell:binmode-yes"
else
check_categories="$check_categories shell:textmode-yes shell:binmode-no"
cpp_define MKSH_WITH_TEXTMODE 1
fi
if test_z "$srcdisp"; then
CPPFLAGS="-I. $CPPFLAGS"
else
CPPFLAGS="-I. -I'$srcdir' $CPPFLAGS"
fi
test_z "$LDSTATIC" || if test_z "$LDFLAGS"; then
LDFLAGS=$LDSTATIC
else
LDFLAGS="$LDFLAGS $LDSTATIC"
fi
if test_z "$TARGET_OS"; then
x=`uname -s 2>/dev/null || uname`
case $x in
scosysv)
# SVR4 Unix with uname -s = uname -n, whitelist
TARGET_OS=$x
;;
syllable)
# other OS with uname -s = uname = uname -n, whitelist
TARGET_OS=$x
;;
*)
test x"$x" = x"`uname -n 2>/dev/null`" || TARGET_OS=$x
;;
esac
fi
if test_z "$TARGET_OS"; then
echo "$me: Set TARGET_OS, your uname is broken!" >&2
exit 1
fi
osnote=
oswarn=
ccpc=-Wc,
ccpl=-Wl,
tsts=
ccpr='|| for _f in ${tcfn}*; do case $_f in lksh.1|mksh.1|mksh.faq|mksh.ico) ;; *) rm -f "$_f" ;; esac; done'
# Evil hack
if test x"$TARGET_OS" = x"Android"; then
check_categories="$check_categories android"
TARGET_OS=Linux
fi
# Evil OS
if test x"$TARGET_OS" = x"Minix"; then
echo >&2 "
WARNING: additional checks before running Build.sh required!
You can avoid these by calling Build.sh correctly, see below.
"
cat_h_blurb >conftest.c <<'EOF'
#include <sys/types.h>
const char *
#ifdef _NETBSD_SOURCE
ct="Ninix3"
#else
ct="Minix3"
#endif
;
EOF
ct=unknown
vv ']' "${CC-cc} -E $CFLAGS $Cg $CPPFLAGS $NOWARN conftest.c | grep ct= | tr -d \\\\015 >x"
sed 's/^/[ /' x
eval `cat x`
rmf x vv.out
case $ct in
Minix3|Ninix3)
echo >&2 "
Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous.
Please set it to either Minix3 or Ninix3, whereas the latter is
all versions of Minix with even partial NetBSD(R) userland. The
value determined from your compiler for the current compilation
(which may be wrong) is: $ct
"
TARGET_OS=$ct
;;
*)
echo >&2 "
Warning: you set TARGET_OS to $TARGET_OS but that is ambiguous.
Please set it to either Minix3 or Ninix3, whereas the latter is
all versions of Minix with even partial NetBSD(R) userland. The
proper value couldn't be determined, continue at your own risk.
"
;;
esac
fi
# Configuration depending on OS revision, on OSes that need them
case $TARGET_OS in
NEXTSTEP)
test_n "$TARGET_OSREV" || TARGET_OSREV=`hostinfo 2>&1 | \
grep 'NeXT Mach [0-9][0-9.]*:' | \
sed 's/^.*NeXT Mach \([0-9][0-9.]*\):.*$/\1/'`
;;
BeOS|HP-UX|QNX|SCO_SV)
test_n "$TARGET_OSREV" || TARGET_OSREV=`uname -r`
;;
esac
# SVR4 (some) workaround
int_as_ssizet() {
cpp_define SSIZE_MIN INT_MIN
cpp_define SSIZE_MAX INT_MAX
cpp_define ssize_t int
}
cmplrflgs=
# Configuration depending on OS name
case $TARGET_OS in
386BSD)
: "${HAVE_CAN_OTWO=0}"
cpp_define MKSH_NO_SIGSETJMP 1
cpp_define MKSH_TYPEDEF_SIG_ATOMIC_T int
;;
4.4BSD)
osnote='; assuming BOW (BSD on Windows)'
check_categories="$check_categories nopiddependent noxperms"
check_categories="$check_categories nosymlink noweirdfilenames"
;;
A/UX)
add_cppflags -D_POSIX_SOURCE
: "${CC=gcc}"
: "${LIBS=-lposix}"
# GCC defines AUX but cc nothing
add_cppflags -D__A_UX__
;;
AIX)
add_cppflags -D_ALL_SOURCE
;;
BeOS)
: "${CC=gcc}"
case $TARGET_OSREV in
[012345].*)
oswarn="; it has MAJOR issues"
test x"$TARGET_OSREV" = x"5.1" || \
cpp_define MKSH_NO_SIGSUSPEND 1
;;
*)
oswarn="; it has minor issues"
;;
esac
case $KSH_VERSION in
*MIRBSD\ KSH*)
;;
*)
case $ZSH_VERSION in
*[0-9]*)
;;
*)
oswarn="; you must recompile mksh with"
oswarn="$oswarn${nl}itself in a second stage"
;;
esac
;;
esac
: "${MKSH_UNLIMITED=1}"
# BeOS has no real tty either
cpp_define MKSH_UNEMPLOYED 1
cpp_define MKSH_DISABLE_TTY_WARNING 1
# BeOS doesn't have different UIDs and GIDs
cpp_define MKSH__NO_SETEUGID 1
: "${HAVE_SETRESUGID=0}"
;;
BSD/OS)
: "${HAVE_POSIX_UTF8_LOCALE=0}"
;;
Coherent)
oswarn="; it has major issues"
cpp_define MKSH__NO_SYMLINK 1
check_categories="$check_categories nosymlink"
cpp_define MKSH__NO_SETEUGID 1
: "${HAVE_SETRESUGID=0}"
cpp_define MKSH_DISABLE_TTY_WARNING 1
;;
CYGWIN*)
: "${HAVE_POSIX_UTF8_LOCALE=0}"
;;
Darwin)
add_cppflags -D_DARWIN_C_SOURCE
;;
DragonFly)
;;
FreeBSD)
;;
FreeMiNT)
oswarn="; it has minor issues"
add_cppflags -D_GNU_SOURCE
: "${HAVE_POSIX_UTF8_LOCALE=0}"
;;
GNU)
case $CC in
*tendracc*) ;;
*) add_cppflags -D_GNU_SOURCE ;;
esac
cpp_define SETUID_CAN_FAIL_WITH_EAGAIN 1
;;
GNU/kFreeBSD)
case $CC in
*tendracc*) ;;
*) add_cppflags -D_GNU_SOURCE ;;
esac
cpp_define SETUID_CAN_FAIL_WITH_EAGAIN 1
;;
Haiku)
cpp_define MKSH_ASSUME_UTF8 1
HAVE_ISSET_MKSH_ASSUME_UTF8=1
HAVE_ISOFF_MKSH_ASSUME_UTF8=0
;;
Harvey)
add_cppflags -D_POSIX_SOURCE
add_cppflags -D_LIMITS_EXTENSION
add_cppflags -D_BSD_EXTENSION
add_cppflags -D_SUSV2_SOURCE
add_cppflags -D_GNU_SOURCE
cpp_define MKSH_ASSUME_UTF8 1
HAVE_ISSET_MKSH_ASSUME_UTF8=1
HAVE_ISOFF_MKSH_ASSUME_UTF8=0
: "${HAVE_POSIX_UTF8_LOCALE=0}"
cpp_define MKSH__NO_SYMLINK 1
check_categories="$check_categories nosymlink"
cpp_define MKSH_NO_CMDLINE_EDITING 1
cpp_define MKSH__NO_SETEUGID 1
: "${HAVE_SETRESUGID=0}"
oswarn=' and will currently not work'
cpp_define MKSH_UNEMPLOYED 1
cpp_define MKSH_NOPROSPECTOFWORK 1
# these taken from Harvey-OS github and need re-checking
cpp_define _setjmp setjmp
cpp_define _longjmp longjmp
: "${HAVE_CAN_NO_EH_FRAME=0}"
: "${HAVE_CAN_FNOSTRICTALIASING=0}"
: "${HAVE_CAN_FSTACKPROTECTORSTRONG=0}"
;;
HP-UX)
case $TARGET_OSREV in
B.09.*)
: "${CC=c89}"
add_cppflags -D_HPUX_SOURCE
cpp_define MBSDINT_H_SMALL_SYSTEM 1
;;
esac
;;
Interix)
ccpc='-X '
ccpl='-Y '
add_cppflags -D_ALL_SOURCE
: "${LIBS=-lcrypt}"
: "${HAVE_POSIX_UTF8_LOCALE=0}"
;;
IRIX*)