Makefile 1.65 KB
Newer Older
1
2
CC = gcc
MCC = mpicc
3
#C_FLAGS_ALL = -Wconversion -Wpedantic
4
C_FLAGS = -Wall -Wextra -Wshadow -Wfatal-errors
5
6
LD_FLAGS = -lm -pthread
DEF =
7

8
9

.PHONY : clean clear install install_slurm
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

# Final binary
BIN = a.out
# 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)

# Actual target of the binary - depends on all .o files.
$(BUILD_DIR)/$(BIN) : $(OBJ)
32
	$(MCC) $(C_FLAGS) $^ -o $@ $(LD_FLAGS)
33
34
35
	@ echo -n "dir=\"" > $(BUILD_DIR)/config.txt
	@ realpath -z $$(echo "$$(pwd)/..") >> $(BUILD_DIR)/config.txt
	@ echo "\"" >> $(BUILD_DIR)/config.txt
36
37
38
39
40
41
42
43
44
45
46
47

# 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)
48
	$(MCC) $(C_FLAGS) $(DEF) -MMD -c $< -o $@
49
50

clean:
51
	-rm $(BUILD_DIR)/$(BIN) $(BUILD_DIR)/config.txt $(OBJ) $(DEP)
52
53
clear:
	-rm -rf $(BUILDDIR)
54

55

56
57
58
59
60
61
62
install: $(BIN)
	echo "Done"

# Builds target with slurm
install_slurm: LD_FLAGS += -lslurm
install_slurm: DEF += -DUSE_SLURM
install_slurm: install