Makefile 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. ifeq ($(EXAMPLE_IPC), 1)
  50. C_SOURCES += ../applications/examples/ipc.c
  51. C_DEFS += -DEXAMPLE_IPC
  52. endif
  53. # User application
  54. # Add C_SOURCES +=, C_DEFS += or CPP_SOURCES += here
  55. #######################################
  56. # binaries
  57. #######################################
  58. CC = gcc
  59. CPP = g++
  60. AS =
  61. CP = objcopy
  62. SZ = size
  63. HEX = $(CP) -O ihex
  64. BIN = $(CP) -O binary -S
  65. #######################################
  66. # Rust library
  67. #######################################
  68. RUST_LIB_SRC = $(realpath $(PROJECT_DIR)/../core-rs)
  69. RUST_LIB_NAME = flipper_core
  70. RUST_LIB_TARGET = x86_64-unknown-linux-gnu
  71. RUST_LIB_FLAGS = --target=$(RUST_LIB_TARGET)
  72. ifeq ($(DEBUG), 1)
  73. RUST_LIB_PATH = $(RUST_LIB_SRC)/target/$(RUST_LIB_TARGET)/debug
  74. else
  75. RUST_LIB_FLAGS += --release
  76. RUST_LIB_PATH = $(RUST_LIB_SRC)/target/$(RUST_LIB_TARGET)/release
  77. endif
  78. RUST_LIB_CMD = cd $(RUST_LIB_SRC) && cargo build -p flipper-core $(RUST_LIB_FLAGS)
  79. #######################################
  80. # CFLAGS
  81. #######################################
  82. # C includes
  83. C_INCLUDES = \
  84. -IInc \
  85. -I../applications \
  86. -I../core \
  87. -I../core-rs/flipper-core/bindings
  88. # compile gcc flags
  89. CFLAGS = $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections -pthread
  90. ifeq ($(DEBUG), 1)
  91. CFLAGS += -g -gdwarf-2
  92. endif
  93. # Generate dependency information
  94. CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
  95. CPPFLAGS = -fno-threadsafe-statics
  96. #######################################
  97. # LDFLAGS
  98. #######################################
  99. # libraries
  100. LIBS = -lc -lm -l$(RUST_LIB_NAME)
  101. LIBDIR = -L$(RUST_LIB_PATH)
  102. LDFLAGS = $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections -pthread
  103. # default action: build all
  104. all: $(BUILD_DIR)/$(TARGET)
  105. rust_lib:
  106. $(RUST_LIB_CMD)
  107. example_blink:
  108. rm -f $(BUILD_DIR)/app.o
  109. EXAMPLE_BLINK=1 make
  110. $(BUILD_DIR)/$(TARGET)
  111. example_uart_write:
  112. rm -f $(BUILD_DIR)/app.o
  113. EXAMPLE_UART_WRITE=1 make
  114. $(BUILD_DIR)/$(TARGET)
  115. example_ipc:
  116. rm -f $(BUILD_DIR)/app.o
  117. EXAMPLE_IPC=1 make
  118. $(BUILD_DIR)/$(TARGET)
  119. test:
  120. rm -f $(BUILD_DIR)/app.o
  121. TEST=1 make
  122. $(BUILD_DIR)/$(TARGET)
  123. .PHONY: all rust_lib example_blink example_uart_write test
  124. #######################################
  125. # build the application
  126. #######################################
  127. # list of objects
  128. OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
  129. vpath %.c $(sort $(dir $(C_SOURCES)))
  130. OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES:.cpp=.o)))
  131. vpath %.cpp $(sort $(dir $(CPP_SOURCES)))
  132. $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
  133. $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
  134. $(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR)
  135. $(CPP) -c $(CFLAGS) $(CPPFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
  136. $(RUST_LIB_PATH)/lib$(RUST_LIB_NAME).a: rust_lib
  137. $(BUILD_DIR)/$(TARGET): $(RUST_LIB_PATH)/lib$(RUST_LIB_NAME).a $(OBJECTS) Makefile
  138. $(CPP) $(OBJECTS) $(LDFLAGS) -o $@
  139. $(SZ) $@
  140. $(BUILD_DIR):
  141. mkdir $@
  142. #######################################
  143. # clean up
  144. #######################################
  145. clean:
  146. -rm -fR $(BUILD_DIR)
  147. cd $(RUST_LIB_SRC) && cargo clean
  148. #######################################
  149. # dependencies
  150. #######################################
  151. -include $(wildcard $(BUILD_DIR)/*.d)
  152. # *** EOF ***