Any qmake experts out there?
Jef Driesen
jef at libdivecomputer.org
Thu Jan 29 06:20:24 PST 2015
On 2015-01-29 14:38, Thiago Macieira wrote:
> On Thursday 29 January 2015 15:30:43 Lubomir I. Ivanov wrote:
>> this is what i would do:
>> -----------------
>>
>> all: main.exe
>>
>> .PHONY: persist
>>
>> version.h: persist
>> cat $@ 2> /dev/null || git rev-parse HEAD > $@
>> git rev-parse HEAD > $@.tmp
>> git diff --quiet $@ $@.tmp || cp $@.tmp $@
>> rm -f $@.tmp
>>
>> main.o: main.c version.h
>> gcc -c main.c -o main.o
>>
>> main.exe: main.o
>> gcc main.o -o main.exe
>>
>> -------------------
>>
>> what it does is, it writes the output of "git rev-parse" to a TMP file
>> and if that TMP file differs to the previous version.h file it updates
>> version.h
>> but since version.h may not change, main is not recompiled.
>
> The way I read this, persist is phony, so it will always be found to be
> out-
> of-date. Therefore, version.h is always out of date, so is main.o and
> therefore main.exe will too.
>
> Are you saying that if the version.h command doesn't actually touch
> version.h,
> then Make does not find it to be out of date?
For libdivecomputer, I use a very similar construct:
FORCE:
$(top_srcdir)/revision: FORCE
@if (test -d $(top_srcdir)/.git && cd $(top_srcdir) \
&& git rev-parse --verify HEAD) > revision-t 2>/dev/null \
&& ! cmp -s revision-t $@; then \
mv -f revision-t $@; \
else \
rm -f revision-t; \
if ! test -f $@; then touch $@; fi; \
fi
revision.h: $(top_srcdir)/revision Makefile.am
$(AM_V_GEN) echo "#define DC_VERSION_REVISION \""`cat
$(top_srcdir)/revision`"\"" > $@
BUILT_SOURCES = revision.h
EXTRA_DIST = $(top_srcdir)/revision
CLEANFILES = revision.h revision-t
The main difference is that the "revision" file is also included in the
tarballs. That way, the build (including the git based version string)
still works if you're building from a tarball. This systems works very
well for me. It only re-builds when the version changes. Exactly what I
needed.
(I asked the the automake guys for advice on this stuff a few years ago,
and the above system is what they suggested.)
Jef
More information about the subsurface
mailing list