Makefile 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. GCC = gcc
  2. CFLAGS = -g -Wall -Wshadow
  3. LIBS =
  4. SOURCES = answer02.c pa02.c
  5. TARGET = pa02
  6. TESTT := my_strlen my_countchar my_strupper my_strlower my_strcpy my_strncpy my_strcat my_strncat my_strstr my_strinsert my_strdelete
  7. TESTN := $(shell seq 0 $(shell expr 10 \* $(shell echo "$(TESTT)" | wc -w) - 1))
  8. # -------------------------------------------------------------
  9. TESTS := $(addprefix test,${TESTN})
  10. .PHONY : all build clean environment help testall $(TESTS)
  11. .DEFAULT_GOAL := build
  12. OBJF = obj
  13. OBJS = $(patsubst %.c,$(OBJF)/%.o,$(SOURCES))
  14. -include $(SOURCES:%=$(OBJF)/%.P)
  15. all: | build testall
  16. testall: | $(TESTS)
  17. build: $(TARGET)
  18. clean:
  19. @cd $(CURDIR)
  20. rm -rf $(TARGET) $(OBJF) outputs
  21. environment:
  22. @cd $(CURDIR)
  23. @mkdir -p outputs
  24. @mkdir -p $(OBJF)
  25. help:
  26. @echo
  27. @echo " You do NOT need to use make to run your program. (See below.)"
  28. @echo
  29. @echo " make Build $(TARGET)"
  30. @echo " make testall Run /all/ testcases"
  31. @echo " make clean Remove all temporary files"
  32. @echo " make help Print this message"
  33. @echo
  34. @echo " After building $(TARGET), you can run it manually as follows:"
  35. @echo
  36. @echo " aturing > ./$(TARGET) -h"
  37. @echo
  38. @echo " It is highly recommended that you do this as you debug and"
  39. @echo " test your code."
  40. @echo
  41. @echo " There are 110 testcases. (i.e., 0 through 109.) You can run an "
  42. @echo " individual testcase as follows:"
  43. @echo
  44. @echo " make test0 Run the zeroeth testcase"
  45. @echo " make test1 Run the first testcase"
  46. @echo " ... etc."
  47. @echo
  48. $(TARGET): $(OBJS) | environment
  49. $(GCC) $(CFLAGS) $(OBJS) $(LIBS) -o $@
  50. $(OBJF)/%.o: %.c | environment
  51. @$(GCC) -MM $(CFLAGS) $< | sed 's,^\([^ ]\),$(OBJF)\/\1,g' | sed '$$ s,$$, \\,' > $(OBJF)/$<.P
  52. $(GCC) $(CFLAGS) -c -o $@ $<
  53. ${TESTS}: test%: $(TARGET) | environment
  54. @./bin/test.sh "$(TARGET)" $(shell echo "$(TESTT)" | awk "{ print \$$$(shell expr 1 + $* / 10); }") inputs/input$(shell expr $* % 10) outputs/output$* expected/expected$(shell expr $* % 10)_$(shell echo "$(TESTT)" | awk "{ print \$$$(shell expr 1 + $* / 10); }") outputs/valgrind-log$*