1 #-----------------------------------------------------------------------------
2 # This code is licensed to you under the terms of the GNU GPL, version 2 or,
3 # at your option, any later version. See the LICENSE.txt file for the text of
5 #-----------------------------------------------------------------------------
6 # Common makefile functions for all platforms
7 #-----------------------------------------------------------------------------
9 # Make sure that all is the default target
10 # (The including Makefile still needs to define what 'all' is)
14 # This Makefile might have been called from various subdirs, trying to find our Makefile.defs
15 ifeq ($(DEFSBEENHERE),)
16 -include Makefile.defs
18 ifeq ($(DEFSBEENHERE),)
19 -include ../Makefile.defs
21 ifeq ($(DEFSBEENHERE),)
22 -include ../../Makefile.defs
24 ifeq ($(DEFSBEENHERE),)
25 $(error Can't find Makefile.defs)
31 OBJCOPY = $(CROSS)objcopy
35 INCLUDE = -I../include -I../common_arm -I../common_fpga -I../common -I.
37 # Also search prerequisites in the common directory (for usb.c), the fpga directory (for fpga.bit), and the lz4 directory
38 VPATH = . ../common_arm ../common ../common/crapto1 ../common/mbedtls ../common/lz4 ../fpga ../armsrc/Standalone
40 INCLUDES = ../include/proxmark3_arm.h ../include/at91sam7s512.h ../include/config_gpio.h ../include/pm3_cmd.h
42 ARMCFLAGS = -mthumb-interwork -fno-builtin
43 DEFCFLAGS = -Wall -Werror -Os -pedantic -fstrict-aliasing -pipe
45 # Some more warnings we want as errors:
46 DEFCFLAGS += -Wbad-function-cast -Wchar-subscripts -Wundef -Wunused -Wuninitialized -Wpointer-arith -Wformat -Wformat-security -Winit-self -Wmissing-include-dirs -Wnested-externs -Wempty-body -Wignored-qualifiers -Wmissing-field-initializers -Wtype-limits
48 # Some more warnings we need first to eliminate, so temporarely tolerated:
49 DEFCFLAGS += -Wshadow -Wno-error=shadow
50 DEFCFLAGS += -Winline -Wno-error=inline
51 DEFCFLAGS += -Wmissing-prototypes -Wno-error=missing-prototypes
52 DEFCFLAGS += -Wmissing-declarations -Wno-error=missing-declarations
53 DEFCFLAGS += -Wstrict-prototypes -Wno-error=strict-prototypes
54 # still vsnprintf etc to sort out...
55 #DEFCFLAGS += -Wredundant-decls -Wno-error=redundant-decls
56 #DEFCFLAGS += -Wcast-align -Wno-error=cast-align
58 # Next ones are activated only if GCCEXTRA=1
60 EXTRACFLAGS += -Wunused-parameter -Wno-error=unused-parameter
61 EXTRACFLAGS += -Wswitch-enum -Wno-error=switch-enum
62 EXTRACFLAGS += -Wsign-compare -Wno-error=sign-compare
63 EXTRACFLAGS += -Wold-style-definition -Wno-error=old-style-definition
64 EXTRACFLAGS += -Wconversion -Wno-error=conversion -Wno-error=sign-conversion -Wno-error=float-conversion
66 # unknown to clang or old gcc:
67 # First we activate Wextra then we explicitly list those we know about
68 # Those without -Wno-error are supposed to be completely solved
69 GCCEXTRACFLAGS = -Wextra
70 # unknown to arm-none-eabi/4.9.3
71 GCCEXTRACFLAGS += -Wwrite-strings -Wno-error=discarded-qualifiers
73 GCCEXTRACFLAGS += -Wold-style-declaration -Wno-error=old-style-declaration
74 GCCEXTRACFLAGS += -Wimplicit-fallthrough=3 -Wno-error=implicit-fallthrough
75 GCCEXTRACFLAGS += -Wclobbered
76 GCCEXTRACFLAGS += -Wcast-function-type
77 GCCEXTRACFLAGS += -Wmissing-parameter-type
78 GCCEXTRACFLAGS += -Woverride-init
79 GCCEXTRACFLAGS += -Wshift-negative-value
80 GCCEXTRACFLAGS += -Wunused-but-set-parameter
81 # Not yet enabled in DEFCFLAGS:
82 GCCEXTRACFLAGS += -Wredundant-decls -Wno-error=redundant-decls
83 GCCEXTRACFLAGS += -Wcast-align -Wno-error=cast-align
86 DEFCFLAGS += $(GCCEXTRACFLAGS) $(EXTRACFLAGS)
89 DEFCFLAGS += -Wno-error
92 CROSS_CFLAGS ?= $(DEFCFLAGS)
93 CROSS_CFLAGS += $(ARMCFLAGS) -c $(INCLUDE) -std=c99 -DON_DEVICE $(APP_CFLAGS)
95 CROSS_LDFLAGS += -nostartfiles -nodefaultlibs -Wl,-gc-sections -Wl,--build-id=none -n
98 # Flags to generate temporary dependency files
99 DEPFLAGS = -MT $@ -MMD -MP -MF $(OBJDIR)/$*.Td
100 # make temporary to final dependency files after successful compilation
101 POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d
103 THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(THUMBSRC)))
104 ARMOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(ARMSRC)))
105 ASMOBJ = $(patsubst %.s,$(OBJDIR)/%.o,$(notdir $(ASMSRC)))
106 VERSIONOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(VERSIONSRC)))
108 $(THUMBOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES)
110 $(Q)$(CC) $(CROSS_CFLAGS) $(DEPFLAGS) -mthumb -o $@ $<
113 $(ARMOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES)
115 $(Q)$(CC) $(CROSS_CFLAGS) $(DEPFLAGS) -o $@ $<
118 $(ASMOBJ): $(OBJDIR)/%.o: %.s
120 $(Q)$(CC) $(CROSS_CFLAGS) -o $@ $<
122 $(VERSIONOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES)
124 $(Q)$(CC) $(CROSS_CFLAGS) -mthumb -o $@ $<
126 # This objcopy call translates physical flash addresses to logical addresses
127 # without touching start address or RAM addresses (.bss and .data sections)
128 # See ldscript.common. -- Henryk Plötz <henryk@ploetzli.ch> 2009-08-27
129 OBJCOPY_TRANSLATIONS = --no-change-warnings \
130 --change-addresses -0x100000 --change-start 0 \
131 --change-section-address .bss+0 --change-section-address .data-0x100000 \
132 --change-section-address .commonarea+0
133 $(OBJDIR)/%.s19: $(OBJDIR)/%.elf
135 $(Q)$(OBJCOPY) -Osrec --srec-forceS3 --strip-debug $(OBJCOPY_TRANSLATIONS) $^ $@
137 # easy printing of MAKE VARIABLES
138 print-%: ; @echo $* = $($*)
140 # Automatic dependency generation
141 DEPENDENCY_FILES = $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(THUMBSRC))) \
142 $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(ARMSRC))) \
143 $(patsubst %.s,$(OBJDIR)/%.d,$(notdir $(ASMSRC)))
145 $(DEPENDENCY_FILES): Makefile ../common_arm/Makefile.common
146 .PRECIOUS: $(DEPENDENCY_FILES)
148 -include $(DEPENDENCY_FILES)