Last active
January 16, 2016 18:20
-
-
Save guyhughes/385f1dabe004b927cf77 to your computer and use it in GitHub Desktop.
comp2402 run script and makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # _ | |
| # (_)____ _ _ __ ____ _ | |
| # / // __ `/| | / // __ `/ | |
| # / // /_/ / | |/ // /_/ / | |
| # __/ / \__,_/ |___/ \__,_/ | |
| # /___/ | |
| # __ ____ _ __ | |
| # ____ ___ ____ _ / /__ ___ / __/(_)/ /___ | |
| # / __ `__ \ / __ `// //_// _ \ / /_ / // // _ \ | |
| # / / / / / // /_/ // ,< / __// __// // // __/ | |
| # /_/ /_/ /_/ \__,_//_/|_| \___//_/ /_//_/ \___/ | |
| # by Guy Hughes | |
| MK_CLASSPATH := ./.out | |
| MK_SOURCEPATH := | |
| MK_JAVADOCPATH := ./doc | |
| COMPILER := javac | |
| COMPILE_OPTIONS := -d $(MK_CLASSPATH) -classpath $(MK_CLASSPATH) | |
| DEBUG_OPTIONS := -Xlint:unchecked | |
| RUN_OPTIONS := -ea | |
| # http://stackoverflow.com/a/12959764/3337659 | |
| rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2)) | |
| sourcefiles = $(call rwildcard,$(MK_SOURCEPATH),*.java) | |
| classfiles = $(patsubst %.java,$(MK_CLASSPATH)/%.class,$(sourcefiles)) | |
| runtargets = $(subst /,.,$(patsubst $(MK_SOURCEPATH)/%,%,$(patsubst $(MK_CLASSPATH)/%,%,$(classfiles:.class=)))) | |
| .PHONY: total all clean doc debug targets default | |
| default: total | |
| total: clean all | |
| all: | |
| @mkdir -p $(MK_CLASSPATH) | |
| $(COMPILER) $(COMPILE_OPTIONS) $(sourcefiles) | |
| debug: | |
| @mkdir -p $(MK_CLASSPATH) | |
| $(COMPILER) $(COMPILE_OPTIONS) $(DEBUG_OPTIONS) $(sourcefiles) | |
| doc: | |
| @mkdir -p $(MK_JAVADOCPATH) | |
| javadoc $(sourcefiles) -d $(MK_JAVADOCPATH) | |
| xdg-open $(MK_JAVADOCPATH)/index.html >/dev/null 2>&1 | |
| $(runtargets): all | |
| java -classpath $(MK_CLASSPATH) $(RUN_OPTIONS) $@ ${IN} ${OUT} | |
| targets: | |
| @echo $(runtargets) | |
| clean: | |
| rm -rf $(MK_JAVADOCPATH) | |
| rm -f $(classfiles) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| TESTDIR=./tests | |
| IN= | |
| OUT= | |
| NUMBER= | |
| DIFFOPTS="-qs" | |
| FORCE= | |
| sanity () { | |
| if [ -z "$NUMBER" ]; then | |
| echo "-n must be first arg" | |
| exit 1 | |
| fi | |
| } | |
| perform () { | |
| make comp2402a1.Part${NUMBER} IN="${IN}" OUT="${OUT}" | |
| } | |
| fmt () { | |
| if [ $# -ne 1 ]; then | |
| print "invalid fmt params" | |
| exit -1 | |
| fi | |
| printf "%02d" "$1" | |
| } | |
| while [ $# -gt 0 ]; do | |
| case "$1" in | |
| -n|--number) | |
| shift | |
| NUMBER="$1" | |
| ;; | |
| -v|--verbose) | |
| DIFFOPTS="-y --suppress-common-lines" | |
| ;; | |
| -f|--force) | |
| FORCE=1 | |
| ;; | |
| -t|--test) | |
| sanity | |
| shift | |
| IN="${TESTDIR}/test${NUMBER}-$(fmt $1).in" | |
| OUT= | |
| perform | |
| ;; | |
| -s|--special) | |
| shift | |
| IN="${TESTDIR}/test${1}.in" | |
| OUT= | |
| perform | |
| ;; | |
| -d|--diff) | |
| sanity | |
| shift | |
| IN="${TESTDIR}/test${NUMBER}-$(fmt $1).in" | |
| OUT="${TESTDIR}/temp" | |
| perform | |
| diff ${DIFFOPTS} "${TESTDIR}/test${NUMBER}-$(fmt $1).out" "${OUT}" | |
| rm "${OUT}" | |
| ;; | |
| --gen|--generate) | |
| sanity | |
| shift | |
| IN="${TESTDIR}/test${NUMBER}-$(fmt $1).in" | |
| OUT="${TESTDIR}/test${NUMBER}-$(fmt $1).out" | |
| if [ -z $FORCE ] && [ -e "$OUT" ]; then | |
| echo "out file exists: ${OUT}" | |
| echo "aborting..." | |
| exit 1 | |
| fi | |
| perform | |
| ;; | |
| --in) | |
| shift | |
| IN="$1" | |
| ;; | |
| --out) | |
| shift | |
| OUT="$1" | |
| ;; | |
| --) | |
| shift | |
| case $# in | |
| 2) | |
| IN="$1" | |
| OUT="$2" | |
| ;; | |
| 1) | |
| IN="$1" | |
| ;; | |
| *) | |
| echo "too many params after --" | |
| exit 1 | |
| ;; | |
| esac | |
| perform | |
| break | |
| ;; | |
| *) | |
| echo "invalid param: $1" | |
| exit 1 | |
| ;; | |
| esac | |
| shift | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment