-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
139 lines (110 loc) · 3.96 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# NOTE, for the pkg-config you might require to add yours in the path variable
# export PKG_CONFIG_PATH="/usr/lib64/pkgconfig:$PKG_CONFIG_PATH"
# REPORT
REPORT_TYPE := long
# DOCKER
DOCKER_TAG :=
# LIBRARIES
LIBRARIES := sqlite3 check
LINKING_LIBRARIES :=
# COMPILER
CC := mpicc # compiler
CPPFLAGS := -O3 -Iinclude -lm -MMD -MP $(foreach pkg, ${LIBRARIES}, $(shell pkg-config --cflags ${pkg})) # preprocessor flags
CFLAGS := -O3 -fopenmp -g -Wall -lm # compiler flags
LDFLAGS := -O3 -fopenmp -Llib -lm # linker flags
LDLIBS := $(foreach pkg, ${LIBRARIES}, $(shell pkg-config --libs ${pkg}))
TESTFLAGS := -lcheck
# DOXYGEN
DOXYGEN := doxygen
DOXYGEN_CONF := -w html
DOXYFILE := Doxyfile
DOXYGEN_INDEX := html/index.html
# STANDARD DIRECTORIES
SRC_DIR := src
TEST_DIR := tests
DIRS := $(notdir $(wildcard $(SRC_DIR)/*))
OBJ_DIR := obj
BIN_DIR := bin
INC_DIR := include
DOC_DIR := docs
# TARGET
TARGET := $(BIN_DIR)/particle-swarm-optimization
TEST_TARGET := $(BIN_DIR)/test
# FILES
SRC := $(shell find $(SRC_DIR) -name '*.c')
TESTS := $(shell find $(TEST_DIR) -name '*.c')
OBJ := $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC))
TEST_OBJ := $(patsubst $(TEST_DIR)/%.c, $(OBJ_DIR)/%.o, $(TESTS)) $(filter-out $(OBJ_DIR)/main.o,$(OBJ))
DEPS := $(wildcard $(INC_DIR)/*.h)
# COMMANDS
MKDIR := mkdir -p
RM := rm
ECHO := echo -e
OPEN := xdg-open
# COLORS
RED := \033[31m
GREEN := \033[32m
YELLOW := \033[33m
BLUE := \033[34m
NONE := \033[0m
# RULES
# all
all: clean test build
# phony: not targets
.PHONY: all clean help test build report
build: $(TARGET)
test: $(TEST_TARGET)
# building target, dealing with the linking phase, the compiling is over
$(TARGET): $(OBJ) | $(BIN_DIR)
@$(ECHO) "$(GREEN)Program compiled successfully$(NONE)";
@$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ -lm $(LINKING_LIBRARIES)
@$(ECHO) "$(GREEN)Program linked successfully$(NONE)";
# building objects
$(OBJ_DIR)/%.o: $(TEST_DIR)/%.c $(DEPS) | $(OBJ_DIR)
@$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(DEPS) | $(OBJ_DIR)
@$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
# create object folder if not present yet
$(BIN_DIR) $(OBJ_DIR):
@$(MKDIR) $@
@$(foreach dir,$(DIRS),$(MKDIR) $@/$(dir);)
$(TEST_TARGET): $(TEST_OBJ) | $(BIN_DIR)
@$(ECHO) "$(GREEN)Program compiled successfully for tests$(NONE)";
@$(CC) $(LDFLAGS) $^ $(LDLIBS) $(TESTFLAGS) -o $@ -lm $(LINKING_LIBRARIES)
@$(ECHO) "$(GREEN)Program linked successfully for tests$(NONE)";
@$(TEST_TARGET)
clean:
@$(RM) -rf $(BIN_DIR) $(OBJ_DIR) $(TEST_OBJ_DIR)
@$(ECHO) "$(YELLOW)Artifacts cleaned successfully$(NONE)";
doc:
@$(MKDIR) $(DOC_DIR)
@$(DOXYGEN) $(DOXYFILE) $(DOXYGEN_CONF)
report:
@./scripts/generate_report.sh --$(REPORT_TYPE)
slides:
@./scripts/generate_slides.sh
cluster-run:
@./scripts/generate_cluster_runs.sh
cluster-pull:
@./scripts/build.sh --cluster
cluster-clear:
@qstat -u $USER | tail -n +6 | awk -F' ' '{print $1}' | awk -F '.' '{print $1}' | xargs qdel
docker-build:
@./scripts/build.sh $(DOCKER_TAG)
open-doc:
@$(OPEN) $(DOC_DIR)/$(DOXYGEN_INDEX)
help:
@$(ECHO) "$(BLUE)Makefile help\n \
* build : compiles the program and creates the object files and the executable files\n \
* test : compiles tests and creates the object files and the executable test files\n \
* clean : removes all the object and binary files\n \
* doc : generates the code documentation in HTML\n \
* report : generates pdf report\n \
* slides : generates pdf presentation\n \
* cluster-run : launches multiple qsub runs\n \
* cluster-pull : pulls latest udocker container\n \
* cluster-clear : deletes all submitted jobs\n \
* docker-build : builds latest docker container\n \
* open-doc : compiles and then opens the HTML documentation\n \
* all : clean and then compiles$(NONE)";
-include $(OBJ:.o=.d) # The dash is used to silence errors if the files don't exist yet