Makefile 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. TARGET = target_lo
  2. ######################################
  3. # building variables
  4. ######################################
  5. # debug build?
  6. DEBUG = 1
  7. # optimization
  8. OPT = -Og
  9. #######################################
  10. # paths
  11. #######################################
  12. PROJECT_DIR = $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
  13. # Build path
  14. BUILD_DIR = build
  15. ######################################
  16. # source
  17. ######################################
  18. C_SOURCES =
  19. CPP_SOURCES =
  20. C_DEFS =
  21. # Target
  22. C_SOURCES += Src/main.c
  23. C_SOURCES += Src/flipper_hal.c
  24. C_SOURCES += Src/lo_os.c
  25. C_SOURCES += Src/lo_hal.c
  26. C_DEFS += -DFURI_DEBUG
  27. # Core
  28. CPP_SOURCES += ../core/app.cpp
  29. C_SOURCES += ../core/log.c
  30. C_SOURCES += ../core/tty_uart.c
  31. C_SOURCES += ../core/furi.c
  32. C_SOURCES += ../core/furi_ac.c
  33. # System applications
  34. ifeq ($(TEST), 1)
  35. C_SOURCES += ../applications/tests/furiac_test.c
  36. C_SOURCES += ../applications/tests/furi_record_test.c
  37. C_SOURCES += ../applications/tests/test_index.c
  38. C_DEFS += -DTEST
  39. endif
  40. # Examples
  41. ifeq ($(EXAMPLE_BLINK), 1)
  42. C_SOURCES += ../applications/examples/blink.c
  43. C_DEFS += -DEXAMPLE_BLINK
  44. endif
  45. ifeq ($(EXAMPLE_UART_WRITE), 1)
  46. C_SOURCES += ../applications/examples/uart_write.c
  47. C_DEFS += -DEXAMPLE_UART_WRITE
  48. endif
  49. # User application
  50. # Add C_SOURCES +=, C_DEFS += or CPP_SOURCES += here
  51. #######################################
  52. # binaries
  53. #######################################
  54. CC = gcc
  55. CPP = g++
  56. AS =
  57. CP = objcopy
  58. SZ = size
  59. HEX = $(CP) -O ihex
  60. BIN = $(CP) -O binary -S
  61. #######################################
  62. # Rust library
  63. #######################################
  64. RUST_LIB_SRC = $(realpath $(PROJECT_DIR)/../core-rs)
  65. RUST_LIB_NAME = flipper_core
  66. RUST_LIB_TARGET = x86_64-unknown-linux-gnu
  67. RUST_LIB_FLAGS = --target=$(RUST_LIB_TARGET)
  68. ifeq ($(DEBUG), 1)
  69. RUST_LIB_PATH = $(RUST_LIB_SRC)/target/$(RUST_LIB_TARGET)/debug
  70. else
  71. RUST_LIB_FLAGS += --release
  72. RUST_LIB_PATH = $(RUST_LIB_SRC)/target/$(RUST_LIB_TARGET)/release
  73. endif
  74. RUST_LIB_CMD = cd $(RUST_LIB_SRC) && cargo build $(RUST_LIB_FLAGS)
  75. #######################################
  76. # CFLAGS
  77. #######################################
  78. # C includes
  79. C_INCLUDES = \
  80. -IInc \
  81. -I../applications \
  82. -I../core \
  83. -I../core-rs/bindings
  84. # compile gcc flags
  85. CFLAGS = $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections -pthread
  86. ifeq ($(DEBUG), 1)
  87. CFLAGS += -g -gdwarf-2
  88. endif
  89. # Generate dependency information
  90. CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
  91. CPPFLAGS = -fno-threadsafe-statics
  92. #######################################
  93. # LDFLAGS
  94. #######################################
  95. # libraries
  96. LIBS = -lc -lm -l$(RUST_LIB_NAME)
  97. LIBDIR = -L$(RUST_LIB_PATH)
  98. LDFLAGS = $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections -pthread
  99. # default action: build all
  100. all: $(BUILD_DIR)/$(TARGET)
  101. example_blink:
  102. EXAMPLE_BLINK=1 make
  103. rm $(BUILD_DIR)/app.o
  104. $(BUILD_DIR)/$(TARGET)
  105. example_uart_write:
  106. EXAMPLE_UART_WRITE=1 make
  107. rm $(BUILD_DIR)/app.o
  108. $(BUILD_DIR)/$(TARGET)
  109. test:
  110. TEST=1 make
  111. rm $(BUILD_DIR)/app.o
  112. $(BUILD_DIR)/$(TARGET)
  113. #######################################
  114. # build the application
  115. #######################################
  116. # list of objects
  117. OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
  118. vpath %.c $(sort $(dir $(C_SOURCES)))
  119. OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES:.cpp=.o)))
  120. vpath %.cpp $(sort $(dir $(CPP_SOURCES)))
  121. $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
  122. $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
  123. $(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR)
  124. $(CPP) -c $(CFLAGS) $(CPPFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
  125. $(RUST_LIB_PATH)/lib$(RUST_LIB_NAME).a:
  126. $(RUST_LIB_CMD)
  127. $(BUILD_DIR)/$(TARGET): $(RUST_LIB_PATH)/lib$(RUST_LIB_NAME).a $(OBJECTS) Makefile
  128. $(CPP) $(OBJECTS) $(LDFLAGS) -o $@
  129. $(SZ) $@
  130. $(BUILD_DIR):
  131. mkdir $@
  132. #######################################
  133. # clean up
  134. #######################################
  135. clean:
  136. -rm -fR $(BUILD_DIR)
  137. cd $(RUST_LIB_SRC) && cargo clean
  138. #######################################
  139. # dependencies
  140. #######################################
  141. -include $(wildcard $(BUILD_DIR)/*.d)
  142. -include $(wildcard $(RUST_LIB_PATH)/*.d)
  143. # *** EOF ***