1
\$\begingroup\$

I wrote a simple Makefile to build .expected files and compare them. It works as expected and I was wondering it would be great if I could get some feedback. More specifically if I followed all conventions and if it can be improved upon. This is my first Makefile.

# Relative path
RELATIVE_PATH=..
APSSCHED=$(RELATIVE_PATH)/bin/apssched
EXAMPLES=$(RELATIVE_PATH)/examples
BASE=.:$(RELATIVE_PATH)/base:$(EXAMPLES)
FLAGS=-DCOT
CASES=simple-binding1 simple-binding2 simple-binding3

# Generate output and store it in a file
%.output: $(EXAMPLES)/%.aps
    $(APSSCHED) $(FLAGS) -p $(BASE) $(basename $<) > $@

# Copy actual output as expected
%.expected: %.output
    cp -f $< $@

# Compare actual output with expected
.PHONY: %.compare
%.compare: %.output
# maybe there is a better way without using basename ...
    diff $(basename $@).expected $<

# Generate and verify all outputs
.PHONY: all
all: $(addsuffix .compare,$(CASES))

# Regenerate expected output
.PHONY: build.expected
build.expected: $(addsuffix .expected,$(CASES))

.PHONY: clean.expected
clean.expected:
    -rm -f *.expected
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to CodeReview@SE. \$\endgroup\$
    – greybeard
    Commented May 16, 2020 at 6:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.