| 1 |
# Copyright (c) The mldsa-native project authors |
| 2 |
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT |
| 3 |
|
| 4 |
.PHONY: build run clean |
| 5 |
.DEFAULT_GOAL := all |
| 6 |
|
| 7 |
CC ?= gcc |
| 8 |
|
| 9 |
# Adjust CFLAGS if needed |
| 10 |
CFLAGS := \ |
| 11 |
-Wall \ |
| 12 |
-Wextra \ |
| 13 |
-Werror=unused-result \ |
| 14 |
-Wpedantic \ |
| 15 |
-Werror \ |
| 16 |
-Wmissing-prototypes \ |
| 17 |
-Wshadow \ |
| 18 |
-Wpointer-arith \ |
| 19 |
-Wredundant-decls \ |
| 20 |
-Wconversion \ |
| 21 |
-Wsign-conversion \ |
| 22 |
-Wno-long-long \ |
| 23 |
-Wno-unknown-pragmas \ |
| 24 |
-Wno-unused-command-line-argument \ |
| 25 |
-O3 \ |
| 26 |
-fomit-frame-pointer \ |
| 27 |
-std=c99 \ |
| 28 |
-pedantic \ |
| 29 |
-MMD \ |
| 30 |
$(CFLAGS) |
| 31 |
|
| 32 |
# If you want to use the native backends, the compiler needs to know about |
| 33 |
# the target architecture. Here, we import the default host detection from |
| 34 |
# mldsa-native's tests, but you can write your own or specialize accordingly. |
| 35 |
AUTO ?= 1 |
| 36 |
include auto.mk |
| 37 |
|
| 38 |
# The following only concerns the cross-compilation tests. |
| 39 |
# You can likely ignore the following for your application. |
| 40 |
# |
| 41 |
# Append cross-prefix for cross compilation |
| 42 |
# When called from the root Makefile, CROSS_PREFIX has already been added here |
| 43 |
ifeq (,$(findstring $(CROSS_PREFIX),$(CC))) |
| 44 |
CC := $(CROSS_PREFIX)$(CC) |
| 45 |
endif |
| 46 |
|
| 47 |
# Part A: |
| 48 |
# |
| 49 |
# mldsa-native source and header files |
| 50 |
# |
| 51 |
# In this example, we compile the individual mldsa-native source files directly. |
| 52 |
# Alternatively, you can compile the 'monobuild' source file mldsa_native.c. |
| 53 |
# See examples/monolithic_build for that. |
| 54 |
MLD_SOURCE=$(wildcard \ |
| 55 |
mldsa_native/src/*.c \ |
| 56 |
mldsa_native/src/**/*.c \ |
| 57 |
mldsa_native/src/**/**/*.c \ |
| 58 |
mldsa_native/src/**/**/**/*.c \ |
| 59 |
mldsa_native/src/**/**/**/**/*.c) |
| 60 |
|
| 61 |
INC=-Imldsa_native -Imldsa_native/mldsa |
| 62 |
|
| 63 |
# Part B: |
| 64 |
# |
| 65 |
# Random number generator |
| 66 |
# |
| 67 |
# !!! WARNING !!! |
| 68 |
# |
| 69 |
# The randombytes() implementation used here is for TESTING ONLY. |
| 70 |
# You MUST NOT use this implementation outside of testing. |
| 71 |
# |
| 72 |
# !!! WARNING !!! |
| 73 |
RNG_SOURCE=$(wildcard test_only_rng/*.c) |
| 74 |
|
| 75 |
# Part C: |
| 76 |
# |
| 77 |
# Your application source code |
| 78 |
APP_SOURCE=$(wildcard *.c) |
| 79 |
|
| 80 |
ALL_SOURCE=$(MLD_SOURCE) $(RNG_SOURCE) $(APP_SOURCE) |
| 81 |
|
| 82 |
BUILD_DIR=build |
| 83 |
BIN=test_binary |
| 84 |
|
| 85 |
BINARY_NAME_FULL_44=$(BUILD_DIR)/$(BIN)44 |
| 86 |
BINARY_NAME_FULL_65=$(BUILD_DIR)/$(BIN)65 |
| 87 |
BINARY_NAME_FULL_87=$(BUILD_DIR)/$(BIN)87 |
| 88 |
BINARIES_FULL=$(BINARY_NAME_FULL_44) $(BINARY_NAME_FULL_65) $(BINARY_NAME_FULL_87) |
| 89 |
|
| 90 |
$(BINARY_NAME_FULL_44): CFLAGS += -DMLD_CONFIG_PARAMETER_SET=44 |
| 91 |
$(BINARY_NAME_FULL_65): CFLAGS += -DMLD_CONFIG_PARAMETER_SET=65 |
| 92 |
$(BINARY_NAME_FULL_87): CFLAGS += -DMLD_CONFIG_PARAMETER_SET=87 |
| 93 |
|
| 94 |
$(BINARIES_FULL): $(ALL_SOURCE) |
| 95 |
echo "$@" |
| 96 |
mkdir -p $(BUILD_DIR) |
| 97 |
$(CC) $(CFLAGS) $(INC) $^ -o $@ |
| 98 |
|
| 99 |
all: build |
| 100 |
|
| 101 |
build: $(BINARIES_FULL) |
| 102 |
|
| 103 |
run: $(BINARIES_FULL) |
| 104 |
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_44) |
| 105 |
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_65) |
| 106 |
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_87) |
| 107 |
|
| 108 |
clean: |
| 109 |
rm -rf $(BUILD_DIR) |