diff --git a/.gitignore b/.gitignore index 0e89c7d..75952f2 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ tests/*/*.elf TAGS litedram/build/* obj_dir/* +git.vhdl diff --git a/Makefile b/Makefile index 097bf3e..2d43332 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,9 @@ core_files = decode_types.vhdl common.vhdl wishbone_types.vhdl fetch1.vhdl \ loadstore1.vhdl mmu.vhdl dcache.vhdl writeback.vhdl core_debug.vhdl \ core.vhdl +git.vhdl: git.vhdl.in + ./make_version.sh $@ + soc_files = $(core_files) wishbone_arbiter.vhdl wishbone_bram_wrapper.vhdl sync_fifo.vhdl \ wishbone_debug_master.vhdl xics.vhdl syscon.vhdl soc.vhdl \ spi_rxtx.vhdl spi_flash_ctrl.vhdl git.vhdl @@ -272,5 +275,5 @@ distclean: _clean make -f scripts/mw_debug/Makefile distclean make -f hello_world/Makefile distclean -.PHONY: all prog check check_light clean distclean +.PHONY: all prog check check_light clean distclean git.vhdl .PRECIOUS: microwatt.json microwatt_out.config microwatt.bit diff --git a/git.vhdl b/git.vhdl deleted file mode 100644 index 7b2d520..0000000 --- a/git.vhdl +++ /dev/null @@ -1,9 +0,0 @@ -library ieee; -use ieee.std_logic_1164.all; - -library work; - -package git is - constant GIT_HASH : std_ulogic_vector(27 downto 0) := x"1234567"; - constant GIT_DIRTY : std_ulogic := '0'; -end git; diff --git a/git.vhdl.in b/git.vhdl.in new file mode 100644 index 0000000..3ca2174 --- /dev/null +++ b/git.vhdl.in @@ -0,0 +1,9 @@ +library ieee; +use ieee.std_logic_1164.all; + +library work; + +package git is + constant GIT_HASH : std_ulogic_vector(27 downto 0) := x"@hash@"; + constant GIT_DIRTY : std_ulogic := '@dirty@'; +end git; diff --git a/make_version.sh b/make_version.sh new file mode 100755 index 0000000..9569221 --- /dev/null +++ b/make_version.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +dirty="0" + +usage() { + echo "$0 " + echo -e "\tSubstitute @hash@ and @dirty@ in with gathered values." +} + +if [ "$1" = "-h" -o "$1" = "--help" ] ; +then + usage + exit 1; +fi +if [ -z $1 ] ; +then + usage + exit 1; +fi + +src=$1 + +if test -e .git || git rev-parse --is-inside-work-tree > /dev/null 2>&1; +then + version=$(git describe --exact-match 2>/dev/null) + if [ -z "$version" ]; + then + version=$(git describe 2>/dev/null) + fi + if [ -z "$version" ]; + then + version=$(git rev-parse --verify --short HEAD 2>/dev/null) + fi + if git diff-index --name-only HEAD |grep -qv '.git'; + then + dirty="1" + fi + echo "hash=$version dirty=$dirty" + sed -e "s/@hash@/$version/" -e "s/@dirty@/$dirty/" ${src}.in > ${src} +fi