Makefile 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. GCC = gcc
  2. CFLAGS = -g -Wall -Wshadow
  3. LIBS =
  4. SOURCES = answer01.c pa01.c
  5. TARGET = pa01
  6. TESTCASES := $(shell seq 0 19)
  7. # -------------------------------------------------------------
  8. TESTS := $(addprefix test,${TESTCASES})
  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: | $(TARGET) $(TESTS)
  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 " You do NOT need to use make to run your program. (See below.)"
  27. @echo
  28. @echo " make Build $(TARGET)"
  29. @echo " make testall Run /all/ testcases"
  30. @echo " make clean Remove all temporary files"
  31. @echo " make help Print this message"
  32. @echo
  33. @echo " After building $(TARGET), you can run it manually as follows:"
  34. @echo
  35. @echo " aturing > ./$(TARGET) -h"
  36. @echo
  37. @echo " It is highly recommended that you do this as you debug and"
  38. @echo " test your code."
  39. @echo
  40. @echo " There are 20 testcases. (i.e., 0 through 19.) You can run an "
  41. @echo " individual testcase as follows:"
  42. @echo
  43. @echo " make test0 Run the zeroeth testcase"
  44. @echo " make test1 Run the first testcase"
  45. @echo " ... etc."
  46. @echo
  47. $(TARGET): $(OBJS) | environment
  48. $(GCC) $(CFLAGS) $(OBJS) $(LIBS) -o $@
  49. $(OBJF)/%.o: %.c | environment
  50. @$(GCC) -MM $(CFLAGS) $< | sed 's,^\([^ ]\),$(OBJF)\/\1,g' | sed '$$ s,$$, \\,' > $(OBJF)/$<.P
  51. $(GCC) $(CFLAGS) -c -o $@ $<
  52. ${TESTS}: test%: $(TARGET) | environment
  53. @./bin/test.sh "$(TARGET)" inputs/input$* outputs/output$* expected/expected$* outputs/valgrind-log$*