-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
116 lines (96 loc) · 2.46 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
# Detect system OS.
ifeq ($(OS),Windows_NT)
detected_OS := Windows
else
detected_OS := $(shell sh -c 'uname -s 2>/dev/null || echo not')
endif
C_SRCS=$(shell find src -name *.c)
CXX_SRCS=$(shell find src -type f -name *.cc -o -name *.cpp -o -name *.cxx)
CXX_OBJS=$(CXX_SRCS:.cc=.o)
CXX_OBJS_1=$(CXX_OBJS:.cpp=.o)
CXX_OBJS_2=$(CXX_OBJS_1:.cxx=.o)
OBJS=$(C_SRCS:.c=.o)
OBJS+=$(CXX_OBJS_2)
# Use libstdc++ in CC
ifneq (,$(CXX_SRCS))
LIBCXX=-lstdc++
endif
ifneq (,$(OBJCXX_SRCS))
LIBCXX=-lstdc++
endif
# Modify the executable name by yourself.
ifeq (,$(LIBRARY))
LIBRARY=libalgebra
endif
ifeq ($(detected_OS),Windows)
DYNAMIC_LIB=$(LIBRARY).dll
else
ifeq ($(detected_OS),Darwin)
DYNAMIC_LIB=$(LIBRARY).dylib
else
DYNAMIC_LIB=$(LIBRARY).so
endif # Darwin
endif # Windows
STATIC_LIB=$(LIBRARY).a
# Set the C standard.
ifeq (,$(C_STD))
C_STD=c11
endif
# Set the C++ standard.
ifeq (,$(CXX_STD))
CXX_STD=c++17
endif
.PHONY: all dynamic static clean
all: dynamic
dynamic: dist/$(DYNAMIC_LIB)
dist/$(DYNAMIC_LIB): $(OBJS)
$(CC) -shared -o dist/$(DYNAMIC_LIB) $(OBJS) $(LIBCXX)
static: dist/$(STATIC_LIB)
dist/$(STATIC_LIB): $(OBJS)
ifeq ($(detected_OS),Darwin)
libtool -o dist/$(STATIC_LIB) $(OBJS)
else
$(AR) rcs -o dist/$(STATIC_LIB) $(OBJS)
endif
%.o:%.c
ifeq (,$(MAKECMDGOALS))
$(CC) -fPIC -std=$(C_STD) -c $< -o $@ $(CFLAGS) -I include
else
ifeq (dynamic,$(MAKECMDGOALS))
$(CC) -fPIC -std=$(C_STD) -c $< -o $@ $(CFLAGS) -I include
else
$(CC) -std=$(C_STD) -c $< -o $@ $(CFLAGS) -I include
endif # make dynamic
endif # make
%.o:%.cc
ifeq (,$(MAKECMDGOALS))
$(CXX) -fPIC -std=$(CXX_STD) -c $< -o $@ $(CXXFLAGS) -I include
else
ifeq (dynamic,$(MAKECMDGOALS))
$(CXX) -fPIC -std=$(CXX_STD) -c $< -o $@ $(CXXFLAGS) -I include
else
$(CXX) -std=$(CXX_STD) -c $< -o $@ $(CXXFLAGS) -I include
endif # make dynamic
endif # make
%.o:%.cpp
ifeq (,$(MAKECMDGOALS))
$(CXX) -fPIC -std=$(CXX_STD) -c $< -o $@ $(CXXFLAGS) -I include
else
ifeq (dynamic,$(MAKECMDGOALS))
$(CXX) -fPIC -std=$(CXX_STD) -c $< -o $@ $(CXXFLAGS) -I include
else
$(CXX) -std=$(CXX_STD) -c $< -o $@ $(CXXFLAGS) -I include
endif # make dynamic
endif # make
%.o:%.cxx
ifeq (,$(MAKECMDGOALS))
$(CXX) -fPIC -std=$(CXX_STD) -c $< -o $@ $(CXXFLAGS) -I include
else
ifeq (dynamic,$(MAKECMDGOALS))
$(CXX) -fPIC -std=$(CXX_STD) -c $< -o $@ $(CXXFLAGS) -I include
else
$(CXX) -std=$(CXX_STD) -c $< -o $@ $(CXXFLAGS) -I include
endif # make dynamic
endif # make
clean:
$(RM) dist/$(DYNAMIC_LIB) dist/$(STATIC_LIB) $(OBJS)