Micro template library A library for building device drivers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

166 lines
4.8 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. # Source directories list(space seperated). Full or relative path
  23. SRC_DIR_LIST := tests gtest
  24. # Include directories list(space seperated). Full or relative path
  25. INC_DIR_LIST := ../include gtest
  26. # Exclude files list(space seperated). Filenames only.
  27. # EXC_FILE_LIST := bad.cpp old.cpp
  28. # Build directories
  29. BUILD_DIR := bin
  30. OBJ_DIR := $(BUILD_DIR)/obj
  31. DEP_DIR := $(BUILD_DIR)/.dep
  32. # ========== Compiler settings ==========
  33. CLANGXX := clang++
  34. GCCXX := g++
  35. CSIZE := size
  36. # Compiler flags for debug and release
  37. DEB_CFLAGS := -DDEBUG -g3 -Wall -Wextra
  38. REL_CFLAGS := -Wall -Wextra -O2
  39. # Pre-defines
  40. # PRE_DEFS := MYCAB=1729 SUPER_MODE
  41. # ========== Linker settings ==========
  42. # Linker flags
  43. LDFLAGS := -pthread
  44. # Map output file
  45. MAP_FILE := output.map
  46. MAP_FLAG := -Xlinker -Map=$(BUILD_DIR)/$(MAP_FILE)
  47. # ========== Default settings ==========
  48. # compiler and compiler flagfs
  49. CFLAGS := $(DEB_CFLAGS)
  50. CXX := $(GCCXX)
  51. #
  52. # =========== Main body and Patterns ===========
  53. #
  54. INC := $(foreach dir,$(INC_DIR_LIST),-I$(dir))
  55. DEF := $(foreach def,$(PRE_DEFS),-D$(def))
  56. EXC := $(foreach fil,$(EXC_FILE_LIST), \
  57. $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/$(fil))) \
  58. )
  59. # source files, object and dependencies list
  60. # recursive search into current and source directories
  61. SRC := $(wildcard *.cpp)
  62. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/*.cpp))
  63. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/**/*.cpp))
  64. SRC := $(abspath $(filter-out $(EXC),$(SRC)))
  65. OBJ := $(foreach file,$(SRC:%.cpp=%.o),$(OBJ_DIR)$(file))
  66. DEP := $(foreach file,$(SRC:%.cpp=%.d),$(DEP_DIR)$(file))
  67. # Make Dependencies pattern.
  68. # This little trick enables recompilation only when dependencies change
  69. # and it does so for changes both in source AND header files ;)
  70. #
  71. # It is based on Tom Tromey's method.
  72. #
  73. # Invoke cpp to create makefile rules with dependencies for each source file
  74. $(DEP_DIR)%.d: %.cpp
  75. @mkdir -p $(@D)
  76. @$(CXX) -E $(CFLAGS) $(INC) $(DEF) -MM -MT $(OBJ_DIR)$(<:.cpp=.o) -MF $@ $<
  77. # objects depent on .cpp AND dependency files, which have an empty recipe
  78. $(OBJ_DIR)%.o: %.cpp $(DEP_DIR)%.d
  79. @mkdir -p $(@D)
  80. $(CXX) -c $(CFLAGS) $(INC) $(DEF) -o $@ $<
  81. # empty recipe for dependency files. This prevents make errors
  82. $(DEP):
  83. # now include all dependencies
  84. # After all they are makefile dependency rules ;)
  85. include $(wildcard $(DEP))
  86. # main target rule
  87. $(BUILD_DIR)/$(TARGET): $(OBJ)
  88. @mkdir -p $(@D)
  89. @echo Linking to target: $(TARGET)
  90. @echo $(CXX) $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET) '$$(OBJ)'
  91. @$(CXX) $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET) $(OBJ)
  92. @echo
  93. @echo Print size information
  94. @$(CSIZE) $(@D)/$(TARGET)
  95. @echo Done
  96. .PHONY: clean
  97. clean:
  98. @echo Cleaning build directories
  99. @rm -rf $(OBJ_DIR)
  100. @rm -rf $(DEP_DIR)
  101. @rm -rf $(BUILD_DIR)
  102. #
  103. # ============ User Rules =============
  104. #
  105. .PHONY: gcc14
  106. gcc14: CFLAGS += -std=c++14
  107. gcc14: $(BUILD_DIR)/$(TARGET)
  108. .PHONY: gcc14_conc
  109. gcc14_conc: CFLAGS += -std=c++14 -fconcepts
  110. gcc14_conc: $(BUILD_DIR)/$(TARGET)
  111. .PHONY: gcc17
  112. gcc17: CFLAGS += -std=c++17
  113. gcc17: $(BUILD_DIR)/$(TARGET)
  114. .PHONY: gcc17_conc
  115. gcc17_conc: CFLAGS += -std=c++17 -fconcepts
  116. gcc17_conc: $(BUILD_DIR)/$(TARGET)
  117. .PHONY: gcc2a
  118. gcc2a: CFLAGS += -std=c++2a
  119. gcc2a: $(BUILD_DIR)/$(TARGET)
  120. .PHONY: clang14
  121. clang14: CXX := $(CLANGXX)
  122. clang14: CFLAGS += -std=c++14
  123. clang14: $(BUILD_DIR)/$(TARGET)
  124. .PHONY: clang17
  125. clang17: CXX := $(CLANGXX)
  126. clang17: CFLAGS += -std=c++17
  127. clang17: $(BUILD_DIR)/$(TARGET)
  128. .PHONY: clang2a
  129. clang2a: CXX := $(CLANGXX)
  130. clang2a: CFLAGS += -std=c++2a
  131. clang2a: $(BUILD_DIR)/$(TARGET)
  132. .PHONY: debug
  133. debug: $(BUILD_DIR)/$(TARGET)
  134. .PHONY: release
  135. release: CFLAGS := $(REL_FLAGS)
  136. release: clean $(BUILD_DIR)/$(TARGET)
  137. .PHONY: all
  138. all: clean release