Advertisement
Guest User

makefile

a guest
Sep 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 2.17 KB | None | 0 0
  1. #make - to compile for normal run
  2. #make test - to compile for unit testing
  3. #make clean -  to clean up
  4.  
  5. #put here the names of your files
  6. PROGRAM_NAME = string
  7. UNIT_TEST_NAME = $(PROGRAM_NAME)_test_case
  8. HEADER_FILE_NAME = string
  9.  
  10.  
  11.  
  12. #Targetfolder
  13. BIN_DIR = bin
  14. MK_DIR = mkdir
  15.  
  16.  
  17. # variable to find the test environment
  18. GTEST_DIR =${HOME}/Studium/WS18_fin/prg_c/ESP/googletest/googletest
  19.  
  20. #Compiler
  21. CC = gcc
  22. CPP = g++
  23.  
  24.  
  25. #Flags for the compiler to create .o files
  26. CCFLAGS = -Wall -c
  27. CPPFLAGS =
  28.  
  29.  
  30. # Flags for libs
  31. LIBFLAGS=
  32.  
  33.  
  34. #target is the result of the makefile.
  35. # make alone will try to create the first target in the file
  36. # Targets:
  37.  
  38. #make /make Programname
  39. $(PROGRAM_NAME): $(PROGRAM_NAME).o main.o
  40.         $(CC) $(PROGRAM_NAME).o -o $(BIN_DIR)/$(PROGRAM_NAME) $(LIBFLAGS)
  41.  
  42. #make test
  43. test: Gtest_main.o libgtest.a $(UNIT_TEST_NAME).o $(PROGRAM_NAME)_test.o $(BIN_DIR)
  44.         $(CPP) $(LIBFLAGS) -I $(GTEST_DIR)/include -pthread $(UNIT_TEST_NAME).o Gtest_main.o libgtest.a $(PROGRAM_NAME).o -o $(BIN_DIR)/$(PROGRAM_NAME)_test
  45.  
  46.  
  47. ##Normal##
  48. #still needs to be finished to compile a the file as an normal application
  49.  
  50. $(PROGRAM_NAME).o: $(PROGRAM_NAME).c
  51.         $(CC) $(CCFLAGS) $(PROGRAM_NAME).c
  52.  
  53.  
  54. main.o: main.c
  55.         $(CC) $(CCFLAGS) main.c
  56.  
  57.  
  58.  
  59. #### Unit Test ####
  60.  
  61. Gtest_main.o: Gtest_main.c
  62.         g++ -c -isystem $(GTEST_DIR)/include -I$(GTEST_DIR) Gtest_main.c
  63.  
  64. ## Google Test Framework ##
  65. libgtest.a:
  66.         g++ -isystem $(GTEST_DIR)/include -I$(GTEST_DIR) -pthread -c $(GTEST_DIR)/src/gtest-all.cc
  67.         ar -rv libgtest.a gtest-all.o
  68.  
  69. ## own Unit test code
  70. $(UNIT_TEST_NAME).o: $(UNIT_TEST_NAME).c $(HEADER_FILE_NAME).h
  71.         $(CPP) -c -isystem $(GTEST_DIR)/include -I$(GTEST_DIR) $(UNIT_TEST_NAME).c
  72.  
  73.  
  74. $(PROGRAM_NAME)_test.o: $(PROGRAM_NAME).c
  75.         $(CPP) $(CCFLAGS) $(PROGRAM_NAME).c
  76.  
  77.  
  78.  
  79. $(BIN_DIR):
  80.         $(MK_DIR) $(BIN_DIR)
  81.  
  82. #### Clean ####
  83. .PHONY: clean
  84. clean:
  85.         rm -f *.o
  86.         rm -rf $(BIN_DIR)
  87.  
  88.  
  89.                                                                                                                                                                                     88,0-1       Ende
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement