Advertisement
Guest User

Untitled

a guest
Apr 29th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 2.25 KB | None | 0 0
  1. OBJECTS = counts.o tests.o
  2.  
  3. # OS identification from: https://stackoverflow.com/questions/714100/os-detecting-makefile
  4. OS := $(shell uname -s)
  5.  
  6. ifeq ($(OS), Darwin)
  7.   CUNIT_PATH_PREFIX = /usr/local/Cellar/cunit/2.1-3/
  8.   CUNIT_DIRECTORY = cunit
  9. endif
  10. ifeq ($(OS), Linux)
  11.   CUNIT_PATH_PREFIX = /usr/
  12.   CUNIT_DIRECTORY = CUnit/
  13. endif
  14.  
  15. CC = gcc
  16. NO_DEBUG_FLAGS = -c -Wall -std=c11
  17. DEBUG_FLAGS = -g -c -Wall -std=c11
  18. FLAGS = $(DEBUG_FLAGS)
  19.  
  20. SRC = helper.c
  21. TST = test.c
  22. GEX = test-gprof
  23. VEX = test-valgrind
  24. TEX = tests
  25. FLAGS = -pg -fprofile-arcs -ftest-coverage
  26. CFLAGS = -L $(CUNIT_PATH_PREFIX)lib -I $(CUNIT_PATH_PREFIX)include/$(CUNIT_DIRECTORY)
  27. CLIB = -lcunit
  28.  
  29. .PHONY: clean
  30. clean:
  31.     rm -rf *~ *.o $(GEX) $(TEX) $(VEX) *.dSYM *.gc?? analyze.txt gmon.out
  32.  
  33. helper.o: helper.c
  34.     gcc -c -g -O0 -Wall -std=c11 $(SRC)
  35.  
  36. test.o: test.c
  37.     gcc -c -g -O0 -Wall -std=c11 -I $(CUNIT_PATH_PREFIX)include/$(CUNIT_DIRECTORY) $(TST)
  38.  
  39. c-exec: helper.o
  40.     gcc -g -O0 -Wall $(FLAGS) $(CFLAGS) -o $(GEX) $(SRC) main.c
  41.  
  42. c-test: test.o helper.o
  43.     gcc -g -O0 -Wall $(FLAGS) $(CFLAGS) -o $(TEX) $(SRC) $(TST) $(CLIB)
  44.  
  45. v-exec: test.o
  46.     gcc -g -O0 -Wall $(CFLAGS) -o $(VEX) $(SRC) main.c
  47.  
  48. .PHONY: andRunPerformance
  49. andRunPerformance:
  50.     make clean
  51.     make c-exec
  52.     ./$(GEX)
  53.     gprof -b ./$(GEX) gmon.out > analyze.txt
  54.     gcov $(SRC)
  55.     @echo "Look at analyze.txt for gprof timing data"
  56.     @echo "Look at $(SRC).gcov for gcov annotated source code with execution counts"
  57.  
  58. .PHONY: andRunTests
  59. andRunTests:
  60.     make clean
  61.     make c-test
  62.     ./$(TEX)
  63.     gcov $(SRC)
  64.     @echo "Look at $(SRC).gcov for gcov annotated source code with execution counts"
  65.  
  66. .PHONY: andRunCallGrind
  67. andRunCallGrind:
  68.     make clean
  69.     make v-exec
  70.     @echo "******************************************************************************"
  71.     @echo "** Running program on large file using callgrind. This may take a minute... **"
  72.     @echo "******************************************************************************"
  73.     valgrind --tool=callgrind ./$(VEX) 1000 1000
  74.     @echo "******************************************************************************"
  75.     @echo "** Done! Use callgrind_annotate to interpret the data file                  **"
  76.     @echo "******************************************************************************"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement