Makefile 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. GCC = gcc
  2. CFLAGS = -g -Wall -Wshadow
  3. LIBS =
  4. SOURCES = answer06.c pa06.c
  5. TARGET = pa06
  6. TESTN := $(shell seq 0 4)
  7. # -------------------------------------------------------------
  8. TESTS := $(addprefix test,${TESTN})
  9. .PHONY : all build clean environment help testall $(TESTS)
  10. .DEFAULT_GOAL := build
  11. OBJF = obj
  12. OBJS = $(patsubst %.c,$(OBJF)/%.o,$(SOURCES))
  13. -include $(SOURCES:%=$(OBJF)/%.P)
  14. all: | build testall
  15. testall: | test0 test1 test2 test3 test4
  16. build: $(TARGET)
  17. clean:
  18. @cd $(CURDIR)
  19. rm -rf $(TARGET) $(OBJF) outputs
  20. environment:
  21. @cd $(CURDIR)
  22. @mkdir -p outputs
  23. @mkdir -p $(OBJF)
  24. help:
  25. @echo
  26. @echo " make Build $(TARGET)"
  27. @echo " make testall Run /all/ testcases"
  28. @echo " make clean Remove all temporary files"
  29. @echo " make help Print this message"
  30. $(TARGET): $(OBJS) | environment
  31. $(GCC) $(CFLAGS) $(OBJS) $(LIBS) -o $@
  32. $(OBJF)/%.o: %.c | environment
  33. @$(GCC) -MM $(CFLAGS) $< | sed 's,^\([^ ]\),$(OBJF)\/\1,g' | sed '$$ s,$$, \\,' > $(OBJF)/$<.P
  34. $(GCC) $(CFLAGS) -c -o $@ $<
  35. test0: $(TARGET) | environment
  36. @./bin/test.sh "$(TARGET)" images/01-unnormalized-smile.ee264 outputs/01-smile.ppm expected/01-smile.ppm outputs/valgrind-log0
  37. test1: $(TARGET) | environment
  38. @./bin/test.sh "$(TARGET)" images/02-unnormalized-cat-chess.ee264 outputs/02-cat-chess.ppm expected/02-cat-chess.ppm outputs/valgrind-log1
  39. test2: $(TARGET) | environment
  40. @./bin/test.sh "$(TARGET)" images/03-unnormalized-hawkes-bay-NZ.ee264 outputs/03-hawkes-bay-NZ.ppm expected/03-hawkes-bay-NZ.ppm outputs/valgrind-log2
  41. test3: $(TARGET) | environment
  42. @./bin/test.sh "$(TARGET)" images/04-unnormalized-nelsonmandela.ee264 outputs/04-nelsonmandela.ppm expected/04-nelsonmandela.ppm outputs/valgrind-log3
  43. test4: $(TARGET) | environment
  44. @./bin/test.sh "$(TARGET)" images/05-unnormalized-sagan-stamp.ee264 outputs/05-sagan-stamp.ppm expected/05-sagan-stamp.ppm outputs/valgrind-log4