Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows and Darwin support #268

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*.a
*.so
*.so.*
*.dll
*.dylib
*.out
*.out.exe
*.vec
*.gch
*.sav
Expand Down
92 changes: 76 additions & 16 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,48 @@
.POSIX:
.SUFFIXES:

ifeq ($(OS),Windows_NT)
WIN32 = 1
else
UNAME := $(shell uname -s || :)
ifeq ($(UNAME),Darwin)
DARWIN = 1
endif
endif

CC ?= gcc -std=c99
CFLAGS ?= -pedantic -Wall -Wextra -O3 -march=native
DESTDIR ?=
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
LIBDIR ?= $(PREFIX)/lib
INCLUDEDIR ?= $(PREFIX)/include
PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
MANDIR ?= $(PREFIX)/share/man/man3
SONAME = libmonocypher.so.4
SOVERSION = 4
# MinGW/CygWin convention + implib generation
ifdef WIN32
SONAME = libmonocypher-$(SOVERSION).dll
EXESUFFIX = .exe
SOSUFFIX = .dll
SOFLAGS = -Wl,-soname,$(SONAME),--out-implib,lib/libmonocypher.dll.a
# Darwin convention
else ifdef DARWIN
SONAME = libmonocypher.$(SOVERSION).dylib
EXESUFFIX =
SOSUFFIX = .dylib
SOFLAGS = -install_name $(SONAME) -current_version $(SOVERSION) \
-compatibility_version $(SOVERSION)
else
SONAME = libmonocypher.so.$(SOVERSION)
EXESUFFIX =
SOSUFFIX = .so
SOFLAGS = -Wl,-soname,$(SONAME)
endif

ifdef DARWIN
else
endif

.PHONY: all library static-library dynamic-library \
install install-lib install-pc install-doc \
Expand All @@ -73,14 +106,14 @@ SONAME = libmonocypher.so.4
all : library doc/man3/intro.3monocypher
check: test

test: test.out
./test.out
test: test.out$(EXESUFFIX)
./test.out$(EXESUFFIX)

tis-ci: tis-ci.out
./tis-ci.out
tis-ci: tis-ci.out$(EXESUFFIX)
./tis-ci.out$(EXESUFFIX)

ctgrind: ctgrind.out
valgrind ./ctgrind.out
ctgrind: ctgrind.out$(EXESUFFIX)
valgrind ./ctgrind.out$(EXESUFFIX)

clean:
rm -rf lib/ doc/html/ doc/man3/
Expand All @@ -94,9 +127,21 @@ 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)
# Dynamic library should be installed into `bin` on Windows
ifdef WIN32
mkdir -p $(DESTDIR)$(BINDIR)
cp -P lib/libmonocypher.a lib/libmonocypher.dll.a $(DESTDIR)$(LIBDIR)
cp -P lib/libmonocypher*.dll $(DESTDIR)$(BINDIR)
else ifdef DARWIN
cp -P lib/libmonocypher.a lib/libmonocypher*.dylib $(DESTDIR)$(LIBDIR)
# Adjust install name
install_name_tool -change $(SONAME) $(DESTDIR)$(LIBDIR)/$(SONAME) \
$(DESTDIR)$(LIBDIR)/$(SONAME)
else
cp -P lib/libmonocypher.a lib/libmonocypher.so* $(DESTDIR)$(LIBDIR)
endif
cp -P src/monocypher.h $(DESTDIR)$(INCLUDEDIR)
cp -P src/optional/monocypher-ed25519.h $(DESTDIR)$(INCLUDEDIR)

install-pc: monocypher.pc
mkdir -p $(DESTDIR)$(PKGCONFIGDIR)
Expand All @@ -109,7 +154,14 @@ install-doc: doc/man3/intro.3monocypher

uninstall:
rm -f $(DESTDIR)$(LIBDIR)/libmonocypher.a
ifdef WIN32
rm -f $(DESTDIR)$(LIBDIR)/libmonocypher.dll.a
rm -f $(DESTDIR)$(BINDIR)/libmonocypher*.dll
else ifdef DARWIN
rm -f $(DESTDIR)$(LIBDIR)/libmonocypher*.dylib
else
rm -f $(DESTDIR)$(LIBDIR)/libmonocypher.so*
endif
rm -f $(DESTDIR)$(INCLUDEDIR)/monocypher.h
rm -f $(DESTDIR)$(INCLUDEDIR)/monocypher-ed25519.h
rm -f $(DESTDIR)$(PKGCONFIGDIR)/monocypher.pc
Expand All @@ -120,19 +172,27 @@ uninstall:
##################
library: static-library dynamic-library
static-library : lib/libmonocypher.a
dynamic-library: lib/libmonocypher.so lib/$(SONAME)
# On Windows implib used instead of symlink
ifdef WIN32
# Created by library target
lib/libmonocypher.dll.a: lib/$(SONAME)

dynamic-library: lib/$(SONAME) lib/libmonocypher.dll.a
else
dynamic-library: lib/libmonocypher$(SOSUFFIX) lib/$(SONAME)
endif

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)
lib/libmonocypher$(SOSUFFIX): lib/$(SONAME)
ln -sf `basename lib/$(SONAME)` $@

lib/$(SONAME): $(MAIN_O)
$(CC) $(CFLAGS) $(LDFLAGS) -shared -Wl,-soname,$(SONAME) -o $@ $(MAIN_O)
$(CC) $(CFLAGS) $(LDFLAGS) -shared $(SOFLAGS) -o $@ $(MAIN_O)

lib/monocypher.o: src/monocypher.c src/monocypher.h
@mkdir -p $(@D)
Expand Down Expand Up @@ -170,13 +230,13 @@ lib/ctgrind.o: tests/ctgrind.c $(TEST_COMMON)
######################
TEST_OBJ = lib/utils.o lib/monocypher.o lib/monocypher-ed25519.o

test.out: lib/test.o $(TEST_OBJ)
test.out$(EXESUFFIX): lib/test.o $(TEST_OBJ)
$(CC) $(CFLAGS) -o $@ lib/test.o $(TEST_OBJ)

tis-ci.out: lib/tis-ci.o $(TEST_OBJ)
tis-ci.out$(EXESUFFIX): lib/tis-ci.o $(TEST_OBJ)
$(CC) $(CFLAGS) -o $@ lib/tis-ci.o $(TEST_OBJ)

ctgrind.out: lib/ctgrind.o $(TEST_OBJ)
ctgrind.out$(EXESUFFIX): lib/ctgrind.o $(TEST_OBJ)
$(CC) $(CFLAGS) -o $@ lib/ctgrind.o $(TEST_OBJ)
# Remove lines below for the tarball

Expand Down
22 changes: 14 additions & 8 deletions tests/gen/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@
# 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/>
CC ?= gcc -std=c99
CFLAGS ?= -pedantic -Wall -Wextra

CC ?= gcc -std=c99
CFLAGS ?= -pedantic -Wall -Wextra
ifeq ($(OS),Windows_NT)
EXESUFFIX = .exe
else
EXESUFFIX =
endif

.PHONY: all clean

Expand All @@ -67,7 +73,7 @@ VECTORS = ../vectors.h
all: $(VECTORS)

clean:
rm -f *.out *.vec *.o
rm -f *.out$(EXESUFFIX) *.vec *.o
rm -f $(VECTORS)

elligator_inv.vec: elligator-inverse.py elligator.py elligator_scalarmult.py
Expand All @@ -76,7 +82,7 @@ elligator_dir.vec: elligator-direct.py elligator.py
./$< >$@
sha512_hkdf.vec: sha512_hkdf.py
./$< >$@
%.vec: %.out
%.vec: %.out$(EXESUFFIX)
./$< > $@

utils.o: utils.c utils.h
Expand All @@ -90,7 +96,7 @@ utils.o: utils.c utils.h
-I ../../src/optional \
$$(pkg-config --cflags libsodium)

%.out: %.o ed25519.o utils.o
%.out$(EXESUFFIX): %.o ed25519.o utils.o
$(CC) $(CFLAGS) -o $@ $^ \
$$(pkg-config --libs libsodium)

Expand All @@ -105,7 +111,7 @@ ed25519.o: ../externals/ed25519-donna/ed25519.c \
-DED25519_NO_INLINE_ASM \
-DED25519_FORCE_32BIT

vector_to_header.out: vector_to_header.c
vector_to_header.out$(EXESUFFIX): vector_to_header.c
$(CC) $(CFLAGS) $< -o $@

chacha20.all.vec : chacha20.vec vectors/chacha20
Expand Down Expand Up @@ -134,8 +140,8 @@ $(VEC2):
mkdir -p $(@D)
cat $^ > $@

%.h.vec: %.all.vec vector_to_header.out
./vector_to_header.out $(patsubst %.all.vec,%,$<) < $< > $@
%.h.vec: %.all.vec vector_to_header.out$(EXESUFFIX)
./vector_to_header.out$(EXESUFFIX) $(patsubst %.all.vec,%,$<) < $< > $@

prelude.h.vec:
@echo "creating prelude.h.vec"
Expand Down
39 changes: 22 additions & 17 deletions tests/speed/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@
# with this software. If not, see
# <https://creativecommons.org/publicdomain/zero/1.0/>

CC ?= gcc -std=gnu99
CFLAGS ?= -pedantic -Wall -Wextra -O3 -march=native
CC ?= gcc -std=gnu99
CFLAGS ?= -pedantic -Wall -Wextra -O3 -march=native
ifeq ($(OS),Windows_NT)
EXESUFFIX = .exe
else
EXESUFFIX =
endif

.PHONY: speed speed-sodium speed-hydrogen speed-tweetnacl speed-c25519 \
speed-donna \
Expand All @@ -62,23 +67,23 @@ CFLAGS ?= -pedantic -Wall -Wextra -O3 -march=native
##################
all: speed

speed : speed.out
speed : speed.out$(EXESUFFIX)
./$<
speed-sodium : speed-sodium.out
speed-sodium : speed-sodium.out$(EXESUFFIX)
./$<
speed-hydrogen : speed-hydrogen.out
speed-hydrogen : speed-hydrogen.out$(EXESUFFIX)
./$<
speed-tweetnacl: speed-tweetnacl.out
speed-tweetnacl: speed-tweetnacl.out$(EXESUFFIX)
./$<
speed-c25519 : speed-c25519.out
speed-c25519 : speed-c25519.out$(EXESUFFIX)
./$<
speed-donna : speed-donna.out
speed-donna : speed-donna.out$(EXESUFFIX)
./$<
speed-tinyssh : speed-tinyssh.out
speed-tinyssh : speed-tinyssh.out$(EXESUFFIX)
./$<

clean:
rm -f *.o *.out
rm -f *.o *.out$(EXESUFFIX)

####################
## Base libraries ##
Expand Down Expand Up @@ -186,23 +191,23 @@ speed-donna.o : speed-donna.c speed.h ../utils.h $(DONNA_HEADERS)
speed-tinyssh.o : speed-tinyssh.c speed.h ../utils.h $(TSSH_H)
$(CC) -c $(CFLAGS) $< -o $@ -I .. -I $(TSSH)

speed.out: speed.o utils.o monocypher.o monocypher-ed25519.o
speed.out$(EXESUFFIX): speed.o utils.o monocypher.o monocypher-ed25519.o
$(CC) $(CFLAGS) -o $@ $^
speed-sodium.out: speed-sodium.o utils.o
speed-sodium.out$(EXESUFFIX): speed-sodium.o utils.o
$(CC) $(CFLAGS) -o $@ $^ \
`pkg-config --cflags libsodium` \
`pkg-config --libs libsodium`
speed-donna.out: speed-donna.o donna.o utils.o
speed-donna.out$(EXESUFFIX): speed-donna.o donna.o utils.o
$(CC) $(CFLAGS) -o $@ $^ \
`pkg-config --cflags libsodium` \
`pkg-config --libs libsodium`
speed-hydrogen.out: speed-hydrogen.o utils.o
speed-hydrogen.out$(EXESUFFIX): speed-hydrogen.o utils.o
$(CC) $(CFLAGS) -o $@ $^ \
`pkg-config --cflags libhydrogen` \
`pkg-config --libs libhydrogen`
speed-tweetnacl.out: speed-tweetnacl.o tweetnacl.o utils.o
speed-tweetnacl.out$(EXESUFFIX): speed-tweetnacl.o tweetnacl.o utils.o
$(CC) $(CFLAGS) -o $@ $^
speed-c25519.out : speed-c25519.o $(C25519_OBJECTS) utils.o
speed-c25519.out$(EXESUFFIX) : speed-c25519.o $(C25519_OBJECTS) utils.o
$(CC) $(CFLAGS) -o $@ $^
speed-tinyssh.out : speed-tinyssh.o $(TSSH_O) utils.o
speed-tinyssh.out$(EXESUFFIX) : speed-tinyssh.o $(TSSH_O) utils.o
$(CC) $(CFLAGS) -o $@ $^
Loading