1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-22 23:48:58 +00:00
pqcrypto/Makefile

120 lines
3.4 KiB
Makefile

# This -Wall was supported by the European Commission through the ERC Starting Grant 805031 (EPOQUE)
CFLAGS=-Wall -Wextra -Wpedantic -Werror -std=c99 -g $(EXTRAFLAGS)
ALL_SCHEMES=$(filter-out crypto_%.c, $(wildcard crypto_*/*))
COMMON_FILES = common/fips202.c common/sha2.c
RANDOM_IMPL = common/randombytes.c
default: help
.PHONY: require_scheme
require_scheme:
# assumes a SCHEME variable; e.g. make functest SCHEME=crypto_kem/kyber768
ifndef SCHEME
$(error The SCHEME variable is not set. Example: SCHEME=crypto_kem/kyber768)
endif
bin/functest_$(subst /,_,$(SCHEME)): test/$(dir $(SCHEME))functest.c $(wildcard $(SCHEME)/clean/*.c) $(wildcard $(SCHEME)/clean/*.h) | require_scheme
mkdir -p bin
$(CC) $(CFLAGS) \
-DPQCLEAN_NAMESPACE=$(shell echo PQCLEAN_$(subst -,,$(notdir $(SCHEME)))_CLEAN | tr a-z A-Z) \
-iquote "./common/" \
-iquote "$(SCHEME)/clean/" \
-o bin/functest_$(subst /,_,$(SCHEME)) \
$(SCHEME)/clean/*.c \
$(COMMON_FILES) \
$(RANDOM_IMPL) \
$<
.PHONY: functest
functest: bin/functest_$(subst /,_,$(SCHEME))
.PHONY: run-functest
run-functest: bin/functest_$(subst /,_,$(SCHEME))
./$<
.PHONY: run-valgrind
run-valgrind: bin/functest_$(subst /,_,$(SCHEME))
ifeq ($(shell uname -s),Linux)
valgrind --leak-check=full --error-exitcode=1 $<
else
@echo "Valgrind not supported on this platform."
endif
bin/shared_$(subst /,_,$(SCHEME))_clean.so: $(wildcard $(SCHEME)/clean/*.c) | require_scheme
mkdir -p bin
$(CC) $(CFLAGS) \
-DPQCLEAN_NAMESPACE=$(shell echo PQCLEAN_$(subst -,,$(notdir $(SCHEME)))_CLEAN | tr a-z A-Z) \
-nostdlib \
-shared \
-fPIC \
-iquote "./common/" \
-iquote "$(SCHEME)/clean/" \
-o $@ \
$^
.PHONY: clean
clean:
rm -rf bin
.PHONY: format
format:
astyle --project crypto_*/*/*/*.[ch] common/*.[ch]
.PHONY: check-format
check-format:
astyle --dry-run --project crypto_*/*/*/*.[ch] common/*.[ch] | grep Formatted && exit 1 || exit 0
.PHONY: tidy
tidy:
$(MAKE) do-tidy
do-tidy: require_scheme
clang-tidy \
-quiet $(.TIDY_FIX) \
$(SCHEME)/clean/*.c \
common/*.c \
-- -iquote "common/" -iquote "$(SCHEME)/clean"
.PHONY: apply-tidy
apply-tidy:
$(MAKE) do-tidy .TIDY_FIX=-fix
# The below should be outlined with ts=8
.PHONY: help
help:
@echo "make test-all Run all tests"
@echo "make functest SCHEME=scheme Build functional tests for SCHEME"
@echo "make run-functest SCHEME=scheme Run functional tests for SCHEME"
@echo "make run-valgrind SCHEME=scheme Run valgrind checks for SCHEME"
@echo "make run-valgrind-all Run valgrind checks all schemes"
@echo "make clean Clean up the bin/ folder"
@echo "make format Automatically formats all the source code"
@echo "make tidy SCHEME=scheme Runs the clang-tidy linter against SCHEME"
@echo "make apply-tidy SCHEME=scheme Tries to automatically fix the issues found by clang-tidy in SCHEME"
@echo "make tidy-all Runs the clang-tidy linter against all schemes"
@echo "make apply-tidy-all Tidy up all schemes"
@echo "make help Displays this message"
.PHONY: run-valgrind-all
run-valgrind-all:
@for scheme in $(ALL_SCHEMES); do \
$(MAKE) run-valgrind SCHEME=$$scheme || exit 1; \
done
.PHONY: test-all
test-all: run-valgrind-all
.PHONY: tidy-all
tidy-all:
@for scheme in $(ALL_SCHEMES); do \
$(MAKE) tidy SCHEME=$$scheme || exit 1 ; \
done
.PHONY: apply-tidy-all
apply-tidy-all:
@for scheme in $(ALL_SCHEMES); do \
$(MAKE) apply-tidy SCHEME=$$scheme; \
done