2022-01-07 08:58:03 +08:00
#-----------------------------------------------------------------------------
# Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# See LICENSE.txt for the text of the license.
#-----------------------------------------------------------------------------
2019-08-31 04:10:06 +08:00
ifneq ($(V),1)
Q?=@
endif
# To see full command lines, use make V=1
# been here
DEFSBEENHERE = true
2022-03-02 17:27:50 +08:00
# USER not defined on some platforms like Archlinux
USER ?= $(shell id -u -n)
2019-08-31 04:10:06 +08:00
CP = cp -a
GZIP = gzip
MKDIR = mkdir -p
RM = rm -f
RMDIR = rm -rf
2023-01-15 19:11:31 +08:00
# rmdir only if dir is empty, you must add "-" when using it to tolerate failure
RMDIR_SOFT = rmdir
2019-08-31 04:10:06 +08:00
MV = mv
TOUCH = touch
FALSE = false
TAR = tar
TARFLAGS ?= -v --ignore-failed-read -r
TARFLAGS += -C .. -f
2022-10-16 15:19:13 +08:00
CROSS ?= arm-none-eabi-
2022-08-21 05:44:32 +08:00
CC ?= gcc
CXX ?= g++
2020-05-21 00:12:41 +08:00
SH = sh
2020-05-22 23:47:30 +08:00
BASH = bash
2020-05-21 00:12:41 +08:00
PERL = perl
2020-11-11 07:03:58 +08:00
SWIG = swig
2020-10-20 03:21:24 +08:00
CC_VERSION = $(shell $(CC) -dumpversion 2>/dev/null|sed 's/\..*//')
CC_VERSION := $(or $(strip $(CC_VERSION)),0)
2019-08-31 04:10:06 +08:00
2022-10-16 15:19:13 +08:00
ECHO = echo
SUDO = sudo
USERMOD = usermod -aG
ADDUSER = adduser
GETENT_BL = getent group bluetooth
2019-08-31 04:10:06 +08:00
PATHSEP=/
2019-09-06 05:20:46 +08:00
PREFIX ?= /usr/local
UDEV_PREFIX ?= /etc/udev/rules.d
INSTALLBINRELPATH ?= bin
INSTALLSHARERELPATH ?= share/proxmark3
INSTALLFWRELPATH ?= share/proxmark3/firmware
INSTALLTOOLSRELPATH ?= share/proxmark3/tools
INSTALLDOCSRELPATH ?= share/doc/proxmark3
2022-05-04 01:04:01 +08:00
export INSTALLSUDO
2019-08-31 04:10:06 +08:00
platform = $(shell uname)
DETECTED_OS=$(platform)
2020-10-22 00:06:00 +08:00
ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
2020-10-22 00:41:18 +08:00
DETECTED_COMPILER = clang
2020-10-22 00:06:00 +08:00
else
2020-10-22 00:41:18 +08:00
DETECTED_COMPILER = gcc
2020-10-22 00:06:00 +08:00
endif
2019-08-31 04:10:06 +08:00
ifeq ($(platform),Darwin)
2023-06-25 08:19:46 +08:00
ifeq ($(shell uname -p),arm64)
# The platform is iOS
USE_BREW ?= 0
# iOS refuses to compile unless this is set
export IPHONEOS_DEPLOYMENT_TARGET=11.0
else
# M* macOS devices return arm
USE_BREW ?= 1
endif
2021-08-23 01:40:29 +08:00
USE_MACPORTS ?= 0
2020-10-22 00:41:18 +08:00
AR= /usr/bin/ar rcs
RANLIB= /usr/bin/ranlib
2019-08-31 04:10:06 +08:00
else
2020-10-22 00:41:18 +08:00
AR= ar rcs
RANLIB= ranlib
2019-08-31 04:10:06 +08:00
endif
2020-05-04 01:25:14 +08:00
2021-05-23 08:14:20 +08:00
ifeq ($(USE_BREW),1)
2022-07-31 00:18:43 +08:00
ifneq ($(strip $(HOMEBREW_PREFIX)),)
BREW_PREFIX = $(HOMEBREW_PREFIX)
else
BREW_PREFIX = $(shell brew --prefix 2>/dev/null)
ifeq ($(strip $(BREW_PREFIX)),)
USE_BREW = 0
endif
2021-07-03 22:07:53 +08:00
endif
2021-01-04 08:27:20 +08:00
endif
2021-08-23 01:40:29 +08:00
ifeq ($(USE_MACPORTS),1)
MACPORTS_PREFIX ?= /opt/local
endif
2020-10-20 07:00:00 +08:00
ifeq ($(DEBUG),1)
DEFCXXFLAGS = -g -O0 -pipe
DEFCFLAGS = -g -O0 -fstrict-aliasing -pipe
DEFLDFLAGS =
else
2023-11-13 17:19:09 +08:00
DEFCXXFLAGS = -Wall -Werror -O3 -pipe
DEFCFLAGS = -Wall -Werror -O3 -fstrict-aliasing -pipe
2020-10-20 07:00:00 +08:00
DEFLDFLAGS =
endif
2020-12-30 07:19:21 +08:00
ifeq ($(DEBUG_ARM),1)
APP_CFLAGS += -g
SKIP_COMPRESSION=1
endif
2020-10-06 22:58:42 +08:00
# Next ones are activated only if SANITIZE=1
ifeq ($(SANITIZE),1)
DEFCFLAGS += -g -fsanitize=address -fno-omit-frame-pointer
DEFCXXFLAGS += -g -fsanitize=address -fno-omit-frame-pointer
DEFLDFLAGS += -g -fsanitize=address
endif
2020-05-04 01:25:14 +08:00
# Some more warnings we want as errors:
2020-05-12 04:15:32 +08:00
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
2020-05-04 01:25:14 +08:00
# Some more warnings we need first to eliminate, so temporarely tolerated:
2020-05-09 21:06:28 +08:00
DEFCFLAGS += -Wcast-align -Wno-error=cast-align
2020-05-12 05:46:26 +08:00
DEFCFLAGS += -Wswitch-enum -Wno-error=switch-enum
2020-10-20 03:21:24 +08:00
# 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)
# beware these flags didn't exist for GCC < 7
ifeq ($(shell expr $(CC_VERSION) \>= 10), 1)
2020-10-22 00:06:00 +08:00
ifneq ($(DETECTED_COMPILER), clang)
2020-10-20 03:21:24 +08:00
DEFCFLAGS += -Wno-stringop-overflow -Wno-error=stringop-overflow
2020-10-22 00:41:18 +08:00
endif
2020-10-20 03:21:24 +08:00
endif
2020-05-12 07:49:01 +08:00
ifeq ($(platform),Darwin)
2023-06-25 08:19:46 +08:00
ifeq ($(shell uname -p),arm64)
# iOS will refuse to compile without the minimum target of iOS 11.0
DEFCFLAGS += -mios-version-min=11.0
endif
2020-10-22 00:41:18 +08:00
# their readline has strict-prototype issues
DEFCFLAGS += -Wno-strict-prototypes
2022-02-28 22:36:03 +08:00
# some warnings about braced initializers on structs we want to ignore
DEFCFLAGS += -Wno-missing-braces
2020-05-12 07:49:01 +08:00
else
2020-10-22 00:41:18 +08:00
DEFCFLAGS += -Wstrict-prototypes
2020-05-12 07:49:01 +08:00
endif
2020-05-09 21:06:28 +08:00
# Next ones are activated only if GCCEXTRA=1 or CLANGEXTRA=1
EXTRACFLAGS =
EXTRACFLAGS += -Wunused-parameter -Wno-error=unused-parameter
EXTRACFLAGS += -Wsign-compare -Wno-error=sign-compare
2020-05-20 19:28:37 +08:00
EXTRACFLAGS += -Wconversion -Wno-error=conversion -Wno-error=sign-conversion -Wno-error=float-conversion
2020-05-09 21:06:28 +08:00
# unknown to clang or old gcc:
# First we activate Wextra then we explicitly list those we know about
2020-05-09 22:12:54 +08:00
# Those without -Wno-error are supposed to be completely solved
2020-05-09 21:06:28 +08:00
GCCEXTRACFLAGS = -Wextra
GCCEXTRACFLAGS += -Wclobbered -Wno-error=clobbered
2020-05-09 22:12:54 +08:00
GCCEXTRACFLAGS += -Wcast-function-type
2020-05-09 21:06:28 +08:00
GCCEXTRACFLAGS += -Wimplicit-fallthrough=3 -Wno-error=implicit-fallthrough
2020-05-09 22:12:54 +08:00
GCCEXTRACFLAGS += -Wmissing-parameter-type
2020-05-09 21:06:28 +08:00
GCCEXTRACFLAGS += -Wold-style-declaration -Wno-error=old-style-declaration
2020-05-09 22:12:54 +08:00
GCCEXTRACFLAGS += -Woverride-init
GCCEXTRACFLAGS += -Wshift-negative-value
2020-05-09 21:06:28 +08:00
GCCEXTRACFLAGS += -Wunused-but-set-parameter -Wno-error=unused-but-set-parameter
2023-11-13 19:22:36 +08:00
# enable gcc static analysis
GCCEXTRACFLAGS += -fanalyzer
2020-05-09 21:06:28 +08:00
ifeq ($(GCCEXTRA),1)
DEFCFLAGS += $(GCCEXTRACFLAGS) $(EXTRACFLAGS)
endif
# unknown to gcc or old clang:
# First we activate Wextra then we explicitly list those we know about
2020-05-09 22:12:54 +08:00
# Those without -Wno-error are supposed to be completely solved
2020-05-09 21:06:28 +08:00
CLANGEXTRACFLAGS = -Wextra
CLANGEXTRACFLAGS += -Wtautological-type-limit-compare
CLANGEXTRACFLAGS += -Wnull-pointer-arithmetic
CLANGEXTRACFLAGS += -Woverride-init
CLANGEXTRACFLAGS += -Wshift-negative-value
CLANGEXTRACFLAGS += -Wimplicit-fallthrough
ifeq ($(CLANGEXTRA),1)
DEFCFLAGS += $(CLANGEXTRACFLAGS) $(EXTRACFLAGS)
endif
2020-05-12 07:49:01 +08:00
ifeq ($(CLANGEVERYTHING),1)
DEFCFLAGS += -Weverything -Wno-error
endif
ifeq ($(NOERROR),1)
DEFCFLAGS += -Wno-error
2020-05-04 01:25:14 +08:00
endif