A triangle counting assignment for A.U.TH Parallel and distributed systems class.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

168 行
5.0 KiB

  1. #
  2. # PDS excercise 1 Makefile
  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. # Project's name
  21. PROJECT := exercise_1
  22. # Excecutable's name
  23. TARGET := triangCounting
  24. # Source directories list(space seperated). Makefile-relative path, UNDER current directory.
  25. SRC_DIR_LIST := src
  26. # Include directories list(space seperated). Makefile-relative path.
  27. INC_DIR_LIST := src inc
  28. # Exclude files list(space seperated). Filenames only.
  29. # EXC_FILE_LIST := bad.cpp old.cpp
  30. # Build directories
  31. BUILD_DIR := bin
  32. OBJ_DIR := $(BUILD_DIR)/obj
  33. DEP_DIR := $(BUILD_DIR)/.dep
  34. # ========== Compiler settings ==========
  35. # Compiler flags for debug and release
  36. DEB_CFLAGS := -DDEBUG -g3 -Wall -Wextra -std=c++14
  37. REL_CFLAGS := -Wall -Wextra -O2 -std=c++14
  38. # Pre-defines
  39. # PRE_DEFS := MYCAB=1729 SUPER_MODE
  40. # ============== Linker settings ==============
  41. # Linker flags (example: -pthread -lm)
  42. LDFLAGS := -pthread
  43. # Map output file
  44. MAP_FILE := output.map
  45. MAP_FLAG := -Xlinker -Map=$(BUILD_DIR)/$(MAP_FILE)
  46. # ============== Docker settings ==============
  47. # We need:
  48. # - Bind the entire project directory(the dir that icludes all the code) as volume.
  49. # - In docker instance, change to working directory(where the makefile is).
  50. DOCKER_VOL_DIR := $${PWD}
  51. DOCKER_WRK_DIR :=
  52. DOCKER_RUN := docker run --rm
  53. DOCKER_FLAGS := -v $(DOCKER_VOL_DIR):/usr/src/$(PROJECT) -w /usr/src/$(PROJECT)/$(DOCKER_WRK_DIR)
  54. # docker invoke mechanism (edit with care)
  55. # note:
  56. # Here, `DOCKER` variable is empty. Rules can assign `DOCKER := DOCKER_CMD` when docker
  57. # functionality is needed.
  58. DOCKER_CMD = $(DOCKER_RUN) $(DOCKER_FLAGS) $(IMAGE)
  59. DOCKER :=
  60. # ============== Tool selection ==============
  61. # compiler and compiler flags.
  62. CSIZE := size
  63. CFLAGS := $(DEB_CFLAGS)
  64. CXX := g++
  65. #
  66. # =========== Main body and Patterns ===========
  67. #
  68. #ifeq ($(OS), Windows_NT)
  69. # TARGET := $(TARGET).exe
  70. #endif
  71. INC := $(foreach dir,$(INC_DIR_LIST),-I$(dir))
  72. DEF := $(foreach def,$(PRE_DEFS),-D$(def))
  73. EXC := $(foreach fil,$(EXC_FILE_LIST), \
  74. $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/$(fil))) \
  75. )
  76. # source files. object and dependencies list
  77. # recursive search into current and source directories
  78. SRC := $(wildcard *.cpp)
  79. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/*.cpp))
  80. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/**/*.cpp))
  81. SRC := $(filter-out $(EXC),$(SRC))
  82. #SRC := $(abspath $(SRC))
  83. OBJ := $(foreach file,$(SRC:%.cpp=%.o),$(OBJ_DIR)/$(file))
  84. DEP := $(foreach file,$(SRC:%.cpp=%.d),$(DEP_DIR)/$(file))
  85. # Make Dependencies pattern.
  86. # This little trick enables recompilation only when dependencies change
  87. # and it does so for changes both in source AND header files ;)
  88. #
  89. # It is based on Tom Tromey's method.
  90. #
  91. # Invoke cpp to create makefile rules with dependencies for each source file
  92. $(DEP_DIR)/%.d: %.cpp
  93. @mkdir -p $(@D)
  94. @$(DOCKER) $(CXX) -E $(CFLAGS) $(INC) $(DEF) -MM -MT $(OBJ_DIR)/$(<:.cpp=.o) -MF $@ $<
  95. # objects depent on .cpp AND dependency files, which have an empty recipe
  96. $(OBJ_DIR)/%.o: %.cpp $(DEP_DIR)/%.d
  97. @mkdir -p $(@D)
  98. $(DOCKER) $(CXX) -c $(CFLAGS) $(INC) $(DEF) -o $@ $<
  99. # empty recipe for dependency files. This prevents make errors
  100. $(DEP):
  101. # now include all dependencies
  102. # After all they are makefile dependency rules ;)
  103. include $(wildcard $(DEP))
  104. # main target rule
  105. $(BUILD_DIR)/$(TARGET): $(OBJ)
  106. @mkdir -p $(@D)
  107. @echo Linking to target: $(TARGET)
  108. @echo $(DOCKER) $(CXX) $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET) '$$(OBJ)'
  109. @$(DOCKER) $(CXX) $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET) $(OBJ)
  110. @echo
  111. @echo Print size information
  112. @$(CSIZE) $(@D)/$(TARGET)
  113. @echo Done
  114. .PHONY: clean
  115. clean:
  116. @echo Cleaning build directories
  117. @rm -rf $(OBJ_DIR)
  118. @rm -rf $(DEP_DIR)
  119. @rm -rf $(BUILD_DIR)
  120. #
  121. # ================ Local build rules =================
  122. # examples:
  123. # make debug
  124. .PHONY: debug
  125. debug: CFLAGS := $(DEB_CFLAGS)
  126. debug: $(BUILD_DIR)/$(TARGET)
  127. .PHONY: release
  128. release: CFLAGS := $(REL_CFLAGS)
  129. release: $(BUILD_DIR)/$(TARGET)
  130. .PHONY: all
  131. all: release
  132. #
  133. # ================ Docker based rules ================
  134. # examples:
  135. # make IMAGE="gcc:8.3" dock
  136. #
  137. .PHONY: dock
  138. dock: DOCKER := $(DOCKER_CMD)
  139. dock: CFLAGS := $(REL_CFLAGS)
  140. dock: $(BUILD_DIR)/$(TARGET)