|
| 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 | + |
| 15 | +# Executable name. |
| 16 | +BINARY_NAME=flutter_webrtc_demo |
| 17 | +# The location of the flutter-desktop-embedding repository. |
| 18 | +FDE_ROOT=$(CURDIR)/../.. |
| 19 | +# The C++ code for the embedder application. |
| 20 | +SOURCES=flutter_webrtc_demo.cc |
| 21 | + |
| 22 | +# Plugins to include from the flutter-desktop-embedding plugins/ directory. |
| 23 | +PLUGIN_NAMES=flutter_webrtc |
| 24 | +# Additional plugins to include from the plugins/flutter_plugins subdirectory. |
| 25 | +FLUTTER_PLUGIN_NAMES=url_launcher_fde |
| 26 | + |
| 27 | + |
| 28 | +# Default build type. For a release build, set BUILD=release. |
| 29 | +# Currently this only sets NDEBUG, which is used to control the flags passed |
| 30 | +# to the Flutter engine in the example shell, and not the complation settings |
| 31 | +# (e.g., optimization level) of the C++ code. |
| 32 | +BUILD=debug |
| 33 | + |
| 34 | +# Configuration provided via flutter tool. |
| 35 | +include flutter/generated_config |
| 36 | + |
| 37 | +# Dependency locations |
| 38 | +FLUTTER_APP_CACHE_DIR=flutter/ |
| 39 | +FLUTTER_APP_DIR=$(CURDIR) |
| 40 | +FLUTTER_APP_BUILD_DIR=$(FLUTTER_APP_DIR)/../build |
| 41 | +PLUGINS_DIR=$(FDE_ROOT) |
| 42 | +FLUTTER_PLUGINS_DIR=$(PLUGINS_DIR)/flutter_plugins_fde |
| 43 | + |
| 44 | +OUT_DIR=$(FLUTTER_APP_BUILD_DIR)/linux |
| 45 | + |
| 46 | +# Libraries |
| 47 | +FLUTTER_LIB_NAME=flutter_linux |
| 48 | +FLUTTER_LIB=$(FLUTTER_APP_CACHE_DIR)/lib$(FLUTTER_LIB_NAME).so |
| 49 | +# The name of each plugin library is the name of its directory with _plugin |
| 50 | +# appended. The exception is example_plugin (to avoid confusion with the |
| 51 | +# top-level example/ directory), so it's added here separately. |
| 52 | +PLUGIN_LIB_NAMES=$(foreach plugin,$(PLUGIN_NAMES) $(FLUTTER_PLUGIN_NAMES),$(plugin)_plugin) |
| 53 | +PLUGIN_LIBS=$(foreach plugin,$(PLUGIN_LIB_NAMES),$(OUT_DIR)/lib$(plugin).so) |
| 54 | +ALL_LIBS=$(FLUTTER_LIB) $(PLUGIN_LIBS) |
| 55 | + |
| 56 | +# Tools |
| 57 | +FLUTTER_BIN=$(FLUTTER_ROOT)/bin/flutter |
| 58 | + |
| 59 | +# Resources |
| 60 | +ICU_DATA_NAME=icudtl.dat |
| 61 | +ICU_DATA_SOURCE=$(FLUTTER_APP_CACHE_DIR)/$(ICU_DATA_NAME) |
| 62 | +FLUTTER_ASSETS_NAME=flutter_assets |
| 63 | +FLUTTER_ASSETS_SOURCE=$(FLUTTER_APP_BUILD_DIR)/$(FLUTTER_ASSETS_NAME) |
| 64 | + |
| 65 | +# Bundle structure |
| 66 | +BUNDLE_OUT_DIR=$(OUT_DIR)/$(BUILD) |
| 67 | +BUNDLE_DATA_DIR=$(BUNDLE_OUT_DIR)/data |
| 68 | +BUNDLE_LIB_DIR=$(BUNDLE_OUT_DIR)/lib |
| 69 | + |
| 70 | +BIN_OUT=$(BUNDLE_OUT_DIR)/$(BINARY_NAME) |
| 71 | +ICU_DATA_OUT=$(BUNDLE_DATA_DIR)/$(ICU_DATA_NAME) |
| 72 | +FLUTTER_LIB_OUT=$(BUNDLE_LIB_DIR)/lib$(FLUTTER_LIB_NAME).so |
| 73 | +ALL_LIBS_OUT=$(foreach lib,$(ALL_LIBS),$(BUNDLE_LIB_DIR)/$(notdir $(lib))) |
| 74 | + |
| 75 | +# Add relevant code from the wrapper library, which is intended to be statically |
| 76 | +# built into the client. |
| 77 | +WRAPPER_ROOT=$(FLUTTER_APP_CACHE_DIR)/cpp_client_wrapper |
| 78 | +WRAPPER_SOURCES= \ |
| 79 | + $(WRAPPER_ROOT)/flutter_window_controller.cc \ |
| 80 | + $(WRAPPER_ROOT)/plugin_registrar.cc \ |
| 81 | + $(WRAPPER_ROOT)/engine_method_result.cc |
| 82 | +SOURCES+=$(WRAPPER_SOURCES) |
| 83 | + |
| 84 | +# Headers |
| 85 | +WRAPPER_INCLUDE_DIR=$(WRAPPER_ROOT)/include |
| 86 | +# The plugin builds place all published headers in a top-level include/. |
| 87 | +PLUGIN_INCLUDE_DIRS=$(OUT_DIR)/include |
| 88 | +INCLUDE_DIRS=$(FLUTTER_APP_CACHE_DIR) $(PLUGIN_INCLUDE_DIRS) \ |
| 89 | + $(WRAPPER_INCLUDE_DIR) |
| 90 | + |
| 91 | +# Build settings |
| 92 | +CXX=clang++ |
| 93 | +CXXFLAGS.release=-DNDEBUG |
| 94 | +CXXFLAGS=-std=c++14 -Wall -Werror $(CXXFLAGS.$(BUILD)) |
| 95 | +CPPFLAGS=$(patsubst %,-I%,$(INCLUDE_DIRS)) |
| 96 | +LDFLAGS=-L$(BUNDLE_LIB_DIR) \ |
| 97 | + -l$(FLUTTER_LIB_NAME) \ |
| 98 | + $(patsubst %,-l%,$(PLUGIN_LIB_NAMES)) \ |
| 99 | + -Wl,-rpath=\$$ORIGIN/lib \ |
| 100 | + -lwebrtc |
| 101 | + |
| 102 | +# Targets |
| 103 | + |
| 104 | +.PHONY: all |
| 105 | +all: $(BIN_OUT) bundle |
| 106 | + |
| 107 | +# This is a phony target because the flutter tool cannot describe |
| 108 | +# its inputs and outputs yet. |
| 109 | +.PHONY: sync |
| 110 | +sync: flutter/generated_config |
| 111 | + $(FLUTTER_ROOT)/packages/flutter_tools/bin/tool_backend.sh linux-x64 $(BUILD) |
| 112 | + |
| 113 | +.PHONY: bundle |
| 114 | +bundle: $(ICU_DATA_OUT) $(ALL_LIBS_OUT) bundleflutterassets |
| 115 | + |
| 116 | +$(BIN_OUT): $(SOURCES) $(ALL_LIBS_OUT) |
| 117 | + mkdir -p $(@D) |
| 118 | + $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(SOURCES) $(LDFLAGS) -o $@ |
| 119 | + |
| 120 | +$(WRAPPER_SOURCES) $(FLUTTER_LIB) $(ICU_DATA_SOURCE) $(FLUTTER_ASSETS_SOURCE): \ |
| 121 | + | sync |
| 122 | + |
| 123 | +# Implicit rules won't match phony targets, so list plugin builds explicitly. |
| 124 | +#$(OUT_DIR)/libexample_plugin.so: | example_plugin |
| 125 | +#$(OUT_DIR)/libcolor_panel_plugin.so: | color_panel |
| 126 | +#$(OUT_DIR)/libfile_chooser_plugin.so: | file_chooser |
| 127 | +#$(OUT_DIR)/libmenubar_plugin.so: | menubar |
| 128 | +#$(OUT_DIR)/libwindow_size_plugin.so: | window_size |
| 129 | +$(OUT_DIR)/liburl_launcher_fde_plugin.so: | url_launcher_fde |
| 130 | +$(OUT_DIR)/libflutter_webrtc_plugin.so: | flutter_webrtc |
| 131 | + |
| 132 | +.PHONY: $(PLUGIN_NAMES) |
| 133 | +$(PLUGIN_NAMES): |
| 134 | + make -C $(PLUGINS_DIR)/$@/linux \ |
| 135 | + OUT_DIR=$(OUT_DIR) FLUTTER_ROOT=$(FLUTTER_ROOT) |
| 136 | + |
| 137 | +.PHONY: $(FLUTTER_PLUGIN_NAMES) |
| 138 | +$(FLUTTER_PLUGIN_NAMES): |
| 139 | + make -C $(FLUTTER_PLUGINS_DIR)/$@/linux \ |
| 140 | + OUT_DIR=$(OUT_DIR) FLUTTER_ROOT=$(FLUTTER_ROOT) |
| 141 | + |
| 142 | +# Plugin library bundling pattern. |
| 143 | +$(BUNDLE_LIB_DIR)/%: $(OUT_DIR)/% |
| 144 | + mkdir -p $(BUNDLE_LIB_DIR) |
| 145 | + cp $< $@ |
| 146 | + |
| 147 | +$(FLUTTER_LIB_OUT): $(FLUTTER_LIB) |
| 148 | + mkdir -p $(@D) |
| 149 | + cp $< $@ |
| 150 | + |
| 151 | +$(ICU_DATA_OUT): $(ICU_DATA_SOURCE) |
| 152 | + mkdir -p $(@D) |
| 153 | + cp $< $@ |
| 154 | + |
| 155 | +# Fully re-copy the assets directory on each build to avoid having to keep a |
| 156 | +# comprehensive list of all asset files here, which would be fragile to changes |
| 157 | +# in the Flutter example (e.g., adding a new font to pubspec.yaml would require |
| 158 | +# changes here). |
| 159 | +.PHONY: bundleflutterassets |
| 160 | +bundleflutterassets: $(FLUTTER_ASSETS_SOURCE) |
| 161 | + mkdir -p $(BUNDLE_DATA_DIR) |
| 162 | + rsync -rpu --delete $(FLUTTER_ASSETS_SOURCE) $(BUNDLE_DATA_DIR) |
| 163 | + |
| 164 | +.PHONY: clean |
| 165 | +clean: |
| 166 | + rm -rf $(OUT_DIR); \ |
| 167 | + cd $(FLUTTER_APP_DIR); \ |
| 168 | + $(FLUTTER_BIN) clean |
0 commit comments