Skip to content

Commit 4bffdec

Browse files
committed
Example: Update to new mlkem-native Makefile for Basic example
The Makefile that the basic example was using was based on a wrongly licensed Makefile in mlkem-native. mlkem-native has since reworked the Makefiles using the correct license (Apache-2.0 OR ISC OR MIT). This commit switches to that Makefile and makes the necessary adjustments to make it work with mldsa-native. Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent 94311a7 commit 4bffdec

File tree

3 files changed

+55
-45
lines changed

3 files changed

+55
-45
lines changed

examples/basic/Makefile

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,65 @@
1-
# (SPDX-License-Identifier: CC-BY-4.0)
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
24

3-
.PHONY: build run clean size
5+
.PHONY: build run clean
46
.DEFAULT_GOAL := all
57

6-
# Append cross-prefix for cross compilation
7-
# Remove or ignore for native builds
88
CC ?= gcc
9-
SIZE ?= size
9+
10+
# Adjust CFLAGS if needed
11+
CFLAGS := \
12+
-Wall \
13+
-Wextra \
14+
-Werror=unused-result \
15+
-Wpedantic \
16+
-Werror \
17+
-Wmissing-prototypes \
18+
-Wshadow \
19+
-Wpointer-arith \
20+
-Wredundant-decls \
21+
-Wconversion \
22+
-Wsign-conversion \
23+
-Wno-long-long \
24+
-Wno-unknown-pragmas \
25+
-Wno-unused-command-line-argument \
26+
-O3 \
27+
-fomit-frame-pointer \
28+
-std=c99 \
29+
-pedantic \
30+
-MMD \
31+
$(CFLAGS)
32+
33+
# If you want to use the native backends, the compiler needs to know about
34+
# the target architecture. Here, we import the default host detection from
35+
# mldsa-native's tests, but you can write your own or specialize accordingly.
36+
AUTO ?= 1
37+
include auto.mk
38+
39+
# The following only concerns the cross-compilation tests.
40+
# You can likely ignore the following for your application.
41+
#
42+
# Append cross-prefix for cross compilation
1043
# When called from the root Makefile, CROSS_PREFIX has already been added here
1144
ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
1245
CC := $(CROSS_PREFIX)$(CC)
1346
endif
1447

15-
ifeq (,$(findstring $(CROSS_PREFIX),$(SIZE)))
16-
SIZE := $(CROSS_PREFIX)$(SIZE)
17-
endif
18-
1948
# Part A:
2049
#
2150
# mldsa-native source and header files
2251
#
2352
# If you are not concerned about minimizing for a specific backend,
2453
# you can just include _all_ source files into your build.
25-
MLD_SOURCE=$(wildcard \
26-
../../mldsa/*.c \
27-
../../mldsa/**/*.c \
28-
../../mldsa/**/**/*.c \
29-
../../mldsa/**/**/**/*.c)
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=$(wildcard \
59+
mldsa_native/mldsa/*.c \
60+
mldsa_native/mldsa/**/*.c \
61+
mldsa_native/mldsa/**/**/*.c \
62+
mldsa_native/mldsa/**/**/**/*.c)
3063

3164
# Part B:
3265
#
@@ -50,29 +83,12 @@ ALL_SOURCE=$(MLD_SOURCE) $(RNG_SOURCE) $(APP_SOURCE)
5083
BUILD_DIR=build
5184
BIN=test_binary
5285

53-
CFLAGS := \
54-
-Wall \
55-
-Wextra \
56-
-Werror \
57-
-Wmissing-prototypes \
58-
-Wshadow \
59-
-Werror \
60-
-Wpointer-arith \
61-
-Wredundant-decls \
62-
-Wconversion \
63-
-Wsign-conversion \
64-
-Wno-long-long \
65-
-Wno-unknown-pragmas \
66-
-Wno-unused-command-line-argument \
67-
-fomit-frame-pointer \
68-
-std=c99 \
69-
-pedantic \
70-
-MMD \
71-
-O3 \
72-
$(CFLAGS)
86+
#
87+
# Configuration adjustments
88+
#
7389

74-
# Use the default namespace prefix from config.h
75-
# CFLAGS += -DMLD_CONFIG_NAMESPACE_PREFIX=mldsa
90+
# Pick prefix
91+
CFLAGS += -DMLD_CONFIG_NAMESPACE_PREFIX=mldsa
7692

7793
BINARY_NAME_FULL_44=$(BUILD_DIR)/$(BIN)44
7894
BINARY_NAME_FULL_65=$(BUILD_DIR)/$(BIN)65
@@ -88,7 +104,7 @@ $(BINARIES_FULL): $(ALL_SOURCE)
88104
mkdir -p $(BUILD_DIR)
89105
$(CC) $(CFLAGS) $^ -o $@
90106

91-
all: build size
107+
all: build
92108

93109
build: $(BINARIES_FULL)
94110

@@ -97,13 +113,5 @@ run: $(BINARIES_FULL)
97113
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_65)
98114
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_87)
99115

100-
size: build
101-
@echo "=== Size info for $(BINARY_NAME_FULL_44) ==="
102-
@$(SIZE) $(BINARY_NAME_FULL_44)
103-
@echo "=== Size info for $(BINARY_NAME_FULL_65) ==="
104-
@$(SIZE) $(BINARY_NAME_FULL_65)
105-
@echo "=== Size info for $(BINARY_NAME_FULL_87) ==="
106-
@$(SIZE) $(BINARY_NAME_FULL_87)
107-
108116
clean:
109117
rm -rf $(BUILD_DIR)

examples/basic/auto.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../test/mk/auto.mk

examples/basic/mldsa_native/mldsa

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../mldsa

0 commit comments

Comments
 (0)