AUTH's THMMY "Parallel and distributed systems" course assignments.
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.
 
 
 
 
 
 

205 lignes
6.1 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 := bitonic
  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 -g3 -std=c11 -Xcompiler "-Wall -Wextra"
  40. REL_CFLAGS := -O3 -std=c11 -Xcompiler "-Wall -Wextra"
  41. DEB_CXXFLAGS := -DDEBUG -g3 -std=c++17 -Xcompiler "-Wall -Wextra"
  42. REL_CXXFLAGS := -O3 -std=c++17 -Xcompiler "-Wall -Wextra"
  43. # Pre-defines
  44. # PRE_DEFS := MYCAB=1729 SUPER_MODE
  45. PRE_DEFS :=
  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++ #mpic++
  72. CC := gcc #mpicc
  73. LINKER := g++
  74. #
  75. # =========== Main body and Patterns ===========
  76. #
  77. #ifeq ($(OS), Windows_NT)
  78. # TARGET := $(TARGET).exe
  79. #endif
  80. INC := $(foreach dir,$(INC_DIR_LIST),-I$(dir))
  81. DEF := $(foreach def,$(PRE_DEFS),-D$(def))
  82. EXC := $(foreach fil,$(EXC_FILE_LIST), \
  83. $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/$(fil))) \
  84. )
  85. # source files. object and dependencies list
  86. # recursive search into current and source directories
  87. SRC := $(wildcard *.cpp)
  88. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/*.cpp))
  89. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/**/*.cpp))
  90. SRC := $(filter-out $(EXC),$(SRC))
  91. #SRC := $(abspath $(SRC))
  92. OBJ := $(foreach file,$(SRC:%.cpp=%.o),$(OBJ_DIR)/$(file))
  93. DEP := $(foreach file,$(SRC:%.cpp=%.d),$(DEP_DIR)/$(file))
  94. # Make Dependencies pattern.
  95. # This little trick enables recompilation only when dependencies change
  96. # and it does so for changes both in source AND header files ;)
  97. #
  98. # It is based on Tom Tromey's method.
  99. #
  100. # Invoke cpp to create makefile rules with dependencies for each source file
  101. #$(DEP_DIR)/%.d: %.c
  102. # @mkdir -p $(@D)
  103. # @$(DOCKER) $(CC) -E $(CFLAGS) $(INC) $(DEF) -MM -MT $(OBJ_DIR)/$(<:.c=.o) -MF $@ $<
  104. # c file objects depent on .c AND dependency files, which have an empty recipe
  105. $(OBJ_DIR)/%.o: %.c
  106. @mkdir -p $(@D)
  107. $(DOCKER) $(CC) -c $(CFLAGS) $(INC) $(DEF) -o $@ $<
  108. #$(DEP_DIR)/%.d: %.cpp
  109. # @mkdir -p $(@D)
  110. # @$(DOCKER) $(CXX) -E $(CXXFLAGS) $(INC) $(DEF) -MM -MT $(OBJ_DIR)/$(<:.cpp=.o) -MF $@ $<
  111. # cpp file objects depend on .cpp AND dependency files, which have an empty recipe
  112. $(OBJ_DIR)/%.o: %.cpp
  113. @mkdir -p $(@D)
  114. $(DOCKER) $(CXX) -c $(CXXFLAGS) $(INC) $(DEF) -o $@ $<
  115. # empty recipe for dependency files. This prevents make errors
  116. #$(DEP):
  117. # now include all dependencies
  118. # After all they are makefile dependency rules ;)
  119. #include $(wildcard $(DEP))
  120. # main target rule
  121. $(BUILD_DIR)/$(TARGET): $(OBJ)
  122. @mkdir -p $(@D)
  123. @echo Linking to target: $(TARGET)
  124. @echo $(DOCKER) $(LINKER) '$$(OBJ)' $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET)
  125. @$(DOCKER) $(LINKER) $(OBJ) $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET)
  126. @echo
  127. @echo Print size information
  128. @$(CSIZE) $(@D)/$(TARGET)
  129. @echo Done
  130. #
  131. # ================ Default local build rules =================
  132. # example:
  133. # make debug
  134. .DEFAULT_GOAL := all
  135. .PHONY: clean
  136. clean:
  137. @echo Cleaning build directories
  138. @rm -rf $(OBJ_DIR)
  139. @rm -rf $(DEP_DIR)
  140. @rm -rf $(BUILD_DIR)
  141. debug: CFLAGS := $(DEB_CFLAGS)
  142. debug: $(BUILD_DIR)/$(TARGET)
  143. release: CFLAGS := $(REL_CFLAGS)
  144. release: $(BUILD_DIR)/$(TARGET)
  145. #
  146. # ================ Build rules =================
  147. #
  148. bitonic_v0: CC := nvcc -x cu
  149. bitonic_v0: CXX := nvcc -x cu
  150. bitonic_v0: LINKER := nvcc
  151. bitonic_v0: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=V0
  152. bitonic_v0: CXXFLAGS := $(REL_CXXFLAGS) -DCODE_VERSION=V0
  153. bitonic_v0: OUTPUT_DIR := $(OUTPUT_DIR)/v0
  154. bitonic_v0: TARGET := bitonic_v0
  155. bitonic_v0: $(BUILD_DIR)/$(TARGET)
  156. @mkdir -p $(OUTPUT_DIR)
  157. cp $(BUILD_DIR)/$(TARGET) $(OUTPUT_DIR)/$(TARGET)
  158. hpc-build:
  159. make clean
  160. make bitonic_v0
  161. all: debug bitonic_v0
  162. # Note:
  163. # Add a gcc based make rule here in order for clangd to successfully scan the project files.
  164. # Otherwise we do not need the gcc build.