-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
81 lines (58 loc) · 1.72 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
ifeq ($(origin CC),default)
CC = gcc
endif
AR := ar
ROOT := .
OBJ := $(ROOT)
SRC := $(ROOT)
TEST_SRC := $(ROOT)/tests
TEST_OBJ := $(ROOT)/tests
GLOBAL_LIB = /usr/local/lib
GLOBAL_INCLUDE = /usr/local/include
INSTALL_LIB ?= $(GLOBAL_LIB)
INSTALL_INCLUDE ?= $(GLOBAL_INCLUDE)
NAME := ed25519_cosi
SOURCES := $(wildcard $(SRC)/*.c)
HEADERS := $(wildcard $(SRC)/*.h)
TEST_SOURCES := $(wildcard $(TEST_SRC)/*.c)
OBJECTS := $(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SOURCES))
TEST_OBJECTS := $(patsubst $(TEST_SRC)/%.c, $(TEST_OBJ)/%.o, $(TEST_SOURCES))
SHARED := $(OBJ)/lib$(NAME).so
ARCHIVE := $(OBJ)/lib$(NAME).a
CFLAGS=-Wall -I$(GLOBAL_INCLUDE) -I$(ROOT) -fPIC
LDFLAGS=
TEST_CFLAGS=
TEST_LDFLAGS=-L$(ROOT) -lsodium -lcheck -pthread -lrt -lm -lsubunit -led25519_cosi
.PHONY:all clean watch
all: build-shared build-archive
build: $(OBJECTS)
check: $(patsubst $(TEST_OBJ)/%.o, check-%, $(TEST_OBJECTS))
build-shared: $(SHARED)
build-archive: $(ARCHIVE)
build-tests: $(TEST_OBJECTS)
$(OBJ)/%.o: $(SRC)/%.c
$(CC) $(CFLAGS) -o $@ -c $< $(LDFLAGS)
$(SHARED): $(OBJECTS)
$(CC) -shared -o $@ $<
$(ARCHIVE): $(OBJECTS)
$(AR) rcs $@ $<
install: uninstall build-shared build-archive
cp $(HEADERS) $(INSTALL_INCLUDE)
cp $(SHARED) $(INSTALL_LIB)
cp $(ARCHIVE) $(INSTALL_LIB)
uninstall:
rm -f $(patsubst $(SRC)/%.h, $(INSTALL_INCLUDE)/%.h, $(HEADERS))
rm -f $(patsubst $(OBJ)/%.so, $(INSTALL_LIB)/%.so, $(SHARED))
rm -f $(patsubst $(OBJ)/%.a, $(INSTALL_LIB)/%.a, $(ARCHIVE))
clean:
rm -f $(OBJECTS)
rm -f $(SHARED)
rm -f $(ARCHIVE)
$(TEST_OBJ)/%.o: $(TEST_SRC)/%.c $(SHARED)
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(TEST_CFLAGS) $(TEST_LDFLAGS)
check-%: $(TEST_OBJ)/%.o
LD_LIBRARY_PATH=$(ROOT) $<
clean-tests:
rm -f $(TEST_OBJECTS)
watch:
@./.watch