Skip to content

Commit a140711

Browse files
committed
windows cross-compilation support
static build runs under minimal wine installation and passes regression tests
1 parent c22b590 commit a140711

File tree

10 files changed

+130
-29
lines changed

10 files changed

+130
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ test_roms/*
66
roms
77
.gopher2600/*
88
gopher2600
9+
gopher2600.exe
910
*.dot
1011
*.ps
1112
*.pdf

Makefile

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
compileFlags = '-c 3 -B -wb=false'
22
profilingRom = roms/Pitfall.bin
33

4-
.PHONY: all generate test clean run_assertions race build_assertions build release release_upx profile profile_display
4+
.PHONY: all generate test clean run_assertions race build_assertions build release check_upx release_upx profile profile_display
55

66
all:
77
@echo "use release target to build release binary"
@@ -16,6 +16,7 @@ test:
1616
clean:
1717
@echo "removing binary and profiling files"
1818
@rm -f gopher2600 cpu.profile mem.profile debug.cpu.profile debug.mem.profile
19+
@rm -f gopher2600.exe
1920
@find ./ -type f | grep "\.orig" | xargs -r rm
2021

2122
race:
@@ -30,12 +31,14 @@ build:
3031
release:
3132
go build -gcflags $(compileFlags) -ldflags="-s -w" -tags="release"
3233

33-
release_upx:
34-
@echo "requires upx to run. edit Makefile to activate"
35-
# go build -gcflags $(compileFlags) -ldflags="-s -w" -tags="release"
36-
# upx -o gopher2600.upx gopher2600
37-
# cp gopher2600.upx gopher2600
38-
# rm gopher2600.upx
34+
check_upx:
35+
@which upx > /dev/null
36+
37+
release_upx: check_upx
38+
go build -gcflags $(compileFlags) -ldflags="-s -w" -tags="release"
39+
upx -o gopher2600.upx gopher2600
40+
cp gopher2600.upx gopher2600
41+
rm gopher2600.upx
3942

4043
profile:
4144
go build -gcflags $(compileFlags)
@@ -47,5 +50,8 @@ profile_display:
4750
./gopher2600 performance --display --profile $(profilingRom)
4851
go tool pprof -http : ./gopher2600 cpu.profile
4952

50-
windows:
51-
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 .
53+
cross_windows:
54+
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" .
55+
56+
cross_windows_static:
57+
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" .

README.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,33 @@ versions earlier than v1.13 because of language features added in that version
122122
(binary literals).
123123

124124
The project uses the Go module system and dependencies will be resolved
125-
automatically. Do note however, that you will required the SDL development
126-
libraries for the Go SDL module to compile.
125+
automatically. Do note however, that you will also require the SDL development
126+
kit installed on the system. For users of UNIX like systems, installation from
127+
your package manager is the easiest option (for MacOS use the homebrew package
128+
manager https://formulae.brew.sh/formula/sdl2)
127129

128130
Compile with GNU Make
129131

130-
> make build
132+
> make release
131133

132134
During development, programmers may find it more useful to use the go command
133135
directly
134136

135137
> go run gopher2600.go
136138

139+
## Cross-Compilation
140+
141+
Native compilation of a Windows executable has not yet been tried. But
142+
cross-compilation does work via the Makefile:
143+
144+
> make cross_windows
145+
146+
Or for a statically linked binary:
147+
148+
> make cross_windows_static
149+
150+
This has been tested on a Linux system with mingw installed.
151+
137152
## Basic usage
138153

139154
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
238253
by specifying a keyword. The list below shows the currently defined keywords.
239254
The rest of the section will give a brief run down of debugger features.
240255

241-
AUDIO BALL BREAK CARTRIDGE CLEAR
242-
CONTROLLER CPU DISASSEMBLY DISPLAY DROP
243-
GREP HALT HELP INSERT JOYSTICK
244-
KEYPAD LAST LINT LIST MEMMAP
245-
MISSILE ONHALT ONSTEP ONTRACE PANEL
246-
PATCH PEEK PLAYER PLAYFIELD POKE
247-
PREF QUANTUM QUIT RAM RESET
248-
RUN SCRIPT STEP SYMBOL TIA
249-
TIMER TRACE TRAP TV WATCH
256+
[ $f000 SEI ] >> help
257+
AUDIO BALL BREAK CARTRIDGE CLEAR
258+
CONTROLLER CPU DISASSEMBLY DISPLAY DROP
259+
GREP HALT HELP INSERT JOYSTICK
260+
KEYPAD LAST LINT LIST LOG
261+
MEMMAP MISSILE ONHALT ONSTEP ONTRACE
262+
PANEL PATCH PEEK PLAYER PLAYFIELD
263+
POKE PREF QUANTUM QUIT RAM
264+
RESET RUN SCRIPT STEP SYMBOL
265+
TIA
250266

251267
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.
252268

@@ -274,6 +290,8 @@ is `.config/gopher2600`.
274290

275291
For MacOS the directory for release executables is `~/Library/Application Support/gopher2600`
276292

293+
For Window, files will be in the user's `Application Data/gopher2600` folder
294+
277295
In all instances, the directory, sub-directory and files will be created automatically
278296
as required.
279297

cartridgeloader/loader.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (cl *Loader) Load() ([]byte, error) {
149149
case "http":
150150
resp, err := http.Get(cl.Filename)
151151
if err != nil {
152-
return nil, errors.New(errors.CartridgeLoader, cl.Filename)
152+
return nil, errors.New(errors.CartridgeLoader, err)
153153
}
154154
defer resp.Body.Close()
155155

@@ -158,7 +158,7 @@ func (cl *Loader) Load() ([]byte, error) {
158158
cl.data = make([]byte, size)
159159
_, err = resp.Body.Read(cl.data)
160160
if err != nil {
161-
return nil, errors.New(errors.CartridgeLoader, cl.Filename)
161+
return nil, errors.New(errors.CartridgeLoader, err)
162162
}
163163

164164
case "file":
@@ -167,21 +167,22 @@ func (cl *Loader) Load() ([]byte, error) {
167167
case "":
168168
f, err := os.Open(cl.Filename)
169169
if err != nil {
170-
return nil, errors.New(errors.CartridgeLoader, cl.Filename)
170+
return nil, errors.New(errors.CartridgeLoader, err)
171171
}
172172
defer f.Close()
173173

174-
// get file info
175-
cfi, err := f.Stat()
174+
// get file info. not using Stat() on the file handle because the
175+
// windows version (when running under wine) does not handle that
176+
cfi, err := os.Stat(cl.Filename)
176177
if err != nil {
177-
return nil, errors.New(errors.CartridgeLoader, cl.Filename)
178+
return nil, errors.New(errors.CartridgeLoader, err)
178179
}
179180
size := cfi.Size()
180181

181182
cl.data = make([]byte, size)
182183
_, err = f.Read(cl.data)
183184
if err != nil {
184-
return nil, errors.New(errors.CartridgeLoader, cl.Filename)
185+
return nil, errors.New(errors.CartridgeLoader, err)
185186
}
186187

187188
default:

debugger/terminal/colorterm/colorterm.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// You should have received a copy of the GNU General Public License
1414
// along with Gopher2600. If not, see <https://www.gnu.org/licenses/>.
1515

16+
// +build !windows
17+
1618
// Package colorterm implements the Terminal interface for the gopher2600
1719
// debugger. It supports color output, history and tab completion.
1820
package colorterm
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// This file is part of Gopher2600.
2+
//
3+
// Gopher2600 is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// Gopher2600 is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with Gopher2600. If not, see <https://www.gnu.org/licenses/>.
15+
16+
// +build windows
17+
18+
// Package colorterm implements the Terminal interface for the gopher2600
19+
// debugger. It supports color output, history and tab completion.
20+
package colorterm
21+
22+
import (
23+
"fmt"
24+
25+
"github.com/jetsetilly/gopher2600/debugger/terminal"
26+
)
27+
28+
// ColorTerminal implements debugger UI interface with a basic ANSI terminal
29+
type ColorTerminal struct {
30+
}
31+
32+
// Initialise perfoms any setting up required for the terminal
33+
func (ct *ColorTerminal) Initialise() error {
34+
return fmt.Errorf("color terminal not available on windows")
35+
}
36+
37+
// CleanUp perfoms any cleaning up required for the terminal
38+
func (ct *ColorTerminal) CleanUp() {
39+
}
40+
41+
// RegisterTabCompletion adds an implementation of TabCompletion to the
42+
// ColorTerminal
43+
func (ct *ColorTerminal) RegisterTabCompletion(tc terminal.TabCompletion) {
44+
}
45+
46+
// IsInteractive satisfies the terminal.Input interface
47+
func (ct *ColorTerminal) IsInteractive() bool {
48+
return false
49+
}
50+
51+
// Silence implements terminal.Terminal interface
52+
func (ct *ColorTerminal) Silence(silenced bool) {
53+
}
54+
55+
// TermRead implements the terminal.Input interface
56+
func (ct *ColorTerminal) TermRead(input []byte, prompt terminal.Prompt, events *terminal.ReadEvents) (int, error) {
57+
return 0, nil
58+
}
59+
60+
// TermReadCheck implements the terminal.Input interface
61+
func (ct *ColorTerminal) TermReadCheck() bool {
62+
return false
63+
}
64+
65+
// TermPrintLine implements the terminal.Output interface
66+
func (ct *ColorTerminal) TermPrintLine(style terminal.Style, s string) {
67+
}

debugger/terminal/colorterm/input.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// You should have received a copy of the GNU General Public License
1414
// along with Gopher2600. If not, see <https://www.gnu.org/licenses/>.
1515

16+
// +build !windows
17+
1618
package colorterm
1719

1820
import (

debugger/terminal/colorterm/output.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// You should have received a copy of the GNU General Public License
1414
// along with Gopher2600. If not, see <https://www.gnu.org/licenses/>.
1515

16+
// +build !windows
17+
1618
package colorterm
1719

1820
import (

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ require (
1212
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7
1313
github.com/inkyblackness/imgui-go/v2 v2.4.1
1414
github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942
15-
github.com/veandco/go-sdl2 v0.4.1
15+
github.com/veandco/go-sdl2 v0.4.4
1616
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
2222
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
2323
github.com/veandco/go-sdl2 v0.4.1 h1:HmSBvVmKWI8LAOeCfTTM8R33rMyPcs6U3o8n325c9Qg=
2424
github.com/veandco/go-sdl2 v0.4.1/go.mod h1:FB+kTpX9YTE+urhYiClnRzpOXbiWgaU3+5F2AB78DPg=
25+
github.com/veandco/go-sdl2 v0.4.4 h1:coOJGftOdvNvGoUIZmm4XD+ZRQF4mg9ZVHmH3/42zFQ=
26+
github.com/veandco/go-sdl2 v0.4.4/go.mod h1:FB+kTpX9YTE+urhYiClnRzpOXbiWgaU3+5F2AB78DPg=

0 commit comments

Comments
 (0)