forked from orangeduck/Cello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
108 lines (74 loc) · 2.11 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
CC ?= gcc
AR ?= ar
VERSION = 1.1.7
PACKAGE = libCello-$(VERSION)
BINDIR = ${PREFIX}/bin
INCDIR = ${PREFIX}/include
LIBDIR = ${PREFIX}/lib
SRC := $(wildcard src/*.c)
OBJ := $(addprefix obj/,$(notdir $(SRC:.c=.o)))
TESTS := $(wildcard tests/*.c)
TESTS_OBJ := $(addprefix obj/,$(notdir $(TESTS:.c=.o)))
DEMOS := $(wildcard demos/*.c)
DEMOS_OBJ := $(addprefix obj/,$(notdir $(DEMOS:.c=.o)))
DEMOS_EXE := $(DEMOS:.c=)
CFLAGS = -I ./include -std=gnu99 -Wall -Werror -Wno-unused -O3 -g
LFLAGS = -shared -g -ggdb
PLATFORM := $(shell uname)
COMPILER := $(shell $(CC) -v 2>&1 )
ifeq ($(findstring MINGW,$(PLATFORM)),MINGW)
PREFIX ?= C:/MinGW64/x86_64-w64-mingw32
DYNAMIC = libCello.dll
STATIC = libCello.a
LIBS =
INSTALL_LIB = cp $(STATIC) $(LIBDIR)/$(STATIC); cp $(DYNAMIC) $(BINDIR)/$(DYNAMIC)
INSTALL_INC = cp -r include/* $(INCDIR)
else
PREFIX ?= /usr/local
DYNAMIC = libCello.so
STATIC = libCello.a
LIBS = -lpthread -ldl -lm
CFLAGS += -fPIC
INSTALL_LIB = mkdir -p ${LIBDIR} && cp -f ${STATIC} ${LIBDIR}/$(STATIC)
INSTALL_INC = mkdir -p ${INCDIR} && cp -r include/* ${INCDIR}
endif
ifeq ($(findstring clang,$(COMPILER)),clang)
CFLAGS += -fblocks
ifneq ($(findstring Darwin,$(PLATFORM)),Darwin)
LIBS += -lBlocksRuntime
endif
endif
# Libraries
all: $(DYNAMIC) $(STATIC)
$(DYNAMIC): $(OBJ)
$(CC) $(OBJ) $(LFLAGS) -o $@
$(STATIC): $(OBJ)
$(AR) rcs $@ $(OBJ)
obj/%.o: src/%.c | obj
$(CC) $< -c $(CFLAGS) -o $@
obj:
mkdir -p obj
# Tests
check: $(TESTS_OBJ) $(STATIC)
$(CC) $(TESTS_OBJ) $(STATIC) $(LIBS) -o test
./test
obj/%.o: tests/%.c | obj
$(CC) $< -c $(CFLAGS) -o $@
# Demos
demos: $(DEMOS_EXE)
demos/%: demos/%.c $(STATIC) | obj
$(CC) $< $(STATIC) $(CFLAGS) $(LIBS) -o $@
# Dist
dist: all | $(PACKAGE)
cp -R demos include src tests INSTALL.md LICENSE.md Makefile README.md $(PACKAGE)
tar -czf $(PACKAGE).tar.gz $(PACKAGE)
$(PACKAGE):
mkdir -p $(PACKAGE)
# Clean
clean:
rm -f $(OBJ) $(TESTS_OBJ) $(DEMOS_OBJ) $(STATIC) $(DYNAMIC)
rm -f test
# Install
install: all
$(INSTALL_LIB)
$(INSTALL_INC)