-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
107 lines (87 loc) · 2.69 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
#
# 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
#
# in case one wants to keep track of the current version and compilation date
# one can use the variables below and append
# `-D_VERSION=\"$(CURRENT_REVISION)\" -D_DATE=\"$(NOW)\"
#
#GIT_VERSION := $(shell git describe --tags)
#CURRENT_REVISION := $(shell git rev-parse --short HEAD)
#NOW := $(shell date +"%FT%T%z")
# Project name
NAME := cans
TARGET := $(NAME)
#PWD=$(shell pwd)
#ROOT_DIR := $(PWD)
#ROOT_DIR := $(shell realpath .)
ROOT_DIR := .
SRCS_DIR := $(ROOT_DIR)/src
APP_DIR := $(ROOT_DIR)/app
EXE_DIR := $(ROOT_DIR)/run
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 := $(SRCS_DIR)/.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)/*-inc.f90 $(SRCS_DIR)/*.h90)
SRCS := $(filter-out $(SRCS_INC), $(wildcard $(SRCS_DIR)/*.f90) $(wildcard $(APP_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 = $(src).o
$(foreach src, $(SRCS), $(eval $(src) := $(obj)))
# Create lists of the build artefacts in this project
OBJS := $(addsuffix .o, $(SRCS))
LIB := $(patsubst %, lib%.a, $(NAME))
DEPS := $(SRCS_DIR)/.depend.mk
# Declare all public targets
.PHONY: all clean allclean libs libsclean run
all: $(EXE)
$(EXE): $(OBJS)
@mkdir -p $(EXE_DIR)/data
$(FC) $(FFLAGS) $^ $(LIBS) $(INCS) -o $(EXE)
run: $(EXE)
@cp $(SRCS_DIR)/dns.in $(EXE_DIR)
@cp $(SRCS_DIR)/cudecomp.in $(EXE_DIR)
@printf "\nDefault input files *.in copied to run folder $(EXE_DIR)\n"
# Create object files from Fortran source
$(OBJS): %.o: %
$(FC) $(FFLAGS) $(CPP) $(DEFINES) $(INCS) $(FFLAGS_MOD_DIR) $(SRCS_DIR) -c -o $@ $<
# Process the Fortran source for module dependencies
$(DEPS):
@echo '# This file contains the module dependencies' > $(DEPS)
@$(foreach file, $(SRCS), $(GD) $(file) >> $(DEPS))
# Define all module interdependencies
-include $(DEPS)
$(foreach dep, $(OBJS), $(eval $(dep): $($(dep))))
# Cleanup, filter to avoid removing source code by accident
clean:
$(RM) $(SRCS_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