doragasu

Makefile for building cmsis examples

Nov 19th, 2012
242
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #*****************************************************************************#
  2. # Makefile: Generic makefile for compiling cmsis examples.                    #
  3. #-----------------------------------------------------------------------------#
  4. # Jesús Alonso Fernández @doragasu, 2012                                      #
  5. #*****************************************************************************#
  6.  
  7. # TODO: Update the build recipes so they consider .h file dependencies.
  8.  
  9. # Set root directory
  10. ROOT ?= ../../..
  11.  
  12. # Import default variables
  13. include $(ROOT)/Makefile.inc
  14.  
  15. # Linker libraries and flags
  16. LIBC   := $(shell $(PREFIX)$(CC) -print-file-name=libc.a)
  17. LIBGCC := $(shell $(PREFIX)$(CC) -print-libgcc-file-name)
  18. LIBM   := $(shell $(PREFIX)$(CC) -print-file-name=libm.a)
  19. LIBDSP := $(ROOT)/Lib/libdsplib_lm4f.a
  20. LIBS   := $(LIBDSP) $(LIBM) $(LIBGCC) $(LIBC)
  21. LFLAGS = --static --gc-sections
  22.  
  23. # Startup code and linker script from Mauro Scomparin (scompo)
  24. STARTUP = $(HOME)/src/stellaris/stellaris-launchpad-template-gcc/LM4F_startup.c
  25. LN_SCRIPT = $(HOME)/src/stellaris/stellaris-launchpad-template-gcc/LM4F.ld
  26.  
  27. OUT_DIR = out
  28. OUT_ELF = $(OUT_DIR)/output.elf
  29. OUT_BIN = $(OUT_DIR)/output.bin
  30.  
  31. # -- End of user defined variables --
  32.  
  33. # Source file for the startup code
  34. start_src=$(notdir $(STARTUP))
  35.  
  36. # Objects to be build
  37. objects  = $(patsubst %.c,$(OUT_DIR)/%.o,$(wildcard *.c))
  38. objects += $(patsubst %.c,$(OUT_DIR)/%.o,$(notdir $(STARTUP)))
  39.  
  40. # Default target. Builds the binary file
  41. $(OUT_BIN): $(OUT_ELF)
  42.     $(PREFIX)$(OBJCOPY) -O binary $< $@
  43.  
  44. # Builds the elf file
  45. $(OUT_ELF): $(objects)
  46.     $(PREFIX)$(LD) $(LFLAGS) $(objects) $(LIBS) -T$(LN_SCRIPT) -o $@
  47.  
  48. # Builds startup code
  49. $(start_src:%.c=$(OUT_DIR)/%.o): $(STARTUP) | $(OUT_DIR)
  50.     $(PREFIX)$(CC) $(CFLAGS) -c $< -o $@
  51.  
  52. # Builds every C file in the project directory
  53. $(OUT_DIR)/%.o: %.c | $(OUT_DIR)
  54.     $(PREFIX)$(CC) $(CFLAGS) -c $< -o $@
  55.  
  56. $(OUT_DIR):
  57.     $(MKDIR) $(OUT_DIR)
  58.  
  59. .PHONY: clean
  60. clean:
  61.     $(RM) $(objects) $(OUT_ELF) $(OUT_BIN)
  62.     $(RM) -d $(OUT_DIR)
RAW Paste Data