Makefile 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. C_SOURCES += ../lib/u8g2/u8x8_d_st7565.c \
  34. ../lib/u8g2/u8g2_d_setup.c \
  35. ../lib/u8g2/u8g2_intersection.c \
  36. ../lib/u8g2/u8g2_setup.c \
  37. ../lib/u8g2/u8g2_d_memory.c \
  38. ../lib/u8g2/u8x8_cad.c \
  39. ../lib/u8g2/u8x8_byte.c \
  40. ../lib/u8g2/u8x8_gpio.c \
  41. ../lib/u8g2/u8x8_display.c \
  42. ../lib/u8g2/u8x8_setup.c \
  43. ../lib/u8g2/u8g2_hvline.c \
  44. ../lib/u8g2/u8g2_ll_hvline.c \
  45. ../lib/u8g2/u8g2_circle.c \
  46. ../lib/u8g2/u8g2_box.c \
  47. ../lib/u8g2/u8g2_buffer.c \
  48. ../lib/u8g2/u8g2_font.c \
  49. ../lib/u8g2/u8g2_fonts.c \
  50. ../lib/u8g2/u8x8_8x8.c \
  51. ../lib/u8g2/u8g2_bitmap.c
  52. # System applications
  53. ifeq ($(TEST), 1)
  54. C_SOURCES += ../applications/tests/furiac_test.c
  55. C_SOURCES += ../applications/tests/furi_record_test.c
  56. C_SOURCES += ../applications/tests/test_index.c
  57. C_DEFS += -DTEST
  58. endif
  59. ifneq ($(TEST), 1)
  60. C_SOURCES += ../applications/display-u8g2/display-u8g2.c
  61. endif
  62. # Examples
  63. # TODO example without condition
  64. ifneq ($(TEST), 1)
  65. C_SOURCES += ../applications/examples/u8g2_example.c
  66. endif
  67. ifeq ($(EXAMPLE_BLINK), 1)
  68. C_SOURCES += ../applications/examples/blink.c
  69. C_DEFS += -DEXAMPLE_BLINK
  70. endif
  71. ifeq ($(EXAMPLE_UART_WRITE), 1)
  72. C_SOURCES += ../applications/examples/uart_write.c
  73. C_DEFS += -DEXAMPLE_UART_WRITE
  74. endif
  75. ifeq ($(EXAMPLE_IPC), 1)
  76. C_SOURCES += ../applications/examples/ipc.c
  77. C_DEFS += -DEXAMPLE_IPC
  78. endif
  79. # User application
  80. # Add C_SOURCES +=, C_DEFS += or CPP_SOURCES += here
  81. #######################################
  82. # binaries
  83. #######################################
  84. CC = gcc
  85. CPP = g++
  86. AS =
  87. CP = objcopy
  88. SZ = size
  89. HEX = $(CP) -O ihex
  90. BIN = $(CP) -O binary -S
  91. #######################################
  92. # Rust library
  93. #######################################
  94. RUST_LIB_SRC = $(realpath $(PROJECT_DIR)/../core-rs)
  95. RUST_LIB_NAME = flipper_core
  96. RUST_LIB_TARGET = x86_64-unknown-linux-gnu
  97. RUST_LIB_FLAGS = --target=$(RUST_LIB_TARGET)
  98. ifeq ($(DEBUG), 1)
  99. RUST_LIB_PATH = $(RUST_LIB_SRC)/target/$(RUST_LIB_TARGET)/debug
  100. else
  101. RUST_LIB_FLAGS += --release
  102. RUST_LIB_PATH = $(RUST_LIB_SRC)/target/$(RUST_LIB_TARGET)/release
  103. endif
  104. RUST_LIB_CMD = cd $(RUST_LIB_SRC) && cargo build -p flipper-core $(RUST_LIB_FLAGS)
  105. #######################################
  106. # CFLAGS
  107. #######################################
  108. # C includes
  109. C_INCLUDES = \
  110. -IInc \
  111. -I../applications \
  112. -I../lib \
  113. -I../core \
  114. -I../core-rs/flipper-core/bindings
  115. # compile gcc flags
  116. CFLAGS = $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections -pthread
  117. ifeq ($(DEBUG), 1)
  118. CFLAGS += -g -gdwarf-2
  119. endif
  120. # Generate dependency information
  121. CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
  122. CPPFLAGS = -fno-threadsafe-statics
  123. #######################################
  124. # LDFLAGS
  125. #######################################
  126. # libraries
  127. LIBS = -lc -lm -l$(RUST_LIB_NAME)
  128. LIBDIR = -L$(RUST_LIB_PATH)
  129. LDFLAGS = $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections -pthread
  130. # default action: build all
  131. all: $(BUILD_DIR)/$(TARGET)
  132. run: all
  133. $(BUILD_DIR)/$(TARGET)
  134. rust_lib:
  135. $(RUST_LIB_CMD)
  136. example_blink:
  137. rm -f $(BUILD_DIR)/app.o
  138. EXAMPLE_BLINK=1 make run
  139. example_uart_write:
  140. rm -f $(BUILD_DIR)/app.o
  141. EXAMPLE_UART_WRITE=1 make run
  142. example_ipc:
  143. rm -f $(BUILD_DIR)/app.o
  144. EXAMPLE_IPC=1 make run
  145. test:
  146. rm -f $(BUILD_DIR)/app.o
  147. TEST=1 make
  148. timeout --signal=9 5 $(BUILD_DIR)/$(TARGET)
  149. .PHONY: all rust_lib example_blink example_uart_write test
  150. #######################################
  151. # build the application
  152. #######################################
  153. # list of objects
  154. OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
  155. vpath %.c $(sort $(dir $(C_SOURCES)))
  156. OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES:.cpp=.o)))
  157. vpath %.cpp $(sort $(dir $(CPP_SOURCES)))
  158. $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
  159. $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
  160. $(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR)
  161. $(CPP) -c $(CFLAGS) $(CPPFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
  162. $(RUST_LIB_PATH)/lib$(RUST_LIB_NAME).a: rust_lib
  163. $(BUILD_DIR)/$(TARGET): $(RUST_LIB_PATH)/lib$(RUST_LIB_NAME).a $(OBJECTS) Makefile
  164. $(CPP) $(OBJECTS) $(LDFLAGS) -o $@
  165. $(SZ) $@
  166. $(BUILD_DIR):
  167. mkdir $@
  168. #######################################
  169. # clean up
  170. #######################################
  171. clean:
  172. -rm -fR $(BUILD_DIR)
  173. cd $(RUST_LIB_SRC) && cargo clean
  174. #######################################
  175. # dependencies
  176. #######################################
  177. -include $(wildcard $(BUILD_DIR)/*.d)
  178. # *** EOF ***