Makefile 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 expected/output-sorted$* > temp
  51. cat temp | sort -g > expected/output-sorted$*
  52. rm temp
  53. cat outputs/output$* | sort -g | diff expected/output-sorted$* -
  54. $(VALGRIND) --log-file=outputs/memoutput$* ./$(TARGET) inputs/input0$* > /dev/null
  55. @echo
  56. @bin/valgrind-checker.sh outputs/memoutput$*
  57. @echo
  58. testz01: $(TARGET) | environment
  59. ./$(TARGET) inputs/input01 > outputs/output1
  60. diff expected/output1 outputs/output1
  61. $(VALGRIND) --log-file=outputs/memoutput1 ./$(TARGET) inputs/input01 >/dev/null
  62. @bin/valgrind-checker.sh outputs/memoutput1