Test your make-fu (update Makefile to maintain a version.h file)

Lubomir I. Ivanov neolit123 at gmail.com
Tue Feb 26 02:58:25 PST 2013


On 26 February 2013 12:25, Cristian Ionescu-Idbohrn
<cristian.ionescu-idbohrn at axis.com> wrote:
> Trying to understand something that, for me, vanished from my world
> many, many moons ago :)
>
> On Tue, 26 Feb 2013, Lubomir I. Ivanov wrote:
>>
>
> So this is what needs to be done:
>
>> write a Makefile that reads a version.h file and compares that to a
>> "git describe" version.
>
> Now, do I understand you correctly?
> The reason for this Makefile montruosity is that a certain OS lacks a
> *nix shell but has access to make, grep, cat, cut?
>

well, i find no need to use an unix shell where it's not needed, but
also GNU Make works without it and same goes for tools like grep.
such software should not be bound to a shell.

the default Subsurface Makefile seems to depend on bash (or bash like
shells), so the addition discussed in this thread would probably
follow that as well.
my example (of make-fu written in 30minutes) is for something i will
use for my own needs for the native Windows build, were bash is also
available in fact. :-).

now the question is, can someone write the same functionality for the
default Makefile (which i don't use due to the oddities in my Windows
and Linux setups) in a prettier way?
i'm sure that answers most of the questions bellow with a few exceptions.

>> ------------------
>> other notes:
>
> Of course, make can use a whole arsenal of commands, but if possible
> avoid as much as possible and use primarily builtin make functions.
>
>> - uses only grep, cat, cut
>
> Now, this is hard to understand:
>
>> - this is a portable version, things like "if / fi" aren't portable
>               ^^^^^^^^
> Portable to what?  Never mind.  Don't answer that ;)  Do you have
> access to the `test' application in that odd build environment?
>

well test.c is trivial:

#include <stdio.h>
#include "version.h"

int main(void)
{
	puts(VERSION);
	return 0;
}

> I can't even imagine that the `make' I know of, "GNU Make", works
> without a proper *nix shell.  You could use the variable SHELL to
> point make to a another *nix shell, but AFAIU you don't have access to
> one?
>
>>   outside of bash/sh, but the current Makefile uses them anyway.
>     ^^^^^^^^^^^^^^^^^^
> And there's no such beast in your build environment ?
>
>> - runs on the windows native shell and on bash/sh with the msys toolchain.
>
> So why is the above exercise so important.  How difficult can it be to
> add a *nix shell to your build environment?
>

the idea of course here is to improve the Makefile, by adding the
"version.h" support in the best way possible.
i think you can ignore my "portability" comments (to a certain extent that is).

>> - seems to work with GNU Make 3.82
>
> Yes, it looks like it is (tested with GNU Make 3.81).
>
>

lubomir
--


More information about the subsurface mailing list