bd20f8f4 |
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 |
4 | # the license. |
5 | #----------------------------------------------------------------------------- |
6 | # Common makefile functions for all platforms |
7 | #----------------------------------------------------------------------------- |
8 | |
7e931bbd |
9 | # This new makefile replaces the previous Makefile/Makefile.linux |
10 | # with as much common code for both environments as possible. |
11 | # Following is a short OS detection to set up variables, all the |
12 | # remaining Makefile should be portable and only depend on these |
13 | # variables |
0fc0fca5 |
14 | # |
15 | |
16 | # Make sure that all is the default target |
17 | # (The including Makefile still needs to define what 'all' is) |
bd846386 |
18 | |
19 | platform = $(shell uname) |
20 | |
0fc0fca5 |
21 | all: |
7e931bbd |
22 | |
5f60ac57 |
23 | CROSS ?= arm-none-eabi- |
d5be6f7c |
24 | CC = $(CROSS)gcc |
25 | AS = $(CROSS)as |
26 | LD = $(CROSS)ld |
27 | OBJCOPY = $(CROSS)objcopy |
28 | |
29 | OBJDIR = obj |
30 | |
7fe9b0b7 |
31 | INCLUDE = -I../include -I../common |
d5be6f7c |
32 | |
bd846386 |
33 | TAR=tar |
34 | TARFLAGS = -C .. -rvf |
35 | |
7e931bbd |
36 | # Windows' echo echos its input verbatim, on Posix there is some |
37 | # amount of shell command line parsing going on. echo "" on |
38 | # Windows yields literal "", on Linux yields an empty line |
39 | ifeq ($(shell echo ""),) |
0fc0fca5 |
40 | |
db335b3d |
41 | # This is probably a proper system, so we can use uname |
7e931bbd |
42 | UNAME := $(shell uname) |
7e931bbd |
43 | DELETE=rm -rf |
0fc0fca5 |
44 | MOVE=mv |
8a6aec16 |
45 | COPY=cp |
7e931bbd |
46 | PATHSEP=/ |
d5be6f7c |
47 | FLASH_TOOL=client/flasher |
b38742c9 |
48 | DETECTED_OS=$(UNAME) |
0fc0fca5 |
49 | |
7e931bbd |
50 | else |
0fc0fca5 |
51 | |
7e931bbd |
52 | # Assume that we are running on Windows. |
53 | DELETE=del /q |
0fc0fca5 |
54 | MOVE=ren |
8a6aec16 |
55 | COPY=copy |
7e931bbd |
56 | PATHSEP=\\# |
23b598ee |
57 | #FLASH_TOOL=winsrc\\prox.exe |
58 | FLASH_TOOL=winsrc\\flash.exe |
7e931bbd |
59 | DETECTED_OS=Windows |
0fc0fca5 |
60 | |
7e931bbd |
61 | endif |
62 | |
7e931bbd |
63 | |
e73e7172 |
64 | # Also search prerequisites in the common directory (for usb.c), and the fpga directory (for fpga.bit) |
65 | VPATH = . ../common/ ../fpga/ |
7e931bbd |
66 | |
6949aca9 |
67 | INCLUDES = ../include/proxmark3.h ../include/at91sam7s512.h ../include/config_gpio.h ../include/usb_cmd.h $(APP_INCLUDES) |
7e931bbd |
68 | |
28fdb04f |
69 | CFLAGS = -c $(INCLUDE) -Wall -Werror -pedantic -std=c99 $(APP_CFLAGS) -Os |
98540684 |
70 | LDFLAGS = -nostartfiles -nodefaultlibs -Wl,-gc-sections -n |
23b598ee |
71 | |
98540684 |
72 | LIBS = -lgcc |
0fc0fca5 |
73 | |
74 | THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(THUMBSRC)) |
7fe9b0b7 |
75 | ARMOBJ = $(ARMSRC:%.c=$(OBJDIR)/%.o) |
0fc0fca5 |
76 | ASMOBJ = $(patsubst %.s,$(OBJDIR)/%.o,$(ASMSRC)) |
4271e82d |
77 | VERSIONOBJ = $(OBJDIR)/version.o |
0fc0fca5 |
78 | |
79 | $(THUMBOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) |
80 | $(CC) $(CFLAGS) -mthumb -mthumb-interwork -o $@ $< |
81 | |
82 | $(ARMOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) |
83 | $(CC) $(CFLAGS) -mthumb-interwork -o $@ $< |
84 | |
85 | $(ASMOBJ): $(OBJDIR)/%.o: %.s |
86 | $(CC) $(CFLAGS) -mthumb-interwork -o $@ $< |
87 | |
4271e82d |
88 | $(VERSIONOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) |
89 | $(CC) $(CFLAGS) -mthumb -mthumb-interwork -o $@ $< |
90 | |
2bfed17d |
91 | # This objcopy call translates physical flash addresses to logical addresses |
db335b3d |
92 | # without touching start address or RAM addresses (.bss and .data sections) |
2bfed17d |
93 | # See ldscript.common. -- Henryk Plötz <henryk@ploetzli.ch> 2009-08-27 |
4f3bd973 |
94 | OBJCOPY_TRANSLATIONS = --no-change-warnings \ |
db335b3d |
95 | --change-addresses -0x100000 --change-start 0 \ |
8fcbf652 |
96 | --change-section-address .bss+0 --change-section-address .data+0 \ |
4f3bd973 |
97 | --change-section-address .commonarea+0 |
98 | $(OBJDIR)/%.s19: $(OBJDIR)/%.elf |
99 | $(OBJCOPY) -Osrec --srec-forceS3 --strip-debug $(OBJCOPY_TRANSLATIONS) $^ $@ |
0fc0fca5 |
100 | |
8a6aec16 |
101 | # version.c should be remade on every compilation |
102 | .PHONY: version.c |
103 | version.c: default_version.c |
104 | perl ../tools/mkversion.pl .. > $@ || $(COPY) $^ $@ |
105 | |
0fc0fca5 |
106 | # Automatic dependency generation |
107 | DEPENDENCY_FILES = $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(THUMBSRC))) \ |
108 | $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(ARMSRC))) \ |
109 | $(patsubst %.s,$(OBJDIR)/%.d,$(notdir $(ASMSRC))) |
110 | |
111 | $(DEPENDENCY_FILES): Makefile ../common/Makefile.common |
4271e82d |
112 | $(patsubst %.o,%.d,$(THUMBOBJ) $(ARMOBJ)): $(OBJDIR)/%.d: %.c |
8652988d |
113 | @$(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@ |
4271e82d |
114 | $(patsubst %.o,%.d,$(ASMOBJ)):$(OBJDIR)/%.d: %.s |
8652988d |
115 | @$(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@ |
0fc0fca5 |
116 | |
117 | -include $(DEPENDENCY_FILES) |