Add documentation and static build script for windows.

main
Sean Hickey 2022-09-28 15:53:42 -07:00
parent 34e3635f86
commit 96a0f0e83c
8 changed files with 73 additions and 9 deletions

5
.gitignore vendored
View File

@ -1,6 +1,9 @@
# Emacs temp files
*~
# VSCode
.vscode
# SDL libraries
SDL*.dll
SDL*.so
@ -9,4 +12,4 @@ SDL*.a
# Build output
*.exe
output.log
project-ely
/project-ely*

View File

@ -6,7 +6,9 @@ This project is written in Go using SDL2.
## Compiling
You can use the Makefile:
See the [Setup Docs][1] for installing all the necessary dependencies. It's fairly bare-bones, only requiring SDL.
Then you can use the Makefile:
```sh
make release
```

View File

@ -1,11 +1,27 @@
package config
import (
"os"
"gitea.wisellama.rocks/Wisellama/gosimpleconf"
)
var defaultConfig gosimpleconf.ConfigMap = gosimpleconf.ConfigMap{
"game.title": "Project Ely",
"log.writeToFile": "false",
}
func Configure(filename string) (gosimpleconf.ConfigMap, error) {
var err error
_, err = os.Stat(filename)
if os.IsNotExist(err) {
// Config file does not exist, return a default configMap
return defaultConfig, nil
} else if err != nil {
return nil, err
}
configMap, err := gosimpleconf.Load(filename)
if err != nil {
return nil, err

14
docs/README.md Normal file
View File

@ -0,0 +1,14 @@
# Docs
Extra documentation to help with the project.
To get started, see the [Setup][1] directory first. It will help you install the depends and get the development environment set up.
Then there are some other notes and things in this directory that might be helpful.
## Scripts
There are some scripts in the [Scripts][2] directory that may be useful. One of them specifically builds a statically-linked Windows binary for easy distribution.
[1]: setup
[2]: scripts

View File

@ -62,12 +62,12 @@ Go to start menu, search for "env", and select "edit the system environment vari
Set the following env variables (change the username directory to match your username as needed).
First we need to set GCC as our default C compiler:
```
```conf
CC = gcc
``
```
Then we need to enable CGO (allowing the Go compiler to use a C compiler too):
```
```conf
CGO_ENABLED = 1
```
@ -78,7 +78,7 @@ C_INCLUDE_PATH = C:\Users\Username\GCC\x86_64-12.1.0-release-win32-seh-rt_v10-re
Then we need to set our "library" path. This is all of the directories that contain compiled library files (on Windows these are `*.dll` files) that can be imported into our code. This only needs to add all of the SDL2 directories.
```
LIBRARY_PATH = C:\Users\Username\SDL2\SDL2-2.24.0\x86_64-w64-mingw32\bin;C:\Users\Username\SDL2\SDL2_ttf-2.20.1\x86_64-w64-mingw32\bin;C:\Users\Username\SDL2\SDL2_mixer-2.6.2\x86_64-w64-mingw32\bin;C:\Users\Username\SDL2\SDL2_image-2.6.2\x86_64-w64-mingw32\bin;
LIBRARY_PATH = C:\Users\Username\SDL2\SDL2-2.24.0\x86_64-w64-mingw32\lib;C:\Users\Username\SDL2\SDL2_ttf-2.20.1\x86_64-w64-mingw32\lib;C:\Users\Username\SDL2\SDL2_mixer-2.6.2\x86_64-w64-mingw32\lib;C:\Users\Username\SDL2\SDL2_image-2.6.2\x86_64-w64-mingw32\lib;
```
And depending on how you installed GCC, you may need to also add its `bin` directory to your path so that you will be able to call the `gcc` compiler. There are probably other entries already in your `PATH` variable, so just add this as an additional entry:

View File

@ -12,6 +12,8 @@ You will need the following dependencies:
That's all, you may even have most of them installed already.
I also use [golangci-lint][6] as a Go linter. This is used by the Makefile before running `go build`. You can either install this from your package manager or with `go install`. To work-around this, you can just run `go build` directly without the makefile or edit the linter section of the makefile to do nothing.
### Debian
As the most common example, on Debian or Ubuntu, the following `apt` command should install all the dependencies:
@ -55,8 +57,18 @@ As a reference for the BSD crowd, the dependencies in pkgsrc are:
I apologize for not adding more systems, but at some point this list gets annoyingly long to repeat the same thing. Your distribution should almost certainly have these dependencies, and they will be named something similar to the above examples.
## Build
You can use the Makefile to run
```sh
make release
```
or you can use `go build` directly.
[1]: http://pkgsrc.org/
[2]: https://go.dev/
[3]: https://unix.stackexchange.com/q/8049
[4]: https://unix.stackexchange.com/q/107689
[5]: https://brew.sh/
[5]: https://brew.sh/
[6]: https://golangci-lint.run/usage/install/

2
go.sum
View File

@ -1,5 +1,3 @@
gitea.wisellama.rocks/Wisellama/gosimpleconf v0.0.3 h1:g4hcc7TjodjMNrSEQ3UO96HXvltHc2EOiudS+Wfle60=
gitea.wisellama.rocks/Wisellama/gosimpleconf v0.0.3/go.mod h1:kY9gQL8laVTe+tW0ue5bYb6QThw78d7mx6AHwQ5CIzc=
gitea.wisellama.rocks/Wisellama/gosimpleconf v0.0.4 h1:xFjG/dGPUoh1L7/PG9xQRr0GQZwlh1EGI9RnG8Ja8R8=
gitea.wisellama.rocks/Wisellama/gosimpleconf v0.0.4/go.mod h1:kY9gQL8laVTe+tW0ue5bYb6QThw78d7mx6AHwQ5CIzc=
github.com/veandco/go-sdl2 v0.4.25 h1:J5ac3KKOccp/0xGJA1PaNYKPUcZm19IxhDGs8lJofPI=

View File

@ -0,0 +1,19 @@
#!/usr/bin/env sh
# This is intended to run in Git Bash on Windows.
# This builds a statically-linked release version of the binary ready to be deployed.
OUTPUT=project-ely
build(){
OS=$1
ARCH=$2
CGO_ENABLED=1 \
CC=gcc \
GOOS=$OS \
GOARCH=$ARCH \
go build -x -v -trimpath -tags static -ldflags="-s -w -H windowsgui" -o "${OUTPUT}-${OS}-${ARCH}.exe"
}
build windows amd64