Makefile 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. include app_configuration.mk
  2. # Default build type.
  3. BUILD=debug
  4. FLUTTER_MANAGED_DIR=flutter
  5. FLUTTER_EPHEMERAL_DIR=$(FLUTTER_MANAGED_DIR)/ephemeral
  6. # Configuration provided via flutter tool.
  7. FLUTTER_CONFIG_FILE=$(FLUTTER_EPHEMERAL_DIR)/generated_config.mk
  8. include $(FLUTTER_CONFIG_FILE)
  9. # Dependency locations
  10. FLUTTER_APP_DIR=$(CURDIR)/..
  11. FLUTTER_APP_BUILD_DIR=$(FLUTTER_APP_DIR)/build
  12. OUT_DIR=$(FLUTTER_APP_BUILD_DIR)/linux
  13. OBJ_DIR=$(OUT_DIR)/obj/$(BUILD)
  14. # Libraries
  15. FLUTTER_LIB_NAME=flutter_linux_glfw
  16. FLUTTER_LIB=$(FLUTTER_EPHEMERAL_DIR)/lib$(FLUTTER_LIB_NAME).so
  17. # Tools
  18. FLUTTER_BIN=$(FLUTTER_ROOT)/bin/flutter
  19. LINUX_BUILD=$(FLUTTER_ROOT)/packages/flutter_tools/bin/tool_backend.sh
  20. # Resources
  21. ICU_DATA_NAME=icudtl.dat
  22. ICU_DATA_SOURCE=$(FLUTTER_EPHEMERAL_DIR)/$(ICU_DATA_NAME)
  23. FLUTTER_ASSETS_NAME=flutter_assets
  24. FLUTTER_ASSETS_SOURCE=$(FLUTTER_APP_BUILD_DIR)/$(FLUTTER_ASSETS_NAME)
  25. # Bundle structure
  26. BUNDLE_OUT_DIR=$(OUT_DIR)/$(BUILD)
  27. BUNDLE_DATA_DIR=$(BUNDLE_OUT_DIR)/data
  28. BUNDLE_LIB_DIR=$(BUNDLE_OUT_DIR)/lib
  29. BIN_OUT=$(BUNDLE_OUT_DIR)/$(BINARY_NAME)
  30. ICU_DATA_OUT=$(BUNDLE_DATA_DIR)/$(ICU_DATA_NAME)
  31. FLUTTER_LIB_OUT=$(BUNDLE_LIB_DIR)/$(notdir $(FLUTTER_LIB))
  32. ALL_LIBS_OUT=$(FLUTTER_LIB_OUT) \
  33. $(foreach lib,$(EXTRA_BUNDLED_LIBRARIES),$(BUNDLE_LIB_DIR)/$(notdir $(lib)))
  34. # Add relevant code from the wrapper library, which is intended to be statically
  35. # built into the client.
  36. # Use abspath for the wrapper root, which can contain relative paths; the
  37. # intermediate build files will be based on the source path, which will cause
  38. # issues if they start with one or more '../'s.
  39. WRAPPER_ROOT=$(abspath $(FLUTTER_EPHEMERAL_DIR)/cpp_client_wrapper_glfw)
  40. WRAPPER_SOURCES= \
  41. $(WRAPPER_ROOT)/flutter_window_controller.cc \
  42. $(WRAPPER_ROOT)/plugin_registrar.cc \
  43. $(WRAPPER_ROOT)/engine_method_result.cc
  44. # Use abspath for extra sources, which may also contain relative paths (see
  45. # note above about WRAPPER_ROOT).
  46. SOURCES=main.cc window_configuration.cc \
  47. flutter/generated_plugin_registrant.cc \
  48. $(WRAPPER_SOURCES) $(abspath $(EXTRA_SOURCES))
  49. # Headers
  50. WRAPPER_INCLUDE_DIR=$(WRAPPER_ROOT)/include
  51. INCLUDE_DIRS=$(FLUTTER_EPHEMERAL_DIR) $(WRAPPER_INCLUDE_DIR)
  52. # Build settings
  53. ifneq ($(strip $(SYSTEM_LIBRARIES)),)
  54. EXTRA_CPPFLAGS+=$(patsubst -I%,-isystem%,$(shell pkg-config --cflags $(SYSTEM_LIBRARIES)))
  55. EXTRA_LDFLAGS+=$(shell pkg-config --libs $(SYSTEM_LIBRARIES))
  56. endif
  57. CXX=clang++
  58. CPPFLAGS.release=-DNDEBUG
  59. CPPFLAGS.profile=$(CPPFLAGS.release)
  60. CXXFLAGS.release=-O2
  61. CXXFLAGS.profile=$(CXXFLAGS.release)
  62. CXXFLAGS=-std=c++14 -Wall -Werror $(CXXFLAGS.$(BUILD)) $(EXTRA_CXXFLAGS)
  63. CPPFLAGS=$(patsubst %,-I%,$(INCLUDE_DIRS)) \
  64. $(CPPFLAGS.$(BUILD)) $(EXTRA_CPPFLAGS)
  65. LDFLAGS=-L$(BUNDLE_LIB_DIR) \
  66. -l$(FLUTTER_LIB_NAME) \
  67. $(EXTRA_LDFLAGS) \
  68. -Wl,-rpath=\$$ORIGIN/lib
  69. # Intermediate files.
  70. OBJ_FILES=$(SOURCES:%.cc=$(OBJ_DIR)/%.o)
  71. DEPENDENCY_FILES=$(OBJ_FILES:%.o=%.d)
  72. # Targets
  73. .PHONY: all
  74. all: $(BIN_OUT) bundle
  75. # Add the plugin targets, and their associated settings.
  76. include $(FLUTTER_MANAGED_DIR)/generated_plugins.mk
  77. EXTRA_BUNDLED_LIBRARIES+=$(PLUGIN_LIBRARIES)
  78. EXTRA_LDFLAGS+=$(PLUGIN_LDFLAGS)
  79. EXTRA_CPPFLAGS+=$(PLUGIN_CPPFLAGS)
  80. # This is a phony target because the flutter tool cannot describe
  81. # its inputs and outputs yet.
  82. .PHONY: sync
  83. sync: $(FLUTTER_CONFIG_FILE)
  84. $(LINUX_BUILD) linux-x64 $(BUILD)
  85. .PHONY: bundle
  86. bundle: $(ICU_DATA_OUT) $(ALL_LIBS_OUT) bundleflutterassets
  87. $(BIN_OUT): $(OBJ_FILES) $(ALL_LIBS_OUT)
  88. mkdir -p $(@D)
  89. $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OBJ_FILES) $(LDFLAGS) -o $@
  90. $(WRAPPER_SOURCES) $(FLUTTER_LIB) $(ICU_DATA_SOURCE) $(FLUTTER_ASSETS_SOURCE) \
  91. $(PLUGIN_TARGETS): | sync
  92. # Plugin library bundling pattern.
  93. $(BUNDLE_LIB_DIR)/%: $(OUT_DIR)/%
  94. mkdir -p $(BUNDLE_LIB_DIR)
  95. cp $< $@
  96. $(FLUTTER_LIB_OUT): $(FLUTTER_LIB)
  97. mkdir -p $(@D)
  98. cp $< $@
  99. $(ICU_DATA_OUT): $(ICU_DATA_SOURCE)
  100. mkdir -p $(@D)
  101. cp $< $@
  102. -include $(DEPENDENCY_FILES)
  103. $(OBJ_DIR)/%.o : %.cc | sync
  104. mkdir -p $(@D)
  105. $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -c $< -o $@
  106. # Fully re-copy the assets directory on each build to avoid having to keep a
  107. # comprehensive list of all asset files here, which would be fragile to changes
  108. # in other files (e.g., adding a new font to pubspec.yaml).
  109. .PHONY: bundleflutterassets
  110. bundleflutterassets: $(FLUTTER_ASSETS_SOURCE)
  111. mkdir -p $(BUNDLE_DATA_DIR)
  112. rsync -rpu --delete $(FLUTTER_ASSETS_SOURCE) $(BUNDLE_DATA_DIR)
  113. .PHONY: clean
  114. clean:
  115. rm -rf $(OUT_DIR); \
  116. cd $(FLUTTER_APP_DIR); \
  117. $(FLUTTER_BIN) clean