14 April 2020: To read the solution to this riddle click here.

GNU Make Easter egg? What? Well I don't know what else to call it so it'll do. Every so often I come across something interesting or amusing that I never have noticed before nor indeed would I have ever expected. Earlier today this happened with GNU Make (I've not confirmed it with any other implementation of `make'). It's very simple but to give a demonstration I need to present three Makefiles. Actually maybe macOS 'make' isn't GNU and it does the same thing there; under Fedora it happens (GNU make) and under CentOS (which is writing platform) also (naturally is also GNU make).

What happens if a Makefile has no target at all? Let's say it's blank. You might see this:

make: *** No targets.  Stop.

But then what about an empty target? Say say:

default:

You might get a message like:

make: Nothing to be done for `default'.

On some systems that was it. On others it was as if I had that Makefile but a line break after it (so two lines):

default:

That would then create a mysterious file called .Makefile.un~. Now what on Earth is that about? I honestly do not know but here are some curious facts about it.

First of all the type according to the file(1) command:

.Makefile.un~: data

Second is if I open it in vim I see at the beginning the string 'Vim'. Then there's a non-printable byte and then the text UnDoƄ followed by more unprintable bytes and then the next text that's somewhat sensible is default:5. Finally running strings(1) on it shows:

UnDo
hd6.
default:5

Note that if other valid Makefile content is in the Makefile, say CFLAGS, that's also embedded in this data file. But hang on a moment. What happened to the string 'Vim'? That's a really curious question and one I do not know the answer to! In fact opening it in another editor that I installed temporarily (i.e. nano) it still has the string 'Vim'. Furthermore opening it in a hex editor also has it and it includes the same bytes that `od` does too! I cannot explain this but I find it incredibly curious and I thought it worth sharing.

Feel free to download the data file here. I don't know if it'll be saved correctly but either way it's a mystery to me.

The solution to the riddle

Since I wrote about this riddle the other day I have at times seen similar data files but that which aren't Makefiles. I wondered about this but nothing came to mind until a short bit ago when I was working on some code and used in vim 'u' (undo): instead of it being at the last change (since I had only reopened the file) it went back to changes from yesterday. I remembered then. Not long before I had added to my .vimrc file:

set undofile                    " persistent undo even if vim is closed

Of course. That's why the string 'Vim' was in it. What clued me in however was when I saw that option was the 'un' part of the string: first two letters of 'undo'! Commenting that option out and trying this again and the file is not generated in the way I had done. But there's still one part left unsolved:

Why is it that it wasn't created until I ran `make'? More than that why would that command add 'Vim' to it if it wasn't even being edited by Vim at the time? I actually do not have an answer to those questions and I might not have it ever because I have decided that although this option is useful at times it's not useful all the time: in fact it's problematic so I have disabled it.