-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
116 lines (95 loc) · 3.09 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
#
# ┌────────────────────────────────────────────────────────────────────────────┐
# │ RJH: A fortran project makefile example w/ automated dependency generation │
# (depends fortdepend). │
# └────────────────────────────────────────────────────────────────────────────┘
#
FC := gfortran
FFLAGS := -Wall --std=f2003
LBFLAGS := -O -Wall -fbounds-check -g -Wno-uninitialized
FDEBUG := -g -Wextra -Werror
FRELEASE := -O3
LINKER := $(FC) -o
# In principle linker can have different flags.
# FCLINKS := -g -Wall -Wextra -Werror
ARCH := $(shell uname -m)
BUILD := ./build-$(ARCH)
OBJ_DIR := $(BUILD)/obj
LBFOBJ_DIR := $(BUILD)/lbfobj
APP_DIR := $(BUILD)/bin
DEP_FILE := dependencies.dep
TARGET := main
SRC_DIR := src
SRC := $(wildcard $(SRC_DIR)/*.f03)
LBF_DIR := $(SRC_DIR)/Lbfgsb.3.0
LBF_SRC := $(LBF_DIR)/lbfgsb.f $(LBF_DIR)/linpack.f $(LBF_DIR)/blas.f $(LBF_DIR)/timer.f
OBJ := $(SRC:%.f03=$(OBJ_DIR)/%.o)
LBFOBJ := $(LBF_SRC:%.f=$(LBFOBJ_DIR)/%.o)
.DEFAULT_GOAL := all
MAKEDEPEND := fortdepend
red := $(shell echo "\033[0;31m")
grn := $(shell echo "\033[0;32m")
yel := $(shell echo "\033[0;33m")
blu := $(shell echo "\033[0;34m")
mag := $(shell echo "\033[0;35m")
cya := $(shell echo "\033[0;36m")
noc := $(shell echo "\033[0m")
.PHONY: all clean vclean remake dep lbfgsb
# Make and include dependencies file.
dep : $(DEP_FILE)
# Dependencies.
$(DEP_FILE) : $(SRC)
@echo -n "$(cya)"
@echo "[D] Running fortdepend on source files (outputting to $@)."
$(MAKEDEPEND) -w -f $(SRC) -b $(OBJ_DIR) -o $@
@echo -n "$(noc)"
# Don't try to generate depends file if we're clean or vclean.
ifneq ($(MAKECMDGOALS), clean)
ifneq ($(MAKECMDGOALS), vclean)
-include $(DEP_FILE)
endif
endif
# Make all.
all: $(APP_DIR)/$(TARGET) dep
lbfgsb: $(LBFOBJ)
debug: FFLAGS += $(FDEBUG)
debug: TARGET += _DEBUG
debug: all
release: FFLAGS += $(FRELEASE)
release: all
# Objects.
$(OBJ_DIR)/%.o : %.f03
@echo -n "$(grn)"
@echo "[O] Making $@ from $< in $(@D)."
@mkdir -p $(@D)
$(FC) $(FFLAGS) -c $< -o $@ -J$(OBJ_DIR)
@echo -n "$(noc)"
$(LBFOBJ_DIR)/%.o : %.f
@echo -n "$(grn)"
@echo "[O] [LEGACY LBFGSB CODE] Making $@ from $< in $(@D)."
@mkdir -p $(@D)
$(FC) $(LBFLAGS) -c $< -o $@ -J$(LBFOBJ_DIR)
@echo -n "$(noc)"
# Linking objects/mods to target.
$(APP_DIR)/$(TARGET) : $(OBJ) $(LBFOBJ)
@echo -n "$(blu)"
@echo "[T] Making $@ from $< in $(@D)."
@mkdir -p $(@D)
$(LINKER) $@ $(OBJ) $(LBFOBJ) $(FFLAGS) -J$(OBJ_DIR)
@echo -n "$(noc)"
# Clean objects/mods.
clean :
@echo -n "$(yel)"
-@rm -rvf $(OBJ_DIR)
-@rm -rvf $(LBFOBJ_DIR)
-@rm iterate.dat
@echo -n "$(noc)"
# Clean everything.
vclean : clean
@echo -n "$(red)"
-@rm -rvf $(BUILD)
-@rm -rvf $(DEP_FILE)
-@rm -rvf valgrind-out.txt
@echo -n "$(noc)"
# vclean, redo.
remake : vclean all