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 #-----------------------------------------------------------------------------
16 # Common makefile functions for all platforms
17 #-----------------------------------------------------------------------------
19 # Make sure that all is the default target
20 # (The including Makefile still needs to define what 'all' is)
24 # This Makefile might have been called from various subdirs, trying to find our Makefile.defs
25 ifeq ($(DEFSBEENHERE),)
26 -include Makefile.defs
28 ifeq ($(DEFSBEENHERE),)
29 -include ../Makefile.defs
31 ifeq ($(DEFSBEENHERE),)
32 -include ../../Makefile.defs
34 ifeq ($(DEFSBEENHERE),)
35 $(error Can't find Makefile.defs)
38 CROSS_CC = $(CROSS)gcc
39 CROSS_LD = $(CROSS)gcc
40 CROSS_OBJCOPY = $(CROSS)objcopy
44 INCLUDE = -I../include -I../common_arm -I../common_fpga -I../common -I.
46 # Also search prerequisites in the common directory (for usb.c), the fpga directory (for fpga.bit), and the lz4 directory
47 VPATH = . ../common_arm ../common ../common/crapto1 ../common/mbedtls ../common/lz4 ../fpga ../armsrc/Standalone ../common/hitag2
49 INCLUDES = ../include/proxmark3_arm.h ../include/at91sam7s512.h ../include/config_gpio.h ../include/pm3_cmd.h
51 ARMCFLAGS = -mthumb-interwork -fno-builtin
52 DEFCFLAGS = -Wall -Werror -Os -pedantic -fstrict-aliasing -pipe
54 # Some more warnings we want as errors:
55 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
57 # Some more warnings we need first to eliminate, so temporarely tolerated:
58 DEFCFLAGS += -Wshadow -Wno-error=shadow
59 DEFCFLAGS += -Winline -Wno-error=inline
60 DEFCFLAGS += -Wmissing-prototypes -Wno-error=missing-prototypes
61 DEFCFLAGS += -Wmissing-declarations -Wno-error=missing-declarations
62 DEFCFLAGS += -Wstrict-prototypes -Wno-error=strict-prototypes
63 # still vsnprintf etc to sort out...
64 #DEFCFLAGS += -Wredundant-decls -Wno-error=redundant-decls
65 #DEFCFLAGS += -Wcast-align -Wno-error=cast-align
67 # Next ones are activated only if GCCEXTRA=1
69 EXTRACFLAGS += -Wunused-parameter -Wno-error=unused-parameter
70 EXTRACFLAGS += -Wswitch-enum -Wno-error=switch-enum
71 EXTRACFLAGS += -Wsign-compare -Wno-error=sign-compare
72 EXTRACFLAGS += -Wold-style-definition -Wno-error=old-style-definition
73 EXTRACFLAGS += -Wconversion -Wno-error=conversion -Wno-error=sign-conversion -Wno-error=float-conversion
75 # unknown to clang or old gcc:
76 # First we activate Wextra then we explicitly list those we know about
77 # Those without -Wno-error are supposed to be completely solved
78 GCCEXTRACFLAGS = -Wextra
79 # unknown to arm-none-eabi/4.9.3
80 GCCEXTRACFLAGS += -Wwrite-strings -Wno-error=discarded-qualifiers
82 GCCEXTRACFLAGS += -Wold-style-declaration -Wno-error=old-style-declaration
83 GCCEXTRACFLAGS += -Wimplicit-fallthrough=3 -Wno-error=implicit-fallthrough
84 GCCEXTRACFLAGS += -Wclobbered
85 GCCEXTRACFLAGS += -Wcast-function-type
86 GCCEXTRACFLAGS += -Wmissing-parameter-type
87 GCCEXTRACFLAGS += -Woverride-init
88 GCCEXTRACFLAGS += -Wshift-negative-value
89 GCCEXTRACFLAGS += -Wunused-but-set-parameter
90 # Not yet enabled in DEFCFLAGS:
91 GCCEXTRACFLAGS += -Wredundant-decls -Wno-error=redundant-decls
92 GCCEXTRACFLAGS += -Wcast-align -Wno-error=cast-align
95 DEFCFLAGS += $(GCCEXTRACFLAGS) $(EXTRACFLAGS)
98 DEFCFLAGS += -Wno-error
101 CROSS_CFLAGS ?= $(DEFCFLAGS)
102 CROSS_CFLAGS += $(ARMCFLAGS) -c $(INCLUDE) -std=c99 -DON_DEVICE $(APP_CFLAGS)
104 CROSS_LDFLAGS += -nostartfiles -nodefaultlibs -Wl,-gc-sections -Wl,--build-id=none -n
107 # Flags to generate temporary dependency files
108 DEPFLAGS = -MT $@ -MMD -MP -MF $(OBJDIR)/$*.Td
109 # make temporary to final dependency files after successful compilation
110 POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d
112 THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(THUMBSRC)))
113 ARMOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(ARMSRC)))
114 ASMOBJ = $(patsubst %.s,$(OBJDIR)/%.o,$(notdir $(ASMSRC)))
115 VERSIONOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(VERSIONSRC)))
117 $(THUMBOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES)
119 $(Q)$(CROSS_CC) $(CROSS_CFLAGS) $(DEPFLAGS) -mthumb -o $@ $<
122 $(ARMOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES)
124 $(Q)$(CROSS_CC) $(CROSS_CFLAGS) $(DEPFLAGS) -o $@ $<
127 $(ASMOBJ): $(OBJDIR)/%.o: %.s
129 $(Q)$(CROSS_CC) $(CROSS_CFLAGS) -o $@ $<
131 $(VERSIONOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES)
133 $(Q)$(CROSS_CC) $(CROSS_CFLAGS) -mthumb -o $@ $<
135 # This objcopy call translates physical flash addresses to logical addresses
136 # without touching start address or RAM addresses (.bss and .data sections)
137 # See ldscript.common. -- Henryk Plötz <henryk@ploetzli.ch> 2009-08-27
138 OBJCOPY_TRANSLATIONS = --no-change-warnings \
139 --change-addresses -0x100000 --change-start 0 \
140 --change-section-address .bss+0 --change-section-address .data-0x100000 \
141 --change-section-address .commonarea+0
142 $(OBJDIR)/%.s19: $(OBJDIR)/%.elf
144 $(Q)$(CROSS_OBJCOPY) -Osrec --srec-forceS3 --strip-debug $(OBJCOPY_TRANSLATIONS) $^ $@
146 # easy printing of MAKE VARIABLES
147 print-%: ; @echo $* = $($*)
149 # Automatic dependency generation
150 DEPENDENCY_FILES = $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(THUMBSRC))) \
151 $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(ARMSRC))) \
152 $(patsubst %.s,$(OBJDIR)/%.d,$(notdir $(ASMSRC)))
154 $(DEPENDENCY_FILES): Makefile ../common_arm/Makefile.common
155 .PRECIOUS: $(DEPENDENCY_FILES)
157 -include $(DEPENDENCY_FILES)