Makefile 1.98 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
MAM_USE_SLURM ?= 0
MAM_USE_BARRIERS ?= 0
MAM_DEBUG ?= 0
10
DEF = -DMAM_USE_SLURM=$(MAM_USE_SLURM) -DMAM_USE_BARRIERS=$(MAM_USE_BARRIERS) -DMAM_DEBUG=$(MAM_DEBUG)
11

12
ifeq ($(MAM_USE_SLURM),1)
13
14
    LD_FLAGS += -lslurm
endif
15
16
17
18

ifeq ($(shell test $(MAM_DEBUG) -gt 0; echo $$?),0)
    C_FLAGS += -g
endif
19
20
21

# Final binary
BIN = a.out
22
CONFIG = config.txt
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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)

37
38
39
40
41
42
43
44
45
46
47
48
49
50
# BASIC RULES
.PHONY : clean clear install

all: install

clean:
	-rm $(BUILD_DIR)/$(BIN) $(BUILD_DIR)/$(CONFIG) $(OBJ) $(DEP)
clear:
	-rm -rf $(BUILD_DIR)

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

# SPECIFIC RULES
iker_martin's avatar
iker_martin committed
51
52
# Default configuration file
$(CONFIG) : $(BUILD_DIR)/$(CONFIG)
53
54
55
# Default target named after the binary.
$(BIN) : $(BUILD_DIR)/$(BIN)

56
$(BUILD_DIR)/$(CONFIG) :
iker_martin's avatar
iker_martin committed
57
	@mkdir -p $(@D)
58
	@ echo -n "dir=\"" > $(BUILD_DIR)/$(CONFIG)
59
	@ realpath -z $$(echo "$$(pwd)/..") | tr -d '\0' >> $(BUILD_DIR)/$(CONFIG)
60
61
	@ echo "\"" >> $(BUILD_DIR)/$(CONFIG)

62
63
# Actual target of the binary - depends on all .o files.
$(BUILD_DIR)/$(BIN) : $(OBJ)
64
	$(MCC) $(C_FLAGS) $^ -o $@ $(LD_FLAGS)
65
66
67
68
69
70
71
72
73
74
75

# 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
iker_martin's avatar
iker_martin committed
76
	@mkdir -p $(@D)
77
	$(MCC) $(C_FLAGS) $(DEF) -MMD -c $< -o $@