doodle/Makefile

198 lines
6.4 KiB
Makefile
Raw Permalink Normal View History

2017-10-27 01:03:11 +00:00
SHELL := /bin/bash
2020-06-05 07:02:06 +00:00
VERSION=$(shell egrep -e 'Version\s+=' pkg/branding/branding.go | head -n 1 | cut -d '"' -f 2)
2017-10-27 01:03:11 +00:00
BUILD=$(shell git describe --always)
BUILD_DATE=$(shell date +"%Y-%m-%dT%H:%M:%S%z")
2017-10-27 01:03:11 +00:00
CURDIR=$(shell curdir)
# Inject the build version (commit hash) into the executable.
LDFLAGS := -ldflags "-X main.Build=$(BUILD) -X main.BuildDate=$(BUILD_DATE)"
LDFLAGS_W := -ldflags "-X main.Build=$(BUILD) -X main.BuildDate=$(BUILD_DATE) -H windowsgui"
2017-10-27 01:03:11 +00:00
2024-04-19 03:23:07 +00:00
# Doodle++ build tag for official builds of the game.
BUILD_TAGS := -tags=""
ifneq ("$(wildcard ./deps/dpp)", "")
BUILD_TAGS = -tags="dpp"
endif
2017-10-27 01:03:11 +00:00
# `make setup` to set up a new environment, pull dependencies, etc.
.PHONY: setup
setup: clean
# `make build` to build the binary.
.PHONY: build
build:
2024-04-19 03:23:07 +00:00
go build $(LDFLAGS) $(BUILD_TAGS) -o bin/sketchymaze cmd/doodle/main.go
go build $(LDFLAGS) -tags=doodad -o bin/doodad cmd/doodad/main.go
2017-10-27 01:03:11 +00:00
# `make buildall` to run all build steps including doodads.
.PHONY: buildall
buildall: doodads build
# `make build-free` to build the binary in free mode.
.PHONY: build-free
build-free:
gofmt -w .
2024-04-19 03:23:07 +00:00
go build $(LDFLAGS) -o bin/sketchymaze cmd/doodle/main.go
go build $(LDFLAGS) -tags=doodad -o bin/doodad cmd/doodad/main.go
Bindata: Embedding Doodads and Levels (for WASM) * Use `go-bindata` to embed built-in doodads and levels directly into the Doodle binary. `make bindata` produces the bindata source file. * Add `FromJSON()` method to Levels and Doodads to load objects from JSON strings in memory (for bindata built-ins or WASM ajax requests) * Update file loading functions to check the embedded bindata files. * pkg/config.go#EditFile: * Supports editing a level from bindata (TODO: remove this support) * If the "assets/levels/%(simple-name.level)" exists in bindata, edits that drawing. * No such support for editing built-in doodads. * WASM has no filesystem access to edit files except built-in levels (yet) * pkg/doodads#ListDoodads: * Prepends built-in doodads from bindata to the returned list. * WASM: no filesystem access so gets only the built-ins. * pkg/doodads#LoadFile: * Checks built-in bindata store first for doodad files. * WASM: tries an HTTP request if not found in bindata but can go no further if not found (no filesystem access) * pkg/filesystem#FindFile: * This function finds a level/doodad by checking all the places. * If the level or doodad exists in bindata built-in, always returns its system path like "assets/doodads/test.doodad" * WASM: always returns the built-in candidate path even if not found in bindata so that ajax GET can be attempted. * pkg/level#ListSystemLevels: * New function that lists the system level files, similar to the equivalent doodads function. * Prepends the bindata built-in level files. * WASM: only returns the built-ins (no filesystem support) * Desktop: also lists and returns the assets/levels/ directory. * pkg/level#LoadFile: * Like the doodads.LoadFile, tries from built-in bindata first, then ajax request (WASM) before accessing the filesystem (desktop) * Menu Scene: TODO, list the built-in levels in the Load Level menu. This feature will soon go away when WASM gets its own storage for user levels (localStorage instead of filesystem)
2019-06-27 22:07:34 +00:00
# `make bindata` generates the embedded binary assets package.
.PHONY: bindata
bindata:
echo "make bindata: deprecated in favor of Go 1.16 embed; nothing was done"
Bindata: Embedding Doodads and Levels (for WASM) * Use `go-bindata` to embed built-in doodads and levels directly into the Doodle binary. `make bindata` produces the bindata source file. * Add `FromJSON()` method to Levels and Doodads to load objects from JSON strings in memory (for bindata built-ins or WASM ajax requests) * Update file loading functions to check the embedded bindata files. * pkg/config.go#EditFile: * Supports editing a level from bindata (TODO: remove this support) * If the "assets/levels/%(simple-name.level)" exists in bindata, edits that drawing. * No such support for editing built-in doodads. * WASM has no filesystem access to edit files except built-in levels (yet) * pkg/doodads#ListDoodads: * Prepends built-in doodads from bindata to the returned list. * WASM: no filesystem access so gets only the built-ins. * pkg/doodads#LoadFile: * Checks built-in bindata store first for doodad files. * WASM: tries an HTTP request if not found in bindata but can go no further if not found (no filesystem access) * pkg/filesystem#FindFile: * This function finds a level/doodad by checking all the places. * If the level or doodad exists in bindata built-in, always returns its system path like "assets/doodads/test.doodad" * WASM: always returns the built-in candidate path even if not found in bindata so that ajax GET can be attempted. * pkg/level#ListSystemLevels: * New function that lists the system level files, similar to the equivalent doodads function. * Prepends the bindata built-in level files. * WASM: only returns the built-ins (no filesystem support) * Desktop: also lists and returns the assets/levels/ directory. * pkg/level#LoadFile: * Like the doodads.LoadFile, tries from built-in bindata first, then ajax request (WASM) before accessing the filesystem (desktop) * Menu Scene: TODO, list the built-in levels in the Load Level menu. This feature will soon go away when WASM gets its own storage for user levels (localStorage instead of filesystem)
2019-06-27 22:07:34 +00:00
# `make bindata-dev` generates the debug version of bindata package.
.PHONY: bindata-dev
bindata-dev:
echo "make bindata-dev: deprecated in favor of Go 1.16 embed; nothing was done"
Bindata: Embedding Doodads and Levels (for WASM) * Use `go-bindata` to embed built-in doodads and levels directly into the Doodle binary. `make bindata` produces the bindata source file. * Add `FromJSON()` method to Levels and Doodads to load objects from JSON strings in memory (for bindata built-ins or WASM ajax requests) * Update file loading functions to check the embedded bindata files. * pkg/config.go#EditFile: * Supports editing a level from bindata (TODO: remove this support) * If the "assets/levels/%(simple-name.level)" exists in bindata, edits that drawing. * No such support for editing built-in doodads. * WASM has no filesystem access to edit files except built-in levels (yet) * pkg/doodads#ListDoodads: * Prepends built-in doodads from bindata to the returned list. * WASM: no filesystem access so gets only the built-ins. * pkg/doodads#LoadFile: * Checks built-in bindata store first for doodad files. * WASM: tries an HTTP request if not found in bindata but can go no further if not found (no filesystem access) * pkg/filesystem#FindFile: * This function finds a level/doodad by checking all the places. * If the level or doodad exists in bindata built-in, always returns its system path like "assets/doodads/test.doodad" * WASM: always returns the built-in candidate path even if not found in bindata so that ajax GET can be attempted. * pkg/level#ListSystemLevels: * New function that lists the system level files, similar to the equivalent doodads function. * Prepends the bindata built-in level files. * WASM: only returns the built-ins (no filesystem support) * Desktop: also lists and returns the assets/levels/ directory. * pkg/level#LoadFile: * Like the doodads.LoadFile, tries from built-in bindata first, then ajax request (WASM) before accessing the filesystem (desktop) * Menu Scene: TODO, list the built-in levels in the Load Level menu. This feature will soon go away when WASM gets its own storage for user levels (localStorage instead of filesystem)
2019-06-27 22:07:34 +00:00
# `make wasm` builds the WebAssembly port.
.PHONY: wasm
wasm:
cd wasm && make
# `make wasm-serve` builds and launches the WebAssembly server.
.PHONY: wasm-serve
wasm-serve: wasm
sh -c 'sleep 1; xdg-open http://localhost:8080/' &
cd wasm && go run server.go
# `make install` to install the Go binaries to your GOPATH.
.PHONY: install
install:
2022-09-24 22:17:25 +00:00
go install git.kirsle.net/SketchyMaze/doodle/cmd/...
# `make doodads` to build the doodads from the deps/doodads folder.
.PHONY: doodads
doodads:
cd deps/doodads && ./build.sh > /dev/null
# `make mingw` to cross-compile a Windows binary with mingw.
.PHONY: mingw
mingw:
env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \
GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \
go build $(LDFLAGS_W) $(BUILD_TAGS) -o bin/sketchymaze.exe cmd/doodle/main.go
env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \
GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \
go build $(LDFLAGS) -tags=doodad -o bin/doodad.exe cmd/doodad/main.go
2021-09-13 00:15:54 +00:00
# `make mingw32` to cross-compile a Windows binary with mingw (32-bit).
.PHONY: mingw32
mingw32:
2021-09-13 00:15:54 +00:00
env CGO_ENABLED="1" CC="/usr/bin/i686-w64-mingw32-gcc" \
GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \
go build $(LDFLAGS_W) $(BUILD_TAGS) -o bin/sketchymaze.exe cmd/doodle/main.go
2021-09-13 00:15:54 +00:00
env CGO_ENABLED="1" CC="/usr/bin/i686-w64-mingw32-gcc" \
GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \
go build $(LDFLAGS) -tags=doodad -o bin/doodad.exe cmd/doodad/main.go
2021-09-13 00:15:54 +00:00
2019-07-09 02:12:25 +00:00
# `make mingw-free` for Windows binary in free mode.
.PHONY: mingw-free
mingw-free:
2019-07-09 02:12:25 +00:00
env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \
GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \
go build $(LDFLAGS_W) -o bin/sketchymaze.exe cmd/doodle/main.go
env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \
GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \
go build $(LDFLAGS) -tags=doodad -o bin/doodad.exe cmd/doodad/main.go
# `make release` runs the release.sh script, must be run
# after `make dist`
.PHONY: release
release:
./scripts/release.sh
# `make release32` runs release with ARCH_LABEL=32bit to product
# artifacts targeting an i386 architecture (e.g. in rpm and deb packages
# metadata about the release)
.PHONY: release32
release32:
env ARCH_LABEL=32bit ./scripts/release.sh
2022-04-26 04:31:46 +00:00
# `make appimage` builds an AppImage, run it after `make dist`
.PHONY: appimage
appimage:
./appimage.sh
# `make mingw-release` runs a FULL end-to-end release of Linux and Windows
# binaries of the game, zipped and tagged and ready to go.
.PHONY: mingw-release
2022-05-08 03:46:03 +00:00
mingw-release: doodads build mingw __dist-common release
2019-07-09 02:12:25 +00:00
2021-09-13 00:15:54 +00:00
.PHONY: mingw32-release
2022-05-08 03:46:03 +00:00
mingw32-release: doodads build mingw32 __dist-common release32
2021-09-13 00:15:54 +00:00
# `make from-docker64` is an internal command run by the Dockerfile to build the
# game - assumes doodads and assets are in the right spot already.
.PHONY: from-docker64
.PHONY: from-docker32
from-docker64: build mingw __dist-common
ARCH=x86_64 make appimage
make release
from-docker32: build mingw32 __dist-common
ARCH=i686 make appimage
make release32
# `make osx` to cross-compile a Mac OS binary with osxcross.
# .PHONY: osx
# osx: doodads
# CGO_ENABLED=1 CC=[path-to-osxcross]/target/bin/[arch]-apple-darwin[version]-clang GOOS=darwin GOARCH=[arch] go build -tags static -ldflags "-s -w" -a
# `make run` to run it from source.
2017-10-27 01:03:11 +00:00
.PHONY: run
run:
2024-04-19 03:23:07 +00:00
go run ${BUILD_TAGS} cmd/doodle/main.go
# `make run-free` to run it from source with no build tags (foss version).
.PHONY: run-free
run-free:
go run cmd/doodle/main.go
# `make debug` to run it in -debug mode.
.PHONY: debug
debug:
2024-04-19 03:23:07 +00:00
go run $(BUILD_TAGS) cmd/doodle/main.go -debug
2017-10-27 01:03:11 +00:00
# `make guitest` to run it in guitest mode.
.PHONY: guitest
guitest:
go run cmd/doodle/main.go -debug -guitest
2017-10-27 01:03:11 +00:00
# `make test` to run unit tests.
.PHONY: test
test:
go test ./...
# `make dist` builds and tars up a release.
.PHONY: dist
dist: doodads build __dist-common
2019-07-09 02:12:25 +00:00
# `make docker` runs the Dockerfile to do a full release for 64-bit and 32-bit Linux
# and Windows apps.
.PHONY: docker
docker:
2023-12-22 04:17:49 +00:00
./scripts/docker-build.sh
2019-07-09 02:12:25 +00:00
# `make dist-free` builds and tars up a release in shareware mode.
.PHONY: dist-free
dist-free: doodads build-free __dist-common
2019-07-09 02:12:25 +00:00
# Common logic behind `make dist`
.PHONY: __dist-common
__dist-common:
mkdir -p dist/sketchymaze-$(VERSION)
cp bin/* dist/sketchymaze-$(VERSION)/
cp -r README.md Changes.md "Open Source Licenses.md" rtp dist/sketchymaze-$(VERSION)/
if [[ -d ./guidebook ]]; then cp -r guidebook dist/sketchymaze-$(VERSION)/; fi
rm -rf dist/sketchymaze-$(VERSION)/rtp/.git
ln -sf sketchymaze-$(VERSION) dist/sketchymaze-latest
cd dist && tar -czvf sketchymaze-$(VERSION).tar.gz sketchymaze-$(VERSION)
cd dist && zip -r sketchymaze-$(VERSION).zip sketchymaze-$(VERSION)
2017-10-27 01:03:11 +00:00
# `make clean` cleans everything up.
.PHONY: clean
clean:
rm -rf bin dist docker-artifacts