From 54776ec9e1166b042f8c9486ced681accd6ca7d6 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Thu, 27 Jun 2019 20:24:13 -0700 Subject: [PATCH] Makefile Love and Windows Bugfixes * Fixed a bad filepath separator check that failed on Windows. * Disable ANSI colors in logger for Windows console. --- Building.md | 5 +++++ Makefile | 9 +++++++-- pkg/log/log.go | 11 ++++++++++- pkg/userdir/userdir.go | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Building.md b/Building.md index d5b894e..98b62cb 100644 --- a/Building.md +++ b/Building.md @@ -22,7 +22,12 @@ cp /usr/share/fonts/dejavu/{DejaVuSans.ttf,DejaVuSans-Bold.ttf,DejaVuSansMono.tt Makefile commands for Linux: * `make setup`: install Go dependencies and set up the build environment +* `make doodads`: build the default Doodads from sources in `dev-assets/` +* `make bindata`: embed the default doodads, levels and other assets into the + Go program. `make bindata-dev` for lightweight dev versions that will read + from the filesystem at runtime instead. * `make build`: build the Doodle and Doodad binaries to the `bin/` folder. +* `make buildall`: runs all build steps: doodads, bindata, build. * `make build-free`: build the shareware binaries to the `bin/` folder. See Build Tags below. * `make build-debug`: build a debug binary (not release-mode) to the `bin/` diff --git a/Makefile b/Makefile index 0388412..7f2371e 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ LDFLAGS := -ldflags "-X main.Build=$(BUILD) -X main.BuildDate=$(BUILD_DATE)" # `make setup` to set up a new environment, pull dependencies, etc. .PHONY: setup setup: clean + go get -u github.com/go-bindata/go-bindata/... go get ./... # `make build` to build the binary. @@ -20,6 +21,10 @@ build: go build $(LDFLAGS) -i -o bin/doodle cmd/doodle/main.go go build $(LDFLAGS) -i -o bin/doodad cmd/doodad/main.go +# `make buildall` to run all build steps including doodads and bindata. +.PHONY: buildall +buildall: doodads bindata build + # `make build-free` to build the binary in free mode. .PHONY: build-free build-free: @@ -67,7 +72,7 @@ doodads: # `make mingw` to cross-compile a Windows binary with mingw. .PHONY: mingw -mingw: +mingw: doodads bindata 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) -i -o bin/doodle.exe cmd/doodle/main.go @@ -94,7 +99,7 @@ test: # `make dist` builds and tars up a release. .PHONY: dist -dist: build +dist: doodads bindata build mkdir -p dist/doodle-$(VERSION) cp bin/* dist/doodle-$(VERSION)/ cp -r assets fonts README.md dist/doodle-$(VERSION)/ diff --git a/pkg/log/log.go b/pkg/log/log.go index 7dabb01..349506c 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -1,6 +1,10 @@ package log -import "github.com/kirsle/golog" +import ( + "runtime" + + "github.com/kirsle/golog" +) // Logger is the public golog.Logger object. var Logger *golog.Logger @@ -13,6 +17,11 @@ func init() { Colors: golog.ExtendedColor, TimeFormat: "2006-01-02 15:04:05.000000", }) + + // TODO: Disable ANSI colors in logs on Windows. + if runtime.GOOS == "windows" { + Logger.Config.Colors = golog.NoColor + } } // Debug logger function. diff --git a/pkg/userdir/userdir.go b/pkg/userdir/userdir.go index 85ec48d..89e01c0 100644 --- a/pkg/userdir/userdir.go +++ b/pkg/userdir/userdir.go @@ -123,7 +123,7 @@ func ListLevels() ([]string, error) { // resolvePath is the inner logic for LevelPath and DoodadPath. func resolvePath(directory, filename, extension string) string { - if strings.Contains(filename, "/") { + if strings.Contains(filename, string(filepath.Separator)) { return filename }