| 1 |
# Copyright (c) The mlkem-native project authors |
| 2 |
# Copyright (c) The mldsa-native project authors |
| 3 |
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT |
| 4 |
|
| 5 |
.PHONY: build run clean |
| 6 |
.DEFAULT_GOAL := all |
| 7 |
|
| 8 |
CC ?= gcc |
| 9 |
AR ?= ar |
| 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 |
-std=c99 \ |
| 30 |
-pedantic \ |
| 31 |
-MMD \ |
| 32 |
$(CFLAGS) |
| 33 |
|
| 34 |
|
| 35 |
# The following only concerns the cross-compilation tests. |
| 36 |
# You can likely ignore the following for your application. |
| 37 |
# |
| 38 |
# Append cross-prefix for cross compilation |
| 39 |
# When called from the root Makefile, CROSS_PREFIX has already been added here |
| 40 |
ifeq (,$(findstring $(CROSS_PREFIX),$(CC))) |
| 41 |
CC := $(CROSS_PREFIX)$(CC) |
| 42 |
endif |
| 43 |
|
| 44 |
ifeq (,$(findstring $(CROSS_PREFIX),$(AR))) |
| 45 |
AR := $(CROSS_PREFIX)$(AR) |
| 46 |
endif |
| 47 |
|
| 48 |
# Part A: |
| 49 |
# |
| 50 |
# mldsa-native source and header files |
| 51 |
# |
| 52 |
# Here, we use just a single monolithic compilation unit to include |
| 53 |
# multiple instances of mldsa-native. |
| 54 |
|
| 55 |
MLD_SOURCE=mldsa_native_all.c |
| 56 |
|
| 57 |
INC=-Imldsa_native/ -I./ |
| 58 |
|
| 59 |
# Part B: |
| 60 |
# |
| 61 |
# Random number generator |
| 62 |
# |
| 63 |
# !!! WARNING !!! |
| 64 |
# |
| 65 |
# The randombytes() implementation used here is for TESTING ONLY. |
| 66 |
# You MUST NOT use this implementation outside of testing. |
| 67 |
# |
| 68 |
# !!! WARNING !!! |
| 69 |
RNG_SOURCE=$(wildcard test_only_rng/*.c) |
| 70 |
|
| 71 |
# Part C: |
| 72 |
# |
| 73 |
# Your application source code |
| 74 |
APP_SOURCE=$(RNG_SOURCE) main.c |
| 75 |
|
| 76 |
BUILD_DIR=build |
| 77 |
BIN=test_binary |
| 78 |
LIB=libmldsa.a |
| 79 |
|
| 80 |
BINARY_NAME_FULL=$(BUILD_DIR)/$(BIN) |
| 81 |
LIB_NAME_FULL=$(BUILD_DIR)/$(LIB) |
| 82 |
|
| 83 |
$(LIB_NAME_FULL): $(MLD_SOURCE) |
| 84 |
echo "$@" |
| 85 |
mkdir -p $(BUILD_DIR) |
| 86 |
$(CC) -c $(CFLAGS) $(INC) $^ -o $(BUILD_DIR)/mldsa_native.o |
| 87 |
$(AR) rcs $@ $(BUILD_DIR)/mldsa_native.o |
| 88 |
strip -S $@ |
| 89 |
|
| 90 |
$(BINARY_NAME_FULL): $(APP_SOURCE) $(LIB_NAME_FULL) |
| 91 |
echo "$@" |
| 92 |
mkdir -p $(BUILD_DIR) |
| 93 |
$(CC) $(CFLAGS) $(INC) $^ -o $@ |
| 94 |
|
| 95 |
all: build |
| 96 |
|
| 97 |
build: $(BINARY_NAME_FULL) |
| 98 |
|
| 99 |
run: $(BINARY_NAME_FULL) |
| 100 |
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL) |
| 101 |
|
| 102 |
clean: |
| 103 |
rm -rf $(BUILD_DIR) |