-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
78 lines (61 loc) · 1.74 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
.POSIX:
.SUFFIXES:
.PHONY: all static shared test clean
FC := gfortran
FFLAGS := -O2
AR := ar
ARFLAGS := rcs
NAME := version-f
STATIC := lib$(NAME).a
ifeq ($(shell uname), Linux)
SHARED := lib$(NAME).so
LDFLAGS := -Wl,-rpath=.
else ifeq ($(shell uname), Darwin)
SHARED := lib$(NAME).dylib
endif
SRCDIR := src
TESTDIR := test
EXMPLDIR := example
BUILDDIR := build/Makefile
MODDIR := $(BUILDDIR)/mod
OBJDIR := $(BUILDDIR)/obj
EXEDIR := $(BUILDDIR)/exe
SRCS := $(wildcard $(SRCDIR)/*.f90)
OBJS := $(patsubst $(SRCDIR)/%.f90,$(OBJDIR)/%.o,$(SRCS))
EXESRCS := $(foreach dir,$(TESTDIR) $(EXMPLDIR),$(wildcard $(dir)/*.f90))
EXESSTATIC := $(patsubst %.f90,$(EXEDIR)/%_static.out,$(notdir $(EXESRCS)))
EXESSHARED := $(patsubst %.f90,$(EXEDIR)/%_shared.out,$(notdir $(EXESRCS)))
ifeq ($(FC),gfortran)
MODIN := -I$(MODDIR)
MODOUT := -J$(MODDIR)
else
MODIN := -module $(MODDIR)
MODOUT := $(MODIN)
endif
all: $(STATIC) $(SHARED)
static: $(STATIC)
shared: $(SHARED)
$(OBJDIR)/%.o: $(SRCDIR)/%.f90
mkdir -p $(MODDIR) $(OBJDIR)
$(FC) $(FFLAGS) $(MODOUT) -c $< -o $@
$(STATIC): $(OBJS)
$(AR) $(ARFLAGS) $@ $<
$(SHARED): $(SRCS)
mkdir -p $(MODDIR)
$(FC) $(FFLAGS) -fpic -shared $(MODOUT) -o $@ $<
$(EXEDIR):
mkdir -p $(EXEDIR)
$(EXEDIR)/%_static.out: $(TESTDIR)/%.f90 $(STATIC) | $(EXEDIR)
$(FC) $(FFLAGS) $(MODIN) -o $@ $^
$(EXEDIR)/%_static.out: $(EXMPLDIR)/%.f90 $(STATIC) | $(EXEDIR)
$(FC) $(FFLAGS) $(MODIN) -o $@ $^
$(EXEDIR)/%_shared.out: $(TESTDIR)/%.f90 $(SHARED) | $(EXEDIR)
$(FC) $(FFLAGS) $(MODIN) -o $@ $^ $(LDFLAGS)
$(EXEDIR)/%_shared.out: $(EXMPLDIR)/%.f90 $(SHARED) | $(EXEDIR)
$(FC) $(FFLAGS) $(MODIN) -o $@ $^ $(LDFLAGS)
test: $(EXESSTATIC) $(EXESSHARED)
@for f in $^; do $$f; done
clean:
rm -rf $(BUILDDIR)
rm -f $(STATIC)
rm -f $(SHARED)