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