Files
2014-03-17 15:13:14 +00:00

71 lines
1.7 KiB
Python

# This script increases the build number and writes a linker script
# with the correct variables.
#
# usage:
# buildnr <buildno-file> <projectname>
#
# creates/updates
# <buildno-file>
# <buildno-file>.ld
#
# Include buildno-file.ld in your link process, i.e -T<buildno-file>.ld
#
# Best place to start the python script in your makefile, using the buildno
# file as a target and the object files as dependencies, e.g.
#
# $(BUILDNO_FILE) : $(C_OBJS) $(CPP_OBJS) $(S_OBJS)
# python buildnr.py $(BUILDNO_FILE) $(PROJECTNAME)
#
# Now the variables __buildNr_<porjectname> and __buildDate_<projectname>
# are available in your project.
#
# Define these variables as follows (for example):
#
# extern unsigned char __buildNr_MyProject;
# #define BUILD_NUMBER ( (unsigned int)(&__buildNr_MyProject) )
#
# extern unsigned char __buildDate_MyProject;
# #define BUILD_DATE ( (unsigned int)(&__buildDate_MyProject) )
#
# !Don't forget to have a version of Python 2 on your path!
#
# 2012/09/17, VvB.
import os,sys,time
buildfile = sys.argv[1]
project = sys.argv[2]
# increase build number
if not os.path.exists(buildfile):
open(buildfile, "w").write("0")
dateRev = 0
else:
dateRev = int(open(buildfile, "r").read(), 16)
nowDate = int(time.strftime("%y%m%d"), 16)
if nowDate == (dateRev >> 8):
rev = dateRev & 0xFF
dateRev = dateRev & 0xFFFFFF00
dateRev |= rev + 1
else:
dateRev = nowDate << 8
open(buildfile, "w").write("%08x" % dateRev)
# write linker script with info
info = {
"project" : project,
"dateRev" : dateRev
}
open("%s.ld" % buildfile, "w").write(\
"""/* Automagically generated, do not overwrite! */
__dateRev = 0x%(dateRev)08x;""" % info)