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.

Makefile 3.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #
  2. # Makefile
  3. #
  4. # Main makefile for utl Unit test
  5. #
  6. # Copyright (C) 2019 Christos Choutouridis <christos@choutouridis.net>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser General Public License as
  10. # published by the Free Software Foundation, either version 3
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. # ========== Project settings ==========
  22. TARGET := utlTest
  23. SRC_DIR := tests gtest
  24. INC_DIR := ../include gtest
  25. EXC_FILE :=
  26. # build directories
  27. BUILD_DIR := bin
  28. OBJ_DIR := $(BUILD_DIR)/obj
  29. DEP_DIR := $(BUILD_DIR)/.dep
  30. # ========== Compiler settings ==========
  31. CXX := g++
  32. CPP := g++ -E
  33. CSIZE := size
  34. CFLAGS := -std=c++14 -Wall #-Wextra
  35. DEB_FLAGS := -DDEBUG -g3
  36. REL_FLAGS := -O3
  37. LDFLAGS :=
  38. PRE_DEFS :=
  39. MAP_FILE := $(BUILD_DIR)/output.map
  40. MAP_FLAG := -Xlinker -Map=$(MAP_FILE)
  41. #
  42. # =========== Main body and Patterns ===========
  43. #
  44. INC := $(foreach dir,$(INC_DIR),-I$(dir))
  45. DEF := $(foreach def,$(PRE_DEFS),-D$(def))
  46. # source files
  47. # recursive search into current and source directories
  48. SRC := $(wildcard *.cpp)
  49. SRC += $(foreach dir,$(SRC_DIR),$(wildcard $(dir)/*.cpp))
  50. SRC += $(foreach dir,$(SRC_DIR),$(wildcard $(dir)/**/*.cpp))
  51. # exclude every file from the exclude file list
  52. SRC := $(filter-out $(wildcard $(EXC_FILE)),$(SRC))
  53. OBJ := $(foreach file,$(SRC:%.cpp=%.o),$(OBJ_DIR)/$(file))
  54. DEP := $(foreach file,$(SRC:%.cpp=%.d),$(DEP_DIR)/$(file))
  55. # Make Dependencies pattern.
  56. # This little trick enables recompilation only when dependencies change
  57. # and it does so for changes both in source AND header files ;)
  58. #
  59. # It is based on Tom Tromey's method.
  60. #
  61. # Invoke cpp to create makefile rules with dependencies for each source file
  62. $(DEP_DIR)/%.d: %.cpp
  63. @mkdir -p $(@D)
  64. @$(CPP) $(CFLAGS) $(INC) $(DEF) -MM -MT $(OBJ_DIR)/$(<:.cpp=.o) -MF $@ $<
  65. # objects depent on .cpp AND dependency files, which have an empty recipe
  66. $(OBJ_DIR)/%.o: %.cpp $(DEP_DIR)/%.d
  67. @mkdir -p $(@D)
  68. $(CXX) -c $(CFLAGS) $(INC) $(DEF) -o $@ $<
  69. # empty recipe for dependency files. This prevents make errors
  70. $(DEP):
  71. # now include all dependencies
  72. # After all they are makefile dependency rules ;)
  73. include $(wildcard $(DEP))
  74. # main target rule
  75. $(BUILD_DIR)/%/$(TARGET): $(OBJ)
  76. @mkdir -p $(@D)
  77. @echo Linking to target: $(TARGET)
  78. @echo $(CXX) $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET) '$$(OBJ)'
  79. @$(CXX) $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET) $(OBJ)
  80. @echo Done
  81. # @echo
  82. # @echo Print size information
  83. # @$(CSIZE) $(@D)/$(TARGET)
  84. .PHONY: clean
  85. clean:
  86. @echo Cleaning build directories
  87. @rm -rf $(OBJ_DIR)
  88. @rm -rf $(DEP_DIR)
  89. @rm -rf $(BUILD_DIR)
  90. #
  91. # ============ User Rules =============
  92. #
  93. .PHONY: debug
  94. debug: CFLAGS += $(DEB_FLAGS)
  95. debug: $(BUILD_DIR)/debug/$(TARGET)
  96. .PHONY: release
  97. release: CFLAGS += $(REL_FLAGS)
  98. release: clean $(BUILD_DIR)/release/$(TARGET)
  99. .PHONY: all
  100. all: clean release