Skip to content

Instantly share code, notes, and snippets.

@DavidEGrayson
Last active October 24, 2022 14:55
Show Gist options
  • Save DavidEGrayson/65cfc653e6d0aeb08afc to your computer and use it in GitHub Desktop.
Save DavidEGrayson/65cfc653e6d0aeb08afc to your computer and use it in GitHub Desktop.
Getting started with midipix

Getting started with midipix

Let's compile midipix from source and play with it!

  1. Get access to a Linux machine for development.

  2. Install git and gcc on the development machine.

  3. Make the directory ~/midipix_src for holding source code, and navigate to it.

  4. Build the cross-compiler with the following command. This could take a while. It produces build files in ~/temp and puts the compiler files in ~/midipix.

    git clone git://midipix.org/cbb/cbb-gcc && cd cbb-gcc && ./cbb-midipix-cross-gcc.sh
    
  5. Get the cross-compiler on your PATH:

    export PATH=$PATH:~/midipix/bin
    
  6. We now have a working cross-compiler, but it can't do much because we don't have the runtime libraries that the compiled programs need.

  7. See the website midipix.org for information about how to get read access to the latest internal/private git repositories. The publicly-available git repos that you can find easily on the site might be too old and not work for you. Then get the source code for the runtime libraries by running the following multi-line command in your shell from the ~/midipix_src directory. You will need to replace $midipix_internal with something.

    for repo in psxtypes pemagine dalist ntapi ntcon ntctty psxscl; do
      git clone git://midipix.org/$midipix_internal/$repo
    done
    
  8. Copy build.sh from this gist into ~/midipix_src. Run it to update the projects, build them, and install them into the cross-compiler toolchain.

  9. In some new directory, create a file named test.c with a simple "hello world" program:

    #include <stdio.h>
    
    int main()
    {
      printf("hello world\n");
      return 0;
    }
    
  10. Compile the program by running the following command. You should probably wrap it in a Makefile so you don't have to type it every time.

    x86_64-nt64-midipix-gcc test.c -o test.exe
    
  11. Copy test.exe to a Windows machine. (Actually I do my compilation inside a VirtualBox shared folder that is accessible to both the Linux virtual machine and the Windows host machine so I don't need to bother.)

  12. Copy all the shared object (*.so) files from ~/midipix/x86_64-nt64-midipix/lib/ to the Windows machine as well, and put them in the same directory as test.exe so they can be found. (Though for this particular example you should only need libc.so and libpsxscl.so.)

  13. Run .\test.exe on the Windows machine! If you have MSYS2 installed, I recommend running it from a MinTTY bash shell. If you don't have MSYS2 installed, you can run it from a normal Command Prompt, but beware that you won't actually see the program print anything in the Command Prompt. This is not a bug. To get output from the program, pipe its output to a file using a command like .\test.exe > output.txt or run it in mintty.

Thanks to the midipix project author for helping me with these instructions.

#!/bin/sh
set -ue
BASEDIR="$HOME/midipix_src"
DESTDIR1="$HOME/midipix/native"
DESTDIR2="$HOME/midipix/x86_64-nt64-midipix"
for proj in psxtypes; do
git -C "$BASEDIR/$proj" pull origin main
make -C "$BASEDIR/$proj" DESTDIR="$DESTDIR1" install
make -C "$BASEDIR/$proj" DESTDIR="$DESTDIR2" install
done
for proj in dalist pemagine ntapi ntcon ntctty psxscl; do
git -C "$BASEDIR/$proj" pull origin main
rm -rf "$BASEDIR/build-$proj"
mkdir -p "$BASEDIR/build-$proj"
pushd "$BASEDIR/build-$proj"
"$BASEDIR/$proj/configure" --debug --host=x86_64-nt64-midipix
make DESTDIR="$DESTDIR1" install
make DESTDIR="$DESTDIR2" install
popd
done
  • TODO: figure out how to debug with gdb
@p-groarke
Copy link

Why use cmake when you can use literal cancer autotools. Plus it forbids ever compiling using clang for windows. Who would want that for a windows project!? ;)

@JL2210
Copy link

JL2210 commented Jan 12, 2019

CMake is too complicated for some users, and has vague options that can only be specified by poring over CMakeLists.txt. As Midipix and the systems that it are built on contain /bin/bash, I see no problem in this.

Plus it forbids ever compiling using clang for windows.

Not true. You can specify CC=clang CXX=clang++ anywhere in the configure command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment