-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
88 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
OS = $(shell uname)
CC ?= gcc
AR = ar
LD = ld
LN = ln
RM = rm
VALGRIND ?= valgrind
STRIP = strip
PREFIX ?= /usr/local
DESTDIR ?= utf8
VERSION_MAJOR = 0
VERSION_MINOR = 1
LIB_NAME = utf8
TARGET_NAME = lib$(LIB_NAME)
TARGET_STATIC = $(TARGET_NAME).a
TARGET_DSOLIB = $(TARGET_NAME).so.$(VERSION_MAJOR).$(VERSION_MINOR)
TARGET_DYLIB = $(TARGET_NAME).$(VERSION_MAJOR).$(VERSION_MINOR).dylib
TARGET_DSO = $(TARGET_NAME).so
CFLAGS ?= -I. -std=c99 -Wall -fvisibility=hidden -O2 -fPIC -pedantic
LDFLAGS ?= -shared -soname $(TARGET_DSO).$(VERSION_MAJOR)
OSX_LDFLAGS ?= -lc -Wl,-install_name,$(TARGET_DSO), -o $(TARGET_DSOLIB)
SRC = $(wildcard *.c)
OBJS = $(SRC:.c=.o)
TEST_SRC = $(filter-out test/test.c, $(wildcard test/*.c))
TEST_OBJS = $(TEST_SRC:.c=.o)
TEST_MAIN = utf8-test
ifneq ("Darwin","$(OS)")
CFLAGS += -lm
endif
ifdef DEBUG
CFLAGS += -DUTF8_DEBUG
endif
all: $(TARGET_STATIC) $(TARGET_DSO)
$(TARGET_STATIC): clean $(OBJS)
$(AR) crus $(TARGET_STATIC) $(OBJS)
$(TARGET_DSO): clean $(OBJS)
ifeq ("Darwin","$(OS)")
$(CC) -shared $(OBJS) $(OSX_LDFLAGS) -o $(TARGET_DSOLIB)
$(LN) -s $(TARGET_DSOLIB) $(TARGET_DSO)
$(LN) -s $(TARGET_DSOLIB) $(TARGET_DSO).$(VERSION_MAJOR)
else
$(LD) $(OBJS) $(LDFLAGS) -o $(TARGET_DSOLIB)
$(LN) -s $(TARGET_DSOLIB) $(TARGET_DSO)
$(LN) -s $(TARGET_DSOLIB) $(TARGET_DSO).$(VERSION_MAJOR)
$(STRIP) --strip-unneeded $(TARGET_DSO)
endif
src/.c.o:
$(CC) $(CFLAGS) -c $<
test/.c.o:
$(CC) $(CFLAGS) -c $<
check: test
$(VALGRIND) --leak-check=full ./$(TEST_MAIN)
test: $(TEST_OBJS)
$(CC) $(TEST_OBJS) test/test.c ./$(TARGET_STATIC) $(CFLAGS) -o $(TEST_MAIN)
./$(TEST_MAIN)
clean:
$(RM) -f $(TEST_MAIN)
$(RM) -f $(OBJS)
$(RM) -f $(TEST_OBJS)
$(RM) -f $(TARGET_STATIC)
$(RM) -f $(TARGET_DSOLIB)
$(RM) -f $(TARGET_DSO).$(VERSION_MAJOR)
$(RM) -f $(TARGET_DSO)
$(RM) -f $(TARGET_DYLIB)
install:
test -d $(PREFIX)/$(DESTDIR) || mkdir $(PREFIX)/$(DESTDIR)
install $(LIB_NAME).h $(PREFIX)/include/$(DESTDIR)
install $(TARGET_STATIC) $(PREFIX)/lib
install $(TARGET_DSO) $(PREFIX)/lib
uninstall:
rm -rf $(PREFIX)/$(DESTDIR)
rm -f $(PREFIX)/lib/$(TARGET_STATIC)
rm -f $(PREFIX)/lib/$(TARGET_DSO)
.PHONY: test