Makefile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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/debug.c
  30. C_SOURCES += ../core/furi.c
  31. C_SOURCES += ../core/furi_ac.c
  32. # System applications
  33. ifeq ($(TEST), 1)
  34. C_SOURCES += ../applications/tests/furiac_test.c
  35. C_SOURCES += ../applications/tests/furi_record_test.c
  36. C_SOURCES += ../applications/tests/test_index.c
  37. C_DEFS += -DTEST
  38. endif
  39. # Examples
  40. ifeq ($(EXAMPLE_BLINK), 1)
  41. C_SOURCES += ../applications/examples/blink.c
  42. C_DEFS += -DEXAMPLE_BLINK
  43. endif
  44. # User application
  45. # Add C_SOURCES +=, C_DEFS += or CPP_SOURCES += here
  46. #######################################
  47. # binaries
  48. #######################################
  49. CC = gcc
  50. CPP = g++
  51. AS =
  52. CP = objcopy
  53. SZ = size
  54. HEX = $(CP) -O ihex
  55. BIN = $(CP) -O binary -S
  56. #######################################
  57. # Rust library
  58. #######################################
  59. RUST_LIB_SRC = $(realpath $(PROJECT_DIR)/../core-rs)
  60. RUST_LIB_NAME = flipper_core
  61. RUST_LIB_TARGET = x86_64-unknown-linux-gnu
  62. RUST_LIB_FLAGS = --target=$(RUST_LIB_TARGET)
  63. ifeq ($(DEBUG), 1)
  64. RUST_LIB_PATH = $(RUST_LIB_SRC)/target/$(RUST_LIB_TARGET)/debug
  65. else
  66. RUST_LIB_FLAGS += --release
  67. RUST_LIB_PATH = $(RUST_LIB_SRC)/target/$(RUST_LIB_TARGET)/release
  68. endif
  69. RUST_LIB_CMD = cd $(RUST_LIB_SRC) && cargo build $(RUST_LIB_FLAGS)
  70. #######################################
  71. # CFLAGS
  72. #######################################
  73. # C includes
  74. C_INCLUDES = \
  75. -IInc \
  76. -I../applications \
  77. -I../core \
  78. -I../core-rs/bindings
  79. # compile gcc flags
  80. CFLAGS = $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections -pthread
  81. ifeq ($(DEBUG), 1)
  82. CFLAGS += -g -gdwarf-2
  83. endif
  84. # Generate dependency information
  85. CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
  86. CPPFLAGS = -fno-threadsafe-statics
  87. #######################################
  88. # LDFLAGS
  89. #######################################
  90. # libraries
  91. LIBS = -lc -lm -l$(RUST_LIB_NAME)
  92. LIBDIR = -L$(RUST_LIB_PATH)
  93. LDFLAGS = $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections -pthread
  94. # default action: build all
  95. all: $(BUILD_DIR)/$(TARGET)
  96. example_blink:
  97. EXAMPLE_BLINK=1 make
  98. $(BUILD_DIR)/$(TARGET)
  99. test:
  100. TEST=1 make
  101. $(BUILD_DIR)/$(TARGET)
  102. #######################################
  103. # build the application
  104. #######################################
  105. # list of objects
  106. OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
  107. vpath %.c $(sort $(dir $(C_SOURCES)))
  108. OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES:.cpp=.o)))
  109. vpath %.cpp $(sort $(dir $(CPP_SOURCES)))
  110. $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
  111. $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
  112. $(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR)
  113. $(CPP) -c $(CFLAGS) $(CPPFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
  114. $(RUST_LIB_PATH)/lib$(RUST_LIB_NAME).a:
  115. $(RUST_LIB_CMD)
  116. $(BUILD_DIR)/$(TARGET): $(RUST_LIB_PATH)/lib$(RUST_LIB_NAME).a $(OBJECTS) Makefile
  117. $(CPP) $(OBJECTS) $(LDFLAGS) -o $@
  118. $(SZ) $@
  119. $(BUILD_DIR):
  120. mkdir $@
  121. #######################################
  122. # clean up
  123. #######################################
  124. clean:
  125. -rm -fR $(BUILD_DIR)
  126. cd $(RUST_LIB_SRC) && cargo clean
  127. #######################################
  128. # dependencies
  129. #######################################
  130. -include $(wildcard $(BUILD_DIR)/*.d)
  131. -include $(wildcard $(RUST_LIB_PATH)/*.d)
  132. # *** EOF ***