forked from orangeduck/Cello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
180 lines (134 loc) · 3.93 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
CC ?= gcc
AR ?= ar
VERSION = 2.0.3
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)))
EXAMPLES := $(wildcard examples/*.c)
EXAMPLES_OBJ := $(addprefix obj/,$(notdir $(EXAMPLES:.c=.o)))
EXAMPLES_EXE := $(EXAMPLES:.c=)
CFLAGS = -I ./include -std=gnu99 -Wall -Wno-unused -g -ggdb
PLATFORM := $(shell uname)
COMPILER := $(shell $(CC) -v 2>&1 )
ifeq ($(findstring CYGWIN,$(PLATFORM)),CYGWIN)
PREFIX ?= /usr/local
DYNAMIC = libCello.so
STATIC = libCello.a
LIBS = -lpthread -lm
ifneq (,$(wildcard ${LIBDIR}/libdbghelp.a))
LIBS += -lDbgHelp
else
CFLAGS += -DCELLO_NSTRACE
endif
INSTALL_LIB = mkdir -p ${LIBDIR} && cp -f ${STATIC} ${LIBDIR}/$(STATIC)
INSTALL_INC = mkdir -p ${INCDIR} && cp -r include/Cello.h ${INCDIR}
UNINSTALL_LIB = rm -f ${LIBDIR}/$(STATIC)
UNINSTALL_INC = rm -f ${INCDIR}/Cello.h
else ifeq ($(findstring MINGW,$(PLATFORM)),MINGW)
# MSYS2
ifeq ($(findstring MINGW32,$(MSYSTEM)),MINGW32)
CC = i686-w64-mingw32-gcc
PREFIX ?= /mingw32
else ifeq ($(findstring MINGW64,$(MSYSTEM)),MINGW64)
CC = x86_64-w64-mingw32-gcc
PREFIX ?= /mingw64
else ifeq ($(findstring MSYS,$(MSYSTEM)),MSYS)
CC = gcc
PREFIX ?= /usr
else
# MinGW64 mingw-builds
prefix ?= c:/mingw64/x86_64-w64-mingw32
endif
DYNAMIC = libCello.dll
STATIC = libCello.a
ifneq (,$(wildcard ${LIBDIR}/libdbghelp.a))
LIBS += -lDbgHelp
else
CFLAGS += -DCELLO_NSTRACE
endif
INSTALL_LIB = cp $(STATIC) $(LIBDIR)/$(STATIC); cp $(DYNAMIC) $(BINDIR)/$(DYNAMIC)
INSTALL_INC = cp -r include/Cello.h $(INCDIR)
UNINSTALL_LIB = rm -f ${LIBDIR}/$(STATIC); rm -f ${BINDIR}/$(DYNAMIC)
UNINSTALL_INC = rm -f ${INCDIR}/Cello.h
else ifeq ($(findstring FreeBSD,$(PLATFORM)),FreeBSD)
PREFIX ?= /usr/local
DYNAMIC = libCello.so
STATIC = libCello.a
LIBS = -lpthread -lm
CFLAGS += -fPIC
ifneq (,$(wildcard ${LIBDIR}/libexecinfo.a))
LIBS += -lexecinfo
LFLAGS += -rdynamic
else
CFLAGS += -DCELLO_NSTRACE
endif
INSTALL_LIB = mkdir -p ${LIBDIR} && cp -f ${STATIC} ${LIBDIR}/$(STATIC)
INSTALL_INC = mkdir -p ${INCDIR} && cp -r include/Cello.h ${INCDIR}
UNINSTALL_LIB = rm -f ${LIBDIR}/$(STATIC)
UNINSTALL_INC = rm -f ${INCDIR}/Cello.h
else
PREFIX ?= /usr/local
DYNAMIC = libCello.so
STATIC = libCello.a
LIBS = -lpthread -lm
CFLAGS += -fPIC
ifneq (,$(wildcard ${LIBDIR}/libexecinfo.a))
LIBS += -lexecinfo
LFLAGS += -rdynamic
else
CFLAGS += -DCELLO_NSTRACE
endif
INSTALL_LIB = mkdir -p ${LIBDIR} && cp -f ${STATIC} ${LIBDIR}/$(STATIC)
INSTALL_INC = mkdir -p ${INCDIR} && cp -r include/Cello.h ${INCDIR}
UNINSTALL_LIB = rm -f ${LIBDIR}/$(STATIC)
UNINSTALL_INC = rm -f ${INCDIR}/Cello.h
endif
# Libraries
all: $(DYNAMIC) $(STATIC)
$(DYNAMIC): $(OBJ)
$(CC) $(OBJ) -shared $(LFLAGS) $(LIBS) -o $@
$(STATIC): $(OBJ)
$(AR) rcs $@ $(OBJ)
obj/%.o: src/%.c | obj
$(CC) $< -c $(CFLAGS) -o $@
obj:
mkdir -p obj
# Tests
check: CFLAGS += -Werror -g -ggdb
check: $(TESTS_OBJ) $(STATIC)
$(CC) $(TESTS_OBJ) $(STATIC) $(LIBS) $(LFLAGS) -o ./tests/test
./tests/test
rm -f ./tests/test.bin ./tests/test.txt
obj/%.o: tests/%.c | obj
$(CC) $< -c $(CFLAGS) -o $@
# Benchmarks
bench: CFLAGS += -DCELLO_NDEBUG -pg
bench: clean $(STATIC)
cd benchmarks; ./benchmark; cd ../
# Examples
examples: $(EXAMPLES_EXE)
examples/%: CFLAGS += -Werror
examples/%: examples/%.c $(STATIC) | obj
$(CC) $< $(STATIC) $(CFLAGS) $(LIBS) $(LFLAGS) -o $@
# Dist
dist: all | $(PACKAGE)
cp -R examples include src tests LICENSE.md Makefile README.md $(PACKAGE)
tar -czf $(PACKAGE).tar.gz $(PACKAGE) --exclude='*.exe' --exclude='*.pdb'
$(PACKAGE):
mkdir -p $(PACKAGE)
# Clean
clean:
rm -f $(OBJ) $(TESTS_OBJ) $(EXAMPLES_OBJ) $(STATIC) $(DYNAMIC) tests/test
# Install
install: all
$(INSTALL_LIB)
$(INSTALL_INC)
# Uninstall
uninstall:
$(UNINSTALL_LIB)
$(UNINSTALL_INC)