forked from LoupVaillant/Monocypher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
211 lines (180 loc) · 7 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# This file is dual-licensed. Choose whichever licence you want from
# the two licences listed below.
#
# The first licence is a regular 2-clause BSD licence. The second licence
# is the CC-0 from Creative Commons. It is intended to release Monocypher
# to the public domain. The BSD licence serves as a fallback option.
#
# SPDX-License-Identifier: BSD-2-Clause OR CC0-1.0
#
# ------------------------------------------------------------------------
#
# Copyright (c) 2017-2019, Loup Vaillant
# Copyright (c) 2017, 2019, Fabio Scotoni
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ------------------------------------------------------------------------
#
# Written in 2017-2019 by Loup Vaillant and Fabio Scotoni
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software. If not, see
# <https://creativecommons.org/publicdomain/zero/1.0/>
.POSIX:
.SUFFIXES:
CC ?= gcc -std=c99
CFLAGS ?= -pedantic -Wall -Wextra -O3 -march=native
DESTDIR ?=
PREFIX ?= /usr/local
LIBDIR ?= $(PREFIX)/lib
INCLUDEDIR ?= $(PREFIX)/include
PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
MANDIR ?= $(PREFIX)/share/man/man3
SONAME = libmonocypher.so.4
.PHONY: all library static-library dynamic-library \
install install-lib install-pc install-doc \
check test tis-ci ctgrind \
clean uninstall dist
##################
## Main targets ##
##################
all : library doc/man3/intro.3monocypher
check: test
test: test.out
./test.out
tis-ci: tis-ci.out
./tis-ci.out
ctgrind: ctgrind.out
valgrind ./ctgrind.out
clean:
rm -rf lib/ doc/html/ doc/man3/
rm -f *.out
#############
## Install ##
#############
install: install-lib install-pc install-doc
install-lib: library
mkdir -p $(DESTDIR)$(INCLUDEDIR)
mkdir -p $(DESTDIR)$(LIBDIR)
cp -P lib/libmonocypher.a lib/libmonocypher.so* $(DESTDIR)$(LIBDIR)
cp -P src/monocypher.h $(DESTDIR)$(INCLUDEDIR)
cp -P src/optional/monocypher-ed25519.h $(DESTDIR)$(INCLUDEDIR)
install-pc: monocypher.pc
mkdir -p $(DESTDIR)$(PKGCONFIGDIR)
sed "s|PREFIX|$(PREFIX)|" monocypher.pc \
> $(DESTDIR)$(PKGCONFIGDIR)/monocypher.pc
install-doc: doc/man3/intro.3monocypher
mkdir -p $(DESTDIR)$(MANDIR)
cp -PR doc/man3/*.3monocypher $(DESTDIR)$(MANDIR)
uninstall:
rm -f $(DESTDIR)$(LIBDIR)/libmonocypher.a
rm -f $(DESTDIR)$(LIBDIR)/libmonocypher.so*
rm -f $(DESTDIR)$(INCLUDEDIR)/monocypher.h
rm -f $(DESTDIR)$(INCLUDEDIR)/monocypher-ed25519.h
rm -f $(DESTDIR)$(PKGCONFIGDIR)/monocypher.pc
rm -f $(DESTDIR)$(MANDIR)/*.3monocypher
##################
## Main library ##
##################
library: static-library dynamic-library
static-library : lib/libmonocypher.a
dynamic-library: lib/libmonocypher.so lib/$(SONAME)
MAIN_O=lib/monocypher.o lib/monocypher-ed25519.o
MAIN_I=-I src -I src/optional
lib/libmonocypher.a: $(MAIN_O)
$(AR) cr $@ $(MAIN_O)
lib/libmonocypher.so: lib/$(SONAME)
ln -sf `basename lib/$(SONAME)` $@
lib/$(SONAME): $(MAIN_O)
$(CC) $(CFLAGS) $(LDFLAGS) -shared -Wl,-soname,$(SONAME) -o $@ $(MAIN_O)
lib/monocypher.o: src/monocypher.c src/monocypher.h
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(MAIN_I) -fPIC -c -o $@ src/monocypher.c
lib/monocypher-ed25519.o: src/optional/monocypher-ed25519.c \
src/optional/monocypher-ed25519.h
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(MAIN_I) -fPIC -c -o $@ src/optional/monocypher-ed25519.c
####################
## Test libraries ##
####################
TEST_COMMON=tests/utils.h src/monocypher.h src/optional/monocypher-ed25519.h
TEST_I=$(MAIN_I) -I tests
lib/utils.o: tests/utils.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(TEST_I) -fPIC -c -o $@ tests/utils.c
lib/test.o: tests/test.c $(TEST_COMMON) tests/vectors.h
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(TEST_I) -fPIC -c -o $@ tests/test.c
lib/tis-ci.o: tests/tis-ci.c $(TEST_COMMON) tests/tis-ci-vectors.h
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(TEST_I) -fPIC -c -o $@ tests/tis-ci.c
lib/ctgrind.o: tests/ctgrind.c $(TEST_COMMON)
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(TEST_I) -fPIC -c -o $@ tests/ctgrind.c
######################
## Test executables ##
######################
TEST_OBJ = lib/utils.o lib/monocypher.o lib/monocypher-ed25519.o
test.out: lib/test.o $(TEST_OBJ)
$(CC) $(CFLAGS) -o $@ lib/test.o $(TEST_OBJ)
tis-ci.out: lib/tis-ci.o $(TEST_OBJ)
$(CC) $(CFLAGS) -o $@ lib/tis-ci.o $(TEST_OBJ)
ctgrind.out: lib/ctgrind.o $(TEST_OBJ)
$(CC) $(CFLAGS) -o $@ lib/ctgrind.o $(TEST_OBJ)
# Remove lines below for the tarball
tests/vectors.h:
@echo ""
@echo "======================================================"
@echo " I cannot perform the tests without the test vectors."
@echo " You must generate them. This requires Libsodium."
@echo " The following will generate the test vectors:"
@echo ""
@echo " $ cd tests/gen"
@echo " $ make"
@echo ""
@echo " Alternatively, you can grab an official release."
@echo " It will include the test vectors, so you won't"
@echo " need libsodium."
@echo "======================================================"
@echo ""
exit 1
doc/man3/intro.3monocypher: \
doc/crypto_aead_lock.3monocypher doc/crypto_argon2.3monocypher \
doc/crypto_blake2b.3monocypher doc/crypto_chacha20_djb.3monocypher \
doc/crypto_ed25519_sign.3monocypher doc/crypto_eddsa_sign.3monocypher \
doc/crypto_elligator_map.3monocypher doc/crypto_poly1305.3monocypher \
doc/crypto_sha512.3monocypher doc/crypto_verify16.3monocypher \
doc/crypto_wipe.3monocypher doc/crypto_x25519.3monocypher \
doc/intro.3monocypher
doc/doc_gen.sh
dist: tests/vectors.h
./dist.sh