-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
172 lines (148 loc) · 6.17 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
####### Platform specifics
# cut is necessary for Cygwin
PLATFORM_OS := $(shell uname | cut -d_ -f1)
####### Makefile Conventions - Directory variables
prefix = /usr
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
sbindir = $(exec_prefix)/sbin
libexecdir = $(exec_prefix)/libexec
datarootdir = $(prefix)/share
datadir = $(datarootdir)
sysconfdir = $(prefix)/etc
localstatedir = $(prefix)/var
includedir = $(prefix)/include
docdir = $(datarootdir)/doc/libsslpkix
infodir = $(datarootdir)/info
libdir = $(exec_prefix)/lib
localedir = $(datarootdir)/locale
mandir = $(datarootdir)/man
man1dir = $(mandir)/man1
manext = .1
man1ext = .1
srcdir = src src/openssl/apps src/x509
testdir = test
####### Makefile Conventions - Utilities
CC ?= gcc
CXX ?= g++
LINK = $(CXX)
CHK_DIR_EXISTS = test -d
CHK_FILE_EXISTS = test -f
INSTALL = install
INSTALL_DATA = ${INSTALL} -m 644
INSTALL_PROGRAM = $(INSTALL)
SYMLINK = ln -sf
MKDIR = mkdir -p
RM = rm -f
RM_DIR = rm -rf
ifeq ($(PLATFORM_OS), Darwin)
STRIP = strip -x
else
STRIP = strip --strip-unneeded
endif
####### Compiler options
DEST = $(DESTDIR)$(libdir)
INCPATH = -Iinclude
override LFLAGS += -lssl -lcrypto
override CFLAGS += -pipe -O0 -g3 -Wall -Wextra -pedantic -fmessage-length=0 -std=c11
override CXXFLAGS += -pipe -O0 -g3 -Wall -Wextra -pedantic -fmessage-length=0 -std=c++14
override CPPFLAGS += -DDEBUG
ifeq ($(PLATFORM_OS), Darwin)
# We disable warnings for deprecated declarations because Apple deprecated OpenSSL in Mac OS X 10.7
override CFLAGS += -Wno-deprecated-declarations
override CXXFLAGS += -Wno-deprecated-declarations
endif
VERSION_MAJOR = 1
VERSION_MINOR = 0
VERSION_PATCH = 1
VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)
LIBNAME = libsslpkix
TESTNAME = run_tests
libsslpkix_BUILDDIR = $(CURDIR)/build
libsslpkix_SRCS_FILTER = $(wildcard ${dir}/*.c) $(wildcard ${dir}/*.cpp)
libsslpkix_SRCS = $(foreach dir, ${srcdir}, ${libsslpkix_SRCS_FILTER})
libsslpkix_OBJS = $(addprefix ${libsslpkix_BUILDDIR}/, $(addsuffix .o, $(basename ${libsslpkix_SRCS})))
test_SRCS_FILTER = $(wildcard ${dir}/*.c) $(wildcard ${dir}/*.cpp)
test_SRCS = $(foreach dir, ${testdir}, ${test_SRCS_FILTER})
test_OBJS = $(addprefix ${libsslpkix_BUILDDIR}/, $(addsuffix .o, $(basename ${test_SRCS})))
####### Build rules
.PHONY : libsslpkix test install strip-binaries install-strip uninstall clean
all: libsslpkix test
test: libsslpkix
test: INCPATH += -Ilib/Catch2/build/installdir/usr/local/include
test: LFLAGS += -L$(libsslpkix_BUILDDIR) -lsslpkix lib/Catch2/build/installdir/usr/local/lib/libCatch2.a
test: $(test_OBJS)
@echo 'Building test binary: $(libsslpkix_BUILDDIR)/$(TESTNAME)'
$(LINK) -o $(libsslpkix_BUILDDIR)/$(TESTNAME) $(test_OBJS) $(LFLAGS)
libsslpkix: CPPFLAGS += -DSSLPKIX_LIBRARY
libsslpkix: CFLAGS += -fPIC
libsslpkix: CXXFLAGS += -fPIC
libsslpkix: $(libsslpkix_OBJS)
@# @echo "Building static library: $(libsslpkix_BUILDDIR)/$(LIBNAME).$(VERSION).a"
@# $(AR) cqv $(libsslpkix_BUILDDIR)/$(LIBNAME).$(VERSION).a $^
@# $(RANLIB) $(libsslpkix_BUILDDIR)/$(LIBNAME).$(VERSION).a
@# major.a -> version.a
@# $(SYMLINK) $(libsslpkix_BUILDDIR)/$(LIBNAME).$(VERSION).a $(libsslpkix_BUILDDIR)/$(LIBNAME).$(VERSION_MAJOR).a
@# .a -> major.a
@# $(SYMLINK) $(libsslpkix_BUILDDIR)/$(LIBNAME).$(VERSION_MAJOR).a $(libsslpkix_BUILDDIR)/$(LIBNAME).a
ifeq ($(PLATFORM_OS), Linux)
@echo 'Building shared library: $(libsslpkix_BUILDDIR)/$(LIBNAME).so.$(VERSION)'
$(LINK) -o $(libsslpkix_BUILDDIR)/$(LIBNAME).so.$(VERSION) $^ $(LFLAGS) -shared -Wl,-soname,$(LIBNAME).so.$(VERSION_MAJOR)
@# .so.major -> .so.version
$(SYMLINK) $(libsslpkix_BUILDDIR)/$(LIBNAME).so.$(VERSION) $(libsslpkix_BUILDDIR)/$(LIBNAME).so.$(VERSION_MAJOR)
@# .so -> .so.major
$(SYMLINK) $(libsslpkix_BUILDDIR)/$(LIBNAME).so.$(VERSION_MAJOR) $(libsslpkix_BUILDDIR)/$(LIBNAME).so
else ifeq ($(PLATFORM_OS), Darwin)
@echo 'Building shared library: $(libsslpkix_BUILDDIR)/$(LIBNAME).$(VERSION).dylib'
$(LINK) -o $(libsslpkix_BUILDDIR)/$(LIBNAME).$(VERSION).dylib $^ $(LFLAGS) \
-headerpad_max_install_names -dynamiclib \
-flat_namespace -install_name $(LIBNAME).$(VERSION).dylib \
-current_version $(VERSION) -compatibility_version $(VERSION_MAJOR).0
@# major.dylib -> version.dylib
$(SYMLINK) $(libsslpkix_BUILDDIR)/$(LIBNAME).$(VERSION).dylib $(libsslpkix_BUILDDIR)/$(LIBNAME).$(VERSION_MAJOR).dylib
@# .dylib -> major.dylib
$(SYMLINK) $(libsslpkix_BUILDDIR)/$(LIBNAME).$(VERSION_MAJOR).dylib $(libsslpkix_BUILDDIR)/$(LIBNAME).dylib
else ifeq ($(PLATFORM_OS), CYGWIN)
@echo 'Building shared library: $(libsslpkix_BUILDDIR)/$(LIBNAME).dll'
$(LINK) -o $(libsslpkix_BUILDDIR)/$(LIBNAME).dll $^ $(LFLAGS) -shared
@# TODO: Use windres to embed a resource with version information into the DLL?
endif
$(libsslpkix_BUILDDIR)/%.o: %.c
@echo 'Building file: $<'
@$(CHK_DIR_EXISTS) $(dir $@) || $(MKDIR) $(dir $@)
$(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) $(INCPATH)
$(libsslpkix_BUILDDIR)/%.o: %.cpp
@echo 'Building file: $<'
@$(CHK_DIR_EXISTS) $(dir $@) || $(MKDIR) $(dir $@)
$(CXX) -c -o $@ $< $(CXXFLAGS) $(CPPFLAGS) $(INCPATH)
install: installdirs
@#$(INSTALL_DATA) $(libsslpkix_BUILDDIR)/$(LIBNAME).a $(DEST)/$(LIBNAME).a.$(VERSION)
@#cd $(DEST); $(SYMLINK) $(LIBNAME).a.$(VERSION) $(LIBNAME).a
@#cd $(DEST); $(SYMLINK) $(LIBNAME).a.$(VERSION) $(LIBNAME).a.1
ifeq ($(PLATFORM_OS), Linux)
$(INSTALL_DATA) $(libsslpkix_BUILDDIR)/$(LIBNAME).so $(DEST)/$(LIBNAME).so.$(VERSION)
cd $(DEST); $(SYMLINK) $(LIBNAME).so.$(VERSION) $(LIBNAME).so
cd $(DEST); $(SYMLINK) $(LIBNAME).so.$(VERSION) $(LIBNAME).so.1
else ifeq ($(PLATFORM_OS), Darwin)
$(INSTALL_DATA) $(libsslpkix_BUILDDIR)/$(LIBNAME).dylib $(DEST)/$(LIBNAME).$(VERSION).dylib
cd $(DEST); $(SYMLINK) $(LIBNAME).$(VERSION).dylib $(LIBNAME).dylib
cd $(DEST); $(SYMLINK) $(LIBNAME).$(VERSION).dylib $(LIBNAME).1.dylib
else ifeq ($(PLATFORM_OS), CYGWIN)
# TODO
endif
installdirs:
@$(CHK_DIR_EXISTS) $(DEST) || $(MKDIR) $(DEST)
strip-binaries:
ifeq ($(PLATFORM_OS), Linux)
$(STRIP) $(LIBNAME).so
else ifeq ($(PLATFORM_OS), Darwin)
$(STRIP) $(LIBNAME).dylib
else ifeq ($(PLATFORM_OS), CYGWIN)
$(STRIP) $(LIBNAME).dll
endif
install-strip: strip-binaries install
uninstall:
$(RM) $(DEST)/$(LIBNAME).so* \
$(DEST)/$(LIBNAME)*.dylib
clean:
$(RM_DIR) $(libsslpkix_BUILDDIR)/*