1 #-----------------------------------------------------------------------------
2 # Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # See LICENSE.txt for the text of the license.
15 #-----------------------------------------------------------------------------
19 # To see full command lines, use make V=1
24 # USER not defined on some platforms like Archlinux
25 USER ?= $(shell id -u -n)
32 # rmdir only if dir is empty, you must add "-" when using it to tolerate failure
38 TARFLAGS ?= -v --ignore-failed-read -r
40 CROSS ?= arm-none-eabi-
47 CC_VERSION = $(shell $(CC) -dumpversion 2>/dev/null|sed 's/\..*//')
48 CC_VERSION := $(or $(strip $(CC_VERSION)),0)
54 GETENT_BL = getent group bluetooth
60 UDEV_PREFIX ?= /etc/udev/rules.d
61 INSTALLBINRELPATH ?= bin
62 INSTALLSHARERELPATH ?= share/proxmark3
63 INSTALLFWRELPATH ?= share/proxmark3/firmware
64 INSTALLTOOLSRELPATH ?= share/proxmark3/tools
65 INSTALLDOCSRELPATH ?= share/doc/proxmark3
68 platform = $(shell uname)
69 DETECTED_OS=$(platform)
71 ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
72 DETECTED_COMPILER = clang
74 DETECTED_COMPILER = gcc
77 ifeq ($(platform),Darwin)
78 ifeq ($(shell uname -p),arm64)
81 # iOS refuses to compile unless this is set
82 export IPHONEOS_DEPLOYMENT_TARGET=11.0
84 # M* macOS devices return arm
89 RANLIB= /usr/bin/ranlib
96 ifneq ($(strip $(HOMEBREW_PREFIX)),)
97 BREW_PREFIX = $(HOMEBREW_PREFIX)
99 BREW_PREFIX = $(shell brew --prefix 2>/dev/null)
100 ifeq ($(strip $(BREW_PREFIX)),)
106 ifeq ($(USE_MACPORTS),1)
107 MACPORTS_PREFIX ?= /opt/local
111 DEFCXXFLAGS = -g -O0 -pipe
112 DEFCFLAGS = -g -O0 -fstrict-aliasing -pipe
115 DEFCXXFLAGS = -Wall -Werror -O3 -pipe
116 DEFCFLAGS = -Wall -Werror -O3 -fstrict-aliasing -pipe
120 ifeq ($(DEBUG_ARM),1)
124 # Next ones are activated only if SANITIZE=1
126 DEFCFLAGS += -g -fsanitize=address -fno-omit-frame-pointer
127 DEFCXXFLAGS += -g -fsanitize=address -fno-omit-frame-pointer
128 DEFLDFLAGS += -g -fsanitize=address
130 # Some more warnings we want as errors:
131 DEFCFLAGS += -Wbad-function-cast -Wredundant-decls -Wmissing-prototypes -Wchar-subscripts -Wshadow -Wundef -Wwrite-strings -Wunused -Wuninitialized -Wpointer-arith -Winline -Wformat -Wformat-security -Winit-self -Wmissing-include-dirs -Wnested-externs -Wmissing-declarations -Wempty-body -Wignored-qualifiers -Wmissing-field-initializers -Wtype-limits -Wold-style-definition
132 # Some more warnings we need first to eliminate, so temporarely tolerated:
133 DEFCFLAGS += -Wcast-align -Wno-error=cast-align
134 DEFCFLAGS += -Wswitch-enum -Wno-error=switch-enum
135 # GCC 10 has issues with false positives on stringop-overflow, let's disable them for now (cf https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92955, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94335)
136 # beware these flags didn't exist for GCC < 7
137 ifeq ($(shell expr $(CC_VERSION) \>= 10), 1)
138 ifneq ($(DETECTED_COMPILER), clang)
139 DEFCFLAGS += -Wno-stringop-overflow -Wno-error=stringop-overflow
142 ifeq ($(platform),Darwin)
143 ifeq ($(shell uname -p),arm64)
144 # iOS will refuse to compile without the minimum target of iOS 11.0
145 DEFCFLAGS += -mios-version-min=11.0
147 # their readline has strict-prototype issues
148 DEFCFLAGS += -Wno-strict-prototypes
149 # some warnings about braced initializers on structs we want to ignore
150 DEFCFLAGS += -Wno-missing-braces
152 DEFCFLAGS += -Wstrict-prototypes
155 # Next ones are activated only if GCCEXTRA=1 or CLANGEXTRA=1
157 EXTRACFLAGS += -Wunused-parameter -Wno-error=unused-parameter
158 EXTRACFLAGS += -Wsign-compare -Wno-error=sign-compare
159 EXTRACFLAGS += -Wconversion -Wno-error=conversion -Wno-error=sign-conversion -Wno-error=float-conversion
161 # unknown to clang or old gcc:
162 # First we activate Wextra then we explicitly list those we know about
163 # Those without -Wno-error are supposed to be completely solved
164 GCCEXTRACFLAGS = -Wextra
165 GCCEXTRACFLAGS += -Wclobbered -Wno-error=clobbered
166 GCCEXTRACFLAGS += -Wcast-function-type
167 GCCEXTRACFLAGS += -Wimplicit-fallthrough=3 -Wno-error=implicit-fallthrough
168 GCCEXTRACFLAGS += -Wmissing-parameter-type
169 GCCEXTRACFLAGS += -Wold-style-declaration -Wno-error=old-style-declaration
170 GCCEXTRACFLAGS += -Woverride-init
171 GCCEXTRACFLAGS += -Wshift-negative-value
172 GCCEXTRACFLAGS += -Wunused-but-set-parameter -Wno-error=unused-but-set-parameter
173 # enable gcc static analysis
174 GCCEXTRACFLAGS += -fanalyzer
176 DEFCFLAGS += $(GCCEXTRACFLAGS) $(EXTRACFLAGS)
178 # unknown to gcc or old clang:
179 # First we activate Wextra then we explicitly list those we know about
180 # Those without -Wno-error are supposed to be completely solved
181 CLANGEXTRACFLAGS = -Wextra
182 CLANGEXTRACFLAGS += -Wtautological-type-limit-compare
183 CLANGEXTRACFLAGS += -Wnull-pointer-arithmetic
184 CLANGEXTRACFLAGS += -Woverride-init
185 CLANGEXTRACFLAGS += -Wshift-negative-value
186 CLANGEXTRACFLAGS += -Wimplicit-fallthrough
187 ifeq ($(CLANGEXTRA),1)
188 DEFCFLAGS += $(CLANGEXTRACFLAGS) $(EXTRACFLAGS)
190 ifeq ($(CLANGEVERYTHING),1)
191 DEFCFLAGS += -Weverything -Wno-error
194 DEFCFLAGS += -Wno-error