This implementation is not nearly pure GNU Make enough for me. :)
Here’s one that is pure Make. Some of it is cribbed from The GNU Make Book and not all the definitions are necessary. Numbers are represented by a list of xs. So 5 would be the string x x x x x.
It counts down from 100 instead of up. I don’t really care.
This implementation is not nearly pure GNU Make enough for me. :)
That’s the spirit :-) I saw a blog post about doing this kind of arithmetic in make but didn’t want to go this far down the rabbit hole. I’m glad you did though.
make‘s default shell is /bin/sh. It’s true that seq is not part of POSIX, but I tried this Makefile on macOS, NixOS, Arch Linux, and OpenBSD (you obviously need to pkg_add gmake) and it worked on all of them. It also works when explicitly setting the shell to Bash, ZSH, or OpenBSD’s kush. It did NOT work with Fish, though not because of seq (which is supported) but because the POSIX-style arithmetic is not supported. That’s portable enough for me but YMMV.
I’ve been trying to think if this is doable in POSIX make, as underpowered as that is… sadly my make-fu is not strong enough. I don’t think it has those good functions in it.
This implementation is not nearly pure GNU Make enough for me. :)
Here’s one that is pure Make. Some of it is cribbed from The GNU Make Book and not all the definitions are necessary. Numbers are represented by a list of
x
s. So 5 would be the stringx x x x x
.It counts down from 100 instead of up. I don’t really care.
That’s the spirit :-) I saw a blog post about doing this kind of arithmetic in
make
but didn’t want to go this far down the rabbit hole. I’m glad you did though.Comments and articles like these are why I love lobste.rs :D
Wow. Some things people were not meant to know.
This note implies GNU make is Turing complete.
https://okmij.org/ftp/Computation/#Makefile-functional
It relies on a specific and nonportable shell builtin.
make
‘s default shell is/bin/sh
. It’s true thatseq
is not part of POSIX, but I tried thisMakefile
on macOS, NixOS, Arch Linux, and OpenBSD (you obviously need topkg_add gmake
) and it worked on all of them. It also works when explicitly setting the shell to Bash, ZSH, or OpenBSD’s kush. It did NOT work with Fish, though not because ofseq
(which is supported) but because the POSIX-style arithmetic is not supported. That’s portable enough for me but YMMV.I’ve been trying to think if this is doable in POSIX make, as underpowered as that is… sadly my make-fu is not strong enough. I don’t think it has those good functions in it.
Much more interesting than FizzBuzz: https://nullprogram.com/blog/2016/04/30/
omg incredible. so it can be done!