This repository has been archived by the owner on Apr 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
114 lines (86 loc) · 3.11 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
# Copyright (c) 2014-2018 Ristretto Developers, Cryptography Research, Inc.
# Released under the MIT License. See LICENSE.txt for license information.
UNAME := $(shell uname)
MACHINE := $(shell uname -m)
# Subdirectories for objects etc.
BUILD_OBJ = build/obj
BUILD_LIB = build/lib
BUILD_IBIN = build/obj/bin
# TODO: fix builds for non-x86_64 architectures
ARCH ?= $(MACHINE)
ifeq ($(UNAME),Darwin)
CC ?= clang
else
CC ?= gcc
endif
LD = $(CC)
AR ?= ar
ASM ?= $(CC)
WARNFLAGS = -pedantic -Wall -Wextra -Werror -Wunreachable-code \
-Wmissing-declarations -Wunused-function -Wno-overlength-strings $(EXWARN)
INCFLAGS = -Iinclude -Isrc -Isrc/arch/$(ARCH)
LANGFLAGS = -std=c99 -fno-strict-aliasing
GENFLAGS = -ffunction-sections -fdata-sections -fomit-frame-pointer -fPIC
OFLAGS ?= -O2
MACOSX_VERSION_MIN ?= 10.9
ifeq ($(UNAME),Darwin)
GENFLAGS += -mmacosx-version-min=$(MACOSX_VERSION_MIN)
endif
ARCHFLAGS ?= -march=native
ifeq ($(CC),clang)
WARNFLAGS_C += -Wgcc-compat
endif
ARCHFLAGS += $(XARCHFLAGS)
CFLAGS = $(LANGFLAGS) $(WARNFLAGS) $(WARNFLAGS_C) $(INCFLAGS) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCFLAGS)
LDFLAGS = $(XLDFLAGS)
ASFLAGS = $(ARCHFLAGS) $(XASFLAGS)
.PHONY: clean test all lib
.PRECIOUS: src/%.c src/*/%.c include/%.h include/*/%.h $(BUILD_IBIN)/%
HEADERS= Makefile $(BUILD_OBJ)/timestamp
# components needed by all targets
COMPONENTS = $(BUILD_OBJ)/bool.o \
$(BUILD_OBJ)/bzero.o \
$(BUILD_OBJ)/f_impl.o \
$(BUILD_OBJ)/f_arithmetic.o \
$(BUILD_OBJ)/ristretto.o \
$(BUILD_OBJ)/scalar.o
# components needed by libristretto255.so
LIBCOMPONENTS = $(COMPONENTS) $(BUILD_OBJ)/elligator.o $(BUILD_OBJ)/ristretto_tables.o
# components needed by the ristretto_gen_tables binary
GENCOMPONENTS = $(COMPONENTS) $(BUILD_OBJ)/ristretto_gen_tables.o
all: lib
# Create all the build subdirectories
$(BUILD_OBJ)/timestamp:
mkdir -p $(BUILD_OBJ) $(BUILD_LIB) $(BUILD_IBIN)
touch $@
$(BUILD_OBJ)/f_impl.o: src/arch/$(ARCH)/f_impl.c $(HEADERS)
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_IBIN)/ristretto_gen_tables: $(GENCOMPONENTS)
$(LD) $(LDFLAGS) -o $@ $^
src/ristretto_tables.c: $(BUILD_IBIN)/ristretto_gen_tables
./$< > $@ || (rm $@; exit 1)
# The libristretto255 library
lib: $(BUILD_LIB)/libristretto255.so $(BUILD_LIB)/libristretto255.a
$(BUILD_LIB)/libristretto255.so: $(BUILD_LIB)/libristretto255.so.1
ln -sf `basename $^` $@
$(BUILD_LIB)/libristretto255.so.1: $(LIBCOMPONENTS)
rm -f $@
ifeq ($(UNAME),Darwin)
libtool -macosx_version_min $(MACOSX_VERSION_MIN) -dynamic -dead_strip -lc -x -o $@ \
$(LIBCOMPONENTS)
else ifeq ($(UNAME),SunOS)
$(LD) $(LDFLAGS) -shared -Wl,-soname,`basename $@` -o $@ $(LIBCOMPONENTS)
strip --discard-all $@
else
$(LD) $(LDFLAGS) -shared -Wl,-soname,`basename $@` -Wl,--gc-sections -o $@ $(LIBCOMPONENTS)
strip --discard-all $@
endif
$(BUILD_LIB)/libristretto255.a: $(LIBCOMPONENTS)
$(AR) rcs $@ $(LIBCOMPONENTS)
$(BUILD_OBJ)/%.o: src/%.c $(HEADERS)
$(CC) $(CFLAGS) -c -o $@ $<
# Test suite: requires Rust is installed
test: $(BUILD_LIB)/libristretto255.a
cd tests && cargo test --all --lib
clean:
rm -fr build tests/target