1
0

Makefile 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. GCC = gcc
  2. CFLAGS = -g -Wall -Wshadow
  3. SOURCES = answer03.c pa03.c
  4. TARGET = pa03
  5. VALGRIND = valgrind --tool=memcheck --leak-check=full --verbose
  6. SHOW = @echo "You can use gthumb to view the image:"
  7. SHOW = feh -Z -F --force-alias
  8. # -------------------------------------------------------------
  9. .PHONY : all test build clean environment help test01 test02 test03 test04 test05 test06 test07 test08 test09 test10 test11 test12 test13 testXX
  10. .DEFAULT_GOAL:= build
  11. OBJF = obj
  12. OBJS = $(patsubst %.c,$(OBJF)/%.o,$(SOURCES))
  13. TARGET_O3 = $(TARGET)-O3
  14. CORRUPT = "outputs/corrupt.ppm"
  15. -include $(SOURCES:%=$(OBJF)/%.P)
  16. all: | build test
  17. test: | test01 test02 test03 test04 test05 test06 test07 test08 test09 test10 test11 test12 test13
  18. test01: $(TARGET) | environment
  19. @bin/test.sh ./$(TARGET) images/typing-practice.ee264 images/x.ee264 outputs/find-x.ppm
  20. test02: $(TARGET) | environment
  21. @bin/test.sh ./$(TARGET) images/typing-practice.ee264 images/k.ee264 outputs/find-k.ppm
  22. test03: $(TARGET) | environment
  23. @bin/test.sh ./$(TARGET) images/typing-practice.ee264 images/z.ee264 outputs/find-z.ppm
  24. test04: $(TARGET) | environment
  25. @bin/test.sh ./$(TARGET) images/typing-practice.ee264 images/w.ee264 outputs/find-w.ppm
  26. test05: $(TARGET) | environment
  27. @bin/test.sh ./$(TARGET) images/typing-practice.ee264 images/corrupt-testcases/incomplete-header.ee264 $(CORRUPT) \
  28. "test05: file has less than 128 bytes, and thus not enough to read a complete header."
  29. test06: $(TARGET) | environment
  30. @bin/test.sh ./$(TARGET) images/typing-practice.ee264 images/corrupt-testcases/check-magic-bits.ee264 $(CORRUPT) \
  31. "test06: file has corrupted magic bits."
  32. test07: $(TARGET) | environment
  33. @bin/test.sh ./$(TARGET) images/typing-practice.ee264 images/corrupt-testcases/width0.ee264 $(CORRUPT) \
  34. "test07: file header specifies 0 width, which is an error that you must check for."
  35. test08: $(TARGET) | environment
  36. @bin/test.sh ./$(TARGET) images/typing-practice.ee264 images/corrupt-testcases/height0.ee264 $(CORRUPT) \
  37. "test08: file header specifies 0 height, which is an error that you must check for."
  38. test09: $(TARGET) | environment
  39. @bin/test.sh ./$(TARGET) images/typing-practice.ee264 images/corrupt-testcases/big-width-height.ee264 $(CORRUPT) \
  40. "test09: file header has crazy values for width and height which should cause malloc to fail."
  41. test10: $(TARGET) | environment
  42. @bin/test.sh ./$(TARGET) images/typing-practice.ee264 images/corrupt-testcases/bad-comment-len.ee264 $(CORRUPT) \
  43. "test10: file header has a crazy value for the comment length which will either cause malloc to fail, or you will fail to find enough bytes in the file to read the comment."
  44. test11: $(TARGET) | environment
  45. @bin/test.sh ./$(TARGET) images/typing-practice.ee264 images/corrupt-testcases/comment-has-no-null-byte.ee264 $(CORRUPT) \
  46. "test11: comment (in file) does not end with a null-byte, which can cause serious problems."
  47. test12: $(TARGET) | environment
  48. @bin/test.sh ./$(TARGET) images/typing-practice.ee264 images/corrupt-testcases/height-wrong.ee264 $(CORRUPT) \
  49. "test12: file header specifies the wrong image height, meaning that you will not find the end of file when you expect to."
  50. test13: $(TARGET) | environment
  51. @bin/test.sh ./$(TARGET) images/typing-practice.ee264 images/corrupt-testcases/incomplete-image.ee264 $(CORRUPT) \
  52. "test13: file is missing some data from the end"
  53. testXX: $(TARGET_O3) | environment
  54. @bin/test.sh ./$(TARGET_O3) images/treasure-map.ee264 images/pentagram.ee264 outputs/find-pentagram.ppm
  55. build: $(TARGET)
  56. clean:
  57. @cd $(CURDIR)
  58. rm -rf $(TARGET) $(TARGET_O3) $(OBJF) output/typing.ppm output/memoutput
  59. environment:
  60. @mkdir -p outputs
  61. @mkdir -p $(OBJF)
  62. help:
  63. @echo
  64. @echo " make build $(TARGET)"
  65. @echo " make all build and test"
  66. @echo " make test run all testcases"
  67. @echo " make clean start from scratch"
  68. @echo
  69. @echo " Temporary files written to ./$(OBJF) "
  70. @echo " Outputs: output/output and output/memoutput "
  71. @echo " You can use gthumb to view output files. Expected output in expected/*.ppm"
  72. @echo
  73. @echo " Testcases: "
  74. @echo
  75. @echo " test01 => test 04 are valid input."
  76. @echo " test05: input file is too small to contain a valid header."
  77. @echo " test06: input file does not have the magic bits set correctly."
  78. @echo " test07: input file header has 0 width. (How can an image have no width?)"
  79. @echo " test08: input file header has 0 height."
  80. @echo " test09: input file header has width and height values that will cause malloc to fail"
  81. @echo " test10: input file header has a crazy value for the comment length that should cause problems"
  82. @echo " test11: input file comment does not end in a NULL byte. You must check for this."
  83. @echo " test12: input file header has too small height, which means you will not find the"
  84. @echo " end-of-file in the specified place"
  85. @echo " test13: input file is missing data from the end of file, so you will not be able to"
  86. @echo " read all the specified pixels"
  87. @echo
  88. $(TARGET): $(OBJS) | environment
  89. $(GCC) $(CFLAGS) $(OBJS) -o $@
  90. $(TARGET_O3): $(SOURCES) | environment
  91. @echo "Building optimized version of $(TARGET): $(TARGET_O3)"
  92. $(GCC) -O3 $(SOURCES) -o $@
  93. $(OBJF)/%.o: %.c | environment
  94. @$(GCC) -MM $(CFLAGS) $< | sed 's,^\([^ ]\),$(OBJF)\/\1,g' | sed '$$ s,$$, \\,' > $(OBJF)/$<.P
  95. $(GCC) $(CFLAGS) -c -o $@ $<