Debian Codegraph @

others/mbedtls/tf-psa-crypto/drivers/pqcp/mldsa-native/examples/multilevel_build_native/Makefile

raw
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 := $(wildcard \
59 mldsa_native/src/*.c \
60 mldsa_native/src/**/*.c \
61 mldsa_native/src/**/**/*.c \
62 mldsa_native/src/**/**/**/*.c \
63 mldsa_native/src/**/**/**/**/*.c \
64 mldsa_native/src/*.S \
65 mldsa_native/src/**/*.S \
66 mldsa_native/src/**/**/*.S \
67 mldsa_native/src/**/**/**/*.S \
68 mldsa_native/src/**/**/**/**/*.S)
69
70 BUILD_DIR=build
71 MLDSA44_DIR = $(BUILD_DIR)/mldsa44
72 MLDSA65_DIR = $(BUILD_DIR)/mldsa65
73 MLDSA87_DIR = $(BUILD_DIR)/mldsa87
74
75 MLDSA44_OBJS=$(patsubst %,$(MLDSA44_DIR)/%.o,$(MLD_SOURCE))
76 MLDSA65_OBJS=$(patsubst %,$(MLDSA65_DIR)/%.o,$(MLD_SOURCE))
77 MLDSA87_OBJS=$(patsubst %,$(MLDSA87_DIR)/%.o,$(MLD_SOURCE))
78
79 $(MLDSA44_OBJS): $(MLDSA44_DIR)/%.o: %
80 $(Q)echo " CC $@"
81 $(Q)[ -d $(@D) ] || mkdir -p $(@D)
82 $(Q)$(CC) -DMLD_CONFIG_MULTILEVEL_WITH_SHARED -DMLD_CONFIG_PARAMETER_SET=44 $(CFLAGS) -c $^ -o $@
83
84 $(MLDSA65_OBJS): $(MLDSA65_DIR)/%.o: %
85 $(Q)echo " CC $@"
86 $(Q)[ -d $(@D) ] || mkdir -p $(@D)
87 $(Q)$(CC) -DMLD_CONFIG_MULTILEVEL_NO_SHARED -DMLD_CONFIG_PARAMETER_SET=65 $(CFLAGS) -c $^ -o $@
88
89 $(MLDSA87_OBJS): $(MLDSA87_DIR)/%.o: %
90 $(Q)echo " CC $@"
91 $(Q)[ -d $(@D) ] || mkdir -p $(@D)
92 $(Q)$(CC) -DMLD_CONFIG_MULTILEVEL_NO_SHARED -DMLD_CONFIG_PARAMETER_SET=87 $(CFLAGS) -c $^ -o $@
93
94 mldsa44_objs: $(MLDSA44_OBJS)
95 mldsa65_objs: $(MLDSA65_OBJS)
96 mldsa87_objs: $(MLDSA87_OBJS)
97 mldsa_objs: mldsa44_objs mldsa65_objs mldsa87_objs
98
99 # Part B:
100 #
101 # Random number generator
102 #
103 # !!! WARNING !!!
104 #
105 # The randombytes() implementation used here is for TESTING ONLY.
106 # You MUST NOT use this implementation outside of testing.
107 #
108 # !!! WARNING !!!
109 RNG_SOURCE=$(wildcard test_only_rng/*.c)
110
111 # Part C:
112 #
113 # Your application source code
114 APP_SOURCE=$(wildcard *.c)
115
116 BIN=test_binary
117 BINARY_NAME_FULL=$(BUILD_DIR)/$(BIN)
118
119 $(BINARY_NAME_FULL): $(APP_SOURCE) $(RNG_SOURCE) $(MLDSA44_OBJS) $(MLDSA65_OBJS) $(MLDSA87_OBJS)
120 $(Q)mkdir -p $(BUILD_DIR)
121 $(Q)$(CC) $(CFLAGS) $^ -o $@
122
123 all: build
124
125 build: $(BINARY_NAME_FULL)
126
127 run: $(BINARY_NAME_FULL)
128 $(EXEC_WRAPPER) ./$(BINARY_NAME_FULL)
129
130 clean:
131 rm -rf $(BUILD_DIR)