-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
143 lines (127 loc) · 4.56 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
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
HEADER_LIBPNG = identicon-c_libpng.h
TARGET_ONLY = NO
SOURCES = identicon-c.c
OBJS = $(SOURCES:.c=.o)
CFLAGS = -Wall -Wextra -fPIC -I. -Ilibs
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 += libs/md5.c libs/sha1.c libs/sha256.c libs/sha512.c
endif
# Check if we have libpng
CHECK_LIBPNG = $(shell pkg-config --exists libpng || echo -n "error")
ifneq ($(CHECK_LIBPNG), error)
DEPS += libpng
CFLAGS += -DHAVE_LIBPNG
endif
# Check what png library we will use
ifeq ($(MAKECMDGOALS), example)
ifeq ($(USE_CAIRO), 1)
DEPS += cairo
CFLAGS += -DUSE_CAIRO
else ifeq ($(USE_LIBPNG), 1)
DEPS += libpng
CFLAGS += -DUSE_LIBPNG
else ifeq ($(USE_STB), 1)
CFLAGS += -DUSE_STB
else
SOURCES += libs/lodepng.c
CFLAGS += -DLODEPNG_NO_COMPILE_CPP
endif
endif
# Check if we can build identicon
ifdef DEPS
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-c)
$(warning ERROR -- You need these libraries)
$(warning ERROR -- $(MISSING_LIBS))
$(error ERROR)
endif
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) 2>/dev/null) $^ -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))
@if [ "$(CHECK_LIBPNG)" != "error" ]; then \
echo "Installing $(HEADER_LIBPNG)" ;\
install -D -m 0644 $(HEADER_LIBPNG) $(abspath $(DESTDIR)/$(INCLUDEDIR)/$(HEADER_LIBPNG)) ;\
fi
@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 libs/*.o example $(TARGET) $(STATIC_LIB)
.PHONY: all clean install