Debian Codegraph @

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

raw
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 -Wno-unused-function \
28 -O3 \
29 -fomit-frame-pointer \
30 -std=c99 \
31 -pedantic \
32 -MMD \
33 $(CFLAGS)
34
35 # If you want to use the native backends, the compiler needs to know about
36 # the target architecture. Here, we import the default host detection from
37 # mldsa-native's tests, but you can write your own or specialize accordingly.
38 AUTO ?= 1
39 include auto.mk
40
41 # The following only concerns the cross-compilation tests.
42 # You can likely ignore the following for your application.
43 #
44 # Append cross-prefix for cross compilation
45 # When called from the root Makefile, CROSS_PREFIX has already been added here
46 ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
47 CC := $(CROSS_PREFIX)$(CC)
48 endif
49
50 ifeq (,$(findstring $(CROSS_PREFIX),$(AR)))
51 AR := $(CROSS_PREFIX)$(AR)
52 endif
53
54 # Part A:
55 #
56 # mldsa-native source and header files
57 #
58 # Here, the monolithic C file for mldsa-native is directly included in main.c,
59 # However, we still need to incldue the monolithic assembly file.
60 MLD_SOURCE_ASM = mldsa_native/mldsa_native.S
61
62 INC=-Imldsa_native/ -I./
63
64 # Part B:
65 #
66 # Random number generator
67 #
68 # !!! WARNING !!!
69 #
70 # The randombytes() implementation used here is for TESTING ONLY.
71 # You MUST NOT use this implementation outside of testing.
72 #
73 # !!! WARNING !!!
74 RNG_SOURCE=$(wildcard test_only_rng/*.c)
75
76 # Part C:
77 #
78 # Your application source code
79 APP_SOURCE=$(RNG_SOURCE) main.c
80
81 BUILD_DIR=build
82 BIN=test_binary
83
84 #
85 # Configuration adjustments
86 #
87
88 ASMFLAGS = -DMLD_CONFIG_MULTILEVEL_WITH_SHARED
89
90 BINARY_NAME_FULL=$(BUILD_DIR)/$(BIN)
91
92 MLD_OBJ_C=$(patsubst %,$(BUILD_DIR)/%.o,$(MLD_SOURCE_C))
93 MLD_OBJ_ASM=$(patsubst %,$(BUILD_DIR)/%.o,$(MLD_SOURCE_ASM))
94
95 Q ?= @
96
97 $(BUILD_DIR)/%.c.o: %.c
98 $(Q)echo "CC $^"
99 $(Q)[ -d $(@D) ] || mkdir -p $(@D)
100 $(Q)$(CC) -c $(CFLAGS) $(INC) $^ -o $@
101
102 $(BUILD_DIR)/%.S.o: %.S
103 $(Q)echo "AS $^"
104 $(Q)[ -d $(@D) ] || mkdir -p $(@D)
105 $(Q)$(CC) -c $(CFLAGS) $(ASMFLAGS) $(INC) $^ -o $@
106
107 $(BINARY_NAME_FULL): $(APP_SOURCE) $(MLD_OBJ_ASM)
108 $(Q)echo "CC $@"
109 $(Q)[ -d $(@D) ] || mkdir -p $(@D)
110 $(Q)$(CC) $(CFLAGS) $(INC) $^ -o $@
111 $(Q)strip -S $@
112
113 all: build
114
115 build: $(BINARY_NAME_FULL)
116
117 run: $(BINARY_NAME_FULL)
118 $(EXEC_WRAPPER) ./$(BINARY_NAME_FULL)
119
120 clean:
121 rm -rf $(BUILD_DIR)