AUTH's THMMY "Parallel and distributed systems" course assignments.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

217 行
6.5 KiB

  1. #
  2. # PDS homework_1 Makefile
  3. #
  4. # Copyright (C) 2024 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 := PDS_homework_2
  22. # Excecutable's name
  23. TARGET := distbitonic
  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 := inc \
  28. src \
  29. # Exclude files list(space seperated). Filenames only.
  30. # EXC_FILE_LIST := bad.cpp old.cpp
  31. # Build directories
  32. BUILD_DIR := bin
  33. OBJ_DIR := $(BUILD_DIR)/obj
  34. DEP_DIR := $(BUILD_DIR)/.dep
  35. # ========== Compiler settings ==========
  36. # Compiler flags for debug and release
  37. DEB_CFLAGS := -DDEBUG -g3 -Wall -Wextra -std=c11
  38. REL_CFLAGS := -Wall -Wextra -O3 -std=c11
  39. DEB_CXXFLAGS := -DDEBUG -g3 -Wall -Wextra -std=c++17
  40. REL_CXXFLAGS := -Wall -Wextra -O3 -std=c++17
  41. # Pre-defines
  42. # PRE_DEFS := MYCAB=1729 SUPER_MODE
  43. PRE_DEFS :=
  44. # ============== Linker settings ==============
  45. # Linker flags (example: -pthread -lm)
  46. LDFLAGS := -pthread
  47. # Map output file
  48. MAP_FILE := output.map
  49. MAP_FLAG := -Xlinker -Map=$(BUILD_DIR)/$(MAP_FILE)
  50. # ============== Docker settings ==============
  51. # We need:
  52. # - Bind the entire project directory(the dir that icludes all the code) as volume.
  53. # - In docker instance, change to working directory(where the makefile is).
  54. DOCKER_VOL_DIR := $(shell pwd)
  55. DOCKER_WRK_DIR :=
  56. DOCKER_RUN := docker run --rm
  57. DOCKER_FLAGS := -v $(DOCKER_VOL_DIR):/usr/src/$(PROJECT) -w /usr/src/$(PROJECT)/$(DOCKER_WRK_DIR)
  58. # docker invoke mechanism (edit with care)
  59. # note:
  60. # Here, `DOCKER` variable is empty. Rules can assign `DOCKER := DOCKER_CMD` when docker
  61. # functionality is needed.
  62. DOCKER_CMD = $(DOCKER_RUN) $(DOCKER_FLAGS) $(IMAGE)
  63. DOCKER :=
  64. # ============== Tool selection ==============
  65. # compiler and compiler flags.
  66. CSIZE := size
  67. CFLAGS := $(DEB_CFLAGS)
  68. CXXFLAGS := $(DEB_CXXFLAGS)
  69. CXX := g++
  70. CC := gcc
  71. #
  72. # =========== Main body and Patterns ===========
  73. #
  74. #ifeq ($(OS), Windows_NT)
  75. # TARGET := $(TARGET).exe
  76. #endif
  77. INC := $(foreach dir,$(INC_DIR_LIST),-I$(dir))
  78. DEF := $(foreach def,$(PRE_DEFS),-D$(def))
  79. EXC := $(foreach fil,$(EXC_FILE_LIST), \
  80. $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/$(fil))) \
  81. )
  82. # source files. object and dependencies list
  83. # recursive search into current and source directories
  84. SRC := $(wildcard *.cpp)
  85. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/*.cpp))
  86. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/**/*.cpp))
  87. SRC := $(filter-out $(EXC),$(SRC))
  88. #SRC := $(abspath $(SRC))
  89. OBJ := $(foreach file,$(SRC:%.cpp=%.o),$(OBJ_DIR)/$(file))
  90. DEP := $(foreach file,$(SRC:%.cpp=%.d),$(DEP_DIR)/$(file))
  91. # Make Dependencies pattern.
  92. # This little trick enables recompilation only when dependencies change
  93. # and it does so for changes both in source AND header files ;)
  94. #
  95. # It is based on Tom Tromey's method.
  96. #
  97. # Invoke cpp to create makefile rules with dependencies for each source file
  98. $(DEP_DIR)/%.d: %.c
  99. @mkdir -p $(@D)
  100. @$(DOCKER) $(CC) -E $(CFLAGS) $(INC) $(DEF) -MM -MT $(OBJ_DIR)/$(<:.c=.o) -MF $@ $<
  101. # c file objects depent on .c AND dependency files, which have an empty recipe
  102. $(OBJ_DIR)/%.o: %.c $(DEP_DIR)/%.d
  103. @mkdir -p $(@D)
  104. @$(DOCKER) $(CC) -c $(CFLAGS) $(INC) $(DEF) -o $@ $<
  105. $(DEP_DIR)/%.d: %.cpp
  106. @mkdir -p $(@D)
  107. @$(DOCKER) $(CXX) -E $(CXXFLAGS) $(INC) $(DEF) -MM -MT $(OBJ_DIR)/$(<:.cpp=.o) -MF $@ $<
  108. # cpp file objects depent on .cpp AND dependency files, which have an empty recipe
  109. $(OBJ_DIR)/%.o: %.cpp $(DEP_DIR)/%.d
  110. @mkdir -p $(@D)
  111. @$(DOCKER) $(CXX) -c $(CXXFLAGS) $(INC) $(DEF) -o $@ $<
  112. # empty recipe for dependency files. This prevents make errors
  113. $(DEP):
  114. # now include all dependencies
  115. # After all they are makefile dependency rules ;)
  116. include $(wildcard $(DEP))
  117. # main target rule
  118. $(BUILD_DIR)/$(TARGET): $(OBJ)
  119. @mkdir -p $(@D)
  120. @echo Linking to target: $(TARGET)
  121. @echo $(DOCKER) $(CXX) '$$(OBJ)' $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET)
  122. @$(DOCKER) $(CXX) $(OBJ) $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET)
  123. @echo
  124. @echo Print size information
  125. @$(CSIZE) $(@D)/$(TARGET)
  126. @echo Done
  127. .PHONY: clean
  128. clean:
  129. @echo Cleaning build directories
  130. @rm -rf $(OBJ_DIR)
  131. @rm -rf $(DEP_DIR)
  132. @rm -rf $(BUILD_DIR)
  133. #
  134. # ================ Local build rules =================
  135. # example:
  136. # make debug
  137. debug: CFLAGS := $(DEB_CFLAGS)
  138. debug: $(BUILD_DIR)/$(TARGET)
  139. release: CFLAGS := $(REL_CFLAGS)
  140. release: $(BUILD_DIR)/$(TARGET)
  141. all: release
  142. hpc-results/post:
  143. $(CXX) $(CFLAGS) -o $@ hpc-results/main.cpp
  144. hpc-clean:
  145. rm hpc-results/post
  146. #
  147. # ================ Local (and/or) via docker build rules =================
  148. #
  149. # examples:
  150. # make IMAGE=hpcimage v0
  151. # make IMAGE=hpcimage v1_cilk
  152. #
  153. dist_v05: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=50
  154. dist_v05: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=50
  155. dist_v05: TARGET := dist_v05
  156. dist_v05: $(BUILD_DIR)/$(TARGET)
  157. dist_v1: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=100
  158. dist_v1: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=100
  159. dist_v1: TARGET := dist_v1
  160. dist_v1: $(BUILD_DIR)/$(TARGET)
  161. #
  162. # ========= Inside CSAL Image build rules ===========
  163. #
  164. # 1) first jump into image (make sure you are in the directory where Makefile is):
  165. # > docker run -it -v ${PWD}:/usr/src/exercise_1 -w /usr/src/exercise_1/ hpcimage
  166. # 2) Clean binaries first **important**
  167. # > make clean
  168. # 3) for v4 cilk for example:
  169. # > make csal_v4_cilk
  170. # 4) run executables from `bin/`. Examples:
  171. # > ./bin/tcount_ompv3 -i mtx/NACA0015.mtx --timing -r 3 -o /dev/null
  172. # > ./bin/tcount_pthv4 -i mtx/com_Youtube.mtx --timing --dynamic --print_count
  173. #
  174. # ======== Run from container =========
  175. #
  176. # examples:
  177. #
  178. # make IMAGE=hpcimage EXEC=knnsearch_v1 run
  179. # make IMAGE=hpcimage EXEC=knnsearch_v1 run
  180. #