make this actually call getopt.sh, correctly, and Heirloom sh compatible

This commit is contained in:
tg
2013-11-20 21:14:50 +00:00
parent 47ba4d13b4
commit 73106b6e75
3 changed files with 114 additions and 93 deletions

View File

@@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.650 2013/11/17 22:22:50 tg Exp $' srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.651 2013/11/20 21:14:49 tg Exp $'
#- #-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013 # 2011, 2012, 2013
@@ -66,7 +66,7 @@ vq() {
rmf() { rmf() {
for _f in "$@"; do for _f in "$@"; do
case $_f in case $_f in
Build.sh|check.pl|check.t|dot.mkshrc|*.c|*.h|*.ico|*.1) ;; Build.sh|check.pl|check.t|dot.mkshrc|genopt.sh|*.1|*.c|*.h|*.ico|*.opt) ;;
*) rm -f "$_f" ;; *) rm -f "$_f" ;;
esac esac
done done
@@ -327,8 +327,17 @@ addsrcs() {
curdir=`pwd` srcdir=`dirname "$0" 2>/dev/null` curdir=`pwd` srcdir=`dirname "$0" 2>/dev/null`
case x$srcdir in case x$srcdir in
x) srcdir=. ;; x)
*"'"*) echo Source directory must not contain single quotes.; exit 1 ;; srcdir=.
;;
*\ *|*" "*|*"$nl"*)
echo >&2 Source directory should not contain space or tab or newline.
echo >&2 Errors may occur.
;;
*"'"*)
echo Source directory must not contain single quotes.
exit 1
;;
esac esac
dstversion=`sed -n '/define MKSH_VERSION/s/^.*"\([^"]*\)".*$/\1/p' "$srcdir/sh.h"` dstversion=`sed -n '/define MKSH_VERSION/s/^.*"\([^"]*\)".*$/\1/p' "$srcdir/sh.h"`
add_cppflags -DMKSH_BUILDSH add_cppflags -DMKSH_BUILDSH
@@ -427,7 +436,7 @@ if test -d $tfn || test -d $tfn.exe; then
echo "$me: Error: ./$tfn is a directory!" >&2 echo "$me: Error: ./$tfn is a directory!" >&2
exit 1 exit 1
fi fi
rmf a.exe* a.out* conftest.c *core core.* lft ${tfn}* no *.bc *.ll *.o \ rmf a.exe* a.out* conftest.c *core core.* lft ${tfn}* no *.bc *.ll *.o *.gen \
Rebuild.sh signames.inc test.sh x vv.out Rebuild.sh signames.inc test.sh x vv.out
SRCS="lalloc.c eval.c exec.c expr.c funcs.c histrap.c jobs.c" SRCS="lalloc.c eval.c exec.c expr.c funcs.c histrap.c jobs.c"
@@ -466,7 +475,7 @@ oswarn=
ccpc=-Wc, ccpc=-Wc,
ccpl=-Wl, ccpl=-Wl,
tsts= tsts=
ccpr='|| for _f in ${tcfn}*; do case $_f in Build.sh|check.pl|check.t|dot.mkshrc|*.c|*.h|*.ico|*.1) ;; *) rm -f "$_f" ;; esac; done' ccpr='|| for _f in ${tcfn}*; do case $_f in Build.sh|check.pl|check.t|dot.mkshrc|genopt.sh|*.1|*.c|*.h|*.ico|*.opt) ;; *) rm -f "$_f" ;; esac; done'
# Evil hack # Evil hack
if test x"$TARGET_OS" = x"Android"; then if test x"$TARGET_OS" = x"Android"; then
@@ -1602,7 +1611,7 @@ else
#define EXTERN #define EXTERN
#define MKSH_INCLUDES_ONLY #define MKSH_INCLUDES_ONLY
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.650 2013/11/17 22:22:50 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.651 2013/11/20 21:14:49 tg Exp $");
int main(void) { printf("Hello, World!\n"); return (0); } int main(void) { printf("Hello, World!\n"); return (0); }
EOF EOF
case $cm in case $cm in
@@ -2228,6 +2237,10 @@ llvm)
;; ;;
esac esac
echo ": # work around NeXTstep bug" >Rebuild.sh echo ": # work around NeXTstep bug" >Rebuild.sh
for file in "$srcdir"/*.opt; do
echo "echo + Running \\\$srcdir/genopt.sh on '$file'..."
echo "(srcfile='$file'; . '$srcdir/genopt.sh')"
done >>Rebuild.sh
echo set -x >>Rebuild.sh echo set -x >>Rebuild.sh
for file in $SRCS; do for file in $SRCS; do
op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'` op=`echo x"$file" | sed 's/^x\(.*\)\.c$/\1./'`
@@ -2259,6 +2272,13 @@ echo "test -f \$tcfn || exit 1; $SIZE \$tcfn" >>Rebuild.sh
if test $cm = makefile; then if test $cm = makefile; then
extras='emacsfn.h genopt.sh rlimits.opt sh.h sh_flags.opt var_spec.h' extras='emacsfn.h genopt.sh rlimits.opt sh.h sh_flags.opt var_spec.h'
test 0 = $HAVE_SYS_SIGNAME && extras="$extras signames.inc" test 0 = $HAVE_SYS_SIGNAME && extras="$extras signames.inc"
gens= genq=
for file in "$srcdir"/*.opt; do
genf=`basename "$file" | sed 's/.opt$/.gen/'`
gens="$gens $genf"
genq="$genq$nl$genf: $srcdir/genopt.sh $file
srcfile=$file; . $srcdir/genopt.sh"
done
cat >Makefrag.inc <<EOF cat >Makefrag.inc <<EOF
# Makefile fragment for building mksh $dstversion # Makefile fragment for building mksh $dstversion
@@ -2276,6 +2296,8 @@ CPPFLAGS= $CPPFLAGS
LDFLAGS= $LDFLAGS LDFLAGS= $LDFLAGS
LIBS= $LIBS LIBS= $LIBS
.depend \$(OBJS_BP):$gens$genq
# not BSD make only: # not BSD make only:
#VPATH= $srcdir #VPATH= $srcdir
#all: \$(PROG) #all: \$(PROG)
@@ -2299,6 +2321,9 @@ EOF
$e Generated Makefrag.inc successfully. $e Generated Makefrag.inc successfully.
exit 0 exit 0
fi fi
for file in "$srcdir"/*.opt; do
v "(srcfile='$file'; . '$srcdir/genopt.sh')" || exit 1
done
if test $cm = combine; then if test $cm = combine; then
objs="-o $mkshexe" objs="-o $mkshexe"
for file in $SRCS; do for file in $SRCS; do

View File

@@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/Makefile,v 1.127 2013/11/17 22:21:17 tg Exp $ # $MirOS: src/bin/mksh/Makefile,v 1.128 2013/11/20 21:14:50 tg Exp $
#- #-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013 # 2011, 2012, 2013
@@ -85,7 +85,7 @@ OPTGENS!= cd ${.CURDIR:Q} && echo *.opt
.for _i in ${OPTGENS} .for _i in ${OPTGENS}
GENERATED+= ${_i:R}.gen GENERATED+= ${_i:R}.gen
${_i:R}.gen: ${_i} ${.CURDIR}/genopt.sh ${_i:R}.gen: ${_i} ${.CURDIR}/genopt.sh
${MKSH} ${.CURDIR:Q}/genopt.sh ${.CURDIR:Q}/${_i} (srcfile=${.CURDIR:Q}/${_i}; . ${.CURDIR:Q}/genopt.sh)
.endfor .endfor
CLEANFILES+= ${GENERATED} CLEANFILES+= ${GENERATED}

164
genopt.sh
View File

@@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
# $MirOS: src/bin/mksh/genopt.sh,v 1.3 2013/11/20 20:55:01 tg Exp $ # $MirOS: src/bin/mksh/genopt.sh,v 1.4 2013/11/20 21:14:50 tg Exp $
#- #-
# Copyright (c) 2013 # Copyright (c) 2013
# Thorsten Glaser <tg@mirbsd.org> # Thorsten Glaser <tg@mirbsd.org>
@@ -87,89 +87,85 @@ scond() {
esac esac
} }
for srcfile test -f "$srcfile" || die Source file \$srcfile not set.
do bn=`basename "$srcfile" | sed 's/.opt$//'`
bn=`basename "$srcfile" | sed 's/.opt$//'` o_gen=
o_gen= o_str=
o_str= o_sym=
o_sym= ddefs=
ddefs= state=0
state=0 exec <"$srcfile"
exec <"$srcfile" while IFS= read -r line; do
while IFS= read -r line; do case $state:$line in
case $state:$line in 2:'|'*)
2:'|'*) # end of input
# end of input o_sym=`echo "$line" | sed 's/^.//'`
o_sym=`echo "$line" | sed 's/^.//'` o_gen=$o_gen$nl"#undef F0"
o_gen=$o_gen$nl"#undef F0" o_gen=$o_gen$nl"#undef FN"
o_gen=$o_gen$nl"#undef FN" o_gen=$o_gen$ddefs
for sym in $ddefs; do state=3
o_gen=$o_gen$nl"#undef $sym" ;;
done 1:@@)
state=3 # begin of data block
;; o_gen=$o_gen$nl"#endif"
1:@@) o_gen=$o_gen$nl"#ifndef F0"
# begin of data block o_gen=$o_gen$nl"#define F0 FN"
o_gen=$o_gen$nl"#endif" o_gen=$o_gen$nl"#endif"
o_gen=$o_gen$nl"#ifndef F0" state=2
o_gen=$o_gen$nl"#define F0 FN" ;;
o_gen=$o_gen$nl"#endif" *:@@*)
state=2 die ;;
;; 0:@*|1:@*)
*:@@*) # begin of a definition block
die ;; sym=`echo "$line" | sed 's/^@//'`
0:@*|1:@*) if test $state = 0; then
# begin of a definition block o_gen=$o_gen$nl"#if defined($sym)"
sym=`echo "$line" | sed 's/^@//'` else
if test $state = 0; then o_gen=$o_gen$nl"#elif defined($sym)"
o_gen=$o_gen$nl"#if defined($sym)" fi
else ddefs="$ddefs$nl#undef $sym"
o_gen=$o_gen$nl"#elif defined($sym)" state=1
fi ;;
ddefs="$ddefs $sym" 0:*|3:*)
state=1 die ;;
;; 1:*)
0:*|3:*) # definition line
die ;; o_gen=$o_gen$nl$line
1:*) ;;
# definition line 2:'<'*'|'*)
o_gen=$o_gen$nl$line soptc
;; ;;
2:'<'*'|'*) 2:'>'*'|'*)
soptc soptc
;; cond=`echo "$line" | sed 's/^[^|]*|//'`
2:'>'*'|'*)
soptc
cond=`echo "$line" | sed 's/^[^|]*|//'`
scond
case $optc in
'|') optc=0 ;;
*) optc=\'$optc\' ;;
esac
IFS= read -r line || die Unexpected EOF
test -n "$cond" && o_gen=$o_gen$nl"$cond"
o_gen=$o_gen$nl"$line, $optc)"
test -n "$cond" && o_gen=$o_gen$nl"#endif"
;;
esac
done
case $state:$o_sym in
3:) die Expected optc sym at EOF ;;
3:*) ;;
*) die Missing EOF marker ;;
esac
echo "$o_str" | sort | while IFS='|' read -r x opts cond; do
test -n "$x" || continue
scond scond
test -n "$cond" && echo "$cond" case $optc in
echo "\"$opts\"" '|') optc=0 ;;
test -n "$cond" && echo "#endif" *) optc=\'$optc\' ;;
done | { esac
echo "#ifndef $o_sym$o_gen" IFS= read -r line || die Unexpected EOF
echo "#else" test -n "$cond" && o_gen=$o_gen$nl"$cond"
cat o_gen=$o_gen$nl"$line, $optc)"
echo "#undef $o_sym" test -n "$cond" && o_gen=$o_gen$nl"#endif"
echo "#endif" ;;
} >"$bn.gen" esac
done done
case $state:$o_sym in
3:) die Expected optc sym at EOF ;;
3:*) ;;
*) die Missing EOF marker ;;
esac
echo "$o_str" | sort | while IFS='|' read -r x opts cond; do
test -n "$x" || continue
scond
test -n "$cond" && echo "$cond"
echo "\"$opts\""
test -n "$cond" && echo "#endif"
done | {
echo "#ifndef $o_sym$o_gen"
echo "#else"
cat
echo "#undef $o_sym"
echo "#endif"
} >"$bn.gen"
exit 0 exit 0