Makefile 1.89 KB
Newer Older
1
2
CC = gcc
MCC = mpicc
3
#C_FLAGS_ALL = -Wconversion -Wpedantic
4
C_FLAGS = -Wall -Wextra -Wshadow -Wfatal-errors
5
LD_FLAGS = -lm -pthread
6
7
8
9
10
11
12
13
14

USE_MAL_SLURM ?= 0
USE_MAL_BARRIERS ?= 0
USE_MAL_DEBUG ?= 0

ifeq ($(USE_MAL_SLURM),1)
    LD_FLAGS += -lslurm
endif
DEF = -DUSE_MAL_SLURM=$(USE_MAL_SLURM) -DUSE_MAL_BARRIERS=$(USE_MAL_BARRIERS) -DUSE_MAL_DEBUG=$(USE_MAL_DEBUG)
15

16
17

.PHONY : clean clear install install_slurm
18
19
20

# Final binary
BIN = a.out
21
CONFIG = config.txt
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Put all auto generated stuff to this build dir.
BUILD_DIR = ./build

# List of all directories where source files are located
SRCDIRS = IOcodes Main malleability malleability/spawn_methods malleability/distribution_methods

# List of all .c source files.
C_FILES = $(foreach dire, $(SRCDIRS), $(wildcard $(dire)/*.c))

# All .o files go to build dir.
OBJ = $(C_FILES:%.c=$(BUILD_DIR)/%.o)
# Gcc will create these .d files containing dependencies.
DEP = $(OBJ:%.o=%.d)

# Default target named after the binary.
$(BIN) : $(BUILD_DIR)/$(BIN)

39
40
41
42
43
# Default configuration file
$(CONFIG) : $(BUILD_DIR)/$(CONFIG)
$(BUILD_DIR)/$(CONFIG) :
	mkdir -p $(@D)
	@ echo -n "dir=\"" > $(BUILD_DIR)/$(CONFIG)
44
	@ realpath -z $$(echo "$$(pwd)/..") | tr -d '\0' >> $(BUILD_DIR)/$(CONFIG)
45
46
	@ echo "\"" >> $(BUILD_DIR)/$(CONFIG)

47
48
# Actual target of the binary - depends on all .o files.
$(BUILD_DIR)/$(BIN) : $(OBJ)
49
	$(MCC) $(C_FLAGS) $^ -o $@ $(LD_FLAGS)
50
51
52
53
54
55
56
57
58
59
60
61

# Include all .d files
# .d files are used for knowing the dependencies of each source file
-include $(DEP)

# Build target for every single object file.
# The potential dependency on header files is covered
# by calling `-include $(DEP)`.
# The -MMD flags additionaly creates a .d file with
# the same name as the .o file.
$(BUILD_DIR)/%.o : %.c
	mkdir -p $(@D)
62
	$(MCC) $(C_FLAGS) $(DEF) -MMD -c $< -o $@
63
64

clean:
65
	-rm $(BUILD_DIR)/$(BIN) $(BUILD_DIR)/$(CONFIG) $(OBJ) $(DEP)
66
67
clear:
	-rm -rf $(BUILDDIR)
68

69

70
install: $(BIN) $(CONFIG)
71
	echo "Done"