AUTH's THMMY "Parallel and distributed systems" course assignments.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

221 lines
7.0 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 := 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 := include \
  28. test \
  29. test/gtest/ \
  30. /usr/lib/x86_64-linux-gnu/openmpi/include/ \
  31. src
  32. # Exclude files list(space seperated). Filenames only.
  33. # EXC_FILE_LIST := bad.cpp old.cpp
  34. # Build directories
  35. BUILD_DIR := bin
  36. OBJ_DIR := $(BUILD_DIR)/obj
  37. DEP_DIR := $(BUILD_DIR)/.dep
  38. # ========== Compiler settings ==========
  39. # Compiler flags for debug and release
  40. DEB_CFLAGS := -DDEBUG -g3 -Wall -Wextra -std=c11
  41. REL_CFLAGS := -Wall -Wextra -O3 -std=c11
  42. DEB_CXXFLAGS := -DDEBUG -g3 -Wall -Wextra -std=c++17
  43. REL_CXXFLAGS := -Wall -Wextra -O3 -std=c++17
  44. # Pre-defines
  45. # PRE_DEFS := MYCAB=1729 SUPER_MODE
  46. PRE_DEFS :=
  47. # ============== Linker settings ==============
  48. # Linker flags (example: -pthread -lm)
  49. LDFLAGS := -pthread
  50. # Map output file
  51. MAP_FILE := output.map
  52. MAP_FLAG := -Xlinker -Map=$(BUILD_DIR)/$(MAP_FILE)
  53. # ============== Docker settings ==============
  54. # We need:
  55. # - Bind the entire project directory(the dir that icludes all the code) as volume.
  56. # - In docker instance, change to working directory(where the makefile is).
  57. DOCKER_VOL_DIR := $(shell pwd)
  58. DOCKER_WRK_DIR :=
  59. DOCKER_RUN := docker run --rm
  60. DOCKER_FLAGS := -v $(DOCKER_VOL_DIR):/usr/src/$(PROJECT) -w /usr/src/$(PROJECT)/$(DOCKER_WRK_DIR)
  61. # docker invoke mechanism (edit with care)
  62. # note:
  63. # Here, `DOCKER` variable is empty. Rules can assign `DOCKER := DOCKER_CMD` when docker
  64. # functionality is needed.
  65. DOCKER_CMD = $(DOCKER_RUN) $(DOCKER_FLAGS) $(IMAGE)
  66. DOCKER :=
  67. # ============== Tool selection ==============
  68. # compiler and compiler flags.
  69. CSIZE := size
  70. CFLAGS := $(DEB_CFLAGS)
  71. CXXFLAGS := $(DEB_CXXFLAGS)
  72. CXX := g++ #mpic++
  73. CC := gcc #mpicc
  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 $(DEP_DIR)/%.d
  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 depent on .cpp AND dependency files, which have an empty recipe
  112. $(OBJ_DIR)/%.o: %.cpp $(DEP_DIR)/%.d
  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) $(CXX) '$$(OBJ)' $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET)
  125. @$(DOCKER) $(CXX) $(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. # Local or inside HPC rules
  149. distbubbletonic: CC := mpicc
  150. distbubbletonic: CXX := mpic++
  151. distbubbletonic: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=BUBBLETONIC
  152. distbubbletonic: CXXFLAGS := $(REL_CXXFLAGS) -DCODE_VERSION=BUBBLETONIC
  153. distbubbletonic: TARGET := distbubbletonic
  154. distbubbletonic: $(BUILD_DIR)/$(TARGET)
  155. distbitonic: CC := mpicc
  156. distbitonic: CXX := mpic++
  157. distbitonic: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=BITONIC
  158. distbitonic: CXXFLAGS := $(REL_CXXFLAGS) -DCODE_VERSION=BITONIC
  159. distbitonic: TARGET := distbitonic
  160. distbitonic: $(BUILD_DIR)/$(TARGET)
  161. deb_distbubbletonic: CC := mpicc
  162. deb_distbubbletonic: CXX := mpic++
  163. deb_distbubbletonic: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=BUBBLETONIC -DDEBUG
  164. deb_distbubbletonic: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=BUBBLETONIC -DDEBUG
  165. deb_distbubbletonic: TARGET := deb_distbubbletonic
  166. deb_distbubbletonic: $(BUILD_DIR)/$(TARGET)
  167. deb_distbitonic: CC := mpicc
  168. deb_distbitonic: CXX := mpic++
  169. deb_distbitonic: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=BITONIC -DDEBUG
  170. deb_distbitonic: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=BITONIC -DDEBUG
  171. deb_distbitonic: TARGET := deb_distbitonic
  172. deb_distbitonic: $(BUILD_DIR)/$(TARGET)
  173. tests: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=BITONIC -DDEBUG -DTESTING
  174. tests: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=BITONIC -DDEBUG -DTESTING
  175. tests: TARGET := tests
  176. tests: $(BUILD_DIR)/$(TARGET)
  177. all: debug distbubbletonic distbitonic
  178. # Note:
  179. # Add a gcc based make rule here in order for clangd to successfully scan the project files.
  180. # Otherwise we do not need the gcc build.