From aa46cc48e5f6a85c734e41561c0304abfd05ff46 Mon Sep 17 00:00:00 2001 From: Ivan Izaguirre Date: Thu, 26 Dec 2019 23:11:32 +0100 Subject: [PATCH] Use docker to build --- README.md | 19 +++++++------------ dockerbuild/.gitignore | 2 ++ dockerbuild/Dockerfile | 15 +++++++++++++++ dockerbuild/build.sh | 5 +++++ dockerbuild/buildindocker.sh | 27 +++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 dockerbuild/.gitignore create mode 100644 dockerbuild/Dockerfile create mode 100755 dockerbuild/build.sh create mode 100644 dockerbuild/buildindocker.sh diff --git a/README.md b/README.md index bee44bb..fca465a 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ Displays super hi-res box art as seen with the VidHD card. ### Terminal mode To run text mode right on the terminal without the SDL2 dependency, use `apple2console`. It runs on the console using ANSI escape codes. Input is sent to the emulated Apple II one line at a time: ``` -casa@servidor:~$ ./apple2console +casa@servidor:~$ ./apple2console -model 2plus ############################################ # # @@ -199,17 +199,12 @@ $ go get github.com/ivanizag/apple2/apple2sdl $ go build github.com/ivanizag/apple2/apple2sdl ``` -### Cross compile apple2sdl.exe for Windows in Ubuntu +### Use docker to cross compile for Linux and Windows -Install the mingw cross compile tools and the [SDL2 Windows libs for mingw](https://www.libsdl.org/download-2.0.php). +To create executables for Linux and Windows without installing Go, SDL2 or the Windows cross compilation toosl, run: ``` -$ sudo apt install mingw-w64 -$ wget https://www.libsdl.org/release/SDL2-devel-2.0.9-mingw.tar.gz -$ tar -xzf SDL2-devel-2.0.9-mingw.tar.gz -$ sudo cp -r SDL2-2.0.9/x86_64-w64-mingw32/* /usr/x86_64-w64-mingw32 +$ cd docker +$ ./build.sh ``` -Compile: -``` -$ env CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc GOOS=windows CGO_LDFLAGS="-L/usr/x86_64-w64-mingw32/lib -lSDL2 --verbose" CGO_FLAGS="-I/usr/x86_64-w64-mingw32/include -D_REENTRANT" go build -o apple2sdl.exe -x github.com/ivanizag/apple2/apple2sdl -``` -To run the executable in Windows, copy the file `SDL2.dll` on the same folder. The latest `SDL2.dll` can be found in the [Runtime binary for Windows 64-bit](https://www.libsdl.org/download-2.0.php). + +To run in Windows, copy the file `SDL2.dll` on the same folder as `apple2sdl.exe`. The latest `SDL2.dll` can be found in the [Runtime binary for Windows 64-bit](https://www.libsdl.org/download-2.0.php). diff --git a/dockerbuild/.gitignore b/dockerbuild/.gitignore new file mode 100644 index 0000000..9ef9604 --- /dev/null +++ b/dockerbuild/.gitignore @@ -0,0 +1,2 @@ +build + diff --git a/dockerbuild/Dockerfile b/dockerbuild/Dockerfile new file mode 100644 index 0000000..af8c5ca --- /dev/null +++ b/dockerbuild/Dockerfile @@ -0,0 +1,15 @@ +FROM circleci/golang:1.12 + +LABEL MAINTAINER="Ivan Izaguirre " + +RUN sudo apt-get update +RUN sudo apt-get install -y libsdl2-dev mingw-w64 + +RUN wget https://www.libsdl.org/release/SDL2-devel-2.0.9-mingw.tar.gz +RUN sudo tar -xzf SDL2-devel-2.0.9-mingw.tar.gz +RUN sudo cp -r SDL2-2.0.9/x86_64-w64-mingw32 /usr + +COPY buildindocker.sh . +RUN sudo chmod +x buildindocker.sh + +CMD ["./buildindocker.sh"] diff --git a/dockerbuild/build.sh b/dockerbuild/build.sh new file mode 100755 index 0000000..3c681b4 --- /dev/null +++ b/dockerbuild/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash +cd "$( dirname $0)" +docker build . -t apple2builder +mkdir -p ${PWD}/build +docker run --rm -it -v ${PWD}/build:/build apple2builder diff --git a/dockerbuild/buildindocker.sh b/dockerbuild/buildindocker.sh new file mode 100644 index 0000000..b19fbd9 --- /dev/null +++ b/dockerbuild/buildindocker.sh @@ -0,0 +1,27 @@ +#!/bin/bash +cd /tmp +git clone https://github.com/ivanizag/apple2 + +# Build apple2console for Linux +cd /tmp/apple2/apple2console +go build . +sudo chown --reference /build apple2console +sudo cp apple2console /build + +# Build apple2console.exe for Windows +cd /tmp/apple2/apple2console +env CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc GOOS=windows CGO_LDFLAGS="-L/usr/x86_64-w64-mingw32/lib" CGO_FLAGS="-I/usr/x86_64-w64-mingw32/include -D_REENTRANT" go build -o apple2console.exe . +sudo chown --reference /build apple2console.exe +sudo cp apple2console.exe /build + +# Build apple2sdl for Linux +cd /tmp/apple2/apple2sdl +go build . +sudo chown --reference /build apple2sdl +sudo cp apple2sdl /build + +# Build apple2sdl.exe for Windows +cd /tmp/apple2/apple2sdl +env CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc GOOS=windows CGO_LDFLAGS="-L/usr/x86_64-w64-mingw32/lib -lSDL2" CGO_FLAGS="-I/usr/x86_64-w64-mingw32/include -D_REENTRANT" go build -o apple2sdl.exe . +sudo chown --reference /build apple2sdl.exe +sudo cp apple2sdl.exe /build