-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
103 lines (82 loc) · 2.29 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
CC ?= mpicc
CFLAGS ?= -Wall -Wextra -Wpedantic -Wno-unused-function -Wno-unused-parameter -std=c99 -g
LDFLAGS ?=
DEBUG ?= 0
UNDERSCORE ?= 1
SYNC_BY_REDUCTION ?= 1
BLAS ?= 0
BLASDIR ?=
BLASFLAGS ?= -lblas -llapack
GSLIBPATH ?=
########################## Don't touch what follows ###########################
ifeq ($(GSLIBPATH),)
$(error Specify GSLIBPATH=<path to gslib build>)
endif
MKFILEPATH := $(abspath $(lastword $(MAKEFILE_LIST)))
SRCROOT := $(realpath $(patsubst %/,%,$(dir $(MKFILEPATH))))
SRCDIR = $(SRCROOT)/src
EXAMPLEDIR = $(SRCROOT)/examples
BUILDROOT = $(SRCROOT)/build
ifneq (,$(strip $(DESTDIR)))
INSTALLROOT = $(DESTDIR)
else
INSTALLROOT = $(SRCROOT)/install
endif
SRCS = $(wildcard $(SRCDIR)/*.c)
SRCOBJS = $(patsubst $(SRCROOT)/%.c,$(BUILDROOT)/%.o,$(SRCS))
EXAMPLES = $(wildcard $(EXAMPLEDIR)/*.c)
EXAMPLEBINS = $(patsubst $(SRCROOT)/%.c,$(BUILDROOT)/%,$(EXAMPLES))
LIB = $(BUILDROOT)/lib/libparRSB.a
ifneq ($(DEBUG),0)
PP += -DPARRSB_DEBUG
CFLAGS += -g
else
CFLAGS += -O2
endif
PP += -DPARRSB_MPI
ifneq ($(UNDERSCORE),0)
PP += -DPARRSB_UNDERSCORE
endif
ifneq ($(SYNC_BY_REDUCTION),0)
PP += -DPARRSB_SYNC_BY_REDUCTION
endif
ifneq ($(BLAS),0)
PP += -DPARRSB_BLAS
ifneq ($(BLASDIR),)
LDFLAGS+= -L$(BLASDIR)
endif
LDFLAGS += $(BLASFLAGS)
endif
INCFLAGS = -I$(SRCDIR) -I$(GSLIBPATH)/include
CCCMD = $(CC) $(CFLAGS) $(INCFLAGS) $(PP)
LDFLAGS += -lm
.PHONY: all lib install examples format clean
all: lib install examples
lib: $(SRCOBJS)
@mkdir -p $(BUILDROOT)/lib
@$(AR) cr $(LIB) $?
@ranlib $(LIB)
install: lib
@mkdir -p $(INSTALLROOT)/lib 2>/dev/null
@cp -v $(LIB) $(INSTALLROOT)/lib 2>/dev/null
@mkdir -p $(INSTALLROOT)/include 2>/dev/null
@cp $(SRCDIR)/*.h $(INSTALLROOT)/include 2>/dev/null
examples: lib install $(EXAMPLEBINS)
format:
find . -iname *.h -o -iname *.c -o -iname *.okl | xargs clang-format -i
clean:
@$(RM) -rf $(BUILDROOT)
print-%:
$(info [ variable name]: $*)
$(info [ origin]: $(origin $*))
$(info [ value]: $(value $*))
$(info [expanded value]: $($*))
$(info)
@true
$(BUILDROOT)/%.o: $(SRCROOT)/%.c
$(CCCMD) -c $< -o $@
$(BUILDROOT)/%: $(SRCROOT)/%.c | lib install
$(CCCMD) $< -o $@ -L$(INSTALLROOT)/lib -lparRSB -L$(GSLIBPATH)/lib -lgs \
$(LDFLAGS)
$(shell mkdir -p $(BUILDROOT)/examples)
$(shell mkdir -p $(BUILDROOT)/src)