Friday, 20 September 2013
basename basically not so basic
It appears that GNU has three kinds of basename.
They all do different things despite looking like the same thing, and usually it would make sense for something as basic as basename to be consistent. However, no such luck, and I ended up suitably confused, and asked a friend to clue me up. This is what he wrote:
"There are two different things called 'basename' here. There is 'locate --basename', and there is the GNU make function $(basename ...). They are both inspired by the command basename(1), which does yet a third conceptually similar thing (strip off the directory part and optionally a given suffix, if present), but other than that they have no connection to each other at all.
"Note that $(basename ...) is running the *GNU make function* 'basename': it is *not* doing the same thing that $(basename ...) would do in the shell and running the shell command 'basename'. If you wanted to do that in make, you'd use $(shell basename ...).
locate considers the basename of a file to be the last component of a filename. GNU make considers it to be *everything* in the filename before the first dot. When you consider their likely use cases, this makes sense: in make, you generally don't want to throw paths away when transforming names, because you're going to want to look those paths up again. If you wanted to strip pathnames too, you could say $(notdir $(basename ...))."
...so basically, basename is the same basic idea based on different bases.
In other, unrelated news, those who have managed to miss this video about 'Bohemian Gravity' below should watch it right now: