Makefile 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. GCC = gcc
  2. CFLAGS = -g -Wall -Wshadow
  3. LIBS = -lm
  4. SOURCES = answer04.c pa04.c
  5. TARGET = pa04
  6. TESTN := $(shell seq 1 9)
  7. VALGRIND = valgrind --tool=memcheck --leak-check=full --verbose
  8. # -------------------------------------------------------------
  9. TESTS := $(addprefix test,${TESTN})
  10. .PHONY : all build clean environment help testall $(TESTS)
  11. .DEFAULT_GOAL := build
  12. OBJF = obj
  13. OBJS = $(patsubst %.c,$(OBJF)/%.o,$(SOURCES))
  14. -include $(SOURCES:%=$(OBJF)/%.P)
  15. all: | build testall
  16. testall: | $(TESTS)
  17. build: $(TARGET)
  18. clean:
  19. @cd $(CURDIR)
  20. rm -rf $(TARGET) $(OBJF) outputs
  21. environment:
  22. @cd $(CURDIR)
  23. @mkdir -p outputs
  24. @mkdir -p $(OBJF)
  25. help:
  26. @echo
  27. @echo "make build $(TARGET)"
  28. @echo "make testall run all testcases"
  29. @echo "make clean start from scratch"
  30. @echo
  31. @echo "make test1 test on partition all"
  32. @echo "make test2 test on partition increasing"
  33. @echo "make test3 test on partition decreasing"
  34. @echo "make test4 test on partition with odd number only"
  35. @echo "make test5 test on partition with even number only"
  36. @echo "make test6 small test case on partition with alternate odd and even number"
  37. @echo "make test7 large test case on partition with alternate odd and even number"
  38. @echo "make test8 small test case on partition with prime number only"
  39. @echo "make test9 large test case on partition with prime number only"
  40. $(TARGET): $(OBJS) | environment
  41. $(GCC) $(CFLAGS) $(OBJS) $(LIBS) -o $@
  42. $(OBJF)/%.o: %.c | environment
  43. @$(GCC) -MM $(CFLAGS) $< | sed 's,^\([^ ]\),$(OBJF)\/\1,g' | sed '$$ s,$$, \\,' > $(OBJF)/$<.P
  44. $(GCC) $(CFLAGS) -c -o $@ $<
  45. ${TESTS}: test%: $(TARGET) | environment
  46. @echo '***************************************'
  47. @echo "test$*"
  48. @echo '***************************************'
  49. ./$(TARGET) inputs/input0$* > outputs/output$*
  50. cat outputs/output$* | sort | diff expected/output-sorted$* -
  51. $(VALGRIND) --log-file=outputs/memoutput$* ./$(TARGET) inputs/input0$* > /dev/null
  52. @echo
  53. @bin/valgrind-checker.sh outputs/memoutput$*
  54. @echo
  55. testz01: $(TARGET) | environment
  56. ./$(TARGET) inputs/input01 > outputs/output1
  57. diff expected/output1 outputs/output1
  58. $(VALGRIND) --log-file=outputs/memoutput1 ./$(TARGET) inputs/input01 >/dev/null
  59. @bin/valgrind-checker.sh outputs/memoutput1