-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile_example
107 lines (67 loc) · 1.8 KB
/
Makefile_example
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
target := test
main := test
gpp := /usr/bin/g++
shared_lib := testLib
INC :=
LIBS :=
sources = A.cpp B.cpp C.cpp
#topdir := .
#topdir := src
#sources := $(shell find $(topdir) -name "*.cpp" ! -path "$(topdir)/$(main).cpp")
opt ?= -O3
dbg ?=
warn ?= -Wall #-Werror
cppflags := $(opt) $(dbg) $(warn) -fPIC -fopenmp
A_INC = -I/A_DIR/INC
INC += $(A_INC)
#mkl lib
INTL_DIR = /intel_dir
INTL_LIB_DIR = $(INTL_DIR)/compiler/lib/intel64_lin
MKL_DIR = $(INTL_DIR)/mkl
MKL_INC = -I$(MKL_DIR)/include
MKL_LIB_DIR = $(MKL_DIR)/lib/intel64_lin
MKL_LIB = -Wl,-rpath,$(INTL_LIB_DIR) -L$(INTL_LIB_DIR) -liomp5 -Wl,-rpath,$(MKL_LIB_DIR) -L$(MKL_LIB_DIR) -lmkl_core -lmkl_gnu_thread -lmkl_intel_lp64
INC += $(MKL_INC)
LIBS += $(MKL_LIB)
# gcc lib
gpp_lib = /gcc_lib
LIBS += -Wl,-rpath,$(gpp_lib)
cppflags += $(INC)
all : $(target)
$(target): lib$(shared_lib).so $(main).o
@echo "generating binary...$(target)"
$(gpp) $(main).o -o $(target) -Bdynamic $(INC) $(LIBS) -Wl,-rpath,. -L. -l$(shared_lib) -fopenmp
objects := $(patsubst %.cpp,%.o,$(sources))
lib$(shared_lib).so : $(objects)
@echo "showing all objs: " $(objects)
@echo "linking shared lib $(shared_lib)..."
$(gpp) -shared $(objects) $(INC) $(LIBS) -o $@
@echo "shared lib generated."
%.o: %.cpp
$(gpp) -c $^ $(cppflags) -o $@
clean:
rm -f *.o *.so $(target) makefile.*dep
#----- Dependency Generation -----
#
# If a particular set of sources is non-empty, then have rules for
# generating the necessary dep files.
#
ccdep := ccdep.mk
cdep := cdep.mk
depfiles =
ifneq ($(ccsources),)
depfiles += $(ccdep)
$(ccdep): $(ccsources)
$(gpp) -MM $(ccsources) > $(ccdep)
else
$(ccdep):
endif
ifneq ($(csources),)
depfiles += $(cdep)
$(cdep): $(csources)
$(gcc) -MM -x c $(csources) > $(cdep)
else
$(cdep):
endif
.PHONY: dep
dep: $(depfiles)