Computer Organization and Design assignements
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.
 
 
 
 
 

121 lignes
3.1 KiB

  1. #
  2. # Makefile
  3. #
  4. # Copyright (C) 2020 Christos Choutouridis <cchoutou@ece.auth.gr>
  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. TARGET := matmul
  21. SRC_DIR := src
  22. INC_DIR :=
  23. EXC_FILE :=
  24. # build directories
  25. BUILD_DIR := bin
  26. OBJ_DIR := $(BUILD_DIR)/obj
  27. DEP_DIR := $(BUILD_DIR)/.dep
  28. # ========== Compiler settings ==========
  29. CXX := gcc
  30. CPP := gcc -E
  31. CSIZE := size
  32. CFLAGS := -std=gnu99 -Wall -Wextra
  33. DEB_FLAGS := -DDEBUG -g3
  34. REL_FLAGS := -O3
  35. LDFLAGS := -lm
  36. PRE_DEFS :=
  37. #
  38. # =========== Main body and Patterns ===========
  39. #
  40. INC := $(foreach dir,$(INC_DIR),-I$(dir))
  41. DEF := $(foreach def,$(PRE_DEFS),-D$(def))
  42. # source files
  43. # recursive search into current and source directories
  44. SRC := $(wildcard *.c)
  45. SRC += $(foreach dir,$(SRC_DIR),$(wildcard $(dir)/*.c))
  46. SRC += $(foreach dir,$(SRC_DIR),$(wildcard $(dir)/**/*.c))
  47. # exclude every file from the exclude file list
  48. SRC := $(filter-out $(wildcard $(EXC_FILE)),$(SRC))
  49. OBJ := $(foreach file,$(SRC:%.c=%.o),$(OBJ_DIR)/$(file))
  50. DEP := $(foreach file,$(SRC:%.c=%.d),$(DEP_DIR)/$(file))
  51. # Make Dependencies pattern.
  52. # This little trick enables recompilation only when dependencies change
  53. # and it does so for changes both in source AND header files ;)
  54. #
  55. # It is based on Tom Tromey's method.
  56. #
  57. # Invoke cpp to create makefile rules with dependencies for each source file
  58. $(DEP_DIR)/%.d: %.c
  59. @mkdir -p $(@D)
  60. @$(CPP) $(CFLAGS) $(INC) $(DEF) -MM -MT $(OBJ_DIR)/$(<:.c=.o) -MF $@ $<
  61. # objects depent on .c AND dependency files, which have an empty recipe
  62. $(OBJ_DIR)/%.o: %.c $(DEP_DIR)/%.d
  63. @mkdir -p $(@D)
  64. $(CXX) -c $(CFLAGS) $(INC) $(DEF) -o $@ $<
  65. # empty recipe for dependency files. This prevents make errors
  66. $(DEP):
  67. # now include all dependencies
  68. # After all they are makefile dependency rules ;)
  69. include $(wildcard $(DEP))
  70. # main target rule
  71. $(BUILD_DIR)/$(TARGET): $(OBJ)
  72. @mkdir -p $(@D)
  73. @echo Linking to target: $(TARGET)
  74. #@echo $(CXX) $(LDFLAGS) -o $(@D)/$(TARGET) '$$(OBJ)'
  75. $(CXX) -o $(@D)/$(TARGET) $(OBJ) $(LDFLAGS)
  76. @echo
  77. @echo Print size information
  78. @$(CSIZE) $(@D)/$(TARGET)
  79. @echo Done
  80. .PHONY: clean
  81. clean:
  82. @echo Cleaning build directories
  83. @rm -rf $(OBJ_DIR)
  84. @rm -rf $(DEP_DIR)
  85. @rm -rf $(BUILD_DIR)
  86. #
  87. # ============ User Rules =============
  88. #
  89. .PHONY: debug
  90. debug: CFLAGS += $(DEB_FLAGS)
  91. debug: $(BUILD_DIR)/$(TARGET)
  92. .PHONY: release
  93. release: CFLAGS += $(REL_FLAGS)
  94. release: $(BUILD_DIR)/$(TARGET)
  95. .PHONY: all
  96. all: clean release