-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
64 lines (50 loc) · 1.21 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
# 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)
OBJS=$(C_SRCS:.c=.o)
# 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
.PHONY: all dynamic static clean
all: dynamic
dynamic: dist/$(DYNAMIC_LIB)
dist/$(DYNAMIC_LIB): $(OBJS)
$(CC) -shared -o dist/$(DYNAMIC_LIB) $(OBJS)
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
clean:
$(RM) dist/$(DYNAMIC_LIB) dist/$(STATIC_LIB) $(OBJS)