A triangle counting assignment for A.U.TH Parallel and distributed systems class.
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.

Makefile 6.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #
  2. # PDS excercise 1 Makefile
  3. #
  4. # Copyright (C) 2019-2020 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 := exercise_1
  22. # Excecutable's name
  23. TARGET := triangCounting
  24. # Source directories list(space seperated). Makefile-relative path, UNDER current directory.
  25. SRC_DIR_LIST := src
  26. # Include directories list(space seperated). Makefile-relative path.
  27. INC_DIR_LIST := src inc
  28. # Exclude files list(space seperated). Filenames only.
  29. # EXC_FILE_LIST := bad.cpp old.cpp
  30. # Build directories
  31. BUILD_DIR := bin
  32. OBJ_DIR := $(BUILD_DIR)/obj
  33. DEP_DIR := $(BUILD_DIR)/.dep
  34. # ========== Compiler settings ==========
  35. # Compiler flags for debug and release
  36. DEB_CFLAGS := -DDEBUG -g3 -Wall -Wextra -std=c++14
  37. REL_CFLAGS := -DDEBUG -g3 -Wall -Wextra -O2 -std=c++14
  38. # Pre-defines
  39. # PRE_DEFS := MYCAB=1729 SUPER_MODE
  40. PRE_DEFS :=
  41. # ============== Linker settings ==============
  42. # Linker flags (example: -pthread -lm)
  43. LDFLAGS := -pthread
  44. # Map output file
  45. MAP_FILE := output.map
  46. MAP_FLAG := -Xlinker -Map=$(BUILD_DIR)/$(MAP_FILE)
  47. # ============== Docker settings ==============
  48. # We need:
  49. # - Bind the entire project directory(the dir that icludes all the code) as volume.
  50. # - In docker instance, change to working directory(where the makefile is).
  51. DOCKER_VOL_DIR := $${PWD}
  52. DOCKER_WRK_DIR :=
  53. DOCKER_RUN := docker run --rm
  54. DOCKER_FLAGS := -v $(DOCKER_VOL_DIR):/usr/src/$(PROJECT) -w /usr/src/$(PROJECT)/$(DOCKER_WRK_DIR)
  55. # docker invoke mechanism (edit with care)
  56. # note:
  57. # Here, `DOCKER` variable is empty. Rules can assign `DOCKER := DOCKER_CMD` when docker
  58. # functionality is needed.
  59. DOCKER_CMD = $(DOCKER_RUN) $(DOCKER_FLAGS) $(IMAGE)
  60. DOCKER :=
  61. # ============== Tool selection ==============
  62. # compiler and compiler flags.
  63. CSIZE := size
  64. CFLAGS := $(DEB_CFLAGS)
  65. CXX := g++
  66. #
  67. # =========== Main body and Patterns ===========
  68. #
  69. #ifeq ($(OS), Windows_NT)
  70. # TARGET := $(TARGET).exe
  71. #endif
  72. INC := $(foreach dir,$(INC_DIR_LIST),-I$(dir))
  73. DEF := $(foreach def,$(PRE_DEFS),-D$(def))
  74. EXC := $(foreach fil,$(EXC_FILE_LIST), \
  75. $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/$(fil))) \
  76. )
  77. # source files. object and dependencies list
  78. # recursive search into current and source directories
  79. SRC := $(wildcard *.cpp)
  80. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/*.cpp))
  81. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/**/*.cpp))
  82. SRC := $(filter-out $(EXC),$(SRC))
  83. #SRC := $(abspath $(SRC))
  84. OBJ := $(foreach file,$(SRC:%.cpp=%.o),$(OBJ_DIR)/$(file))
  85. DEP := $(foreach file,$(SRC:%.cpp=%.d),$(DEP_DIR)/$(file))
  86. # Make Dependencies pattern.
  87. # This little trick enables recompilation only when dependencies change
  88. # and it does so for changes both in source AND header files ;)
  89. #
  90. # It is based on Tom Tromey's method.
  91. #
  92. # Invoke cpp to create makefile rules with dependencies for each source file
  93. $(DEP_DIR)/%.d: %.cpp
  94. @mkdir -p $(@D)
  95. $(DOCKER) $(CXX) -E $(CFLAGS) $(INC) $(DEF) -MM -MT $(OBJ_DIR)/$(<:.cpp=.o) -MF $@ $<
  96. # objects depent on .cpp AND dependency files, which have an empty recipe
  97. $(OBJ_DIR)/%.o: %.cpp $(DEP_DIR)/%.d
  98. @mkdir -p $(@D)
  99. $(DOCKER) $(CXX) -c $(CFLAGS) $(INC) $(DEF) -o $@ $<
  100. # empty recipe for dependency files. This prevents make errors
  101. $(DEP):
  102. # now include all dependencies
  103. # After all they are makefile dependency rules ;)
  104. include $(wildcard $(DEP))
  105. # main target rule
  106. $(BUILD_DIR)/$(TARGET): $(OBJ)
  107. @mkdir -p $(@D)
  108. @echo Linking to target: $(TARGET)
  109. @echo $(DOCKER) $(CXX) $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET) '$$(OBJ)'
  110. @$(DOCKER) $(CXX) $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET) $(OBJ)
  111. @echo
  112. @echo Print size information
  113. @$(CSIZE) $(@D)/$(TARGET)
  114. @echo Done
  115. .PHONY: clean
  116. clean:
  117. @echo Cleaning build directories
  118. @rm -rf $(OBJ_DIR)
  119. @rm -rf $(DEP_DIR)
  120. @rm -rf $(BUILD_DIR)
  121. #
  122. # ================ Local build rules =================
  123. # examples:
  124. # make debug
  125. debug: CFLAGS := $(DEB_CFLAGS)
  126. debug: $(BUILD_DIR)/$(TARGET)
  127. release: CFLAGS := $(REL_CFLAGS)
  128. release: $(BUILD_DIR)/$(TARGET)
  129. all: release
  130. local_v3: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=V3
  131. local_v3: TARGET := local_v3
  132. local_v3: $(BUILD_DIR)/$(TARGET)
  133. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  134. local_v4: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=V4
  135. local_v4: TARGET := local_v4
  136. local_v4: $(BUILD_DIR)/$(TARGET)
  137. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  138. v3: DOCKER := $(DOCKER_CMD)
  139. v3: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=V3
  140. v3: TARGET := tcount_v3
  141. v3: $(BUILD_DIR)/$(TARGET)
  142. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  143. v3_cilk: DOCKER := $(DOCKER_CMD)
  144. v3_cilk: CXX := /usr/local/OpenCilk-9.0.1-Linux/bin/clang++
  145. v3_cilk: CFLAGS := $(REL_CFLAGS) -fcilkplus -DCODE_VERSION=V3 -DCILK
  146. v3_cilk: LDFLAGS += -fcilkplus
  147. v3_cilk: TARGET := tcount_cilkv3
  148. v3_cilk: $(BUILD_DIR)/$(TARGET)
  149. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  150. v3_omp: DOCKER := $(DOCKER_CMD)
  151. v3_omp: CFLAGS := $(REL_CFLAGS) -fopenmp -DCODE_VERSION=V3 -DOMP
  152. v3_omp: LDFLAGS += -fopenmp
  153. v3_omp: TARGET := tcount_ompv3
  154. v3_omp: $(BUILD_DIR)/$(TARGET)
  155. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  156. v4: DOCKER := $(DOCKER_CMD)
  157. v4: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=V4
  158. v4: TARGET := tcount_v4
  159. v4: $(BUILD_DIR)/$(TARGET)
  160. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  161. v4_cilk: DOCKER := $(DOCKER_CMD)
  162. v4_cilk: CXX := /usr/local/OpenCilk-9.0.1-Linux/bin/clang++
  163. v4_cilk: CFLAGS := $(REL_CFLAGS) -fcilkplus -DCODE_VERSION=V4 -DCILK
  164. v4_cilk: LDFLAGS += -fcilkplus
  165. v4_cilk: TARGET := tcount_cilkv4
  166. v4_cilk: $(BUILD_DIR)/$(TARGET)
  167. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  168. v4_omp: DOCKER := $(DOCKER_CMD)
  169. v4_omp: CFLAGS := $(REL_CFLAGS) -fopenmp -DCODE_VERSION=V4 -DOMP
  170. v4_omp: LDFLAGS += -fopenmp
  171. v4_omp: TARGET := tcount_ompv4
  172. v4_omp: $(BUILD_DIR)/$(TARGET)
  173. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  174. v4_pthreads: DOCKER := $(DOCKER_CMD)
  175. v4_pthreads: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=V4 -DTHREADS
  176. v4_pthreads: TARGET := tcount_pthv4
  177. v4_pthreads: $(BUILD_DIR)/$(TARGET)
  178. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  179. #
  180. # ================ Docker based rules ================
  181. # examples:
  182. # make IMAGE="gcc:8.3" dock
  183. #
  184. dock: DOCKER := $(DOCKER_CMD)
  185. dock: CFLAGS := $(REL_CFLAGS)
  186. dock: $(BUILD_DIR)/$(TARGET)