Debian Codegraph @

crt/s2n/s2n.mk

raw symbols SCIP
1 # You may not use this file except in compliance with the License.
2 # A copy of the License is located at
3 #
4 # http://aws.amazon.com/apache2.0
5 #
6 # or in the "license" file accompanying this file. This file is distributed
7 # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
8 # express or implied. See the License for the specific language governing
9 # permissions and limitations under the License.
10 #
11
12 ifeq ($(PLATFORM),Darwin)
13 LIBS = -lc -pthread
14 else ifeq ($(PLATFORM),FreeBSD)
15 LIBS = -lthr
16 else ifeq ($(PLATFORM),NetBSD)
17 LIBS = -pthread
18 else ifeq ($(PLATFORM),OpenBSD)
19 LIBS = -pthread -lkvm
20 else
21 LIBS = -pthread -ldl -lrt
22 endif
23
24 CRYPTO_LIBS = -lcrypto
25
26 CC := $(CROSS_COMPILE)$(CC)
27 CXX := $(CROSS_COMPILE)$(CXX)
28 AR = $(CROSS_COMPILE)ar
29 RANLIB = $(CROSS_COMPILE)ranlib
30 CLANG ?= clang-3.9
31 LLVMLINK ?= llvm-link-3.9
32
33 SOURCES = $(wildcard *.c *.h)
34 CRUFT = $(wildcard *.c~ *.h~ *.c.BAK *.h.BAK *.o *.a *.so *.dylib *.bc *.gcov *.gcda *.gcno *.info *.profraw *.tmp)
35 INDENT = $(shell (if indent --version 2>&1 | grep GNU > /dev/null; then echo indent ; elif gindent --version 2>&1 | grep GNU > /dev/null; then echo gindent; else echo true ; fi ))
36
37 # BoringSSL is a C11 library and has less strict compiler flags than s2n. All other libcryptos use the default c99 flags
38 ifeq ($(S2N_LIBCRYPTO), boringssl)
39 DEFAULT_CFLAGS = -std=c11
40 else ifeq ($(S2N_LIBCRYPTO), awslc)
41 # AWS-LC is a BoringSSL derivative and has fixed the c11 issues but not all -Wcast-qual warnings
42 DEFAULT_CFLAGS = -std=c99
43 else ifeq ($(S2N_LIBCRYPTO), awslc-fips)
44 # AWS-LC is a BoringSSL derivative and has fixed the c11 issues but not all -Wcast-qual warnings
45 DEFAULT_CFLAGS = -std=c99
46 else
47 DEFAULT_CFLAGS = -std=c99 -Wcast-qual
48 endif
49
50 DEFAULT_CFLAGS += -pedantic -Wall -Werror -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized \
51 -Wshadow -Wcast-align -Wwrite-strings -fPIC -Wno-missing-braces\
52 -O2 -I$(LIBCRYPTO_ROOT)/include/ \
53 -DS2N_BUILD_RELEASE -include utils/s2n_prelude.h \
54 -I$(S2N_ROOT)/api/ -I$(S2N_ROOT) -Wno-deprecated-declarations -Wno-unknown-pragmas -Wformat-security \
55 -fgnu89-inline -fvisibility=hidden -DS2N_EXPORTS
56
57 COVERAGE_CFLAGS = -fprofile-arcs -ftest-coverage
58 COVERAGE_LDFLAGS = --coverage
59 LDFLAGS = -z relro -z now -z noexecstack
60
61 # Add a flag to disable stack protector for alternative libcs without
62 # libssp.
63 ifneq ($(NO_STACK_PROTECTOR), 1)
64 DEFAULT_CFLAGS += -Wstack-protector -fstack-protector-all
65 endif
66
67 ifeq ($(NO_INLINE), 1)
68 DEFAULT_CFLAGS += -fno-inline
69 endif
70
71 CFLAGS += ${DEFAULT_CFLAGS}
72
73 ifdef GCC_VERSION
74 ifneq ("$(GCC_VERSION)","NONE")
75 CC=gcc-$(GCC_VERSION)
76 # Make doesn't support greater than checks, this uses `test` to compare values, then `echo $$?` to return the value of test's
77 # exit code and finally uses the built in make `ifeq` to check if it was true and then adds the extra flag.
78 ifeq ($(shell test $(GCC_VERSION) -gt 7; echo $$?), 0)
79 CFLAGS += -Wimplicit-fallthrough
80 endif
81
82 ifeq ($(shell test $(GCC_VERSION) -ge 10; echo $$?), 0)
83 CFLAGS += -fanalyzer
84 endif
85 endif
86 endif
87
88 DEBUG_CFLAGS = -g3 -ggdb -fno-omit-frame-pointer -fno-optimize-sibling-calls
89
90 ifdef S2N_ADDRESS_SANITIZER
91 CFLAGS += -fsanitize=address -fuse-ld=gold -DS2N_ADDRESS_SANITIZER=1 ${DEBUG_CFLAGS}
92 endif
93
94 ifdef S2N_GDB
95 S2N_DEBUG = 1
96 CFLAGS += -O0
97 endif
98
99 ifdef S2N_DEBUG
100 CFLAGS += ${DEBUG_CFLAGS}
101 endif
102
103 # Prepare CPPFLAGS by stripping out the unsupported options
104 CPPFLAGS = ${CFLAGS}
105 CPPFLAGS:=$(filter-out -Wimplicit,${CPPFLAGS})
106 CPPFLAGS:=$(filter-out -std=c99,${CPPFLAGS})
107 CPPFLAGS:=$(filter-out -fgnu89-inline,${CPPFLAGS})
108
109 # Prints more information when running tests
110 ifdef S2N_TEST_DEBUG
111 DEFAULT_CFLAGS += -DS2N_TEST_DEBUG
112 endif
113
114 LLVM_GCOV_MARKER_FILE=${COVERAGE_DIR}/use-llvm-gcov.tmp
115
116 # Disable strict-prototypes check in clang
117 ifneq '' '$(findstring clang,$(CC))'
118 CFLAGS += -Wno-strict-prototypes
119 DEFAULT_CFLAGS += -Wno-strict-prototypes
120 CPPFLAGS += -Wno-strict-prototypes
121 endif
122
123 # If COV_TOOL isn't set, pick a default COV_TOOL depending on if the LLVM Marker File was created.
124 ifndef COV_TOOL
125 ifneq ("$(wildcard $(LLVM_GCOV_MARKER_FILE))","")
126 COV_TOOL=llvm-gcov.sh
127 endif
128 endif
129
130 # Used for testing.
131 prefix ?= /usr/local
132 exec_prefix ?= $(prefix)
133 bindir ?= $(exec_prefix)/bin
134 libdir ?= $(exec_prefix)/lib64
135 includedir ?= $(exec_prefix)/include
136
137 feature_probe = $(shell $(CC) $(CFLAGS) $(shell cat $(S2N_ROOT)/tests/features/GLOBAL.flags) $(shell cat $(S2N_ROOT)/tests/features/$(1).flags) -c -o tmp.o $(S2N_ROOT)/tests/features/$(1).c > /dev/null 2>&1 && echo "-D$(1)=1"; rm tmp.o > /dev/null 2>&1)
138
139 FEATURES := $(notdir $(patsubst %.c,%,$(wildcard $(S2N_ROOT)/tests/features/*.c)))
140 SUPPORTED_FEATURES := $(foreach feature,$(FEATURES),$(call feature_probe,$(feature)))
141 CFLAGS += $(SUPPORTED_FEATURES)
142 DEFAULT_CFLAGS += $(SUPPORTED_FEATURES)
143 CPPCFLAGS += $(SUPPORTED_FEATURES)
144
145 # only enable stacktraces if execinfo is available
146 ifneq ("$(call feature_probe,S2N_EXECINFO_AVAILABLE)","")
147 CFLAGS += -DS2N_STACKTRACE
148 DEFAULT_CFLAGS += -DS2N_STACKTRACE
149 CPPCFLAGS += -DS2N_STACKTRACE
150 endif
151
152 CFLAGS_LLVM = ${DEFAULT_CFLAGS} -emit-llvm -c -g -O1
153
154 $(BITCODE_DIR)%.bc: %.c
155 $(CLANG) $(CFLAGS_LLVM) -o $@ $<
156
157
158 INDENTOPTS = -npro -kr -i4 -ts4 -nut -sob -l180 -ss -ncs -cp1
159
160 .PHONY : indentsource
161 indentsource:
162 ( for source in ${SOURCES} ; do ${INDENT} ${INDENTOPTS} $$source; done )
163
164 .PHONY : lcov
165 lcov:
166 lcov --capture --directory . --gcov-tool $(COV_TOOL) --output ./coverage.info
167
168
169 .PHONY : decruft
170 decruft:
171 $(RM) -- ${CRUFT}