-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
146 lines (109 loc) · 4.02 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
140
141
142
143
144
145
146
# ---------------------------------------------------------------------
# CONFIGURATION
ifneq ($(prefix), )
install_dir=$(prefix)
else
install_dir=$(DEFAULT_INSTALL_DIR)
endif
ifneq ($(type), )
btype=$(type)
else
btype=release
endif
PY=python
GEN=./scripts/saw/gen_src.py
GEN_ICE=./scripts/ice/gen_src.py
GEN_NAW=./scripts/naw/gen_src.py
GEN_PTE=./scripts/pte/gen_src.py
SRC_FYPP=$(wildcard *.fypp)
SRC_FYPP_F90=$(patsubst %.fypp, %.f90, $(SRC_FYPP))
F_MODULE = ./src/ciaaw_saw.f90 ./src/ciaaw_ice.f90 ./src/ciaaw_naw.f90 ./src/ciaaw_pte.f90
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# TARGETS
.PHONY: build data sources doc docs clean logo
all: $(LIBNAME)
$(LIBNAME): build copy_a shared
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# SOURCES
sources: $(SRC_FYPP_F90) $(F_MODULE)
./src/ciaaw_saw.f90: ./data/saw_2021.toml
$(PY) $(GEN) $< $@
./src/ciaaw_ice.f90: ./data/ice_2013.toml
$(PY) $(GEN_ICE) $< $@
./src/ciaaw_naw.f90: ./data/naw_2020.toml
$(PY) $(GEN_NAW) $< $@
./src/ciaaw_pte.f90: ./data/saw_2021.toml ./data/ice_2013.toml
$(PY) $(GEN_PTE) $^ $@
./src/%.f90: ./src/%.fypp
fypp -I ../include $< $@
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# COMPILATION
build:
fpm build --profile=$(btype)
test: build
fpm test --profile=$(btype)
example: build
fpm run --profile=$(btype) --example example_in_f
fpm run --profile=$(btype) --example example_in_c
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# LINKING - STATIC and DYNAMIC LIBS
copy_a:
cp -f $(shell find ./build/gfortran* -type f -name $(LIBNAME).a) $(BUILD_DIR)
shared: shared_$(PLATFORM)
shared_linux:
$(FC) -shared -o $(BUILD_DIR)/$(LIBNAME).so -Wl,--whole-archive $(BUILD_DIR)/$(LIBNAME).a -Wl,--no-whole-archive
shared_darwin:
$(FC) -dynamiclib -install_name @rpath/$(LIBNAME).dylib $(FPM_LDFLAGS) -o $(BUILD_DIR)/$(LIBNAME).dylib -Wl,-all_load $(BUILD_DIR)/$(LIBNAME).a
shared_windows:
$(FC) -shared $(FPM_LDFLAGS) -o $(BUILD_DIR)/$(LIBNAME).dll -Wl,--out-implib=$(BUILD_DIR)/$(LIBNAME).dll.a,--export-all-symbols,--enable-auto-import,--whole-archive $(BUILD_DIR)/$(LIBNAME).a -Wl,--no-whole-archive
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# INSTALLATION
install: install_dirs install_$(PLATFORM)
install_dirs:
mkdir -p $(install_dir)/bin
mkdir -p $(install_dir)/include
mkdir -p $(install_dir)/lib
fpm install --prefix=$(install_dir) --profile=$(btype)
cp -f $(INCLUDE_DIR)/$(NAME)*.h $(install_dir)/include
install_linux:
cp -f $(BUILD_DIR)/$(LIBNAME).so $(install_dir)/lib
install_darwin:
cp -f $(BUILD_DIR)/$(LIBNAME).dylib $(install_dir)/lib
install_windows:
cp -f $(BUILD_DIR)/$(LIBNAME).dll.a $(install_dir)/lib
cp -f $(BUILD_DIR)/$(LIBNAME).dll $(install_dir)/lib
cp -f $(BUILD_DIR)/$(LIBNAME).dll $(install_dir)/bin
uninstall:
rm -f $(install_dir)/include/$(NAME)*.h
rm -f $(install_dir)/include/$(NAME)*.mod
rm -f $(install_dir)/lib/$(LIBNAME).a
rm -f $(install_dir)/lib/$(LIBNAME).so
rm -f $(install_dir)/lib/$(LIBNAME).dylib
rm -f $(install_dir)/lib/$(LIBNAME).dll.a
rm -f $(install_dir)/lib/$(LIBNAME).dll
rm -f $(install_dir)/bin/$(LIBNAME).dll
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# OTHERS
doc:
ford API-doc-FORD-file.md
docs:
rm -rf docs/*
cp -rf API-doc/* docs/
logo:
make -C media
clean:
make -C data clean
rm -rf $(F_MODULE) $(SRC_FYPP_F90)
make -C py clean
fpm clean --all
rm -rf API-doc/*
py: $(LIBNAME)
make install prefix=py/src/py$(NAME)
make -C py
# ---------------------------------------------------------------------