summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2020-01-03 11:55:46 +0200
committerAdrian Thurston <thurston@colm.net>2020-01-03 14:21:24 +0200
commite673499ac9ca4739bfbf943e527b7624c50504f0 (patch)
tree70dcf79dc9f9cff64e658c70c8f56c9149655ee5
parent41b04f64ea5c607d2cb00765b68d28226e14a7e8 (diff)
downloadcolm-e673499ac9ca4739bfbf943e527b7624c50504f0.tar.gz
updated colm-pack wrapper: parse args first then switch on output
Other updates to colm/Makefile.am: don't depend on gen dir to have it built, causes rebuilding when new files go in. Do it the old way using mkdir -p gen in the rule that puts files there. Also colm-pack.sh needs to go into EXTRA_DIST. refs #85
-rw-r--r--colm/Makefile.am14
-rw-r--r--colm/colm-pack.sh87
2 files changed, 51 insertions, 50 deletions
diff --git a/colm/Makefile.am b/colm/Makefile.am
index 8e4bc0bb..2b10991a 100644
--- a/colm/Makefile.am
+++ b/colm/Makefile.am
@@ -74,9 +74,6 @@ colminc_HEADERS = $(RUNTIME_HDR)
BUILT_SOURCES = version.h include/colm
-gen:
- mkdir -p gen
-
if EXTERNAL_COLM
#
@@ -109,7 +106,8 @@ bootstrap0_LDADD = libprog.a libcolm.la
# the colm syntax/semantics that is implemented in colm itself.
#
-gen/bootstrap1.pack: colm-pack gen bootstrap0$(EXEEXT)
+gen/bootstrap1.pack: colm-pack bootstrap0$(EXEEXT)
+ mkdir -p gen
$(builddir)/colm-pack bootstrap0 -p $@ \
-c -o gen/parse1.c -e gen/if1.h -x gen/if1.cc
@@ -143,7 +141,8 @@ bootstrap1_LDADD = libprog.a libcolm.la
# and thus generates the sources used in the colm binary.
#
-gen/bootstrap2.pack: colm-pack gen bootstrap1$(EXEEXT) colm.lm
+gen/bootstrap2.pack: colm-pack bootstrap1$(EXEEXT) colm.lm
+ mkdir -p gen
$(builddir)/colm-pack bootstrap1 -p $@ \
-c -o gen/parse2.c -e gen/if2.h -x gen/if2.cc colm.lm
@@ -167,7 +166,8 @@ bootstrap2_LDADD = libprog.a libcolm.la
endif
-gen/bootstrap3.pack: colm-pack gen $(BUILD_PARSE_3_WITH) prog.lm colm.lm
+gen/bootstrap3.pack: colm-pack $(BUILD_PARSE_3_WITH) prog.lm colm.lm
+ mkdir -p gen
$(builddir)/colm-pack $(BUILD_PARSE_3_WITH) -p $@ \
-c -o gen/parse3.c -e gen/if3.h -x gen/if3.cc prog.lm
@@ -201,7 +201,7 @@ config.h: ../src/config.h
cp ../src/config.h ./
CLEANFILES = $(BUILT_SOURCES)
-EXTRA_DIST = prog.lm colm.lm loadfinal.cc
+EXTRA_DIST = prog.lm colm.lm loadfinal.cc colm-pack.sh
colm-pack: colm-pack.sh
@$(top_srcdir)/sedsubst $< $@ -w,+x $(SED_SUBST)
diff --git a/colm/colm-pack.sh b/colm/colm-pack.sh
index 9975cb0e..0a737e5f 100644
--- a/colm/colm-pack.sh
+++ b/colm/colm-pack.sh
@@ -1,55 +1,56 @@
#!/bin/bash
#
-if [ $1 = "unpack" ]; then
- shift 1
- while getopts "o:" opt; do
- case $opt in
- o) parser_output=$OPTARG;;
- esac
- done
- shift $((OPTIND - 1));
-
- tar -xmf "$@" $parser_output
- exit $?
+# This wrapper around the colm program (and bootstrap programs) allows us to
+# stick to one output per run of the program. It packs up the multiple colm
+# output files into one file. We can extract them one at a time afterwards.
+
+CMD=$1;
+shift 1
+
+ARGS=""
+while getopts "p:o:e:x:RcD:I:L:vdlirS:M:vHh?-:sVa:m:b:E:" opt; do
+ # For the unpack case.
+ if [ "$opt" = 'o' ]; then
+ output=$OPTARG
+ fi
+ # For the colm wrapper case.
+ case "$opt" in
+ p)
+ # Pack file name
+ pack_file=$OPTARG
+ ;;
+ [oexm])
+ ARGS="$ARGS -$opt $OPTARG.pack"
+ PACKS="$PACKS $OPTARG.pack"
+ ;;
+ [DILSMambE-]) ARGS="$ARGS -$opt $OPTARG" ;;
+ [RcvdlirvHhsV]) ARGS="$ARGS -$opt" ;;
+ ?)
+ exit 1;
+ ;;
+ esac
+done
+
+# Shift over the args.
+shift $((OPTIND - 1));
+
+if [ $CMD = "unpack" ]; then
+ tar -xmf "$@" $output
+ EXIT_STATUS=$?
else
-
- if [ "`basename $0`" != "$0" ] && [ -x "`dirname $0`/$1" ]; then
- COLM="`dirname $0`/$1"
+ if [ "`basename $0`" != "$0" ] && [ -x "`dirname $0`/$CMD" ]; then
+ COLM="`dirname $0`/$CMD"
else
- COLM=@prefix@/bin/$1
+ COLM=@prefix@/bin/$CMD
fi
- shift 1
-
- ARGS=""
-
- # Using silent mode to pass other options through.
- while getopts "p:o:e:x:RcD:I:L:vdlirS:M:vHh?-:sVa:m:b:E:" opt; do
-
- case $opt in
- p)
- # Pack file name
- pack_file=$OPTARG
- ;;
- [oexm])
- # Parser Output (C)
- parser_output=$OPTARG
- ARGS="$ARGS -$opt $OPTARG.pack"
- PACKS="$PACKS $OPTARG.pack"
- ;;
- [DILSMambE-]) ARGS="$ARGS -$opt $OPTARG" ;;
- [RcvdlirvHhsV]) ARGS="$ARGS -$opt" ;;
- ?)
- exit 1;
- ;;
- esac
- done
-
- shift $((OPTIND - 1));
-
$COLM $ARGS "$@"
+ EXIT_STATUS=$?
tar --transform 's/.pack$//' -cf "$pack_file" $PACKS
rm -f $PACKS
fi
+
+exit $EXIT_STATUS
+