Browse Source

Add DTC release version information.

Adopted the version information and implementation
from of the Linux Kernel Makefiles.

Signed-off-by: Jon Loeliger <jdl@jdl.com>
main
Jon Loeliger 18 years ago
parent
commit
a657ce8fb7
  1. 67
      Makefile
  2. 9
      dtc.c
  3. 22
      scripts/setlocalversion

67
Makefile

@ -1,3 +1,49 @@ @@ -1,3 +1,49 @@
#
# Device Tree Compiler
#

#
# Version information will be constructed in this order:
# EXTRAVERSION might be "-rc", for example.
# LOCAL_VERSION is likely from command line.
# CONFIG_LOCALVERSION from some future config system.
#
VERSION = 1
PATCHLEVEL = 0
SUBLEVEL = 0
EXTRAVERSION =
LOCAL_VERSION =
CONFIG_LOCALVERSION =

DTC_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
VERSION_FILE = version_gen.h

CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
else if [ -x /bin/bash ]; then echo /bin/bash; \
else echo sh; fi ; fi)

nullstring :=
space := $(nullstring) # end of line

localver_config = $(subst $(space),, $(string) \
$(patsubst "%",%,$(CONFIG_LOCALVERSION)))

localver_cmd = $(subst $(space),, $(string) \
$(patsubst "%",%,$(LOCALVERSION)))

localver_scm = $(shell $(CONFIG_SHELL) ./scripts/setlocalversion)
localver_full = $(localver_config)$(localver_cmd)$(localver_scm)

dtc_version = $(DTC_VERSION)$(localver_full)

#
# Contents of the generated version file.
#
define filechk_version
(echo "#define DTC_VERSION \"DTC $(dtc_version)\""; )
endef


CPPFLAGS = -I libfdt
CFLAGS = -Wall -g
LDFLAGS = -Llibfdt
@ -28,11 +74,14 @@ endif @@ -28,11 +74,14 @@ endif

all: dtc ftdump libfdt tests


STD_CLEANFILES = *~ *.o *.d *.a *.i *.s core a.out
GEN_CLEANFILES = $(VERSION_FILE)

clean: libfdt_clean tests_clean
@$(VECHO) CLEAN
rm -f $(STD_CLEANFILES)
rm -f $(GEN_CLEANFILES)
rm -f *.tab.[ch] lex.yy.c *.output vgcore.*
rm -f $(BIN)

@ -82,6 +131,9 @@ dtc-parser.tab.c dtc-parser.tab.h dtc-parser.output: dtc-parser.y @@ -82,6 +131,9 @@ dtc-parser.tab.c dtc-parser.tab.h dtc-parser.output: dtc-parser.y
@$(VECHO) ---- Expect 2 s/r and 2 r/r. ----
$(BISON) -d $<

$(VERSION_FILE): Makefile FORCE
$(call filechk,version)

lex.yy.c: dtc-lexer.l
@$(VECHO) LEX $@
$(LEX) $<
@ -123,3 +175,18 @@ install: dtc ftdump @@ -123,3 +175,18 @@ install: dtc ftdump
$(INSTALL) -d $(DESTDIR)$(BINDIR)
$(INSTALL) -m 755 dtc $(DESTDIR)$(BINDIR)
$(INSTALL) -m 755 ftdump $(DESTDIR)$(BINDIR)

define filechk
set -e; \
echo ' CHK $@'; \
mkdir -p $(dir $@); \
$(filechk_$(1)) < $< > $@.tmp; \
if [ -r $@ ] && cmp -s $@ $@.tmp; then \
rm -f $@.tmp; \
else \
echo ' UPD $@'; \
mv -f $@.tmp $@; \
fi;
endef

FORCE:

9
dtc.c

@ -21,6 +21,8 @@ @@ -21,6 +21,8 @@
#include "dtc.h"
#include "srcpos.h"

#include "version_gen.h"

/*
* Command line options
*/
@ -99,6 +101,8 @@ static void usage(void) @@ -99,6 +101,8 @@ static void usage(void)
fprintf(stderr, "\t\tSet the physical boot cpu\n");
fprintf(stderr, "\t-f\n");
fprintf(stderr, "\t\tForce - try to produce output even if the input tree has errors\n");
fprintf(stderr, "\t-v\n");
fprintf(stderr, "\t\tPrint DTC version and exit\n");
exit(2);
}

@ -120,7 +124,7 @@ int main(int argc, char *argv[]) @@ -120,7 +124,7 @@ int main(int argc, char *argv[])
reservenum = 0;
minsize = 0;

while ((opt = getopt(argc, argv, "hI:O:o:V:R:S:fqb:")) != EOF) {
while ((opt = getopt(argc, argv, "hI:O:o:V:R:S:fqb:v")) != EOF) {
switch (opt) {
case 'I':
inform = optarg;
@ -149,6 +153,9 @@ int main(int argc, char *argv[]) @@ -149,6 +153,9 @@ int main(int argc, char *argv[])
case 'b':
boot_cpuid_phys = strtol(optarg, NULL, 0);
break;
case 'v':
printf("Version: %s\n", DTC_VERSION);
exit(0);
case 'h':
default:
usage();

22
scripts/setlocalversion

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
#!/bin/sh
# Print additional version information for non-release trees.

usage() {
echo "Usage: $0 [srctree]" >&2
exit 1
}

cd "${1:-.}" || usage

# Check for git and a git repo.
if head=`git rev-parse --verify HEAD 2>/dev/null`; then
# Do we have an untagged version?
if git name-rev --tags HEAD | grep -E '^HEAD[[:space:]]+(.*~[0-9]*|undefined)$' > /dev/null; then
printf '%s%s' -g `echo "$head" | cut -c1-8`
fi

# Are there uncommitted changes?
if git diff-index HEAD | read dummy; then
printf '%s' -dirty
fi
fi
Loading…
Cancel
Save