diff --git a/Building.md b/Building.md index 1dec40f..6cb8f94 100644 --- a/Building.md +++ b/Building.md @@ -29,6 +29,49 @@ sudo dnf -y install golang SDL2-devel SDL2_ttf-devel sudo apt -y install golang libsdl2-dev libsdl2-ttf-dev ``` -## Windows +## Windows Cross-Compile from Linux -TBD. +Install the Mingw C compiler: + +```bash +# Fedora +sudo dnf -y install mingw64-gcc # for 64-bit +sudo dnf -y install mingw32-gcc # for 32-bit + +# Arch Linux +pacman -S mingw-w64 +``` + +Download the SDL2 Mingw development libraries [here](https://libsdl.org/download-2.0.php) +and SDL2_TTF from [here](https://www.libsdl.org/projects/). + +Extract each and copy their library folder into the mingw path. + +```bash +# e.g. /usr/x86_64-w64-mingw32 is usually the correct path, verify on e.g. +# Fedora with `rpm -ql mingw64-filesystem` +tar -xzvf SDL2_ttf-devel-2.0.15-mingw.tar.gz +cd SDL_ttf-2.0.15 +sudo cp -r x86_64-w64-mingw32 /usr +``` + +Make and set permissions for Go to download the standard library for Windows: + +```bash +mkdir /usr/lib/golang/pkg/windows_amd64 +chown your_username /usr/lib/golang/pkg/windows_amd64 +``` + +And run `make mingw` to build the Windows binary. + +### Windows DLLs + +For the .exe to run it will need SDL2.dll and such. + +``` +# SDL2.dll and SDL2_ttf.dll +cp /usr/x86_64-w64-mingw32/bin/SDL*.dll bin/ +``` + +SDL2_ttf requires libfreetype, you can get its DLL here: +https://github.com/ubawurinna/freetype-windows-binaries diff --git a/Makefile b/Makefile index 56fdeb7..72c3c3d 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,18 @@ build: go build $(LDFLAGS) -i -o bin/doodle cmd/doodle/main.go go build $(LDFLAGS) -i -o bin/doodad cmd/doodad/main.go +# `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) -i -o bin/doodle.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) -i -o bin/doodad.exe cmd/doodad/main.go + + + # `make run` to run it in debug mode. .PHONY: run run: diff --git a/pkg/wallpaper/texture.go b/pkg/wallpaper/texture.go index 71a81ad..490d696 100644 --- a/pkg/wallpaper/texture.go +++ b/pkg/wallpaper/texture.go @@ -58,13 +58,17 @@ func texture(e render.Engine, img *image.RGBA, name string) (render.Texturer, er if _, err := os.Stat(filename); os.IsNotExist(err) { fh, err := os.Create(filename) if err != nil { - return nil, fmt.Errorf("CornerTexture: %s", err.Error()) + return nil, fmt.Errorf("texture(%s): %s", name, err.Error()) } - defer fh.Close() err = bmp.Encode(fh, img) if err != nil { - return nil, fmt.Errorf("CornerTexture: bmp.Encode: %s", err.Error()) + return nil, fmt.Errorf("texture(%s): bmp.Encode: %s", name, err.Error()) + } + + err = fh.Close() + if err != nil { + return nil, fmt.Errorf("texture(%s): fh.Close: %s", name, err.Error()) } }