From 73106b6e755847f5a545c12af1bb1d72a5f8a004 Mon Sep 17 00:00:00 2001 From: tg Date: Wed, 20 Nov 2013 21:14:50 +0000 Subject: [PATCH] make this actually call getopt.sh, correctly, and Heirloom sh compatible --- Build.sh | 39 ++++++++++--- Makefile | 4 +- genopt.sh | 164 ++++++++++++++++++++++++++---------------------------- 3 files changed, 114 insertions(+), 93 deletions(-) diff --git a/Build.sh b/Build.sh index feac5d6..31a56e0 100644 --- a/Build.sh +++ b/Build.sh @@ -1,5 +1,5 @@ #!/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, # 2011, 2012, 2013 @@ -66,7 +66,7 @@ vq() { rmf() { for _f in "$@"; do 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" ;; esac done @@ -327,8 +327,17 @@ addsrcs() { curdir=`pwd` srcdir=`dirname "$0" 2>/dev/null` case x$srcdir in -x) srcdir=. ;; -*"'"*) echo Source directory must not contain single quotes.; exit 1 ;; +x) + 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 dstversion=`sed -n '/define MKSH_VERSION/s/^.*"\([^"]*\)".*$/\1/p' "$srcdir/sh.h"` 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 exit 1 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 SRCS="lalloc.c eval.c exec.c expr.c funcs.c histrap.c jobs.c" @@ -466,7 +475,7 @@ oswarn= ccpc=-Wc, ccpl=-Wl, 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 if test x"$TARGET_OS" = x"Android"; then @@ -1602,7 +1611,7 @@ else #define EXTERN #define MKSH_INCLUDES_ONLY #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); } EOF case $cm in @@ -2228,6 +2237,10 @@ llvm) ;; esac 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 for file in $SRCS; do 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 extras='emacsfn.h genopt.sh rlimits.opt sh.h sh_flags.opt var_spec.h' 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 < @@ -87,89 +87,85 @@ scond() { esac } -for srcfile -do - bn=`basename "$srcfile" | sed 's/.opt$//'` - o_gen= - o_str= - o_sym= - ddefs= - state=0 - exec <"$srcfile" - while IFS= read -r line; do - 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" - for sym in $ddefs; do - o_gen=$o_gen$nl"#undef $sym" - done - state=3 - ;; - 1:@@) - # begin 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 - ;; - *:@@*) - die ;; - 0:@*|1:@*) - # begin 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 $sym" - state=1 - ;; - 0:*|3:*) - die ;; - 1:*) - # definition line - o_gen=$o_gen$nl$line - ;; - 2:'<'*'|'*) - soptc - ;; - 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 +test -f "$srcfile" || die Source file \$srcfile not set. +bn=`basename "$srcfile" | sed 's/.opt$//'` +o_gen= +o_str= +o_sym= +ddefs= +state=0 +exec <"$srcfile" +while IFS= read -r line; do + 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:@@) + # begin 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 + ;; + *:@@*) + die ;; + 0:@*|1:@*) + # begin 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:*) + die ;; + 1:*) + # definition line + o_gen=$o_gen$nl$line + ;; + 2:'<'*'|'*) + soptc + ;; + 2:'>'*'|'*) + soptc + cond=`echo "$line" | sed 's/^[^|]*|//'` 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" + 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 + 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