Makefile 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #
  2. # Pavel Kirienko, 2014 <pavel.kirienko@gmail.com>
  3. #
  4. CPPSRC := $(wildcard src/*.cpp) \
  5. $(wildcard src/sys/*.cpp)
  6. CSRC := $(wildcard lpc_chip_11cxx_lib/src/*.c) \
  7. $(wildcard src/sys/*.c)
  8. DEF = -DFW_VERSION_MAJOR=1 -DFW_VERSION_MINOR=0
  9. INC = -Isrc/sys \
  10. -isystem lpc_chip_11cxx_lib/inc
  11. #
  12. # UAVCAN library
  13. #
  14. DEF += -DUAVCAN_TINY=1
  15. include ../../../libuavcan/include.mk
  16. CPPSRC += $(LIBUAVCAN_SRC)
  17. INC += -I$(LIBUAVCAN_INC)
  18. include ../driver/include.mk
  19. CPPSRC += $(LIBUAVCAN_LPC11C24_SRC)
  20. INC += -I$(LIBUAVCAN_LPC11C24_INC)
  21. $(info $(shell $(LIBUAVCAN_DSDLC) $(UAVCAN_DSDL_DIR)))
  22. INC += -Idsdlc_generated
  23. #
  24. # Git commit hash
  25. #
  26. GIT_HASH := $(shell git rev-parse --short HEAD)
  27. ifeq ($(words $(GIT_HASH)),1)
  28. DEF += -DGIT_HASH=0x$(GIT_HASH)
  29. endif
  30. #
  31. # Build configuration
  32. #
  33. BUILDDIR = build
  34. OBJDIR = $(BUILDDIR)/obj
  35. DEPDIR = $(BUILDDIR)/dep
  36. DEF += -DNDEBUG -DCHIP_LPC11CXX -DCORE_M0 -DTHUMB_NO_INTERWORKING -U__STRICT_ANSI__
  37. FLAGS = -mthumb -mcpu=cortex-m0 -mno-thumb-interwork -flto -Os -g3 -Wall -Wextra -Werror -Wundef -ffunction-sections \
  38. -fdata-sections -fno-common -fno-exceptions -fno-unwind-tables -fno-stack-protector -fomit-frame-pointer \
  39. -Wfloat-equal -Wconversion -Wsign-conversion -Wmissing-declarations
  40. C_CPP_FLAGS = $(FLAGS) -MD -MP -MF $(DEPDIR)/$(@F).d
  41. CFLAGS = $(C_CPP_FLAGS) -std=c99
  42. CPPFLAGS = $(C_CPP_FLAGS) -pedantic -std=c++11 -fno-rtti -fno-threadsafe-statics
  43. LDFLAGS = $(FLAGS) -nodefaultlibs -lc -lgcc -nostartfiles -Tlpc11c24.ld -Xlinker --gc-sections \
  44. -Wl,-Map,$(BUILDDIR)/output.map
  45. # Link with nano newlib. Other toolchains may not support this option, so it can be safely removed.
  46. LDFLAGS += --specs=nano.specs
  47. COBJ = $(addprefix $(OBJDIR)/, $(notdir $(CSRC:.c=.o)))
  48. CPPOBJ = $(addprefix $(OBJDIR)/, $(notdir $(CPPSRC:.cpp=.o)))
  49. OBJ = $(COBJ) $(CPPOBJ)
  50. VPATH = $(sort $(dir $(CSRC)) $(dir $(CPPSRC)))
  51. ELF = $(BUILDDIR)/firmware.elf
  52. BIN = $(BUILDDIR)/firmware.bin
  53. #
  54. # Rules
  55. #
  56. TOOLCHAIN ?= arm-none-eabi-
  57. CC = $(TOOLCHAIN)gcc
  58. CPPC = $(TOOLCHAIN)g++
  59. AS = $(TOOLCHAIN)gcc
  60. LD = $(TOOLCHAIN)g++
  61. CP = $(TOOLCHAIN)objcopy
  62. SIZE = $(TOOLCHAIN)size
  63. all: $(OBJ) $(ELF) $(BIN) size
  64. $(OBJ): | $(BUILDDIR)
  65. $(BUILDDIR):
  66. @mkdir -p $(BUILDDIR)
  67. @mkdir -p $(DEPDIR)
  68. @mkdir -p $(OBJDIR)
  69. $(BIN): $(ELF)
  70. @echo
  71. $(CP) -O binary $(ELF) $@
  72. $(ELF): $(OBJ)
  73. @echo
  74. $(LD) $(OBJ) $(LDFLAGS) -o $@
  75. $(COBJ): $(OBJDIR)/%.o: %.c
  76. @echo
  77. $(CC) -c $(DEF) $(INC) $(CFLAGS) $< -o $@
  78. $(CPPOBJ): $(OBJDIR)/%.o: %.cpp
  79. @echo
  80. $(CPPC) -c $(DEF) $(INC) $(CPPFLAGS) $< -o $@
  81. clean:
  82. rm -rf $(BUILDDIR) dsdlc_generated
  83. size: $(ELF)
  84. @if [ -f $(ELF) ]; then echo; $(SIZE) $(ELF); echo; fi;
  85. .PHONY: all clean size $(BUILDDIR)
  86. # Include the dependency files, should be the last of the makefile
  87. -include $(shell mkdir $(DEPDIR) 2>/dev/null) $(wildcard $(DEPDIR)/*)