rgbds
rgbds copied to clipboard
[Feature request] Prologues (from the command line)
A prologue, in this context, is code implicitly appended to the beginning of every file. This can be done for a number of reasons: to include some necessary macros that belong in every file, to enforce some initial configuration (e.g., defining some variables — -D only allows EQUS), or even to define an initial context for a group of files (e.g., compiling a number of files into a single section, by inserting a SECTION FRAGMENT declaration at the top of all of them).
Right now, the only way to do such a thing is via scripting:
function assemble {
local prologue="$1"
shift
for file; do
rgbasm -hL -o "${file%.asm}.o" - <(echo "$prologue" && cat "$file")
done
}
This is obviously problematic for a number of reasons, including the fact that it isn't practical to include in a build script such as a Makefile.
Therefore, what I'm asking for is a command-line option, say -P, that would allow inserting code at the beginning of all files this way: something like rgbasm -P 'def version equ 2' foo.asm -o foo.o or rgbasm -P "SECTION FRAGMENT \"data files $name\", ROMX" would do the right thing, and it would be easy to integrate into build systems, etc.
(This was inspired by the comments on #1000, as -P pushs would achieve what that issue describes, allowing a pop+push combination to be used as a section clear.)
So you'd like to be able to do this:
RGBASM_FLAGS = -hL -Weverything -P "INCLUDE \"prologue.inc\""
%.o: %.asm
rgbasm $(RGBASM_FLAGS) -o $@ $<
You can currently do this instead:
RGBASM_FLAGS = -hL -Weverything
%.o: %.asm
cat prologue.inc $< | rgbasm $(RGBASM_FLAGS) -o $@ -
If this were a feature, I'd rather just pass a filename to be included, since a large project's prologue will probably be more than one line a a small project doesn't need that much abstraction:
RGBASM_FLAGS = -hL -Weverything -P prologue.inc
%.o: %.asm
rgbasm $(RGBASM_FLAGS) -o $@ $<
A project needing more than one line can just do -P "foo" -P "bar"... or maybe there's a way to pass newlines inside a command-line argument that I don't know about?
(Well, powershell can do it trivially, but I'm not starting powershell just to run rgbasm...)
If this is added, we could deprecate -D in exchange; it's limited anyway by only defining EQUS.
I think if -D is deprecated by this we should not include the file directly from the command line. -Dversion=2 is a lot easier than creating a file containing the definition and including it in the prologue
I do prefer the prologue being included directly though, so I guess my point is that -D should stay
if you want to write code directly:
RGBASM_FLAGS = -hL -Weverything
%.o: %.asm
echo "PUSHS" | cat - $< | rgbasm $(RGBASM_FLAGS) -o $@ -
I'll accept -P containing inline code if you can manage to make it work without a bunch of crashes... so let's rather have -I/--include follow precedent and behave as if an implicit INCLUDE "<file>" was given.
I don't see much point over actually writing INCLUDE "defines.asm" at the top of every file, but I can accept the feature if it's not too hacky and works well.
I'm working on -I/--includefile (--include is already used for -i to specify a path in which to search for INCLUDEs and INCBINs).
...confusingly so. -I is the standard for that in C compilers, I think it should alias -i (deprecating it?), and --include being long-only.
How about if we add --includefile as long-only for now, add uppercase -I for --include, and deprecate lowercase -i. Then the next version can switch to using lowercase -i for --includefile, or just discard it and leave that as long-only. (Although I'd like to ultimately have a short flag for both.)