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