1
0

Makefile 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. GCC = gcc
  2. CFLAGS = -g -Wall -Wshadow
  3. SOURCES = answer01.c pa01.c
  4. TARGET = pa01
  5. VALGRIND = valgrind --tool=memcheck --leak-check=full --verbose
  6. # -------------------------------------------------------------
  7. .PHONY : all test memcheck build clean environment help
  8. .DEFAULT_GOAL:= build
  9. OBJF = obj
  10. OBJS = $(patsubst %.c,$(OBJF)/%.o,$(SOURCES))
  11. -include $(SOURCES:%=$(OBJF)/%.P)
  12. all: | build test memcheck
  13. test: $(TARGET) | environment
  14. ./$(TARGET) > outputs/output
  15. cat outputs/output | sort | diff -w -q - expected/expected_sorted
  16. @echo "Grade: $(shell RES="0" ; cat outputs/output | sort | diff -w -q - expected/expected_sorted 1>/dev/null 2>/dev/null && RES="6" ; echo "$$RES")"
  17. test_detail: $(TARGET) | environment
  18. ./$(TARGET) > outputs/output
  19. cat outputs/output | sort | diff -w - expected/expected_sorted
  20. memcheck: $(TARGET) | environment
  21. $(VALGRIND) --log-file=outputs/memoutput ./$< > outputs/output
  22. @echo && ./expected/valgrind-checker.sh outputs/memoutput
  23. grading: $(TARGET) | environment
  24. ./$(TARGET) > outputs/output
  25. cat outputs/output | sort | diff -w -q - expected/expected_sorted
  26. build: $(TARGET)
  27. clean:
  28. @cd $(CURDIR)
  29. rm -rf $(TARGET) $(OBJF) output/output output/memoutput
  30. environment:
  31. @mkdir -p outputs
  32. @mkdir -p $(OBJF)
  33. help:
  34. @echo
  35. @echo " make build $(TARGET)"
  36. @echo " make all build, test and memcheck"
  37. @echo " make test run tests"
  38. @echo " make test_detail run tests and output detail results"
  39. @echo " make memcheck run valgrind to check memory"
  40. @echo " make clean start from scratch"
  41. @echo
  42. @echo " Temporary files written to ./$(OBJF) "
  43. @echo " Outputs: output/output and output/memoutput "
  44. @echo " Example output: expected/example-output "
  45. @echo " make grading run tests for grading"
  46. $(TARGET): $(OBJS) | environment
  47. $(GCC) $(CFLAGS) $(OBJS) -o $@
  48. $(OBJF)/%.o: %.c | environment
  49. @$(GCC) -MM $(CFLAGS) $< | sed 's,^\([^ ]\),$(OBJF)\/\1,g' | sed '$$ s,$$, \\,' > $(OBJF)/$<.P
  50. $(GCC) $(CFLAGS) -c -o $@ $<