-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·80 lines (68 loc) · 2.49 KB
/
Makefile
File metadata and controls
executable file
·80 lines (68 loc) · 2.49 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
#####################################
# Makefile to compile Telemac tools #
#####################################
#
# Usage:
# * `make` or `make all`: compile main fortran files
# * `make clean`: remove intermediate files
# * `make mrproper`: remove all generated files
#
# Info:
# - Requires gfortran
# - File organisation:
# * ./bin/ main program binaries (compiled files)
# * ./lib/ subroutines dependencies (are compiled but not linked)
# * ./mod/ modules dependencies (are compiled but not linked)
# * ./src/ main program sources
#
# Warning:
# for a complete compatibility, compilation with Fortran 2003 standard is required.
#
# Problem/todo:
# * compilation is not optimal:
# Everything is compiled with the whole list of `lib ` files (even if they are not used/required)
# As a workaround, the `strip``tool is used to purge binary files
# * The use of `stip` is not compatible with code profiling, because symbols are removed for debugging.
# * Some files (such as .mod files) are invisible for the Makefile but they are built at compilation
#
## COMPILER (/!\ options: -o and -c are used)
### gfortran
FC = gfortran
FFLAGS_ORI = -ffixed-line-length-132
FFLAGS = $(FFLAGS_ORI) -Wall
#FFLAGS = $(FFLAGS_ORI) -g -fbacktrace #debug (remove set strip to `false`)
STRIP = true #false
## FILES/FOLDER STRUCTURE
LIB_FOLDER = lib
LIB_OBJ = $(patsubst %.f, %.o, $(wildcard $(LIB_FOLDER)/*.f))
MOD_FOLDER = mod
MOD_OBJ = $(MOD_FOLDER)/common_data.o $(patsubst %.f, %.o, $(wildcard $(MOD_FOLDER)/*.f)) #FIXME: common_data.o est dupliqué
BIN_FOLDER = bin
BIN_OBJ = $(patsubst src/%.f, bin/%, $(wildcard src/*.f))
.PHONY: bin createfolder clean mrproper
.PRECIOUS: %.o
# Create BIN_FOLDER and compile all main programs
bin: createfolder $(BIN_OBJ) clean
createfolder:
mkdir -p $(BIN_FOLDER)
# Compile and link main program without warnings (src/*_ori.f -> bin)
bin/%_ori: $(LIB_OBJ) src/%_ori.f
$(FC) $(FFLAGS_ORI) $^ -o $@
# Compile and link main program with warnings (src -> bin)
bin/%: $(LIB_OBJ) $(MOD_OBJ) src/%.f
$(FC) $(FFLAGS) $^ -o $@
ifeq ($(STRIP),true)
strip $@
endif
# Compile an individual file (lib)
$(LIB_FOLDER)/%.o: $(LIB_FOLDER)/%.f
$(FC) $(FFLAGS) -c $^ -o $@
# Compile an individual file (mod)
#FIXME: position of mod files is compiler dependant?
$(MOD_FOLDER)/%.o %.mod: $(LIB_FOLDER)/%.f
$(FC) $(FFLAGS) -c $^ -o $@
clean :
find -name '*.o' -delete
find -name '*.mod' -delete
mrproper: clean
rm -rf $(BIN_FOLDER)