Debian Codegraph @

others/mbedtls/tf-psa-crypto/drivers/pqcp/mldsa-native/test/mk/config.mk

raw symbols SCIP
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 ifndef _CONFIG
5 _CONFIG :=
6
7 SRCDIR := $(CURDIR)
8
9 ##############
10 # GCC config #
11 ##############
12
13 CROSS_PREFIX ?=
14 CC ?= gcc
15 CPP ?= cpp
16 AR ?= ar
17 CC := $(CROSS_PREFIX)$(CC)
18 CPP := $(CROSS_PREFIX)$(CPP)
19 AR := $(CROSS_PREFIX)$(AR)
20 LD := $(CC)
21 OBJCOPY := $(CROSS_PREFIX)objcopy
22 SIZE := $(CROSS_PREFIX)size
23
24 # NOTE: gcc-ar is a wrapper around ar that ensures proper integration with GCC plugins,
25 # such as lto. Using gcc-ar is preferred when creating or linking static libraries
26 # if the binary is compiled with -flto. However, it is not universally present, so
27 # only use it if available.
28 CC_AR ?= $(if $(and $(findstring gcc,$(shell $(CC) --version)), $(findstring gcc-ar, $(shell which $(CROSS_PREFIX)gcc-ar))),gcc-ar,ar)
29 CC_AR := $(CROSS_PREFIX)$(CC_AR)
30
31 #################
32 # Common config #
33 #################
34 CFLAGS := \
35 -Wall \
36 -Wextra \
37 -Werror=unused-result \
38 -Wpedantic \
39 -Werror \
40 -Wmissing-prototypes \
41 -Wshadow \
42 -Wpointer-arith \
43 -Wredundant-decls \
44 -Wconversion \
45 -Wsign-conversion \
46 -Wno-long-long \
47 -Wno-unknown-pragmas \
48 -Wno-unused-command-line-argument \
49 -O3 \
50 -fomit-frame-pointer \
51 -std=c99 \
52 -pedantic \
53 -MMD \
54 $(CFLAGS)
55
56 ##################
57 # Some Variables #
58 ##################
59 Q ?= @
60
61 HOST_PLATFORM := $(shell uname -s)-$(shell uname -m)
62 # linux x86_64
63 ifeq ($(HOST_PLATFORM),Linux-x86_64)
64 CFLAGS += -z noexecstack
65 endif
66
67 ifeq ($(CYCLES),PMU)
68 CFLAGS += -DPMU_CYCLES
69 endif
70
71 ifeq ($(CYCLES),PERF)
72 CFLAGS += -DPERF_CYCLES
73 endif
74
75 ifeq ($(CYCLES),MAC)
76 CFLAGS += -DMAC_CYCLES
77 endif
78
79 ##############################
80 # Include retained variables #
81 ##############################
82
83 RETAINED_VARS := CROSS_PREFIX CYCLES OPT AUTO
84
85 # Capture values of environment variables before setting defaults,
86 # this ensures we can detect when they change in order to trigger a rebuild.
87 define CAPTURE_VAR
88 $(1)_FROM_ENV := $$($(1))
89 endef
90 $(foreach var,$(RETAINED_VARS),$(eval $(call CAPTURE_VAR,$(var))))
91
92 CYCLES ?=
93 OPT ?= 1
94
95 MAKE_OBJS = $(2:%=$(1)/%.o)
96 OBJS = $(call MAKE_OBJS,$(BUILD_DIR),$(1))
97
98 CONFIG := $(BUILD_DIR)/config.mk
99
100 -include $(CONFIG)
101
102 # After including the cached config, restore environment/command-line values if they were set
103 define RESTORE_VAR
104 ifneq ($$($(1)_FROM_ENV),)
105 $(1) := $$($(1)_FROM_ENV)
106 endif
107 endef
108 $(foreach var,$(RETAINED_VARS),$(eval $(call RESTORE_VAR,$(var))))
109
110 $(CONFIG):
111 @echo " GEN $@"
112 $(Q)[ -d $(@D) ] || mkdir -p $(@D)
113 @echo "# These variables are retained and can't be changed without a clean" > $@
114 @$(foreach var,$(RETAINED_VARS),echo "$(var) := $($(var))" >> $@; echo "LAST_$(var) := $($(var))" >> $@;)
115
116 define VAR_CHECK
117 ifneq ($$(origin LAST_$(1)),undefined)
118 ifneq "$$($(1))" "$$(LAST_$(1))"
119 $$(info Variable $(1) changed, forcing rebuild!)
120 .PHONY: $(CONFIG)
121 endif
122 endif
123 endef
124
125 $(foreach VAR,$(RETAINED_VARS),$(eval $(call VAR_CHECK,$(VAR))))
126 endif