1
0

Makefile 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. GCC = gcc
  2. CFLAGS = -g -Wall -Wshadow
  3. LIBS =
  4. SOURCES = answer03.c pa03.c
  5. TARGET = pa03
  6. TESTN := $(shell seq 0 12)
  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: | $(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 " There are 13 testcases. (i.e., 0 through 109.) You can run an "
  34. @echo " individual testcase as follows:"
  35. @echo
  36. @echo " make test0 Run the zeroeth testcase"
  37. @echo " make test1 Run the first testcase"
  38. @echo " ... etc."
  39. @echo
  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. @./bin/test.sh "$(TARGET)" inputs/input$* outputs/output$* expected/expected$* outputs/valgrind-log$*