This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Cross-platform build file?

Cross-platform build file?
by on (#234625)
I've seen projects come with a .bat file to build the project.

Being on a macOS computer, I open these files and see unix commands wrapped in what must be batch file syntax. I'll copy and paste the lines that look relevant to me into my terminal, or create a sh file and paste the commands in there.

Is there a good way to write a cross-platform build file that supports building an NES project for Windows users and Mac/Unix users?
Re: Cross-platform build file?
by on (#234626)
ericandrewlewis wrote:
Is there a good way to write a cross-platform build file that supports building an NES project for Windows users and Mac/Unix users?

IMO there is no good solution for this.

Maybe having Windows users install a version of Make is about as close as you can get (or even providing a binary of it).

Most cross platform software I maintain or have worked on simply has separate build scripts for different platforms.
Re: Cross-platform build file?
by on (#234631)
Any cross-platform solution will require people to have something installed. Makefiles, or other build script systems (gradle, tup, etc, etc, etc) are pretty common, but all require something to be installed (which might be already installed on Linux or Mac). You could write your build scripts in a general scripting language like Python or Perl, but again, that requires an install on windows.

That said, I'm a proponent of Make. As long as windows users have the Make executable, then the build file can often be the same across platforms. And despite Make's TERRIBLE syntax, it's really flexible and handles incremental builds well. (which admittedly doesn't matter much when you're just compiling a little bit of assembly, but if you're doing significant asset conversions, it can make a big difference)
Re: Cross-platform build file?
by on (#234655)
Most projects I've seen which offer both, provide separate files for each system type -- one for *IX systems (shell script, Makefile, whatever), one for Win32 systems (bat file). There is no sane and KISS-compliant way to accomplish this in in a single file/manner.
Re: Cross-platform build file?
by on (#234658)
For a simple nes project, what I'm doing in my case is a generic makeFile. On windows 10, I install WSL (Windows subsystem for linux) and I just install the tools I need. On mac I install homebrew and install was is missing. On linux, just install what I need.

Then I just prepare a few shell scripts that launch the emulator for the target platform so the only part that changes are the shellscript. In most case, only the path change in the script.

I change often computer and I had no issue with ca65 that way. This is one way to do it, doesn't means it "the way" of doing it.
Re: Cross-platform build file?
by on (#234660)
And on Windows 7 or 8.1, Git Bash + ezwinports Make gives you what you need to run a makefile.
Re: Cross-platform build file?
by on (#234666)
There is the abomination called CMake.. although I think most people would just run from your project before actually using it.

That being said if you want MAC and Windows support and you willing to touch JS. You could use

jsc your_script.js on mac
cscript your_script.js on windows

probably going to need some fancy "detect machine" code so you can change the "host library" calls though.
Re: Cross-platform build file?
by on (#234783)
I'm a lazy user of .bat files, as my NES related project build scripts are just calls to my custom command line converters and then four or five cc65-related oneliners. I know I'd better learn make, but its syntax (which seems to be designed to be written by some kind of crazy robot) just gets me on my nerves :D
Re: Cross-platform build file?
by on (#234785)
na_th_an wrote:
I'm a lazy user of .bat files, as my NES related project build scripts are just calls to my custom command line converters and then four or five cc65-related oneliners. I know I'd better learn make, but its syntax (which seems to be designed to be written by some kind of crazy robot) just gets me on my nerves :D

Not to get off-topic, but 3 of the problems with Make historically were 1) bad compatibility amongst all the makes (GNU vs. BSD vs. Sun vs. other implementations), 2) very bad documentationand 3) atrocious examples found throughout lots of open-source or free projects.

#1 today is better than it used to be but not quite there (to write compatible Makefiles across different Makes, you really have to familiarise yourself with both GNU and BSD make. You can usually interchange between the two but there are syntactical and variable differences. GNU letting people use spaces instead of tabs for indented actions of a target is probably still the biggest gotcha). #2 is better than it used to be: GNU make today has tolerable documentation, though it caters towards those who read it and not skim. #3 is still a big problem: you either have gargantuan projects with Makefiles that fit said description ("...designed to be written by some kind of crazy robot..."), or you have very small projects whose authors have literally no clue what they're doing -- the latter of which proliferated bad/crummy Makefiles over the course of the past ~25 years. Good Makefiles are often small/simple and don't go crazy; you may have to look up what some variables or fake targets do, but that's about it. Makefiles that shell out to shell utilities to incorporate something into variables are also dangerous as hell, non-portable, and often will break if used with parallelism (I always advise doing everything in Make natively if possible. If it can't be, you may need to reconsider "how" the overall model is being done). Another thing that's remarkably importable with Make that is often rarely ever discussed is only using it on systems which have properly synced clocks via NTP; systems which suffer from clock drift (either due to bad hardware or software/driver nuances) and don't properly keep time will screw Make up beyond belief.

Sadly I don't have a good a solution for this dilemma. I can mention things like tup and some other build systems, but there's nothing that universally works for all projects and everyone's style/workflows. Thus, everyone has to sit down and spend hours of time installing them, trying them, uninstalling them, trying another, etc.. So, in a way, it almost feels like even discussing or trying to solve this problem is wasted human time.
Re: Cross-platform build file?
by on (#234797)
@na_th_an

Since your projects are a mix of C and asm, the makefile I'm using at the moment could be a good starting point. I can try to adapt one of your project and see how it goes, when I find time. When done properly, it will only re-compile what is necessary since I'm using deps and it's now working well.

@koitsu

The main problem with make for myself is that I learn it, create something acceptable, don't touch it for months and when I come back to it to change something I'm like "wtf, how did I make that?" :lol: Unless you use often you then to forget how it work right away.
Re: Cross-platform build file?
by on (#234813)
The most annoying thing with make got to be that most versions discriminates tabs from other kinds of spaces.
I only use make for C projects to keep paths and build flags organized. But there are things make can't do so I end up using a shell script as well that calls make anyway.

For assembly projects I only use shell scripts.
Re: Cross-platform build file?
by on (#234820)
Pokun wrote:
The most annoying thing with make got to be that most versions discriminates tabs from other kinds of spaces.

Yup, which is also why having an OS with unexpand is handy. People are supposed to use hard tabs, but GNU is the one Make that lets folks use spaces instead.

Pokun wrote:
But there are things make can't do so I end up using a shell script as well that calls make anyway.

Using a shell script that does tweaking/whatever, then calls make, is certainly the right approach, and a lot of the time can also be "ported" over to Windows cmd/batch easily. But that just circles back to what I said initially: most projects I encounter provide both a .bat version for Win32 and an .sh version for *IX -- though quite often if the maintainers only use a single OS type (ex. Linux), they neglect the uncommonly-used-by-them script. YMMV.
Re: Cross-platform build file?
by on (#234894)
Good to know thanks! I'm not doing anything complicated so I don't think it's anything that can't be ported to other systems' shell script.