Makefile 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # Copyright 2018 Google LLC
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # Example-specific variables.
  15. # To modify this Makefile for a different application, these are the values
  16. # that are mostly likely to need to be changed.
  17. # Executable name.
  18. BINARY_NAME=flutter_desktop_example
  19. # The C++ code for the embedder application.
  20. SOURCES=flutter_embedder_example.cc
  21. # Default build type. For a release build, set BUILD=release.
  22. # Currently this only sets NDEBUG, which is used to control the flags passed
  23. # to the Flutter engine in the example shell, and not the complation settings
  24. # (e.g., optimization level) of the C++ code.
  25. BUILD=debug
  26. # Dependency locations
  27. FLUTTER_APP_DIR=$(CURDIR)/..
  28. FLUTTER_APP_BUILD_DIR=$(FLUTTER_APP_DIR)/build
  29. FLUTTER_ROOT:=$(shell cat $(CURDIR)/.generated_flutter_root)
  30. FLUTTER_ARTIFACT_CACHE_DIR=$(FLUTTER_ROOT)/bin/cache/artifacts/engine/linux-x64
  31. OUT_DIR=$(FLUTTER_APP_BUILD_DIR)/linux
  32. CACHE_DIR=$(OUT_DIR)/cache
  33. FLUTTER_LIBRARY_COPY_DIR=$(CACHE_DIR)/flutter_library
  34. FLUTTER_LIB_NAME=flutter_linux
  35. FLUTTER_LIB=$(FLUTTER_LIBRARY_COPY_DIR)/lib$(FLUTTER_LIB_NAME).so
  36. # Tools
  37. FLUTTER_BIN=$(FLUTTER_ROOT)/bin/flutter
  38. # Resources
  39. ICU_DATA_NAME=icudtl.dat
  40. ICU_DATA_SOURCE=$(FLUTTER_ARTIFACT_CACHE_DIR)/$(ICU_DATA_NAME)
  41. FLUTTER_ASSETS_NAME=flutter_assets
  42. FLUTTER_ASSETS_SOURCE=$(FLUTTER_APP_BUILD_DIR)/$(FLUTTER_ASSETS_NAME)
  43. # Bundle structure
  44. BUNDLE_OUT_DIR=$(OUT_DIR)/$(BUILD)
  45. BUNDLE_DATA_DIR=$(BUNDLE_OUT_DIR)/data
  46. BUNDLE_LIB_DIR=$(BUNDLE_OUT_DIR)/lib
  47. BIN_OUT=$(BUNDLE_OUT_DIR)/$(BINARY_NAME)
  48. ICU_DATA_OUT=$(BUNDLE_DATA_DIR)/$(ICU_DATA_NAME)
  49. FLUTTER_LIB_OUT=$(BUNDLE_LIB_DIR)/$(notdir $(FLUTTER_LIB))
  50. # Add relevant code from the wrapper library, which is intended to be statically
  51. # built into the client.
  52. WRAPPER_ROOT=$(FLUTTER_LIBRARY_COPY_DIR)/cpp_client_wrapper
  53. WRAPPER_SOURCES= \
  54. $(WRAPPER_ROOT)/flutter_window_controller.cc \
  55. $(WRAPPER_ROOT)/plugin_registrar.cc \
  56. $(WRAPPER_ROOT)/engine_method_result.cc
  57. SOURCES+=$(WRAPPER_SOURCES)
  58. # Headers
  59. WRAPPER_INCLUDE_DIR=$(WRAPPER_ROOT)/include
  60. INCLUDE_DIRS=$(FLUTTER_LIBRARY_COPY_DIR) $(WRAPPER_INCLUDE_DIR)
  61. # The stamp file created by copy_flutter_files.
  62. FLUTTER_COPY_STAMP_FILE=$(FLUTTER_LIBRARY_COPY_DIR)/.last_copied_flutter_version
  63. # The Flutter engine version file.
  64. FLUTTER_ENGINE_VERSION_FILE=$(FLUTTER_ROOT)/bin/internal/engine.version
  65. # Build settings
  66. CXX=g++ -std=c++14
  67. CXXFLAGS.release=-DNDEBUG
  68. CXXFLAGS=-Wall -Werror $(CXXFLAGS.$(BUILD))
  69. CPPFLAGS=$(patsubst %,-I%,$(INCLUDE_DIRS))
  70. LDFLAGS=-L$(BUNDLE_LIB_DIR) \
  71. -l$(FLUTTER_LIB_NAME) \
  72. -Wl,-rpath=\$$ORIGIN/lib
  73. # Targets
  74. .PHONY: all
  75. all: $(BIN_OUT) bundle
  76. .PHONY: bundle
  77. bundle: $(ICU_DATA_OUT) $(FLUTTER_LIB_OUT) bundleflutterassets
  78. $(BIN_OUT): $(SOURCES) $(FLUTTER_LIB_OUT)
  79. mkdir -p $(@D)
  80. $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(SOURCES) $(LDFLAGS) -o $@
  81. $(WRAPPER_SOURCES) $(FLUTTER_LIB) $(ICU_DATA_SOURCE): $(FLUTTER_COPY_STAMP_FILE)
  82. # When the Flutter engine version changes, the local copy of engine artifacts
  83. # needs to be updated.
  84. $(FLUTTER_COPY_STAMP_FILE): $(FLUTTER_ENGINE_VERSION_FILE)
  85. $(FLUTTER_BIN) precache --linux --no-android --no-ios
  86. rm -rf $(FLUTTER_LIBRARY_COPY_DIR)
  87. mkdir -p $(FLUTTER_LIBRARY_COPY_DIR)
  88. cp $(FLUTTER_ARTIFACT_CACHE_DIR)/*.h $(FLUTTER_LIBRARY_COPY_DIR)/
  89. cp $(FLUTTER_ARTIFACT_CACHE_DIR)/*.so $(FLUTTER_LIBRARY_COPY_DIR)/
  90. cp -r $(FLUTTER_ARTIFACT_CACHE_DIR)/cpp_client_wrapper \
  91. $(FLUTTER_LIBRARY_COPY_DIR)/
  92. touch $(FLUTTER_COPY_STAMP_FILE)
  93. $(FLUTTER_LIB_OUT): $(FLUTTER_LIB)
  94. mkdir -p $(BUNDLE_LIB_DIR)
  95. cp $(FLUTTER_LIB) $(BUNDLE_LIB_DIR)
  96. $(ICU_DATA_OUT): $(ICU_DATA_SOURCE)
  97. mkdir -p $(dir $(ICU_DATA_OUT))
  98. cp $(ICU_DATA_SOURCE) $(ICU_DATA_OUT)
  99. # Fully re-copy the assets directory on each build to avoid having to keep a
  100. # comprehensive list of all asset files here, which would be fragile to changes
  101. # in the Flutter example (e.g., adding a new font to pubspec.yaml would require
  102. # changes here).
  103. .PHONY: bundleflutterassets
  104. bundleflutterassets: $(FLUTTER_ASSETS_SOURCE)
  105. mkdir -p $(BUNDLE_DATA_DIR)
  106. rsync -rpu --delete $(FLUTTER_ASSETS_SOURCE) $(BUNDLE_DATA_DIR)
  107. # PHONY since the Makefile doesn't have all the dependency information necessary
  108. # to know if 'build bundle' needs to be re-run.
  109. .PHONY: $(FLUTTER_ASSETS_SOURCE)
  110. $(FLUTTER_ASSETS_SOURCE):
  111. cd $(FLUTTER_APP_DIR); \
  112. $(FLUTTER_BIN) build bundle $(FLUTTER_BUNDLE_FLAGS)
  113. .PHONY: clean
  114. clean:
  115. rm -rf $(OUT_DIR); \
  116. cd $(FLUTTER_APP_DIR); \
  117. $(FLUTTER_BIN) clean