common.mk 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ##
  2. # Common settings for Makefiles
  3. #
  4. # Stefan Wendler, sw@kaltpost.de
  5. ##
  6. # compiler prefix
  7. PREFIX ?= msp430-
  8. CC = $(PREFIX)gcc
  9. LD = $(PREFIX)gcc
  10. OBJCOPY = $(PREFIX)objcopy
  11. OBJDUMP = $(PREFIX)objdump
  12. INCDIR += -I./include
  13. CFLAGS += -Os -mmcu=msp430g2553 -g -Wall -Wextra $(INCDIR)
  14. LIBDIR =
  15. LIBS =
  16. LDFLAGS += -mmcu=msp430g2553 $(LIBDIR) $(LIBS)
  17. # where to put generated binaries to
  18. BINDIR ?= ../bin
  19. # doxygen executable
  20. DOXYGEN = doxygen
  21. # doxygen flags
  22. DOXYGENFLAGS = ../doxygen.conf
  23. # styler to use
  24. STYLER = astyle
  25. # which c-style to use
  26. # - see man astyle
  27. STYLERFLAGS = --style=stroustrup
  28. # cpp checker
  29. CHECKER = cppcheck
  30. # flags for checker
  31. # CHECKERFLAGS = --error-exitcode=1 --enable=all
  32. CHECKERFLAGS = --enable=all --error-exitcode=1
  33. .SUFFIXES: .elf .bin .hex .srec .list .images
  34. .SECONDEXPANSION:
  35. .SECONDARY:
  36. all: images
  37. images: $(BINARY).images
  38. %.images: %.bin %.hex %.srec %.list
  39. @#echo "*** $* images generated ***"
  40. %.bin: %.elf
  41. @#printf " OBJCOPY $(*).bin\n"
  42. $(OBJCOPY) -Obinary $(*).elf $(*).bin && cp $(*).bin $(BINDIR)/.
  43. %.hex: %.elf
  44. @#printf " OBJCOPY $(*).hex\n"
  45. $(OBJCOPY) -Oihex $(*).elf $(*).hex && cp $(*).hex $(BINDIR)/.
  46. %.srec: %.elf
  47. @#printf " OBJCOPY $(*).srec\n"
  48. $(OBJCOPY) -Osrec $(*).elf $(*).srec && cp $(*).srec $(BINDIR)/.
  49. %.list: %.elf
  50. @#printf " OBJDUMP $(*).list\n"
  51. $(OBJDUMP) -S $(*).elf > $(*).list && cp $(*).list $(BINDIR)/.
  52. %.elf: $(OBJS) $(LDSCRIPT)
  53. @#printf " LD $(subst $(shell pwd)/,,$(@))\n"
  54. $(LD) $(OBJS) $(LDFLAGS) -o $(*).elf && cp $(*).elf $(BINDIR)/.
  55. %.o: %.c Makefile
  56. @#printf " CC $(subst $(shell pwd)/,,$(@))\n"
  57. $(CC) $(CFLAGS) -o $@ -c $<
  58. %.o: %.cpp Makefile
  59. @#printf " CC $(subst $(shell pwd)/,,$(@))\n"
  60. $(CC) $(CFLAGS) -o $@ -c $<
  61. SRC = $(wildcard *.c)
  62. HDR = $(wildcard include/*.h)
  63. style:
  64. $(STYLER) $(STYLERFLAGS) $(SRC)
  65. $(STYLER) $(STYLERFLAGS) $(HDR)
  66. clean:
  67. rm -f *.o
  68. rm -f *.d
  69. rm -f *.elf
  70. rm -f *.bin
  71. rm -f *.hex
  72. rm -f *.srec
  73. rm -f *.list
  74. rm -f *.orig
  75. .PHONY: images clean