AUTH's THMMY "Parallel and distributed systems" course assignments.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

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