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.

Makefile 7.4 KiB

il y a 4 semaines
il y a 4 semaines
il y a 4 semaines
il y a 4 semaines
il y a 4 semaines
il y a 4 semaines
il y a 4 semaines
il y a 4 semaines
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. @mkdir -p out
  156. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  157. distbitonic: CC := mpicc
  158. distbitonic: CXX := mpic++
  159. distbitonic: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=BITONIC
  160. distbitonic: CXXFLAGS := $(REL_CXXFLAGS) -DCODE_VERSION=BITONIC
  161. distbitonic: TARGET := distbitonic
  162. distbitonic: $(BUILD_DIR)/$(TARGET)
  163. @mkdir -p out
  164. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  165. deb_distbubbletonic: CC := mpicc
  166. deb_distbubbletonic: CXX := mpic++
  167. deb_distbubbletonic: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=BUBBLETONIC -DDEBUG
  168. deb_distbubbletonic: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=BUBBLETONIC -DDEBUG
  169. deb_distbubbletonic: TARGET := deb_distbubbletonic
  170. deb_distbubbletonic: $(BUILD_DIR)/$(TARGET)
  171. @mkdir -p out
  172. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  173. deb_distbitonic: CC := mpicc
  174. deb_distbitonic: CXX := mpic++
  175. deb_distbitonic: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=BITONIC -DDEBUG
  176. deb_distbitonic: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=BITONIC -DDEBUG
  177. deb_distbitonic: TARGET := deb_distbitonic
  178. deb_distbitonic: $(BUILD_DIR)/$(TARGET)
  179. @mkdir -p out
  180. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  181. tests: CC := mpicc
  182. tests: CXX := mpic++
  183. tests: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=BITONIC -DDEBUG -DTESTING
  184. tests: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=BITONIC -DDEBUG -DTESTING
  185. tests: TARGET := tests
  186. tests: $(BUILD_DIR)/$(TARGET)
  187. @mkdir -p out
  188. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  189. measurements:
  190. make clean
  191. make distbubbletonic
  192. make clean
  193. make distbitonic
  194. all: debug distbubbletonic distbitonic
  195. # Note:
  196. # Add a gcc based make rule here in order for clangd to successfully scan the project files.
  197. # Otherwise we do not need the gcc build.