]> git.cworth.org Git - lmno.games/blob - flempires/linux/Makefile
Use an actual space not an   entity.
[lmno.games] / flempires / linux / Makefile
1 include app_configuration.mk
2
3 # Default build type.
4 BUILD=debug
5
6 FLUTTER_MANAGED_DIR=flutter
7 FLUTTER_EPHEMERAL_DIR=$(FLUTTER_MANAGED_DIR)/ephemeral
8
9 # Configuration provided via flutter tool.
10 FLUTTER_CONFIG_FILE=$(FLUTTER_EPHEMERAL_DIR)/generated_config.mk
11 include $(FLUTTER_CONFIG_FILE)
12
13 # Dependency locations
14 FLUTTER_APP_DIR=$(CURDIR)/..
15 FLUTTER_APP_BUILD_DIR=$(FLUTTER_APP_DIR)/build
16
17 OUT_DIR=$(FLUTTER_APP_BUILD_DIR)/linux
18 OBJ_DIR=$(OUT_DIR)/obj/$(BUILD)
19
20 # Libraries
21 FLUTTER_LIB_NAME=flutter_linux_glfw
22 FLUTTER_LIB=$(FLUTTER_EPHEMERAL_DIR)/lib$(FLUTTER_LIB_NAME).so
23
24 # Tools
25 FLUTTER_BIN=$(FLUTTER_ROOT)/bin/flutter
26 LINUX_BUILD=$(FLUTTER_ROOT)/packages/flutter_tools/bin/tool_backend.sh
27
28 # Resources
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)
33
34 # Bundle structure
35 BUNDLE_OUT_DIR=$(OUT_DIR)/$(BUILD)
36 BUNDLE_DATA_DIR=$(BUNDLE_OUT_DIR)/data
37 BUNDLE_LIB_DIR=$(BUNDLE_OUT_DIR)/lib
38
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)))
44
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)
51 WRAPPER_SOURCES= \
52         $(WRAPPER_ROOT)/flutter_window_controller.cc \
53         $(WRAPPER_ROOT)/plugin_registrar.cc \
54         $(WRAPPER_ROOT)/engine_method_result.cc
55
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))
61
62 # Headers
63 WRAPPER_INCLUDE_DIR=$(WRAPPER_ROOT)/include
64 INCLUDE_DIRS=$(FLUTTER_EPHEMERAL_DIR) $(WRAPPER_INCLUDE_DIR)
65
66 # Build settings
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))
70 endif
71 CXX=clang++
72 CPPFLAGS.release=-DNDEBUG
73 CPPFLAGS.profile=$(CPPFLAGS.release)
74 CXXFLAGS.release=-O2
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) \
81         $(EXTRA_LDFLAGS) \
82         -Wl,-rpath=\$$ORIGIN/lib
83
84 # Intermediate files.
85 OBJ_FILES=$(SOURCES:%.cc=$(OBJ_DIR)/%.o)
86 DEPENDENCY_FILES=$(OBJ_FILES:%.o=%.d)
87
88 # Targets
89
90 .PHONY: all
91 all: $(BIN_OUT) bundle
92
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)
98
99 # This is a phony target because the flutter tool cannot describe
100 # its inputs and outputs yet.
101 .PHONY: sync
102 sync: $(FLUTTER_CONFIG_FILE)
103         $(LINUX_BUILD) linux-x64 $(BUILD)
104
105 .PHONY: bundle
106 bundle: $(ICU_DATA_OUT) $(ALL_LIBS_OUT) bundleflutterassets
107
108 $(BIN_OUT): $(OBJ_FILES) $(ALL_LIBS_OUT)
109         mkdir -p $(@D)
110         $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OBJ_FILES) $(LDFLAGS) -o $@
111
112 $(WRAPPER_SOURCES) $(FLUTTER_LIB) $(ICU_DATA_SOURCE) $(FLUTTER_ASSETS_SOURCE) \
113         $(PLUGIN_TARGETS): | sync
114
115 # Plugin library bundling pattern.
116 $(BUNDLE_LIB_DIR)/%: $(OUT_DIR)/%
117         mkdir -p $(BUNDLE_LIB_DIR)
118         cp $< $@
119
120 $(FLUTTER_LIB_OUT): $(FLUTTER_LIB)
121         mkdir -p $(@D)
122         cp $< $@
123
124 $(ICU_DATA_OUT): $(ICU_DATA_SOURCE)
125         mkdir -p $(@D)
126         cp $< $@
127
128 -include $(DEPENDENCY_FILES)
129
130 $(OBJ_DIR)/%.o : %.cc | sync
131         mkdir -p $(@D)
132         $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -c $< -o $@
133
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)
141
142 .PHONY: clean
143 clean:
144         rm -rf $(OUT_DIR); \
145         cd $(FLUTTER_APP_DIR); \
146         $(FLUTTER_BIN) clean