-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMakefile
More file actions
108 lines (89 loc) · 2.99 KB
/
Copy pathMakefile
File metadata and controls
108 lines (89 loc) · 2.99 KB
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
#
# adapted from: https://fortran-lang.org/learn/building_programs/project_make
#
# Disable the default rules
.SUFFIXES:
MAKEFLAGS += --no-builtin-rules --no-builtin-variables
SHELL=/bin/bash
# Project name
NAME := cales
TARGET := $(NAME)
INPUT_FILE := input.nml
ROOT_DIR := .
SRCS_DIR := $(ROOT_DIR)/src
BUILD_DIR := $(ROOT_DIR)/build
EXE_DIR := $(BUILD_DIR)
CONFIG_DIR := $(ROOT_DIR)/configs
LIBS_DIR := $(ROOT_DIR)/dependencies
LIBS :=
INCS :=
DEFINES :=
EXE := $(EXE_DIR)/$(TARGET)
# Configuration settings
FC := mpifort
FFLAGS :=
AR := ar rcs
LD := $(FC)
RM := rm -f
GD := $(ROOT_DIR)/src/.gen-deps.awk
CPP := -cpp
# Edit build.conf file desired
-include $(ROOT_DIR)/build.conf
-include $(CONFIG_DIR)/compilers.mk
-include $(CONFIG_DIR)/flags.mk
-include $(CONFIG_DIR)/libs.mk
# List of all source files
SRCS_INC := $(wildcard $(SRCS_DIR)/*.h90)
SRCS := $(filter-out $(SRCS_INC), $(wildcard $(SRCS_DIR)/*.f90))
# Add source directory to search paths
vpath % .:$(SRCS_DIR)
vpath % $(patsubst -I%,%,$(filter -I%,$(INCS)))
# Define a map from each file name to its object file
obj = $(BUILD_DIR)/$(notdir $(src)).o
$(foreach src, $(SRCS), $(eval $(src) := $(obj)))
# Create lists of the build artefacts in this project
OBJS := $(patsubst $(SRCS_DIR)/%, $(BUILD_DIR)/%.o, $(SRCS))
DEPS := $(BUILD_DIR)/.depend.mk
# Declare all public targets
.PHONY: all clean allclean libs libsclean
all: $(EXE)
$(EXE): $(OBJS)
$(FC) $(FFLAGS) $^ $(LIBS) $(INCS) -o $(EXE)
# Create object files from Fortran source
$(OBJS): $(BUILD_DIR)/%.o: $(SRCS_DIR)/%
$(FC) $(FFLAGS) $(CPP) $(DEFINES) $(INCS) $(FFLAGS_MOD_DIR) $(BUILD_DIR) -c -o $@ $<
# Process the Fortran source for module dependencies
# Create the build directory automatically if missing
$(DEPS):
@mkdir -p $(BUILD_DIR)
@echo '# This file contains the module dependencies' > $(DEPS)
@$(foreach file, $(SRCS), $(GD) $(file) >> $(DEPS))
# Define all module interdependencies
ifneq ($(filter clean libsclean allclean,$(MAKECMDGOALS)),)
else
-include $(DEPS)
endif
$(foreach dep, $(OBJS), $(eval $(dep): $($(dep))))
# Cleanup, filter to avoid removing source code by accident
clean:
$(RM) $(BUILD_DIR)/*.{i,mod,smod,d,o} $(EXE) $(DEPS)
allclean:
@make libsclean
@make clean
#
# rules for building the external libraries (compile with 'make libs'):
#
include $(LIBS_DIR)/external.mk
# Rules to generate config files if missing
$(CONFIG_DIR)/compilers.mk:
@echo "Generating $(CONFIG_DIR)/compilers.mk from $(CONFIG_DIR)/compilers.mk.example..."
cp $(CONFIG_DIR)/compilers.mk.example $(CONFIG_DIR)/compilers.mk
$(CONFIG_DIR)/flags.mk:
@echo "Generating $(CONFIG_DIR)/flags.mk from $(CONFIG_DIR)/flags.mk.example..."
cp $(CONFIG_DIR)/flags.mk.example $(CONFIG_DIR)/flags.mk
$(CONFIG_DIR)/libs.mk:
@echo "Generating $(CONFIG_DIR)/libs.mk from $(CONFIG_DIR)/libs.mk.example..."
cp $(CONFIG_DIR)/libs.mk.example $(CONFIG_DIR)/libs.mk
$(ROOT_DIR)/build.conf:
@echo "Generating $(ROOT_DIR)/build.conf from $(ROOT_DIR)/build.conf.example..."
cp $(ROOT_DIR)/build.conf.example $(ROOT_DIR)/build.conf