AUTH's THMMY "Parallel and distributed systems" course assignments.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

237 líneas
7.2 KiB

  1. #
  2. # PDS HW3 Makefile
  3. #
  4. # Copyright (C) 2025 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_3
  22. # Excecutable's name
  23. TARGET := bitonicCUDA
  24. # Source directories list(space seperated). Makefile-relative path, UNDER current directory.
  25. SRC_DIR_LIST := src #test test/gtest
  26. # Include directories list(space seperated). Makefile-relative path.
  27. INC_DIR_LIST := src
  28. # test \
  29. # test/gtest/ \
  30. # Exclude files list(space seperated). Filenames only.
  31. # EXC_FILE_LIST := bad.cpp old.cpp
  32. # Build directories
  33. BUILD_DIR := bin
  34. OBJ_DIR := $(BUILD_DIR)/obj
  35. DEP_DIR := $(BUILD_DIR)/.dep
  36. OUTPUT_DIR := out
  37. # ========== Compiler settings ==========
  38. # Compiler flags for debug and release
  39. DEB_CFLAGS := -DDEBUG -std=c11 -Xcompiler "-Wall -Wextra -g -DDEBUG"
  40. REL_CFLAGS := -O3 -std=c11 -Xcompiler "-Wall -Wextra"
  41. DEB_CXXFLAGS := -DDEBUG -std=c++17 -Xcompiler "-Wall -Wextra -g -DDEBUG"
  42. REL_CXXFLAGS := -O3 -std=c++17 -Xcompiler "-Wall -Wextra"
  43. # Pre-defines
  44. # PRE_DEFS := MYCAB=1729 SUPER_MODE
  45. PRE_DEFS := TARGET=$(TARGET)
  46. # ============== Linker settings ==============
  47. # Linker flags (example: -pthread -lm)
  48. LDFLAGS :=
  49. # Map output file
  50. MAP_FILE := # output.map
  51. MAP_FLAG := # -Xlinker -Map=$(BUILD_DIR)/$(MAP_FILE)
  52. # ============== Docker settings ==============
  53. # We need:
  54. # - Bind the entire project directory(the dir that includes all the code) as volume.
  55. # - In docker instance, change to working directory(where the makefile is).
  56. DOCKER_VOL_DIR := $(shell pwd)
  57. DOCKER_WRK_DIR :=
  58. DOCKER_RUN := docker run --rm
  59. DOCKER_FLAGS := -v $(DOCKER_VOL_DIR):/usr/src/$(PROJECT) -w /usr/src/$(PROJECT)/$(DOCKER_WRK_DIR)
  60. # docker invoke mechanism (edit with care)
  61. # note:
  62. # Here, `DOCKER` variable is empty. Rules can assign `DOCKER := DOCKER_CMD` when docker
  63. # functionality is needed.
  64. DOCKER_CMD = $(DOCKER_RUN) $(DOCKER_FLAGS) $(IMAGE)
  65. DOCKER :=
  66. # ============== Tool selection ==============
  67. # compiler and compiler flags.
  68. CSIZE := size
  69. CFLAGS := $(DEB_CFLAGS)
  70. CXXFLAGS := $(DEB_CXXFLAGS)
  71. CXX := g++
  72. CC := gcc
  73. LINKER := g++
  74. #
  75. # =========== Main body and Patterns ===========
  76. #
  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. # c file objects depent on .c AND dependency files, which have an empty recipe
  92. $(OBJ_DIR)/%.o: %.c
  93. @mkdir -p $(@D)
  94. $(DOCKER) $(CC) -c $(CFLAGS) $(INC) $(DEF) -o $@ $<
  95. # cpp file objects depend on .cpp AND dependency files, which have an empty recipe
  96. $(OBJ_DIR)/%.o: %.cpp
  97. @mkdir -p $(@D)
  98. $(DOCKER) $(CXX) -c $(CXXFLAGS) $(INC) $(DEF) -o $@ $<
  99. # main target rule
  100. $(BUILD_DIR)/$(TARGET): $(OBJ)
  101. @mkdir -p $(@D)
  102. @echo Linking to target: $(TARGET)
  103. @echo $(DOCKER) $(LINKER) '$$(OBJ)' $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET)
  104. @$(DOCKER) $(LINKER) $(OBJ) $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET)
  105. @echo
  106. @echo Print size information
  107. @$(CSIZE) $(@D)/$(TARGET)
  108. @echo Done
  109. #
  110. # ================ Default local build rules =================
  111. # example:
  112. # make debug
  113. .DEFAULT_GOAL := all
  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. debug: CFLAGS := $(DEB_CFLAGS)
  121. debug: $(BUILD_DIR)/$(TARGET)
  122. release: CFLAGS := $(REL_CFLAGS)
  123. release: $(BUILD_DIR)/$(TARGET)
  124. #
  125. # ================ Build rules =================
  126. #
  127. bitonic_v0deb: CC := nvcc -G -g -x cu
  128. bitonic_v0deb: CXX := nvcc -G -g -x cu
  129. bitonic_v0deb: LINKER := nvcc
  130. bitonic_v0deb: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=V0
  131. bitonic_v0deb: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=V0
  132. bitonic_v0deb: OUTPUT_DIR := $(OUTPUT_DIR)/v0
  133. bitonic_v0deb: $(BUILD_DIR)/$(TARGET)
  134. @mkdir -p $(OUTPUT_DIR)
  135. cp $(BUILD_DIR)/$(TARGET) $(OUTPUT_DIR)/$(TARGET)
  136. bitonic_v1deb: CC := nvcc -G -g -x cu
  137. bitonic_v1deb: CXX := nvcc -G -g -x cu
  138. bitonic_v1deb: LINKER := nvcc
  139. bitonic_v1deb: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=V1
  140. bitonic_v1deb: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=V1
  141. bitonic_v1deb: OUTPUT_DIR := $(OUTPUT_DIR)/v1
  142. bitonic_v1deb: $(BUILD_DIR)/$(TARGET)
  143. @mkdir -p $(OUTPUT_DIR)
  144. cp $(BUILD_DIR)/$(TARGET) $(OUTPUT_DIR)/$(TARGET)
  145. bitonic_v2deb: CC := nvcc -G -g -x cu
  146. bitonic_v2deb: CXX := nvcc -G -g -x cu
  147. bitonic_v2deb: LINKER := nvcc
  148. bitonic_v2deb: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=V2
  149. bitonic_v2deb: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=V2
  150. bitonic_v2deb: OUTPUT_DIR := $(OUTPUT_DIR)/v2
  151. bitonic_v2deb: $(BUILD_DIR)/$(TARGET)
  152. @mkdir -p $(OUTPUT_DIR)
  153. cp $(BUILD_DIR)/$(TARGET) $(OUTPUT_DIR)/$(TARGET)
  154. bitonic_v0: CC := nvcc -x cu
  155. bitonic_v0: CXX := nvcc -x cu
  156. bitonic_v0: LINKER := nvcc
  157. bitonic_v0: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=V0
  158. bitonic_v0: CXXFLAGS := $(REL_CXXFLAGS) -DCODE_VERSION=V0
  159. bitonic_v0: OUTPUT_DIR := $(OUTPUT_DIR)/v0
  160. bitonic_v0: $(BUILD_DIR)/$(TARGET)
  161. @mkdir -p $(OUTPUT_DIR)
  162. cp $(BUILD_DIR)/$(TARGET) $(OUTPUT_DIR)/$(TARGET)
  163. bitonic_v1: CC := nvcc -x cu
  164. bitonic_v1: CXX := nvcc -x cu
  165. bitonic_v1: LINKER := nvcc
  166. bitonic_v1: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=V1
  167. bitonic_v1: CXXFLAGS := $(REL_CXXFLAGS) -DCODE_VERSION=V1
  168. bitonic_v1: OUTPUT_DIR := $(OUTPUT_DIR)/v1
  169. bitonic_v1: $(BUILD_DIR)/$(TARGET)
  170. @mkdir -p $(OUTPUT_DIR)
  171. cp $(BUILD_DIR)/$(TARGET) $(OUTPUT_DIR)/$(TARGET)
  172. bitonic_v2: CC := nvcc -x cu
  173. bitonic_v2: CXX := nvcc -x cu
  174. bitonic_v2: LINKER := nvcc
  175. bitonic_v2: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=V2
  176. bitonic_v2: CXXFLAGS := $(REL_CXXFLAGS) -DCODE_VERSION=V2
  177. bitonic_v2: OUTPUT_DIR := $(OUTPUT_DIR)/v2
  178. bitonic_v2: $(BUILD_DIR)/$(TARGET)
  179. @mkdir -p $(OUTPUT_DIR)
  180. cp $(BUILD_DIR)/$(TARGET) $(OUTPUT_DIR)/$(TARGET)
  181. hpc-build:
  182. make clean
  183. make bitonic_v0
  184. make clean
  185. make bitonic_v1
  186. make clean
  187. make bitonic_v2
  188. all: debug bitonic_v0
  189. # Note:
  190. # Add a gcc based make rule here in order for clangd to successfully scan the project files.
  191. # Otherwise we do not need the gcc build.