Makefile 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ################################Shimatta Makefile####################################
  2. #CPU: STM32F030
  3. #Compiler: arm-none-eabi
  4. #####################################################################################
  5. ifneq ($(VERBOSE),true)
  6. QUIET=@
  7. else
  8. QUIET=
  9. endif
  10. #Add Files and Folders below#########################################################
  11. CFILES = main.c syscalls/syscalls.c setup/system_init.c startup/startup_stm32f0xx.c
  12. ASFILES =
  13. INCLUDEPATH = -Iinclude -Iinclude/cmsis
  14. OBJDIR=obj
  15. target = project
  16. LIBRARYPATH = -Lstartup
  17. LIBRARIES =
  18. DEFINES = -DSTM32F030x6 -DSTM32F0XX
  19. mapfile = memmap
  20. ##Custom Files###
  21. #TODO
  22. ###################################################################################
  23. CC=arm-none-eabi-gcc
  24. OBJCOPY=arm-none-eabi-objcopy
  25. OBJDUMP=arm-none-eabi-objdump
  26. SIZE=arm-none-eabi-size
  27. LFLAGS = -mlittle-endian -mthumb -mcpu=cortex-m0 -mthumb-interwork
  28. LFLAGS += -mfloat-abi=soft --disable-newlib-supplied-syscalls -nostartfiles
  29. LFLAGS += -Tstartup/stm32f030.ld -Wl,-Map=$(mapfile).map -Wl,--gc-sections -g
  30. CFLAGS = -c -fmessage-length=0 -mlittle-endian -mthumb -mcpu=cortex-m0 -mthumb-interwork
  31. CFLAGS += -mfloat-abi=soft -nostartfiles -Wall -g
  32. ####################################################################################
  33. OBJ = $(CFILES:%.c=$(OBJDIR)/%.c.o)
  34. ASOBJ = $(ASFILES:%.S=$(OBJDIR)/%.S.o)
  35. default: $(target).elf
  36. binary: $(target).bin $(target).hex
  37. %.bin: %.elf
  38. $(OBJCOPY) -O binary $^ $@
  39. %.hex: %.elf
  40. $(OBJCOPY) -O ihex $^ $@
  41. #Linking
  42. $(target).elf: $(OBJ) $(ASOBJ)
  43. @echo Linking $@
  44. $(QUIET)$(CC) $(LFLAGS) $(LIBRARYPATH) -o $@ $^ $(LIBRARIES)
  45. $(QUIET)$(SIZE) $@
  46. #Compiling
  47. $(OBJ):
  48. @echo Compiling $@
  49. $(eval OUTPATH=$(dir $@))
  50. @mkdir -p $(OUTPATH)
  51. $(QUIET)$(CC) $(CFLAGS) -MMD -MT $@ $(INCLUDEPATH) $(DEFINES) -o $@ $(@:$(OBJDIR)/%.c.o=%.c)
  52. $(ASOBJ):
  53. @echo Compiling $@
  54. $(eval OUTPATH=$(dir $@))
  55. @mkdir -p $(OUTPATH)
  56. $(QUIET)$(CC) $(CFLAGS) -MMD -MT $@ $(INCLUDEPATH) $(DEFINES) -o $@ $(@:$(OBJDIR)/%.S.o=%.S)
  57. .PHONY: qtproject clean mrproper objcopy disassemble
  58. disassemble: $(target).elf
  59. $(OBJDUMP) -D -s $< > $(target).lss
  60. objcopy: $(target).bin $(target).hex
  61. mrproper:
  62. rm -f $(target).pro
  63. clean:
  64. rm -f $(target).elf $(target).bin $(target).hex $(OBJ) $(ASOBJ) $(mapfile).map $(target).lss
  65. rm -rfv $(OBJDIR)
  66. qtproject:
  67. echo -e "TEMPLATE = app\nCONFIG -= console app_bundle qt" > $(target).pro
  68. echo -e "SOURCES += $(CFILES) $(ASFILES)" >> $(target).pro
  69. echo -ne "INCLUDEPATH += " >> $(target).pro
  70. echo "$(INCLUDEPATH)" | sed "s!-I!./!g" >> $(target).pro
  71. echo -ne "HEADERS += " >> $(target).pro
  72. find -name "*.h" | tr "\\n" " " >> $(target).pro
  73. echo -ne "\nDEFINES += " >> $(target).pro
  74. echo "$(DEFINES)" | sed "s/-D//g" >> $(target).pro
  75. -include $(CFILES:%.c=$(OBJDIR)/%.c.d) $(ASFILES:%.S=$(OBJDIR)/%.S.d)