Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Makefile 3.28 KiB
# This Makefile made available to his students by 
# Prof. Ronald Moore  
#     https://fbi.h-da.de/personen/ronald-moore/  
#     mailto:ronald.moore@h-da.de
# with no warranties whatsoever


## More preliminaries
# See https://www.gnu.org/software/make/manual/html_node/Special-Targets.html
# In this makefile, we want to keep going even if we find errors
.IGNORE :

.NOTPARALLEL :

## Define test collections - each line should contain one or more filenames
GOOD-INPUTS := goodTest.input
BAD-INPUTS := badTest.input

# the sum of all tests
INPUTS := $(GOOD-INPUTS) $(BAD-INPUTS)

# reference files ("correct" output)
REFERENCES := $(INPUTS:.input=.reference)

# output files
OUTPUTS := $(INPUTS:.input=.output)

# Program we'll be testing
PROGRAM := ../interpret++

# Tell make that the following "targets" are "phony"
# Cf. https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html#Phony-Targets
.PHONY : all clean tests goodtests badtests

##  Now, the targets -- the things that will get made!

all: tests

# For convenience, "make check" == "make test"
check: tests

# TESTING
# Calling "make test" should
# (1) make the programs (if necessary)
# (2) erase all the test outputs
# (3) create them again (see rules, below).
# (4) run the special case "bigtest" (see below)
tests: $(PROGRAM)
	cd .. && $(MAKE)
	$(MAKE) clean
	$(MAKE) updatetests

updatetests: $(OUTPUTS)

$(PROGRAM) :
	cd ..
	$(MAKE)
	
# "make clean" or equivalently  "make testclean" deletes all files created by testing
clean: testclean

testclean:
	$(RM) -fv *.output *~ 

# By the way, for more information about calling make from make, see
# https://www.gnu.org/software/make/manual/html_node/Recursion.html#Recursion

# User-defined function (Cf. http://oreilly.com/catalog/make3/book/ch04.pdf)
# Takes two arguments - an output file and a reference output file
# (the two files should be the same). Function  prints "success" or "failure",
# depending on whether the two files are equal.
#define testReferenceOutput
#    @cmp -s $1 $2                                        \
#    && /bin/echo -e "Test against $2 successful" \
#    || /bin/echo -e "\n\tTest against $2 FAILED!!!\n"
#endef

#### If your terminal supports colors, comment out the version above,
# and use this version instead - good tests have a green background,
# failed tests have a red background. See
#    <http://misc.flogisoft.com/bash/tip_colors_and_formatting>
# for information about output formatting (colors, bold, etc.)).

define testReferenceOutput
#    @cmp -s $1 $2
    @diff -qs $1 $2                                        \
    && /bin/echo -e "\e[1;42mTest against $2 successful.\e[0m" \
    || /bin/echo -e "\e[1;41mTest against $2 FAILED!!!  \e[0m"
endef

#  Reminder...
# $@ = The filename representing the target.
# $< = The filename of the first prerequisite.
# $* = The stem of the target (i.e. without .o, .cpp...)
# $(*F) = The stem of the target (i.e. without .o, .cpp... AND without directory)
# $^ = The names of all the prerequisites, with spaces between them.


################ Assembler Tests ###################
# For some files x.job, we have stored the "correct" (expected) output in x.ref
# (where "ref" is short for "reference").
$(OUTPUTS): %.output: %.input %.reference
	../interpret++ $<  >$@  2>&1 
	$(call testReferenceOutput,$@, $*.reference)

# Finished!