Difference between revisions of "Compiling KOS on Windows"

From DCEmulation
Jump to navigation Jump to search
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Cygwin setup ==
==Overview==
# Install Cygwin 32bit, setup-x86.exe from here http://cygwin.com/install.html
# Click next twice, making sure to install from internet.
# Choose install directory. I chose d:\cygwin. Click next.
# Choose download directory. Does not affect install directory. Click next 3 times.
# Chose packages to install. I chose Devel, Libs, and Utils. [[File:Cyg01.jpg]]
# Click next. When the download and install is completed (this can take some time), Cygwin should be good to go.


== Toolchain (cross-compiler and libraries) ==
This tutorial is a step-by-step guide on how to setup a toolchain and KOS environment on your Windows system.
# Run 32bit Cygwin Terminal as administrator [[File:Cyg02.jpg]]
# Download kos-2.0.0-src.tar.gz from here http://sourceforge.net/projects/cadcdev/files/kallistios/2.0.0/
# Create a folder /dc/ in your /Cygwin/usr/local/ folder
# Create a folder /kos/ in your /Cygwin/usr/local/dc/ folder
# Extract the contents of /kos-2.0.0-src/ into your /Cygwin/usr/local/dc/kos/ folder
# Download [http://dcemulation.org/phpBB/download/file.php?id=754 this patch] and extract into your dc-chain folder
# In cygwin, navigate to your dc-chain folder. Since I installed the chain on my d:, my command is $ cd d:/cygwin/usr/local/dc/kos/utils/dc-chain
# Download the libs needed by dc-chain by running the script with this command: $ ./download.sh
# Extract the libs needed by dc-chain by running the script with this command: $ ./unpack.sh
# Patch the default kos install by running the script with this command: $ ./patch.sh
# Build the dc-chain with this command $ make


== KOS ==
The toolchain consists of a C/C++ compiler (GCC), assembler and linker (binutils), and C library (newlib). As the Dreamcast has two processors - the SH4 CPU and the AICA (ARM) sound processor - the toolchain includes compilers for both.
# Download this [http://dcemulation.org/phpBB/download/file.php?id=755 environ.sh] and extract into your /Cygwin/usr/local/dc/kos/ folder
# Navigate to your kos directory in Cygwin. Since I installed the chain on my d:, my command is
$ cd d:/cygwin/usr/local/dc/kos


# Configure your environment by running this command:
KOS consists of the operating system core (kos) and a set of nicely integrated libraries (kos-ports).
$ . ./environ.sh


# Build KOS by running the command
Since KOS was developed for Unix-compatible systems (like Linux, BSD, etc.), a Unix-compatible development environment must be installed. The available choices are Cygwin, MSYS and MSYS2. MSYS is unmaintained and out-dated. Cygwin and MSYS2 both work, but MSYS2 seems to be maintained more actively, work better and also offers a better package management system, so it is preferred.
 
==Preparations==
Install MSYS2 from http://repo.msys2.org/distrib/i686 (this tutorial used http://repo.msys2.org/distrib/i686/msys2-i686-20160205.exe).
 
''Please make sure to use partition C:\''. A user reported issues of git, wget, etc. not working at all when installing to partition D:\. On the MSys2 website it's mentioned that FAT filesystems don't work, so that's an alternative explanation.
 
As the setup completes, it will ask whether you want to open a shell. Don't. Open ''C:\msys32\mingw32_shell.bat'' instead (mingw shell instead of msys2 shell).
 
==Install script==
At this point, please consider trying the install script first. It will perform the remaining steps below automatically.
 
Download the install script: [[File:Kos_setup_script.zip]].
Then change to the directory of the script and execute it (uses Unix paths instead of Windows paths, ''C:\'' becomes ''/c/'')
$ cd /c/Documents\ and\ Settings (''find your Download folder here..'')
$ sh kos_setup.sh
 
The script should perform all the remaining steps. If something goes wrong, you can try to continue the steps manually or ask for help on the forums/IRC.
 
==Install required packages==
MSYS2 uses the ''pacman'' package manager. The following command should download all required programs.
 
$ pacman -Sy --needed mingw-w64-i686-binutils mingw-w64-i686-gcc mingw-w64-i686-pkg-config mingw-w64-i686-libpng mingw-w64-i686-libjpeg-turbo diffutils git make subversion patch python tar texinfo wget
 
==Downloading KOS==
 
KOS is available through a Git repository at SourceForge.
The standard install directory assumed in the configuration files is /opt/toolchains/dc/{kos, kos-ports}.
 
$ git clone git://git.code.sf.net/p/cadcdev/kallistios /opt/toolchains/dc/kos
 
 
==Toolchain (cross-compiler and libraries)==
After cloning the KOS repository, run the toolchain download+unpack+compile scripts:
 
$ cd /opt/toolchains/dc/kos/utils/dc-chain
$ sh download.sh
$ sh unpack.sh
 
Then compile the cross-compiler and system libraries.
The erase=1 will delete temporary files after a successful build.
 
$ make erase=1
 
After this command completes successfully you have a working cross-compiler for Dreamcast and can compile KOS next.
 
==Setting up KOS==
 
You should read the documentation in the kos/doc directory for details, but here are the basic steps required to set up the KOS environment:
 
Go into the kos directory and copy the template configuration:
 
$ cp /opt/toolchains/dc/kos/doc/environ.sh.sample /opt/toolchains/dc/kos/environ.sh
 
Now edit environ.sh to match your installation. If you use the default installation directory you don't need to change anything.
 
Execute the following command to set the KOS environment variables:
 
$ source /opt/toolchains/dc/kos/environ.sh
 
Remember to do this every time you want to use the KOS environment in a newly opened shell.
Dont't forget to run the above command again when editing environ.sh.
 
Now we are finally ready to compile KOS itself. In the kos directory, run:
$ cd /opt/toolchains/dc/kos
  $ make
  $ make




That's All! When kos is built, you are ready to start compiling your own code for the Dreamcast using Kos 2.0 and GCC 4.7.3.
==KOS-Ports==
KOS-Ports is a repository with commonly used libraries for development on the DC, like PNG or MP3 loading.
 
Clone the repository:
 
$ git clone git://git.code.sf.net/p/cadcdev/kos-ports /opt/toolchains/dc/kos-ports
 
Compile all KOS-ports using the build-all script
 
$ sh /opt/toolchains/dc/kos-ports/utils/build-all.sh
 
Now you should have a working Dreamcast development environment :-)
 
Check out the examples in the KallistiOS directory to find out how to use KOS in your own projects!

Latest revision as of 10:13, 7 March 2017

Overview

This tutorial is a step-by-step guide on how to setup a toolchain and KOS environment on your Windows system.

The toolchain consists of a C/C++ compiler (GCC), assembler and linker (binutils), and C library (newlib). As the Dreamcast has two processors - the SH4 CPU and the AICA (ARM) sound processor - the toolchain includes compilers for both.

KOS consists of the operating system core (kos) and a set of nicely integrated libraries (kos-ports).

Since KOS was developed for Unix-compatible systems (like Linux, BSD, etc.), a Unix-compatible development environment must be installed. The available choices are Cygwin, MSYS and MSYS2. MSYS is unmaintained and out-dated. Cygwin and MSYS2 both work, but MSYS2 seems to be maintained more actively, work better and also offers a better package management system, so it is preferred.

Preparations

Install MSYS2 from http://repo.msys2.org/distrib/i686 (this tutorial used http://repo.msys2.org/distrib/i686/msys2-i686-20160205.exe).

Please make sure to use partition C:\. A user reported issues of git, wget, etc. not working at all when installing to partition D:\. On the MSys2 website it's mentioned that FAT filesystems don't work, so that's an alternative explanation.

As the setup completes, it will ask whether you want to open a shell. Don't. Open C:\msys32\mingw32_shell.bat instead (mingw shell instead of msys2 shell).

Install script

At this point, please consider trying the install script first. It will perform the remaining steps below automatically.

Download the install script: File:Kos setup script.zip. Then change to the directory of the script and execute it (uses Unix paths instead of Windows paths, C:\ becomes /c/)

$ cd /c/Documents\ and\ Settings (find your Download folder here..)
$ sh kos_setup.sh

The script should perform all the remaining steps. If something goes wrong, you can try to continue the steps manually or ask for help on the forums/IRC.

Install required packages

MSYS2 uses the pacman package manager. The following command should download all required programs.

$ pacman -Sy --needed mingw-w64-i686-binutils mingw-w64-i686-gcc mingw-w64-i686-pkg-config mingw-w64-i686-libpng mingw-w64-i686-libjpeg-turbo diffutils git make subversion patch python tar texinfo wget

Downloading KOS

KOS is available through a Git repository at SourceForge. The standard install directory assumed in the configuration files is /opt/toolchains/dc/{kos, kos-ports}.

$ git clone git://git.code.sf.net/p/cadcdev/kallistios /opt/toolchains/dc/kos


Toolchain (cross-compiler and libraries)

After cloning the KOS repository, run the toolchain download+unpack+compile scripts:

$ cd /opt/toolchains/dc/kos/utils/dc-chain
$ sh download.sh
$ sh unpack.sh

Then compile the cross-compiler and system libraries. The erase=1 will delete temporary files after a successful build.

$ make erase=1

After this command completes successfully you have a working cross-compiler for Dreamcast and can compile KOS next.

Setting up KOS

You should read the documentation in the kos/doc directory for details, but here are the basic steps required to set up the KOS environment:

Go into the kos directory and copy the template configuration:

$ cp /opt/toolchains/dc/kos/doc/environ.sh.sample /opt/toolchains/dc/kos/environ.sh 

Now edit environ.sh to match your installation. If you use the default installation directory you don't need to change anything.

Execute the following command to set the KOS environment variables:

$ source /opt/toolchains/dc/kos/environ.sh

Remember to do this every time you want to use the KOS environment in a newly opened shell. Dont't forget to run the above command again when editing environ.sh.

Now we are finally ready to compile KOS itself. In the kos directory, run:

$ cd /opt/toolchains/dc/kos 
$ make


KOS-Ports

KOS-Ports is a repository with commonly used libraries for development on the DC, like PNG or MP3 loading.

Clone the repository:

$ git clone git://git.code.sf.net/p/cadcdev/kos-ports /opt/toolchains/dc/kos-ports

Compile all KOS-ports using the build-all script

$ sh /opt/toolchains/dc/kos-ports/utils/build-all.sh

Now you should have a working Dreamcast development environment :-)

Check out the examples in the KallistiOS directory to find out how to use KOS in your own projects!