Only re-compile version.c as often as necessary
[proxmark3-svn] / common / Makefile.common
CommitLineData
7e931bbd 1# This new makefile replaces the previous Makefile/Makefile.linux
2# with as much common code for both environments as possible.
3# Following is a short OS detection to set up variables, all the
4# remaining Makefile should be portable and only depend on these
5# variables
0fc0fca5 6#
7
8# Make sure that all is the default target
9# (The including Makefile still needs to define what 'all' is)
10all:
7e931bbd 11
12# Windows' echo echos its input verbatim, on Posix there is some
13# amount of shell command line parsing going on. echo "" on
14# Windows yields literal "", on Linux yields an empty line
15ifeq ($(shell echo ""),)
0fc0fca5 16
7e931bbd 17# This is properly a proper system, so we can use uname
18UNAME := $(shell uname)
19ifeq ($(UNAME), Linux)
20# Linux. (Todo: Add MacOS X if appropriate)
21DELETE=rm -rf
0fc0fca5 22MOVE=mv
8a6aec16 23COPY=cp
7e931bbd 24PATHSEP=/
25DETECTED_OS=Linux
26# You may/should set this in your environment
27ARMLIB ?= /usr/local/lib/gcc/arm-elf/4.3.3/interwork
28endif
0fc0fca5 29
7e931bbd 30else
0fc0fca5 31
7e931bbd 32# Assume that we are running on Windows.
33DELETE=del /q
0fc0fca5 34MOVE=ren
8a6aec16 35COPY=copy
7e931bbd 36PATHSEP=\\#
37ARMLIB ?= ../../devkitARM/lib/gcc/arm-elf/4.1.0/interwork
38DETECTED_OS=Windows
0fc0fca5 39
7e931bbd 40endif
41
42CC = arm-elf-gcc
43AS = arm-elf-as
44LD = arm-elf-ld
45OBJCOPY = arm-elf-objcopy
46
47OBJDIR = obj
48
49INCLUDE = -I../include
50
e73e7172 51# Also search prerequisites in the common directory (for usb.c), and the fpga directory (for fpga.bit)
52VPATH = . ../common/ ../fpga/
7e931bbd 53
54INCLUDES = ../include/proxmark3.h ../include/at91sam7s128.h ../include/config_gpio.h ../include/usb_cmd.h $(APP_INCLUDES)
55
56CFLAGS = -c $(INCLUDE) -Wall $(APP_CFLAGS)
0fc0fca5 57
58THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(THUMBSRC))
59ARMOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(ARMSRC))
60ASMOBJ = $(patsubst %.s,$(OBJDIR)/%.o,$(ASMSRC))
4271e82d 61VERSIONOBJ = $(OBJDIR)/version.o
0fc0fca5 62
63$(THUMBOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES)
64 $(CC) $(CFLAGS) -mthumb -mthumb-interwork -o $@ $<
65
66$(ARMOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES)
67 $(CC) $(CFLAGS) -mthumb-interwork -o $@ $<
68
69$(ASMOBJ): $(OBJDIR)/%.o: %.s
70 $(CC) $(CFLAGS) -mthumb-interwork -o $@ $<
71
4271e82d 72$(VERSIONOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES)
73 $(CC) $(CFLAGS) -mthumb -mthumb-interwork -o $@ $<
74
2bfed17d 75# This objcopy call translates physical flash addresses to logical addresses
76# See ldscript.common. -- Henryk Plötz <henryk@ploetzli.ch> 2009-08-27
0fc0fca5 77$(OBJDIR)/%.s19: $(OBJDIR)/%.elf
2bfed17d 78 $(OBJCOPY) -Osrec --srec-forceS3 --no-change-warnings \
4271e82d 79 --change-section-address .bootphase1-0x100000 \
80 --change-section-address .bootphase2-0x100000 \
81 --change-section-address .fpgaimage-0x100000 \
2bfed17d 82 --change-section-address .start-0x100000 \
83 --change-section-address .text-0x100000 \
84 --change-section-address .rodata-0x100000 $^ $@
0fc0fca5 85
8a6aec16 86# version.c should be remade on every compilation
87.PHONY: version.c
88version.c: default_version.c
89 perl ../tools/mkversion.pl .. > $@ || $(COPY) $^ $@
90
0fc0fca5 91# Automatic dependency generation
92DEPENDENCY_FILES = $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(THUMBSRC))) \
93 $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(ARMSRC))) \
94 $(patsubst %.s,$(OBJDIR)/%.d,$(notdir $(ASMSRC)))
95
96$(DEPENDENCY_FILES): Makefile ../common/Makefile.common
4271e82d 97$(patsubst %.o,%.d,$(THUMBOBJ) $(ARMOBJ)): $(OBJDIR)/%.d: %.c
8652988d 98 @$(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@
4271e82d 99$(patsubst %.o,%.d,$(ASMOBJ)):$(OBJDIR)/%.d: %.s
8652988d 100 @$(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@
0fc0fca5 101
102-include $(DEPENDENCY_FILES)
Impressum, Datenschutz