I did some experimenting with ZERICO2005's excellent PortCE toolkit (
https://cemetech.net/forum/viewtopic.php?p=307420) and was able to port CE-NICCC to run on my Mac with minimal changes.
I probably won't release this port, but I figured that I would make a guide on how I ported it for others who might be interested in porting their own C programs.
For the purposes of this guide, I am assuming that you:
* are on either macOS or Linux
* are using git for source control
* have a working C compiler and CE C toolchain
* have cmake installed (on macOS, install with Homebrew using brew install cmake)
* and have some basic familiarity with the terminal.
0. Read the PortCE README (
https://github.com/ZERICO2005/PortCE/blob/master/README.md) to understand what is available and whether your program is eligible.
1. Add PortCE as a git submodule: git submodule add
https://github.com/ZERICO2005/PortCE/
This lets you pull updates to PortCE directly from its repository, since
PortCE is a work in progress and changes are constantly being made (as of writing this, the last commit was two weeks ago).
2. Make sure all submodules are up to date: git submodule update --init
3. Make a symlink as follows. In the root directory of your repository (*not* in src/), execute this: ln -s ./PortCE/src_PortCE/ src_PortCE
This makes a shortcut pointing to the src_PortCE directory in the submodule. To the compiler, this does the same thing as copying the src_PortCE directory to the root of your repository, while allowing you to track and update it using git. Note that creating a regular shortcut (or alias on macOS) will not work; you must create a symlink using the ln command.
4. Copy (don't symlink) the CMakeLists.txt and PortCE.config files from the PortCE repository to the root of yours. Edit the CMakeLists.txt for your project (namely, change the project name to match what you want the output executable to be named).
5. Follow the PortCE README instructions (
https://github.com/ZERICO2005/PortCE/blob/master/README.md) to modify your source code to add the appropriate PortCE functions.
Quote:
Aside: macOS specific build stuff
You'll need to make sure that you have the SDL2 and SDL2_mixer libraries installed. You can do that using Homebrew (https://brew.sh) by running brew install SDL2 SDL2_mixer . (Run brew search sdl2 to see the complete list of SDL2 libraries.)
Then, make sure the compiler can link against the libraries by adding the following line to the end of your .bash_profile or .zshrc (for bash or zsh, respectively, or to the corresponding dotfile for your shell of choice):
export LIBRARY_PATH="$LIBRARY_PATH:/opt/homebrew/lib"
Finally, add this line to your CMakeLists.txt after the "find_package(SDL2 REQUIRED)" line to make sure the compiler can see the SDL2 headers:
include_directories(${PROJECT_NAME} ${SDL2_INCLUDE_DIRS})
6. To build and run your program, follow PortCE's instructions. I found it convenient to put them into a shell script so I could run one command to do everything. Note that I have made it so that it deletes the build directory every time for a fresh build; if you are on lower powered hardware, you might want to remove this part.
I called this file portce-make.sh and made it executable with chmod +x ./portce-make.sh . It should be in the root of your repository. Then, you can run it simply by calling ./portce-make.sh .
Code: #!/usr/bin/env bash
# Delete build directory if it already exists.
rm -rf $(dirname $0)/build
# Make a new build directory.
mkdir -p $(dirname $0)/build
# Go into the build directory and create required files for cmake and ninja.
cd $(dirname $0)/build
cmake -G Ninja ..
# Do It
ninja
7. Make updates to your code as needed. In my case, I found that there were a couple quirks that I had to work around before my program could run properly. Since PortCE is a work in progress, these can change at any time. It's best to verify yourself before implementing a workaround.
1. os_GetCSC() seems to always return a non-zero value, even when no key is pressed
2. gfx_FloodFill is not implemented yet
3. ti_Read will sometimes return an incorrect number of bytes read after seeking to the end of an appvar
8. To make the build/run cycle easier, I made a second script (that I called run-portce.sh) which calls my make script and then runs the compiled program. My program uses appvars, so I have it cd into that directory first so the program can find the files. You'll need to remove that part and edit the relative paths if your program doesn't do this.
Code: #!/usr/bin/env bash
# cd into appvar directory so the program can find the appvars.
cd $(dirname $0)/appvar
# make
../portce-make.sh
# run
../build/bin/ce-niccc
# done
cd $(dirname $0)
Feel free to share any feedback on this guide. Also, major kudos to zerico2005 for their work on PortCE!