What kind of output did you pick? BMP? How do you write the output file?
Very cool project.
Thanks!
I chose the
PPM format, since it is simple and text based.
I did have issues coming up with a clean way of outputting an image. Since I set my goal to use absolutely
no external binaries (Not even recalling
make itself), I had to come up with a way to make
make itself write to either
stdout or
stderr, mid-parsing.
The debug directives (.info, .warning, .error) look like an attractive solution at first but they have a bunch of issues that make them not fit this case:
- They always prepend the output text, with line number and file name.
- They output to
stderr.
Since the PPM format requires the magic '
P3' string to be the first thing on the first line of the image file, issue 1. alone made me cross out debug directives. On top of that, issue 2. meant that even if I could somehow solve issue 1., I then couldn't show a simple TUI and progress indicator, because all of that text would also get prepended at the start of
stderr.
Next, for a short while I considred using a
.PHONY target with
PATH set to
/nonexistant, and then just ploping the variable holding the image as an unmuted command;
make would run the target, print the command line to stdout (which would actually be the image), and then fail running it as a command and exit.
It kinda worked, but this sloution is also cheating because
make targets call the shell under the hood, and that would still be a single extarnal binary called, so I looked for yet another option:
I knew of
-V and
-vflags' behavior; when calling
make you specify a variable name with them and they print them to stdout, no preemble, just its raw value. What I didn't know was that you could add them mid-parsing with the
.MAKEFLAGES: special target.
By mixing these two you could print a variable clealy to stdout, with make itself.
Here is the
print.mk file that does this.
So as pointed out in the readme, all you need to do is to run make and redirect it's stdout to your image file:
make > output.ppm
Binary output is also posible, the
:tsc modifier accepts hex escape values, which creates a way for generating arbitury bytes,
but the null byte (
\x00) can never (to the extent of my knowlage) be printed by
make itself (Null terminated strings...), so while a
bmp output is possible, it would need a target with a bunch of calls to
printf(1) a call to shell and so on ... .
IDK I might add support for it just for giggles.