From 0fc0fca5830c9d1a430f40ff935fb399f91b8adc Mon Sep 17 00:00:00 2001 From: "henryk@ploetzli.ch" Date: Wed, 26 Aug 2009 17:34:19 +0000 Subject: [PATCH] Move most rules to Makefile.common Add automatic dependency generation Compile ISO14443 files in ARM mode, as was the case with the Linux Makefile before --- armsrc/Makefile | 47 ++++++++++++++++++++++-------------------- bootrom/Makefile | 15 +++----------- common/Makefile.common | 40 +++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 34 deletions(-) diff --git a/armsrc/Makefile b/armsrc/Makefile index 1acfdd88..ce1ad087 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -1,47 +1,49 @@ # Makefile for armsrc, see ../common/Makefile.common for common settings -include ../common/Makefile.common APP_INCLUDES = apps.h # Add the "-DWITH_LCD" flag in APP_CLFAGS to add support for LCD -# and add OBJLCD to OBJ too +# and add SRC_LCD to SRC_MAIN APP_CFLAGS = -O6 -OBJLCD = $(OBJDIR)/fonts.o \ - $(OBJDIR)/LCD.o +SRC_LCD = fonts.c LCD.c + +SRC_MAIN = start.c \ + appmain.c \ + fpga.c \ + lfops.c \ + iso15693.c \ + util.c \ + usb.c + +# These are to be compiled in ARM mode +SRC_MAIN_FAST = iso14443.c \ + iso14443a.c -OBJ = $(OBJDIR)/start.o \ - $(OBJDIR)/appmain.o \ - $(OBJDIR)/fpga.o \ - $(OBJDIR)/lfops.o \ - $(OBJDIR)/iso14443.o \ - $(OBJDIR)/iso14443a.o \ - $(OBJDIR)/iso15693.o \ - $(OBJDIR)/util.o \ - $(OBJDIR)/usb.o +SRC_FPGA = fpgaimg.c -OBJFPGA = \ - $(OBJDIR)/fpgaimg.o +THUMBSRC = $(SRC_MAIN) $(SRC_FPGA) +ARMSRC = $(SRC_MAIN_FAST) + +MAIN_OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(SRC_MAIN) $(SRC_MAIN_FAST)) + +# Do not move this inclusion before the definition of {THUMB,ASM,ARM}{OBJ,SRC} +include ../common/Makefile.common all: $(OBJDIR)/osimage.s19 $(OBJDIR)/fpgaimage.s19 $(OBJDIR)/fpgaimage.elf: $(OBJDIR)/fpgaimg.o $(LD) -g -Tldscript-fpga -Map=$(patsubst %.elf,%.map,$@) -o $@ $^ -$(OBJDIR)/osimage.elf: $(OBJ) $(OBJCOMMON) $(ARMLIB)/libgcc.a +$(OBJDIR)/osimage.elf: $(MAIN_OBJ) $(ARMLIB)/libgcc.a $(LD) -g -Tldscript -Map=$(patsubst %.elf,%.map,$@) -o $@ $^ -$(OBJDIR)/%.s19: $(OBJDIR)/%.elf - $(OBJCOPY) -Osrec --srec-forceS3 $^ $@ - -$(OBJ) $(OBJFPGA): $(OBJDIR)/%.o: %.c $(INCLUDES) - $(CC) $(CFLAGS) -mthumb -mthumb-interwork $< -o $@ - clean: $(DELETE) $(OBJDIR)$(PATHSEP)*.o $(DELETE) $(OBJDIR)$(PATHSEP)*.elf $(DELETE) $(OBJDIR)$(PATHSEP)*.s19 $(DELETE) $(OBJDIR)$(PATHSEP)*.map + $(DELETE) $(OBJDIR)$(PATHSEP)*.d .PHONY: all clean help help: @@ -51,3 +53,4 @@ help: @echo + osimage.s19 - The OS image @echo + fpgaimage.s19 - The FPGA image @echo + clean - Clean $(OBJDIR) + diff --git a/bootrom/Makefile b/bootrom/Makefile index 652e0ae2..2ab91286 100644 --- a/bootrom/Makefile +++ b/bootrom/Makefile @@ -1,5 +1,4 @@ # Makefile for bootrom, see ../common/Makefile.common for common settings -include ../common/Makefile.common OBJJTAG = $(OBJDIR)/bootrom.o $(OBJDIR)/ram-reset.o $(OBJDIR)/usb.o OBJFLASH = $(OBJDIR)/flash-reset.o $(OBJDIR)/fromflash.o @@ -7,8 +6,8 @@ OBJFLASH = $(OBJDIR)/flash-reset.o $(OBJDIR)/fromflash.o THUMBSRC = usb.c fromflash.c bootrom.c ASMSRC = ram-reset.s flash-reset.s -THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(THUMBSRC)) -ASMOBJ = $(patsubst %.s,$(OBJDIR)/%.o,$(ASMSRC)) +# Do not move this inclusion before the definition of {THUMB,ASM,ARM}{OBJ,SRC} +include ../common/Makefile.common all: bootrom-merged.s19 @@ -21,20 +20,12 @@ $(OBJDIR)/bootrom.elf: $(OBJFLASH) $(OBJDIR)/bootrom-forjtag.elf: $(OBJJTAG) $(LD) -g -Tldscript-ram-jtag --oformat elf32-littlearm -Map=$(patsubst %.elf,%.map,$@) -o $@ $^ -$(OBJDIR)/%.s19: $(OBJDIR)/%.elf - $(OBJCOPY) -Osrec --srec-forceS3 $^ $@ - -$(THUMBOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) - $(CC) $(CFLAGS) -mthumb -mthumb-interwork -o $@ $< - -$(ASMOBJ): $(OBJDIR)/%.o: %.s - $(CC) $(CFLAGS) -mthumb-interwork -o $@ $< - clean: $(DELETE) $(OBJDIR)$(PATHSEP)*.o $(DELETE) $(OBJDIR)$(PATHSEP)*.elf $(DELETE) $(OBJDIR)$(PATHSEP)*.s19 $(DELETE) $(OBJDIR)$(PATHSEP)*.map + $(DELETE) $(OBJDIR)$(PATHSEP)*.d $(DELETE) bootrom-merged.s19 .PHONY: all clean help diff --git a/common/Makefile.common b/common/Makefile.common index 38271f51..c4da75e1 100644 --- a/common/Makefile.common +++ b/common/Makefile.common @@ -3,27 +3,38 @@ # Following is a short OS detection to set up variables, all the # remaining Makefile should be portable and only depend on these # variables +# + +# Make sure that all is the default target +# (The including Makefile still needs to define what 'all' is) +all: # Windows' echo echos its input verbatim, on Posix there is some # amount of shell command line parsing going on. echo "" on # Windows yields literal "", on Linux yields an empty line ifeq ($(shell echo ""),) + # This is properly a proper system, so we can use uname UNAME := $(shell uname) ifeq ($(UNAME), Linux) # Linux. (Todo: Add MacOS X if appropriate) DELETE=rm -rf +MOVE=mv PATHSEP=/ DETECTED_OS=Linux # You may/should set this in your environment ARMLIB ?= /usr/local/lib/gcc/arm-elf/4.3.3/interwork endif + else + # Assume that we are running on Windows. DELETE=del /q +MOVE=ren PATHSEP=\\# ARMLIB ?= ../../devkitARM/lib/gcc/arm-elf/4.1.0/interwork DETECTED_OS=Windows + endif CC = arm-elf-gcc @@ -41,3 +52,32 @@ VPATH = . ../common/ INCLUDES = ../include/proxmark3.h ../include/at91sam7s128.h ../include/config_gpio.h ../include/usb_cmd.h $(APP_INCLUDES) CFLAGS = -c $(INCLUDE) -Wall $(APP_CFLAGS) + +THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(THUMBSRC)) +ARMOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(ARMSRC)) +ASMOBJ = $(patsubst %.s,$(OBJDIR)/%.o,$(ASMSRC)) + +$(THUMBOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) + $(CC) $(CFLAGS) -mthumb -mthumb-interwork -o $@ $< + +$(ARMOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) + $(CC) $(CFLAGS) -mthumb-interwork -o $@ $< + +$(ASMOBJ): $(OBJDIR)/%.o: %.s + $(CC) $(CFLAGS) -mthumb-interwork -o $@ $< + +$(OBJDIR)/%.s19: $(OBJDIR)/%.elf + $(OBJCOPY) -Osrec --srec-forceS3 $^ $@ + +# Automatic dependency generation +DEPENDENCY_FILES = $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(THUMBSRC))) \ + $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(ARMSRC))) \ + $(patsubst %.s,$(OBJDIR)/%.d,$(notdir $(ASMSRC))) + +$(DEPENDENCY_FILES): Makefile ../common/Makefile.common +$(OBJDIR)/%.d: %.c + $(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@ +$(OBJDIR)/%.d: %.s + $(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@ + +-include $(DEPENDENCY_FILES) -- 2.39.5