Skip to content

Instantly share code, notes, and snippets.

@torus
Last active November 10, 2024 10:06
Show Gist options
  • Save torus/7728e18e4315cb130b24d67d6702ae48 to your computer and use it in GitHub Desktop.
Save torus/7728e18e4315cb130b24d67d6702ae48 to your computer and use it in GitHub Desktop.
UE4 でビルドを作る Makefile
node_modules/

Windows(WSL2、MSYS2)、Mac、Linux で UE4 プロジェクトをビルドするための Makefile。

なかみ

  • ue4.mk: Makefile(UE4 が生成する Makefile と名前が重複しないように別の名前にしてます。)
  • package.json: npm で semver をインストールするための設定

あらかじめ必要なもの

  • Node.js
  • Windows の場合は WSL2 か MSYS2
  • Git(なくてもいい)

初期設定

  • CURRENT_VERSION.txt というファイルに semver 形式でバージョン番号を書いておく。(例:0.0.1-1
  • node install
  • PROJECT_NAMEUE4DIR を環境に合わせて編集する。

起動

make -f ue4.mk build

ビルドする。ビルド結果は Build/$(PROJECT_NAME)_$(PLATFORM)_$(CONFIG)_$(VERSION) というディレクトリに保存される。

ビルドするときに、Config/DefaultEngine.iniBuildVersion という変数が定義されていればそれを現在のバージョン番号で上書きする。プログラム内でバージョン番号を得たいときに便利。

make -f ue4.mk zip

ビルドしたのちに ZIP ファイルを作る。

make -f uk4.mk update-proj

環境に応じた C++ プロジェクトファイルを作る。

make -f uk4.mk bump

バージョンのビルド番号(末尾の数値)を 1 進め、Git のタグを付加し、git push する。

その他のオプション

Shipping ビルドを作る

make -f ue4.mk zip CONFIG=Shipping

バージョンをコマンドラインで指定する

make -f ue4.mk zip VERSION=LOCAL

Node.js を使いたくない場合

Node.js は semver コマンドだけのために使っているので、前述の make -f ue4.mk zip VERSION=LOCAL のように VERSION を明示すると Node.js が呼び出されない。

PROJECT_NAME = MyAwesomeGame
CONFIG = Development
#CONFIG = Shipping
MAP =
LEVEL_DIR = Content/Levels
UE4DIR_WSL = /mnt/e/UnrealEngine
UE4DIR_MSYS = /E/UnrealEngine
UE4DIR_LINUX = /mnt/data/UE_5.1
UE4DIR_MAC = $(HOME)/src/UnrealEngine
PROJECT_DIR = $(PWD)
{
"name": "ue4-builder",
"version": "0.3.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "ue4-builder",
"version": "0.3.0",
"license": "ISC",
"dependencies": {
"semver": "^7.3.2"
}
},
"node_modules/lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/semver": {
"version": "7.3.5",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",
"integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
}
}
}
{
"name": "ue4-builder",
"version": "0.3.0",
"description": "Developed with Unreal Engine 4",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://gist.github.com/7728e18e4315cb130b24d67d6702ae48.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://gist.github.com/torus/7728e18e4315cb130b24d67d6702ae48"
},
"homepage": "https://gist.github.com/torus/7728e18e4315cb130b24d67d6702ae48",
"dependencies": {
"semver": "^7.3.2"
}
}
include config.mk
MAKEFILE := $(firstword $(MAKEFILE_LIST))
MSYS = $(shell uname | grep MSYS)
WSL = $(shell uname -a | grep WSL2)
LINUX = $(shell uname | grep Linux)
DARWIN = $(shell uname | grep Darwin)
ifneq ($(WSL),)
UE4DIR = $(UE4DIR_WSL)
UE4EDITOR = $(shell wslpath -w $(UE4DIR)/Engine/Binaries/Win64/UnrealEditor-Cmd.exe)
MONO = /mnt/c/Windows/System32/cmd.exe /C
PLATFORM = WIN64
GIT = git.exe
else ifneq ($(MSYS),)
UE4DIR = $(UE4DIR_MSYS)
UE4EDITOR = $(UE4DIR)\Engine\Binaries\Win64\UnrealEditor-Cmd.exe
MONO =
PLATFORM = WIN64
GIT = git.exe
else ifneq ($(LINUX),)
UE4DIR = $(UE4DIR_LINUX)
UE4EDITOR = $(UE4DIR)/Engine/Binaries/Linux/UnrealEditor
MONO = $(UE4DIR)/Engine/Binaries/ThirdParty/DotNet/6.0.302/linux/dotnet
PLATFORM = Linux
GIT = git
else # Mac
UE4DIR = $(UE4DIR_MAC)
UE4EDITOR = $(UE4DIR)/Engine/Binaries/Mac/UnrealEditor.app/Contents/MacOS/UnrealEditor
MONO = dotnet
PLATFORM = Mac
GIT = git
endif
ifneq ($(WSL),)
PWD = $(shell pwd)
PROJECT = $(shell wslpath -w $(PROJECT_DIR)/$(PROJECT_NAME).uproject)
AUTOMATIONTOOL = $(shell wslpath -w $(UE4DIR)/Engine/Binaries/DotNET/AutomationTool/AutomationTool.exe)
ARCHIVE_FULLPATH = $(shell wslpath -w $(PWD)/$(ARCHIVE_DIR))
else
PROJECT = $(PROJECT_DIR)/$(PROJECT_NAME).uproject
AUTOMATIONTOOL = $(UE4DIR)/Engine/Binaries/DotNET/AutomationTool/AutomationTool.dll
PWD = $(shell pwd)
ARCHIVE_FULLPATH = $(PWD)/$(ARCHIVE_DIR)
endif
ifneq ($(MAP),)
MAP_ARG = -map=$(MAP)
else
LEVEL_ASSETS = $(shell find $(LEVEL_DIR) -name '*.umap')
LEVELS = $(basename $(notdir $(LEVEL_ASSETS)))
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
LEVELS_JOINED = $(subst $(SPACE),+,$(LEVELS))
MAP_ARG = -map=$(LEVELS_JOINED)
endif
VERSION_FILE = CURRENT_VERSION.txt
VERSION = $(shell cat $(VERSION_FILE))
NEXT_VERSION = $(shell ./node_modules/.bin/semver -i prerelease $(VERSION))
BUILD_DIR = Build
BUILD_NAME = $(PROJECT_NAME)_$(PLATFORM)_$(CONFIG)_$(VERSION)
ARCHIVE_DIR = $(BUILD_DIR)/$(BUILD_NAME)
ZIP = $(ARCHIVE_DIR).zip
.PHONY: build bump zip copy-spine-runtime clean update-proj update-config
help:
@echo usage: make -f $(MAKEFILE) PROJECT_NAME=MyGame build
@echo usage: make -f $(MAKEFILE) PROJECT_NAME=MyGame zip
run:
$(UE4EDITOR) $(PROJECT_DIR)/$(PROJECT_NAME).uproject
bump:
echo $(NEXT_VERSION) > $(VERSION_FILE)
$(GIT) commit -m 'version bumped $(NEXT_VERSION)' $(VERSION_FILE)
$(GIT) tag -m 'version bumped $(NEXT_VERSION)' $(NEXT_VERSION)
$(GIT) push
$(GIT) push --tags
build: $(BUILD_DIR) build-xcode update-config
$(GIT) submodule update || echo Ignoreing git error...
$(MONO) "$(AUTOMATIONTOOL)" \
-ScriptsForProject="$(PROJECT)" \
BuildCookRun \
-nocompileeditor \
-nop4 \
-project="$(PROJECT)" \
$(MAP_ARG) \
-cook \
-stage \
-archive \
-archivedirectory="$(ARCHIVE_FULLPATH)" \
-package \
-unrealexe="$(UE4EDITOR)" \
-compressed \
-ddc=DerivedDataBackendGraph \
-pak \
-prereqs \
-nodebuginfo \
-targetplatform=$(PLATFORM) \
-build \
-target=$(PROJECT_NAME) \
-clientconfig=$(CONFIG) \
-utf8output \
-compile \
-CookCultures=$(CULTURES)
find $(PWD)/$(ARCHIVE_DIR) -name '*.dSYM' -print -delete
find $(PWD)/$(ARCHIVE_DIR) -name '*.pdb' -print -delete
git restore $(PROJECT_DIR)/Config/DefaultEngine.ini || echo Ignoreing git error...
update-config:
sed 's/^BuildVersion=.*/BuildVersion=$(BUILD_NAME)\r/' $(PROJECT_DIR)/Config/DefaultEngine.ini > tmp$$$$ && mv tmp$$$$ $(PROJECT_DIR)/Config/DefaultEngine.ini
build-xcode:
ifneq ($(DARWIN),)
if [ -f $(PROJECT_NAME).xcworkspace ]; then \
xcodebuild -workspace $(PROJECT_NAME).xcworkspace -scheme $(PROJECT_NAME) ;\
fi
endif
zip: $(ZIP)
$(ARCHIVE_DIR):
$(MAKE) -f $(MAKEFILE) build
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(ZIP): $(ARCHIVE_DIR)
zip -r $@ $(ARCHIVE_DIR)
SPINECPP = Plugins/SpinePlugin/Source/SpinePlugin/Public/spine-cpp
copy-spine-runtime: clean
$(MAKE) -f $(MAKEFILE) $(SPINECPP)
clean:
rm -rf Plugins/SpinePlugin
Plugins/SpinePlugin:
mkdir -p Plugins
cp -R ../../spine-runtimes/spine-ue4/Plugins/SpinePlugin Plugins
$(SPINECPP): Plugins/SpinePlugin
if [ -d $@ ]; then rm -rf $@; fi
cp -R ../../spine-runtimes/spine-cpp/spine-cpp $@
update-proj:
ifneq ($(WSL),)
/mnt/c/Windows/System32/cmd.exe /C \
$(subst /,\\,$(subst /mnt/e,E:,$(UE4DIR))/Engine/Build/BatchFiles/GenerateProjectFiles.bat) \
-project $(subst /,\\,$(subst /mnt/e,E:,$(shell pwd)))\\$(PROJECT_NAME).uproject -game -2017
else ifneq ($(MSYS),)
(UE4DIR)/Engine/Build/BatchFiles/GenerateProjectFiles.bat -project $(PROJECT) -game
else ifneq ($(DARWIN),)
$(UE4DIR)/Engine/Build/BatchFiles/Mac/GenerateProjectFiles.sh -project $(PROJECT) -game
else
$(UE4DIR)/Engine/Build/BatchFiles/Linux/GenerateProjectFiles.sh -project $(PROJECT) -game
endif
upload-build: $(ZIP)
gdrive files upload --parent $(GDRIVE_BUILD_DIRECTORY_ID) $(ZIP)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment