[PATCH] Generate/update a version.h header file.

Lubomir I. Ivanov neolit123 at gmail.com
Tue Feb 26 09:31:39 PST 2013


On 26 February 2013 19:24, Cristian Ionescu-Idbohrn
<cristian.ionescu-idbohrn at axis.com> wrote:
> This is dedicated to Lubomir ;)
>

thanks for that, i guess. ;)
and thanks for submitting, of course.

> Should work (tm).  Not sure though if you want target
> 'gen_version_file' as a pre-requisite to $(NAME) or some other target.
>
> Signed-off-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn at axis.com>
> ---
>  .gitignore |    1 +
>  Makefile   |   17 +++++++++++++++--
>  2 files changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/.gitignore b/.gitignore
> index ff447f7..50d668f 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -5,6 +5,7 @@
>  *.dmg
>  *.patch
>  *.xml
> +version.h
>  !dives/*.xml
>  *~
>  po/*.mo
> diff --git a/Makefile b/Makefile
> index a8e4d2f..9451855 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -25,6 +25,12 @@ DESKTOPFILE = $(NAME).desktop
>  MANFILES = $(NAME).1
>  XSLTFILES = xslt/*.xslt
>
> +VERSION_FILE = version.h
> +# There's only one line in $(VERSION_FILE); use the shell builtin `read'
> +STORED_VERSION_STRING = \
> +       $(subst ",,$(shell read ignore ignore v <$(VERSION_FILE) && echo $$v))
> +#" workaround editor syntax highlighting quirk
> +
>  UNAME := $(shell $(CC) -dumpmachine 2>&1 | grep -E -o "linux|darwin|win")
>  GET_VERSION = ./scripts/get-version
>  VERSION_STRING := $(shell $(GET_VERSION) linux || echo "v$(VERSION)")
> @@ -157,7 +163,13 @@ OBJS =     main.o dive.o time.o profile.o info.o equipment.o divelist.o deco.o plann
>

sorry, this a on a quick look....does it handle the "not in a git
repository" case (e.g. tarballs) ?
my attempt also handled the "no tags" case via "No names found" string check.

>  DEPS = $(wildcard .dep/*.dep)
>
> -$(NAME): $(OBJS) $(MSGOBJS) $(INFOPLIST)
> +gen_version_file:
> +ifneq ($(STORED_VERSION_STRING),$(VERSION_STRING))
> +       $(info updating $(VERSION_FILE) to $(VERSION_STRING))
> +       @echo \#define VERSION \"$(VERSION_STRING)\" >$(VERSION_FILE)
> +endif
> +
> +$(NAME): gen_version_file $(OBJS) $(MSGOBJS) $(INFOPLIST)
>         $(CC) $(LDFLAGS) -o $(NAME) $(OBJS) $(LIBS)
>
>  install: $(NAME)
> @@ -290,7 +302,8 @@ doc:
>         $(MAKE) -C Documentation doc
>
>  clean:
> -       rm -f $(OBJS) *~ $(NAME) $(NAME).exe po/*~ po/subsurface-new.pot
> +       rm -f $(OBJS) *~ $(NAME) $(NAME).exe po/*~ po/subsurface-new.pot \
> +               $(VERSION_FILE)
>         rm -rf share .dep

a potential problem at "clean".
we may want to keep the version file in case of tarball distributions,
so it should not be deleted, but simply overridden i'd think.
this way the tarball will come with a version that will not depend on
git and the Makefile should not change it.
or do i miss something here?

lubomir
--


More information about the subsurface mailing list