-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
114 lines (100 loc) · 3.77 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
BASE_NAME = libidenticon-c
VERSION = 0.0.0
PREFIX ?= /usr/local
LIBDIR ?= $(PREFIX)/lib
INCLUDEDIR ?= $(PREFIX)/include
STATIC_LIB = $(BASE_NAME).a
PC_FILE = $(BASE_NAME).pc
HEADER = identicon-c.h
TARGET_ONLY = NO
SOURCES = identicon-c.c
OBJS = $(SOURCES:.c=.o)
DEPS = cairo
CFLAGS = -Wall -Wextra -fPIC
LDFLAGS = -shared -lm
# Check what crypto library we will use
ifeq ($(USE_SODIUM), 1)
DEPS += libsodium
CFLAGS += -DUSE_SODIUM
else ifeq ($(USE_OPENSSL), 1)
DEPS += openssl
CFLAGS += -DUSE_OPENSSL
else
SOURCES += md5.c sha1.c sha256.c sha512.c
endif
# Check if we can build identicon
CHECK_DEPS = $(shell pkg-config --exists $(DEPS) || echo -n "error")
ifneq ($(CHECK_DEPS), error)
CFLAGS += $(shell pkg-config --cflags $(DEPS))
LDFLAGS += $(shell pkg-config --libs $(DEPS))
else ifneq ($(MAKECMDGOALS), clean)
MISSING_LIBS = $(shell for lib in $(DEPS) ; do if ! pkg-config --exists $$lib ; then echo $$lib ; fi ; done)
$(warning ERROR -- Cannot compile identicon)
$(warning ERROR -- You need these libraries)
$(warning ERROR -- $(MISSING_LIBS))
$(error ERROR)
endif
# Check on what system we are running
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S), Linux)
SHARED_EXT = so
TARGET = $(BASE_NAME).$(SHARED_EXT).$(VERSION)
SHARED_LIB = $(BASE_NAME).$(SHARED_EXT).$(shell echo $(VERSION) | rev | cut -d "." -f 1 | rev)
LDFLAGS += -Wl,-soname=$(SHARED_LIB)
else ifeq ($(UNAME_S), FreeBSD)
SHARED_EXT = so
TARGET = $(BASE_NAME).$(SHARED_EXT).$(VERSION)
SHARED_LIB = $(BASE_NAME).$(SHARED_EXT).$(shell echo $(VERSION) | rev | cut -d "." -f 1 | rev)
LDFLAGS += -Wl,-soname=$(SHARED_LIB)
else ifeq ($(UNAME_S), Darwin)
SHARED_EXT = dylib
TARGET = $(BASE_NAME).$(VERSION).$(SHARED_EXT)
SHARED_LIB = $(BASE_NAME).$(shell echo $(VERSION) | rev | cut -d "." -f 1 | rev).$(SHARED_EXT)
LDFLAGS += -Wl,-install_name,$(SHARED_LIB)
else ifneq (, $(shell echo $(UNAME_S) | grep -E 'MSYS|MINGW|CYGWIN'))
SHARED_EXT = dll
TARGET = $(BASE_NAME).$(SHARED_EXT)
TARGET_ONLY = YES
NO_STATIC = 1
LDFLAGS += -Wl,--out-implib,$(TARGET).a
endif
# Targets
all: $(TARGET)
%.o: %.c
@echo " CC $@"
@$(CC) -c $(CFLAGS) $< -o $@
$(TARGET): $(OBJS)
@echo " LD $@"
@$(CC) $(LDFLAGS) -shared $^ -o $@
@if [ "$(NO_STATIC)" != "1" ]; then \
echo " AR $(STATIC_LIB)" ;\
ar rcs $(STATIC_LIB) $^ ;\
fi
example: $(OBJS) example.o
@echo " LD $@"
@$(CC) -lm $(shell pkg-config --libs $(DEPS)) $^ -o $@
install: $(TARGET) $(HEADER) $(PC_FILE)
@echo "Installing $(TARGET)"
@install -D -m 0755 $(TARGET) $(abspath $(DESTDIR)/$(LIBDIR)/$(TARGET))
@echo "Installing $(HEADER)"
@install -D -m 0644 $(HEADER) $(abspath $(DESTDIR)/$(INCLUDEDIR)/$(HEADER))
@echo "Installing $(PC_FILE)"
@install -D -m 0644 $(PC_FILE) $(abspath $(DESTDIR)/$(PREFIX)/share/pkgconfig/$(PC_FILE))
@if [ "$(NO_STATIC)" != "1" -a -e "$(STATIC_LIB)" ]; then \
echo "Installing $(STATIC_LIB)" ;\
install -m 0644 $(STATIC_LIB) $(abspath $(DESTDIR)/$(LIBDIR)/$(STATIC_LIB)) ;\
fi
@if [ "$(TARGET_ONLY)" != "YES" ]; then \
cd $(abspath $(DESTDIR)/$(LIBDIR)) ;\
ln -sf $(TARGET) $(SHARED_LIB) ;\
ln -sf $(SHARED_LIB) $(BASE_NAME).$(SHARED_EXT) ;\
fi
@pc_file=$(abspath $(DESTDIR)/$(PREFIX)/share/pkgconfig/$(PC_FILE)) ;\
sed -e 's:__PREFIX__:$(abspath $(PREFIX)):g' $$pc_file > temp_file && mv temp_file $$pc_file ;\
sed -e 's:__LIBDIR__:$(abspath $(LIBDIR)):g' $$pc_file > temp_file && mv temp_file $$pc_file ;\
sed -e 's:__INCLUDEDIR__:$(abspath $(INCLUDEDIR)):g' $$pc_file > temp_file && mv temp_file $$pc_file ;\
sed -e 's:__VERSION__:$(VERSION):g' $$pc_file > temp_file && mv temp_file $$pc_file ;\
sed -e 's:__LIBS__:$(DEPS):g' $$pc_file > temp_file && mv temp_file $$pc_file
clean:
rm -f *.o example $(TARGET) $(STATIC_LIB)
.PHONY: all clean install