windows cross-compilation support

static build runs under minimal wine installation and passes regression tests
This commit is contained in:
JetSetIlly 2020-08-04 10:23:07 +01:00
parent c22b590ee7
commit a140711321
10 changed files with 130 additions and 29 deletions

1
.gitignore vendored
View file

@ -6,6 +6,7 @@ test_roms/*
roms
.gopher2600/*
gopher2600
gopher2600.exe
*.dot
*.ps
*.pdf

View file

@ -1,7 +1,7 @@
compileFlags = '-c 3 -B -wb=false'
profilingRom = roms/Pitfall.bin
.PHONY: all generate test clean run_assertions race build_assertions build release release_upx profile profile_display
.PHONY: all generate test clean run_assertions race build_assertions build release check_upx release_upx profile profile_display
all:
@echo "use release target to build release binary"
@ -16,6 +16,7 @@ test:
clean:
@echo "removing binary and profiling files"
@rm -f gopher2600 cpu.profile mem.profile debug.cpu.profile debug.mem.profile
@rm -f gopher2600.exe
@find ./ -type f | grep "\.orig" | xargs -r rm
race:
@ -30,12 +31,14 @@ build:
release:
go build -gcflags $(compileFlags) -ldflags="-s -w" -tags="release"
release_upx:
@echo "requires upx to run. edit Makefile to activate"
# go build -gcflags $(compileFlags) -ldflags="-s -w" -tags="release"
# upx -o gopher2600.upx gopher2600
# cp gopher2600.upx gopher2600
# rm gopher2600.upx
check_upx:
@which upx > /dev/null
release_upx: check_upx
go build -gcflags $(compileFlags) -ldflags="-s -w" -tags="release"
upx -o gopher2600.upx gopher2600
cp gopher2600.upx gopher2600
rm gopher2600.upx
profile:
go build -gcflags $(compileFlags)
@ -47,5 +50,8 @@ profile_display:
./gopher2600 performance --display --profile $(profilingRom)
go tool pprof -http : ./gopher2600 cpu.profile
windows:
CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" CXX="/usr/bin/x86_64-w64-mingw32-g++" GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" go build -x .
cross_windows:
CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" CXX="/usr/bin/x86_64-w64-mingw32-g++" GOOS="windows" GOARCH="amd64" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" go build -tags "release" -ldflags="-s -w" .
cross_windows_static:
CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" CXX="/usr/bin/x86_64-w64-mingw32-g++" GOOS="windows" GOARCH="amd64" CGO_LDFLAGS="-static-libgcc -static-libstdc++" go build -tags "static release" -ldflags "-s -w" .

View file

@ -122,18 +122,33 @@ versions earlier than v1.13 because of language features added in that version
(binary literals).
The project uses the Go module system and dependencies will be resolved
automatically. Do note however, that you will required the SDL development
libraries for the Go SDL module to compile.
automatically. Do note however, that you will also require the SDL development
kit installed on the system. For users of UNIX like systems, installation from
your package manager is the easiest option (for MacOS use the homebrew package
manager https://formulae.brew.sh/formula/sdl2)
Compile with GNU Make
> make build
> make release
During development, programmers may find it more useful to use the go command
directly
> go run gopher2600.go
## Cross-Compilation
Native compilation of a Windows executable has not yet been tried. But
cross-compilation does work via the Makefile:
> make cross_windows
Or for a statically linked binary:
> make cross_windows_static
This has been tested on a Linux system with mingw installed.
## Basic usage
Once compiled run the executable with the help flag:
@ -238,15 +253,16 @@ Help is available with the HELP command. Help on a specific topic is available
by specifying a keyword. The list below shows the currently defined keywords.
The rest of the section will give a brief run down of debugger features.
AUDIO BALL BREAK CARTRIDGE CLEAR
CONTROLLER CPU DISASSEMBLY DISPLAY DROP
GREP HALT HELP INSERT JOYSTICK
KEYPAD LAST LINT LIST MEMMAP
MISSILE ONHALT ONSTEP ONTRACE PANEL
PATCH PEEK PLAYER PLAYFIELD POKE
PREF QUANTUM QUIT RAM RESET
RUN SCRIPT STEP SYMBOL TIA
TIMER TRACE TRAP TV WATCH
[ $f000 SEI ] >> help
AUDIO BALL BREAK CARTRIDGE CLEAR
CONTROLLER CPU DISASSEMBLY DISPLAY DROP
GREP HALT HELP INSERT JOYSTICK
KEYPAD LAST LINT LIST LOG
MEMMAP MISSILE ONHALT ONSTEP ONTRACE
PANEL PATCH PEEK PLAYER PLAYFIELD
POKE PREF QUANTUM QUIT RAM
RESET RUN SCRIPT STEP SYMBOL
TIA
The debugger allows tab-completion in most situations. For example, pressing `W` followed by the Tab key on your keyboard, will autocomplete the `WATCH` command. This works for command arguments too. It does not currently work for filenames, or symbols. Given a choice of completions, the Tab key will cycle through the available options.
@ -274,6 +290,8 @@ is `.config/gopher2600`.
For MacOS the directory for release executables is `~/Library/Application Support/gopher2600`
For Window, files will be in the user's `Application Data/gopher2600` folder
In all instances, the directory, sub-directory and files will be created automatically
as required.

View file

@ -149,7 +149,7 @@ func (cl *Loader) Load() ([]byte, error) {
case "http":
resp, err := http.Get(cl.Filename)
if err != nil {
return nil, errors.New(errors.CartridgeLoader, cl.Filename)
return nil, errors.New(errors.CartridgeLoader, err)
}
defer resp.Body.Close()
@ -158,7 +158,7 @@ func (cl *Loader) Load() ([]byte, error) {
cl.data = make([]byte, size)
_, err = resp.Body.Read(cl.data)
if err != nil {
return nil, errors.New(errors.CartridgeLoader, cl.Filename)
return nil, errors.New(errors.CartridgeLoader, err)
}
case "file":
@ -167,21 +167,22 @@ func (cl *Loader) Load() ([]byte, error) {
case "":
f, err := os.Open(cl.Filename)
if err != nil {
return nil, errors.New(errors.CartridgeLoader, cl.Filename)
return nil, errors.New(errors.CartridgeLoader, err)
}
defer f.Close()
// get file info
cfi, err := f.Stat()
// get file info. not using Stat() on the file handle because the
// windows version (when running under wine) does not handle that
cfi, err := os.Stat(cl.Filename)
if err != nil {
return nil, errors.New(errors.CartridgeLoader, cl.Filename)
return nil, errors.New(errors.CartridgeLoader, err)
}
size := cfi.Size()
cl.data = make([]byte, size)
_, err = f.Read(cl.data)
if err != nil {
return nil, errors.New(errors.CartridgeLoader, cl.Filename)
return nil, errors.New(errors.CartridgeLoader, err)
}
default:

View file

@ -13,6 +13,8 @@
// You should have received a copy of the GNU General Public License
// along with Gopher2600. If not, see <https://www.gnu.org/licenses/>.
// +build !windows
// Package colorterm implements the Terminal interface for the gopher2600
// debugger. It supports color output, history and tab completion.
package colorterm

View file

@ -0,0 +1,67 @@
// This file is part of Gopher2600.
//
// Gopher2600 is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Gopher2600 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Gopher2600. If not, see <https://www.gnu.org/licenses/>.
// +build windows
// Package colorterm implements the Terminal interface for the gopher2600
// debugger. It supports color output, history and tab completion.
package colorterm
import (
"fmt"
"github.com/jetsetilly/gopher2600/debugger/terminal"
)
// ColorTerminal implements debugger UI interface with a basic ANSI terminal
type ColorTerminal struct {
}
// Initialise perfoms any setting up required for the terminal
func (ct *ColorTerminal) Initialise() error {
return fmt.Errorf("color terminal not available on windows")
}
// CleanUp perfoms any cleaning up required for the terminal
func (ct *ColorTerminal) CleanUp() {
}
// RegisterTabCompletion adds an implementation of TabCompletion to the
// ColorTerminal
func (ct *ColorTerminal) RegisterTabCompletion(tc terminal.TabCompletion) {
}
// IsInteractive satisfies the terminal.Input interface
func (ct *ColorTerminal) IsInteractive() bool {
return false
}
// Silence implements terminal.Terminal interface
func (ct *ColorTerminal) Silence(silenced bool) {
}
// TermRead implements the terminal.Input interface
func (ct *ColorTerminal) TermRead(input []byte, prompt terminal.Prompt, events *terminal.ReadEvents) (int, error) {
return 0, nil
}
// TermReadCheck implements the terminal.Input interface
func (ct *ColorTerminal) TermReadCheck() bool {
return false
}
// TermPrintLine implements the terminal.Output interface
func (ct *ColorTerminal) TermPrintLine(style terminal.Style, s string) {
}

View file

@ -13,6 +13,8 @@
// You should have received a copy of the GNU General Public License
// along with Gopher2600. If not, see <https://www.gnu.org/licenses/>.
// +build !windows
package colorterm
import (

View file

@ -13,6 +13,8 @@
// You should have received a copy of the GNU General Public License
// along with Gopher2600. If not, see <https://www.gnu.org/licenses/>.
// +build !windows
package colorterm
import (

2
go.mod
View file

@ -12,5 +12,5 @@ require (
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7
github.com/inkyblackness/imgui-go/v2 v2.4.1
github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942
github.com/veandco/go-sdl2 v0.4.1
github.com/veandco/go-sdl2 v0.4.4
)

2
go.sum
View file

@ -22,3 +22,5 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/veandco/go-sdl2 v0.4.1 h1:HmSBvVmKWI8LAOeCfTTM8R33rMyPcs6U3o8n325c9Qg=
github.com/veandco/go-sdl2 v0.4.1/go.mod h1:FB+kTpX9YTE+urhYiClnRzpOXbiWgaU3+5F2AB78DPg=
github.com/veandco/go-sdl2 v0.4.4 h1:coOJGftOdvNvGoUIZmm4XD+ZRQF4mg9ZVHmH3/42zFQ=
github.com/veandco/go-sdl2 v0.4.4/go.mod h1:FB+kTpX9YTE+urhYiClnRzpOXbiWgaU3+5F2AB78DPg=