Micro template library A library for building device drivers
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

188 lignes
5.2 KiB

  1. #
  2. # Makefile for utl Unit test
  3. #
  4. # Copyright (C) 2019-2020 Christos Choutouridis <christos@choutouridis.net>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Lesser General Public License as
  8. # published by the Free Software Foundation, either version 3
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Lesser General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Lesser General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # ========== Project settings ==========
  20. # Excecutable's name
  21. TARGET := utlTest
  22. # List(space seperated) of source directories
  23. # ex:
  24. # SRC_DIR_LIST := src1 /var/src2 ../src3
  25. SRC_DIR_LIST := tests gtest
  26. # List(space seperated) of include directories
  27. # ex:
  28. # INC_DIR_LIST := inc /var/inc ../include2
  29. INC_DIR_LIST := ../include gtest
  30. # List(space seperated) of exclude files (filenames only)
  31. # ex:
  32. # EXC_FILE_LIST := bad.cpp old.cpp
  33. EXC_FILE_LIST :=
  34. # build directories
  35. BUILD_DIR := bin
  36. OBJ_DIR := $(BUILD_DIR)/obj
  37. DEP_DIR := $(BUILD_DIR)/.dep
  38. # ========== Compiler settings ==========
  39. CLANGXX := clang++
  40. CLANGPP := clang++ -E
  41. GCCXX := g++
  42. GCCPP := g++ -E
  43. CXX := $(GCCXX)
  44. CPP := $(GCCPP)
  45. CSIZE := size
  46. CFLAGS := -Wall -Wextra
  47. DEB_FLAGS := -DDEBUG -g3
  48. REL_FLAGS := -O2
  49. # example: LDFLAGS := -pthread -lm
  50. LDFLAGS := -pthread
  51. # example: MYCAB=1729 SUPER_MODE
  52. PRE_DEFS :=
  53. MAP_FILE := $(BUILD_DIR)/output.map
  54. MAP_FLAG := -Xlinker -Map=$(MAP_FILE)
  55. #
  56. # =========== Main body and Patterns ===========
  57. #
  58. INC := $(foreach dir,$(INC_DIR_LIST),-I$(dir))
  59. DEF := $(foreach def,$(PRE_DEFS),-D$(def))
  60. EXC := $(foreach fil,$(EXC_FILE_LIST), \
  61. $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/$(fil))) \
  62. )
  63. # source files. object and dependencies list
  64. # recursive search into current and source directories
  65. SRC := $(wildcard *.cpp)
  66. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/*.cpp))
  67. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/**/*.cpp))
  68. SRC := $(abspath $(filter-out $(EXC),$(SRC)))
  69. OBJ := $(foreach file,$(SRC:%.cpp=%.o),$(OBJ_DIR)$(file))
  70. DEP := $(foreach file,$(SRC:%.cpp=%.d),$(DEP_DIR)$(file))
  71. # Make Dependencies pattern.
  72. # This little trick enables recompilation only when dependencies change
  73. # and it does so for changes both in source AND header files ;)
  74. #
  75. # It is based on Tom Tromey's method.
  76. #
  77. # Invoke cpp to create makefile rules with dependencies for each source file
  78. $(DEP_DIR)%.d: %.cpp
  79. @mkdir -p $(@D)
  80. @$(CPP) $(CFLAGS) $(INC) $(DEF) -MM -MT $(OBJ_DIR)$(<:.cpp=.o) -MF $@ $<
  81. # objects depent on .cpp AND dependency files, which have an empty recipe
  82. $(OBJ_DIR)%.o: %.cpp $(DEP_DIR)%.d
  83. @mkdir -p $(@D)
  84. $(CXX) -c $(CFLAGS) $(INC) $(DEF) -o $@ $<
  85. # empty recipe for dependency files. This prevents make errors
  86. $(DEP):
  87. # now include all dependencies
  88. # After all they are makefile dependency rules ;)
  89. include $(wildcard $(DEP))
  90. # main target rule
  91. $(BUILD_DIR)/$(TARGET): $(OBJ)
  92. @mkdir -p $(@D)
  93. @echo Linking to target: $(TARGET)
  94. @echo $(CXX) $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET) '$$(OBJ)'
  95. @$(CXX) $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET) $(OBJ)
  96. @echo
  97. @echo Print size information
  98. @$(CSIZE) $(@D)/$(TARGET)
  99. @echo Done
  100. .PHONY: clean
  101. clean:
  102. @echo Cleaning build directories
  103. @rm -rf $(OBJ_DIR)
  104. @rm -rf $(DEP_DIR)
  105. @rm -rf $(BUILD_DIR)
  106. #
  107. # ============ User Rules =============
  108. #
  109. .PHONY: gcc14
  110. gcc14: CFLAGS += $(DEB_FLAGS)
  111. gcc14: CFLAGS += -std=c++14
  112. gcc14: $(BUILD_DIR)/$(TARGET)
  113. .PHONY: gcc14_conc
  114. gcc14_conc: CFLAGS += $(DEB_FLAGS)
  115. gcc14_conc: CFLAGS += -std=c++14 -fconcepts
  116. gcc14_conc: $(BUILD_DIR)/$(TARGET)
  117. .PHONY: gcc17
  118. gcc17: CFLAGS += $(DEB_FLAGS)
  119. gcc17: CFLAGS += -std=c++17
  120. gcc17: $(BUILD_DIR)/$(TARGET)
  121. .PHONY: gcc17_conc
  122. gcc17_conc: CFLAGS += $(DEB_FLAGS)
  123. gcc17_conc: CFLAGS += -std=c++17 -fconcepts
  124. gcc17_conc: $(BUILD_DIR)/$(TARGET)
  125. .PHONY: gcc2a
  126. gcc2a: CFLAGS += $(DEB_FLAGS)
  127. gcc2a: CFLAGS += -std=c++2a
  128. gcc2a: $(BUILD_DIR)/$(TARGET)
  129. .PHONY: clang14
  130. clang14: CXX := $(CLANGXX)
  131. clang14: CPP := $(CLANGPP)
  132. clang14: CFLAGS += $(DEB_FLAGS)
  133. clang14: CFLAGS += -std=c++14
  134. clang14: $(BUILD_DIR)/$(TARGET)
  135. .PHONY: clang17
  136. clang14: CXX := $(CLANGXX)
  137. clang14: CPP := $(CLANGPP)
  138. clang14: CFLAGS += $(DEB_FLAGS)
  139. clang14: CFLAGS += -std=c++17
  140. clang14: $(BUILD_DIR)/$(TARGET)
  141. .PHONY: clang2a
  142. clang14: CXX := $(CLANGXX)
  143. clang14: CPP := $(CLANGPP)
  144. clang14: CFLAGS += $(DEB_FLAGS)
  145. clang14: CFLAGS += -std=c++2a
  146. clang14: $(BUILD_DIR)/$(TARGET)
  147. .PHONY: debug
  148. debug: CFLAGS += $(DEB_FLAGS)
  149. debug: $(BUILD_DIR)/$(TARGET)
  150. .PHONY: release
  151. release: CFLAGS += $(REL_FLAGS)
  152. release: clean $(BUILD_DIR)/$(TARGET)
  153. .PHONY: all
  154. all: clean release