|
| 1 | +PLUGIN_ID ?= $(shell grep 'plugin\.id' plugin.json | awk '{print $$2}' | grep -o '"[^"]\+"' | sed 's/"//g') |
| 2 | +PLUGIN_NAME ?= $(shell grep 'plugin\.name' plugin.json | awk '{print $$2}' | grep -o '"[^"]\+"' | sed 's/"//g') |
| 3 | + |
| 4 | +GODOT ?= /usr/bin/godot |
| 5 | +OPENGAMEPAD_UI_REPO ?= https://github.com/ShadowBlip/OpenGamepadUI.git |
| 6 | +OPENGAMEPAD_UI_BASE ?= ../OpenGamepadUI |
| 7 | +EXPORT_PRESETS ?= $(OPENGAMEPAD_UI_BASE)/export_presets.cfg |
| 8 | +PLUGINS_DIR := $(OPENGAMEPAD_UI_BASE)/plugins |
| 9 | +BUILD_DIR := $(OPENGAMEPAD_UI_BASE)/build |
| 10 | +INSTALL_DIR := $(HOME)/.local/share/opengamepadui/plugins |
| 11 | + |
| 12 | +##@ General |
| 13 | + |
| 14 | +# The help target prints out all targets with their descriptions organized |
| 15 | +# beneath their categories. The categories are represented by '##@' and the |
| 16 | +# target descriptions by '##'. The awk commands is responsible for reading the |
| 17 | +# entire set of makefiles included in this invocation, looking for lines of the |
| 18 | +# file as xyz: ## something, and then pretty-format the target and help. Then, |
| 19 | +# if there's a line with ##@ something, that gets pretty-printed as a category. |
| 20 | +# More info on the usage of ANSI control characters for terminal formatting: |
| 21 | +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters |
| 22 | +# More info on the awk command: |
| 23 | +# http://linuxcommand.org/lc3_adv_awk.php |
| 24 | + |
| 25 | +.PHONY: help |
| 26 | +help: ## Display this help. |
| 27 | + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) |
| 28 | + |
| 29 | +##@ Development |
| 30 | + |
| 31 | +.PHONY: dist |
| 32 | +dist: build ## Build and package plugin |
| 33 | + |
| 34 | +.PHONY: build |
| 35 | +build: $(PLUGINS_DIR)/$(PLUGIN_ID) export_preset ## Build the plugin |
| 36 | + @echo "Exporting plugin package" |
| 37 | + cd $(OPENGAMEPAD_UI_BASE) && $(MAKE) addons |
| 38 | + mkdir -p dist |
| 39 | + touch dist/.gdignore |
| 40 | + $(GODOT) --headless \ |
| 41 | + --path $(OPENGAMEPAD_UI_BASE) \ |
| 42 | + --export-pack "$(PLUGIN_NAME)" \ |
| 43 | + plugins/$(PLUGIN_ID)/dist/$(PLUGIN_ID).zip |
| 44 | + cd dist && sha256sum $(PLUGIN_ID).zip > $(PLUGIN_ID).zip.sha256.txt |
| 45 | + |
| 46 | +.PHONY: install |
| 47 | +install: dist ## Installs the plugin |
| 48 | + cp -r dist/* "$(INSTALL_DIR)" |
| 49 | + rm -rf $(INSTALL_DIR)/$(PLUGIN_ID) |
| 50 | + @echo "Installed plugin to $(INSTALL_DIR)" |
| 51 | + |
| 52 | +$(OPENGAMEPAD_UI_BASE): |
| 53 | + git clone $(OPENGAMEPAD_UI_REPO) $@ |
| 54 | + |
| 55 | +$(PLUGINS_DIR)/$(PLUGIN_ID): $(OPENGAMEPAD_UI_BASE) |
| 56 | + if ! [ -L $(PLUGINS_DIR)/$(PLUGIN_ID) ]; then ln -s $(PWD) $(PLUGINS_DIR)/$(PLUGIN_ID); fi |
| 57 | + |
| 58 | +.PHONY: export_preset |
| 59 | +export_preset: $(OPENGAMEPAD_UI_BASE) ## Configure plugin export preset |
| 60 | + $(eval LAST_PRESET=$(shell grep -oEi '^\[preset\.([0-9]+)]' $(EXPORT_PRESETS) | tail -n 1)) |
| 61 | + $(eval LAST_PRESET_NUM=$(shell echo "$(LAST_PRESET)" | grep -oE '([0-9]+)')) |
| 62 | + $(eval PRESET_NUM=$(shell echo "$(LAST_PRESET_NUM)+1" | bc)) |
| 63 | + @if grep 'name="$(PLUGIN_NAME)"' $(EXPORT_PRESETS) > /dev/null; then \ |
| 64 | + echo "Export preset already configured"; \ |
| 65 | + else \ |
| 66 | + echo "Preset not configured"; \ |
| 67 | + sed 's/PRESET_NUM/$(PRESET_NUM)/g; s/PLUGIN_NAME/$(PLUGIN_NAME)/g; s/PLUGIN_ID/$(PLUGIN_ID)/g' export_presets.cfg >> $(EXPORT_PRESETS); \ |
| 68 | + fi |
0 commit comments