1
0

Makefile 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. GCC = gcc
  2. CFLAGS = -g -Wall -Wshadow
  3. LIBS =
  4. SOURCES = answer05.c pa05.c
  5. TARGET = pa05
  6. TESTN := $(shell seq 1 17)
  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 *.o
  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 clean Remove all temporary files"
  28. @echo " make help Print this message"
  29. @echo " make test1 Run the zeroeth testcase"
  30. @echo " make test2 Run the first testcase"
  31. @echo " ... etc."
  32. @echo " make test17 Run the 17th testcase"
  33. @echo " make testall Run all testcases"
  34. @echo
  35. @echo " Testcases 1-13 test integer inputs."
  36. @echo " Testcases 14-17 test string inputs."
  37. @echo
  38. @echo " Please try and run your code yourself before testing with the makefile"
  39. @echo " PA06 will have no makefile, so you will cross that bridge soon =0."
  40. @echo
  41. $(TARGET): $(OBJS) | environment
  42. $(GCC) $(CFLAGS) $(OBJS) $(LIBS) -o $@
  43. $(OBJF)/%.o: %.c | environment
  44. @$(GCC) -MM $(CFLAGS) $< | sed 's,^\([^ ]\),$(OBJF)\/\1,g' | sed '$$ s,$$, \\,' > $(OBJF)/$<.P
  45. $(GCC) $(CFLAGS) -c -o $@ $<
  46. ${TESTS}: test%: $(TARGET) | environment
  47. @./bin/test.sh "$(TARGET)" $*