WR for developers
This page is a collection of pointers to various tips, good practices, guidelines which should be applied when developing SW/GW/HW for White Rabbit components and using repositories of WR project.
- Using GIT in WR
- HDLmake
- fmc-bus:Release-howto (for kernel drivers)
- VHDL Coding Recommendation
- Project Specific:
Git version in a binary
The best way to obtain git version is use the following command:
git describe --always --dirty=+
Git version in a makefile
In a Makefile you have various solution to add git version.
1. Passing variable at compilation
The easiest one is to create a variable by doing the following at the top of the Makefile
PROJNAME = wr-switch-sw
GIT_VER = $(shell git describe --always --dirty=+ | sed 's;^$(PROJNAME)-;;')
GIT_USR = $(shell git config --get-all user.name)
and then add some defines while creating your binary:
shw_ver.o: shw_ver.c
${CC} ${CFLAGS} -D__GIT_USR__="\"${GIT_USR}\"" -D__GIT_VER__="\"${GIT_VER}\"" $(LDFLAGS) -c -o $@ $^
Finaly in the code you just need to use the DEFINEs such as:
printf("Version: %s (by %s the %s @ %s) \n",GIT_VER,GIT_USR,DATE,TIME);
2. Creating a version file.
You will need to add a dependency to create the file, and a the version.c file to your list of dependency
...
all: $(OBJS) version.o
${CC} -o $(OUTPUT) $(OBJS)
version.c: ../.git/HEAD ../.git/index
echo "/**" > $@
echo " * File automatically generated by Makefile (DO NOT MODIFIED)\n *\n * To use this you in a c code just add the following lines:\n * " >> $@
echo "\textern const char build_time[];\n\textern const char git_user[];\n\textren const char git_revision[];\n * " >> $@
echo "**/" >> $@
echo 'const char build_time[] = __DATE__ " @ " __TIME__ ;' >> $@
echo "const char git_user[] = \"$(shell git config --get user.name)\";" >> $@
echo "const char git_revision[] = \"$(shell git describe --always --dirty=+)\";" >> $@
echo "" >> $@
...
This solution is better at compilation level (git version is only reload when there is a change), but it is more complex.